public FieldInfo(FieldAttribute fieldAttribute, PropertyAccessor propertyAccessor) { Property = propertyAccessor ?? throw new ArgumentNullException("propertyAccessor"); if (fieldAttribute != null) { var alias = fieldAttribute.Alias; if (string.IsNullOrEmpty(alias) == false) { Alias = alias; var expression = fieldAttribute.SQLExpression; if (string.IsNullOrEmpty(expression)) { throw new InvalidOperationException("If Field Alias is set SQLExpression must be set too"); } SQLExpression = expression; PersistanceFlags = PersistanceFlags.Never; } else { Name = fieldAttribute.Name ?? propertyAccessor.Name; PersistanceFlags = fieldAttribute.PersistanceFlags; } if (fieldAttribute is PrimaryKeyFieldAttribute pkFieldAttr) { IsKeyField = true; } if (fieldAttribute is InfrastructureFieldAttribute iAttr) { DefaultValueProvider = iAttr.DefaultValueProvider; } } else { Name = propertyAccessor.Name; } }
protected void AddPropertyAccessor(PropertyAccessor prop) { if (this.Properties.ContainsKey(prop.Name) == false) { this.Properties.Add(prop.Name, prop); } else { Debug.WriteLine("Property hidden:" + prop.ToString()); //Debug.Fail("property already registered: " + accessor.Name); } }
protected void RegesterProperty(PropertyInfo property, bool isPublic) { var accessor = new PropertyAccessor(property); AddPropertyAccessor(accessor); var attr = Attribute.GetCustomAttribute(property, typeof(BaseFieldAttribute)) as BaseFieldAttribute; if(attr == null) { return; } attr.Property = accessor; var fieldAttr = attr as FieldAttribute; if (fieldAttr != null) { if (string.IsNullOrEmpty(fieldAttr.SourceName)) { fieldAttr.SourceName = this.SourceName; } try { Fields.AddField(fieldAttr); } catch (Exception e) { throw new ORMException("Unable to register property: " + property.Name, e); } } }
public FieldInfo(PropertyAccessor propertyAccessor) : this((FieldAttribute)null, propertyAccessor) { }