public void InterfaceNamesTest() { // Option 1 - Not strongly typed string nameA = typeof(IConvertible).GetMethod("ToBoolean").Name; Console.WriteLine(nameA); // OUTPUT: ToBoolean string nameB = typeof(Lazy <object>).GetProperty("IsValueCreated").Name; Console.WriteLine(nameB); // OUTPUT: ToBoolean // Option 2 - Strongly typed!! Console.WriteLine(); Console.WriteLine("Option 2 - Strongly typed way:"); IConvertible @interface = InterfaceNames <IConvertible> .Create(); Func <IFormatProvider, bool> func = @interface.ToBoolean; string name1 = func.Method.Name; Console.WriteLine(name1); // OUTPUT: ToBoolean string propName = InterfaceNames <Lazy <object> > .GetPropertyName(i => i.IsValueCreated); Console.WriteLine(propName); // OUTPUT: IsValueCreated //OR string propName2 = LazyHelper.GetPropertyName(i => i.IsValueCreated); Console.WriteLine(propName2); // OUTPUT: IsValueCreated // Other options results with complex/unclear code. }
public void InterfaceNamesTest() { // Option 1 - Not strongly typed string name = typeof(IRequest).GetMethod("GetProfiles").Name; Console.WriteLine(name); // OUTPUT: GetProfiles // Option 2 - Strongly typed!! var @interface = InterfaceNames <IRequest> .Create(); Func <List <object> > func = @interface.GetProfiles; var name1 = func.Method.Name; Console.WriteLine(name1); // OUTPUT: GetProfiles Action <object> action = @interface.SetProfile; var name2 = action.Method.Name; Console.WriteLine(name2); // OUTPUT: SetProfile // Other options results with complex/unclear code. }