Click here to Skip to main content
15,905,427 members
Home / Discussions / C#
   

C#

 
AnswerRe: Refreshing data on a parent form at child close Pin
OriginalGriff21-Apr-20 21:44
mveOriginalGriff21-Apr-20 21:44 
GeneralRe: Refreshing data on a parent form at child close Pin
Uranium-23521-Apr-20 22:48
Uranium-23521-Apr-20 22:48 
GeneralRe: Refreshing data on a parent form at child close Pin
OriginalGriff21-Apr-20 23:04
mveOriginalGriff21-Apr-20 23:04 
GeneralRe: Refreshing data on a parent form at child close Pin
Uranium-23522-Apr-20 23:27
Uranium-23522-Apr-20 23:27 
GeneralRe: Refreshing data on a parent form at child close Pin
OriginalGriff23-Apr-20 0:09
mveOriginalGriff23-Apr-20 0:09 
GeneralRe: Refreshing data on a parent form at child close Pin
Uranium-23523-Apr-20 10:46
Uranium-23523-Apr-20 10:46 
GeneralRe: Refreshing data on a parent form at child close Pin
OriginalGriff23-Apr-20 11:06
mveOriginalGriff23-Apr-20 11:06 
GeneralRe: Refreshing data on a parent form at child close Pin
Uranium-23524-Apr-20 17:53
Uranium-23524-Apr-20 17:53 
GeneralRe: Refreshing data on a parent form at child close Pin
OriginalGriff24-Apr-20 20:08
mveOriginalGriff24-Apr-20 20:08 
GeneralRe: Refreshing data on a parent form at child close Pin
Uranium-23525-Apr-20 19:42
Uranium-23525-Apr-20 19:42 
AnswerRe: Refreshing data on a parent form at child close Pin
#realJSOP22-Apr-20 7:15
professional#realJSOP22-Apr-20 7:15 
QuestionMaintain the Runing balance in Datagridview Pin
Mukhtar Ashiq21-Apr-20 9:04
Mukhtar Ashiq21-Apr-20 9:04 
SuggestionRe: Maintain the Runing balance in Datagridview Pin
Richard MacCutchan21-Apr-20 9:15
mveRichard MacCutchan21-Apr-20 9:15 
AnswerRe: Maintain the Runing balance in Datagridview Pin
ZurdoDev21-Apr-20 9:51
professionalZurdoDev21-Apr-20 9:51 
Questionextending an Enum with a function that returns a generic value ? Pin
BillWoodruff20-Apr-20 8:58
professionalBillWoodruff20-Apr-20 8:58 
AnswerRe: extending an Enum with a function that returns a generic value ? Pin
Richard Deeming20-Apr-20 9:34
mveRichard Deeming20-Apr-20 9:34 
GeneralRe: extending an Enum with a function that returns a generic value ? Pin
BillWoodruff20-Apr-20 11:56
professionalBillWoodruff20-Apr-20 11:56 
GeneralRe: extending an Enum with a function that returns a generic value ? Pin
BillWoodruff20-Apr-20 22:10
professionalBillWoodruff20-Apr-20 22:10 
GeneralRe: extending an Enum with a function that returns a generic value ? Pin
Richard Deeming21-Apr-20 0:01
mveRichard Deeming21-Apr-20 0:01 
GeneralRe: extending an Enum with a function that returns a generic value ? Pin
BillWoodruff21-Apr-20 4:30
professionalBillWoodruff21-Apr-20 4:30 
food for thought, thanks ! @RichardDeeming

today, i considered what it would mean to write a factory method to return a hard-coded converter ... what i came up with is rather monstrous Smile | :) but it works:
// sample call
var econverter = WeekDays.Default.MakeConverter<WeekDays>();

WeekDays wkd = econverter("monday", false);
can't say i see enduring value for such elaboration to achieve a limited result. i added a "Default" value to the Enum:
public static Func<string, bool, TEnum> MakeConverter<TEnum>(this Enum tenum)
    where TEnum : struct, IConvertible
{ 
    Type returntype = typeof(TEnum);

    if (!returntype.IsEnum)
        throw new ArgumentException("Return type must be an Enum type");

    Type argtype = tenum.GetType();

    if (! argtype.IsEnum)
        throw new ArgumentException("Type parameter must be an Enum type");

    if (argtype != returntype)
        throw new ArgumentException("Type and Return type must be the same");

    Func<string, bool, TEnum> xFunc = null;

    try
    {
        xFunc = (string str, bool ignorecase) =>
        {
            TEnum result;

            // note ignore case parameter
            if (Enum.TryParse<TEnum>(str, ignorecase, out result))
            {
                return result;
            }

            throw new ArgumentException(
                $"{str} is not a valid string for conversion to {typeof(TEnum).FullName}");
        };
    }
    catch (Exception ex)
    {
        throw new TypeInitializationException(typeof(TEnum).FullName, ex.InnerException);
    }

    return xFunc;
}

«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

GeneralRe: extending an Enum with a function that returns a generic value ? Pin
Richard Deeming21-Apr-20 5:17
mveRichard Deeming21-Apr-20 5:17 
GeneralRe: extending an Enum with a function that returns a generic value ? Pin
BillWoodruff21-Apr-20 8:29
professionalBillWoodruff21-Apr-20 8:29 
AnswerRe: extending an Enum with a function that returns a generic value ? Pin
Matthew Dennis21-Apr-20 5:36
sysadminMatthew Dennis21-Apr-20 5:36 
GeneralRe: extending an Enum with a function that returns a generic value ? Pin
BillWoodruff21-Apr-20 8:27
professionalBillWoodruff21-Apr-20 8:27 
GeneralRe: extending an Enum with a function that returns a generic value ? Pin
Richard Deeming21-Apr-20 8:37
mveRichard Deeming21-Apr-20 8:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.