Exemple #1
0
        public FieldDescriptor(FieldInfo fieldInfo)
        {
            _field     = fieldInfo;
            Type       = _field.FieldType;
            IsNullable = Type.IsNullable();

            if (IsNullable)
            {
                Type = Nullable.GetUnderlyingType(Type);
            }

            DefaultValue = ClassType.GetDefaultValue(_field);
        }
Exemple #2
0
        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);
        }