public FieldDescriptor(FieldInfo fieldInfo) { _field = fieldInfo; Type = _field.FieldType; IsNullable = Type.IsNullable(); if (IsNullable) { Type = Nullable.GetUnderlyingType(Type); } DefaultValue = ClassType.GetDefaultValue(_field); }
public PropertyDescriptor(PropertyInfo property) { var type = property.PropertyType; _property = property; Name = property.Name; Type = type; IsNullable = type.IsNullable(); if (IsNullable) { Type = Nullable.GetUnderlyingType(type); } // Check if the property is marked as read-only. var canWrite = property.CanWrite; var readOnlyAttr = Attribute.GetCustomAttribute(_property, typeof(ReadOnlyAttribute)); var isReadOnlyFromAttr = readOnlyAttr is ReadOnlyAttribute attribute && attribute.IsReadOnly; IsReadonly = !canWrite || isReadOnlyFromAttr; DefaultValue = ClassType.GetDefaultValue(_property); }