/// <summary> /// Get attribute data /// </summary> /// <param name="member"></param> /// <param name="attributes"></param> /// <param name="field"></param> protected override void GetPropertyMetadata(MemberInfo member, object[] attributes, IQObjectMapper.Impl.DelegateInfo fieldTemp) { base.GetPropertyMetadata(member, attributes, fieldTemp); bool ignore = false; string name = member.Name; bool alreadyMapped = TempDelegateInfo.ContainsKey(name); IDelegateInfo field = (IDelegateInfo)fieldTemp; foreach (var attr in attributes) { if (attr is IQIgnore) { if (alreadyMapped) { throw new InvalidOperationException("The field '" + name + "' is marked for ignore, but has been identified in a constructor already."); } ignore = true; break; } if (attr is IQPrimaryKey) { field.IsPrimaryKey = true; } IQField fldAttr = null; if (attr is IQField) { fieldTemp.Include = true; fldAttr = (IQField)attr; } string sqlName = field.SqlName; if (fldAttr != null) { if (!String.IsNullOrEmpty(fldAttr.SqlName)) { sqlName = fldAttr.SqlName; } if (fldAttr.PrimaryKey) { field.IsPrimaryKey = true; } if (fldAttr.IgnoreNull) { field.IgnoreNull = true; } if (fldAttr.ReadOnly) { field.IsSqlReadOnly = true; } } field.SqlName = sqlName; } if (ignore) { field.Include = false; } }
private void GetClassPropertiesMethods() { // It's a regular object. It cannot be extended, but set any same-named properties. IEnumerable <MemberInfo> members = ClassType .GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); //List<Field> tempList = new List<Field>(); bool hasMap = fieldIndexMap.Count > 0; foreach (var member in members) { if (member is PropertyInfo) { PropertyInfo prop = (PropertyInfo)member; // Skip properties that don't have both read and write methods, and ones with no public get. if (!prop.CanWrite || !prop.CanRead || !Utils.IsMappableType(prop.PropertyType)) { continue; } Field fldTemp; string nameLower = prop.Name.ToLower(); bool alreadyMapped = true; // Use the fieldmap info if it exists already as a starting point - but override with any attribute data if (!temporaryFieldInfo.TryGetValue(nameLower, out fldTemp)) { fldTemp = new Field(); alreadyMapped = false; } // Always update name from property, even if field was already mapped from constructor fldTemp.Name = prop.Name; fldTemp.PropInfo = prop; fldTemp.HasPublicGetter = prop.GetGetMethod() != null; object[] attributes = (object[])member.GetCustomAttributes(true); bool ignore = false; //bool nullable = false; foreach (var attr in attributes) { if (attr is IQIgnore) { if (alreadyMapped) { throw new Exception("The field '" + nameLower + "' is marked for ignore, but has been identified in a constructor alread."); } ignore = true; break; } if (attr is IQPrimaryKey) { fldTemp.PK = true; } IQField fldAttr = null; if (attr is IQField) { fldTemp.FieldAttr = true; fldAttr = (IQField)attr; } string sqlName = fldTemp.SqlName; if (fldAttr != null) { if (!String.IsNullOrEmpty(fldAttr.SqlName)) { sqlName = fldAttr.SqlName; } if (fldAttr.PK) { fldTemp.PK = true; } if (fldAttr.IgnoreNull) { fldTemp.IgnoreNull = true; } //if (fldAttr.IsNullable) //{ // fldTemp.IsNullable = true; //} if (fldAttr.ReadOnly) { fldTemp.ReadOnly = true; } } fldTemp.SqlName = sqlName; } if (!ignore) { temporaryFieldInfo[nameLower] = fldTemp; } } else if (member is MethodInfo) { MethodInfo method = (MethodInfo)member; object[] attributes = (object[])member.GetCustomAttributes(true); foreach (var attr in attributes) { if (attr is IQEventHandler) { IQEventHandlerMethod = method; } if (attr is IQConstructor) { try { iqConstructor = (Action <IQClassData>)Delegate .CreateDelegate(typeof(Action <IQClassData>), method); } catch { throw new Exception("The IQ Constructor must have signature 'static void IQConstructor(IQClassData data)'"); } } } } } }