public static SQLPropertyInfo FromPropertyInfo(PropertyInfo pi, SQLTypeInfo TypeInfo) { //If it's SQL ignored, just return null if (pi.GetFirstAttribute<SQLIgnoredFieldAttribute>() != null) { return null; } SQLPropertyInfo myResult = new SQLPropertyInfo(pi, TypeInfo); //Mark as read only now, if applicable myResult.ReadOnly = (pi.GetFirstAttribute<SQLReadOnlyFieldAttribute>() != null); myResult.KeyField = pi.GetFirstAttribute<SQLKeyFieldAttribute>(); //Set the default mappings for standard properties SQLFieldAttribute FieldAttribute = pi.GetFirstAttribute<SQLFieldAttribute>(); //Set the primary field name based on the field attribute if specified, or the property name itself if not myResult.DatabaseFieldName = (FieldAttribute == null ? myResult.PropertyInfo.Name : FieldAttribute.FieldName); //If the database field is a function of any kind it has to be read-only if (myResult.DatabaseFieldName.Contains('(')) { myResult.ReadOnly = true; } else { //It should be an updatable property (unless flagged as read only by the user); //The update from property is always this property's name myResult.UpdateFromProperty = pi.Name; } return myResult; }
//Private constructor so this class can't be created by outside object private SQLPropertyInfo(PropertyInfo pi, SQLTypeInfo TypeInfo) { this.PropertyInfo = pi; this.TypeInfo = TypeInfo; InitializeGet(); InitializeSet(); }