private static CustomPropertyModel Parse(PropertyInfo prop, CustomPropertyModel propResult) { if (propResult.PropertyType.GenericTypeArguments.Any()) { propResult.PropertyType = prop.PropertyType.GenericTypeArguments[0]; propResult.PropertyIsNullable = true; if (propResult.PropertyType.BaseType != null && "System.Enum".Equals(propResult.PropertyType.BaseType.FullName)) { propResult.PropertyIsEnum = true; propResult.PropertyTypeName = CustomPropertyModel.PropertyTypeData.Enum; } } else { if (propResult.PropertyType.BaseType != null && "System.Enum".Equals(propResult.PropertyType.BaseType.FullName)) { propResult.PropertyIsEnum = true; propResult.PropertyTypeName = CustomPropertyModel.PropertyTypeData.Enum; } } if (propResult.PropertyIsEnum) { propResult.PropertyIsEnumFlag = propResult.PropertyType.GetCustomAttribute(typeof(FlagsAttribute)) != null; } else { CustomPropertyModel.PropertyTypeData propTypeName; Enum.TryParse(propResult.PropertyType.Name, out propTypeName); propResult.PropertyTypeName = propTypeName; } return(propResult); }
/// <summary> /// Obtiene la información extendida de una propiedad de cualquier tipo de objeto /// </summary> /// <param name="prop"></param> /// <returns></returns> public static CustomPropertyModel GetAllInfo(this PropertyInfo prop) { var propResult = new CustomPropertyModel { PropertyIsEnum = false, PropertyIsEnumFlag = false, PropertyIsNullable = false, PropertyName = prop.Name, PropertyValue = null, PropertyType = prop.PropertyType, PropertyTypeName = CustomPropertyModel.PropertyTypeData.Others }; return(Parse(prop, propResult)); }