parameterinfo

One method to read parameters, properties and return types at runtime using C#

 ̄綄美尐妖づ 提交于 2020-01-17 06:55:56
问题 With continutation to my earlier thread Using reflection read properties of an object containing array of another object. I am hoping to make this wonderful method from EvgK a generic method that can be used in multiple places in my code base. public static void GetMyProperties(object obj) { List<MyPropertyInfo> oMyProp = new List<MyPropertyInfo>(); foreach (PropertyInfo pinfo in obj.GetType().GetProperties()) { if (!Helper.IsCustomType(pinfo.PropertyType)) { //add properties - name, value,

One method to read parameters, properties and return types at runtime using C#

耗尽温柔 提交于 2020-01-17 06:55:15
问题 With continutation to my earlier thread Using reflection read properties of an object containing array of another object. I am hoping to make this wonderful method from EvgK a generic method that can be used in multiple places in my code base. public static void GetMyProperties(object obj) { List<MyPropertyInfo> oMyProp = new List<MyPropertyInfo>(); foreach (PropertyInfo pinfo in obj.GetType().GetProperties()) { if (!Helper.IsCustomType(pinfo.PropertyType)) { //add properties - name, value,

How to determine if ParameterInfo is of generic type?

孤人 提交于 2019-12-18 05:56:20
问题 I have a MethodInfo of a GenericMethodDefinition. Such as: CallMethod<T>(T arg, string arg2) . The GetParameters() method will give me two ParameterInfo objects, the first of which is generic, the second of which is not. How can I get ParameterInfo to tell me it is generic? What about if it has constraints? 回答1: Check ParameterType.IsGenericParameter . You may also want to check ContainsGenericParameters , which will be true for something like MyMethod<T>(List<T> param) . (Even though List<>

How to determine if ParameterInfo is of generic type?

偶尔善良 提交于 2019-11-29 10:25:41
I have a MethodInfo of a GenericMethodDefinition. Such as: CallMethod<T>(T arg, string arg2) . The GetParameters() method will give me two ParameterInfo objects, the first of which is generic, the second of which is not. How can I get ParameterInfo to tell me it is generic? What about if it has constraints? Check ParameterType.IsGenericParameter . You may also want to check ContainsGenericParameters , which will be true for something like MyMethod<T>(List<T> param) . (Even though List<> isn't a generic parameter) If IsGenericParameter is true, you can also call GetGenericParameterConstraints()