/// <summary> /// Obtain and process data from a static IQ constructor /// </summary> private void CallIQConstructor() { IQClassData data = new IQClassData(); iqConstructor(data); ProcessConstructorData(data); }
/// <summary> /// Main entry point /// </summary> /// <param name="type"></param> /// <param name="tableName"></param> /// <param name="mappedFields"></param> public void MapClass(Type type, IQClassData data = null) { ClassType = type; GetClassMetadata(); GetFieldInfoFromClassAttribute(); GetClassPropertiesMethods(); if (iqConstructor != null) { CallIQConstructor(); } // Data passed in to this will supercede anything else0 if (data != null) { ProcessConstructorData(data); } MapFromTemporaryFields(); if (fieldInfo.Count == 0) { throw new Exception("There were no databound fields in the object."); } if (PrimaryKey == null) { throw new Exception("No primary key was found in the object."); } }
/// <summary> /// fieldList should be a CSV of the properties to include. (PK) after a field name identifies it as the primary key. /// </summary> /// <param name="owner"></param> /// <param name="tableName"></param> /// <param name="fieldList"></param> public DBObjectData(object owner, IQClassData data = null) { OwnerRef = new WeakReference(owner); ClassInfo = GetClassInfo(owner.GetType(), data); TableName = ClassInfo.TableName; if (ClassInfo.IQEventHandlerMethod != null) { IQEventHandlerFunc = (Action <IQEventType, IDBObjectData>)Delegate .CreateDelegate(typeof(Action <IQEventType, IDBObjectData>), owner, ClassInfo.IQEventHandlerMethod); } Clean(); }
/// <summary> /// fieldList should be a CSV of the properties to include. (PK) after a field name identifies it as the primary key. /// </summary> /// <param name="owner"></param> /// <param name="tableName"></param> /// <param name="fieldList"></param> public DBObjectData(object owner, IQClassData data=null) { OwnerRef = new WeakReference(owner); ClassInfo = GetClassInfo(owner.GetType(), data); TableName = ClassInfo.TableName; if (ClassInfo.IQEventHandlerMethod != null) { IQEventHandlerFunc = (Action<IQEventType, IDBObjectData>)Delegate .CreateDelegate(typeof(Action<IQEventType, IDBObjectData>), owner, ClassInfo.IQEventHandlerMethod); } Clean(); }
public static DBClassInfo GetClassInfo(Type type, IQClassData data = null) { DBClassInfo classInfo; if (!type.IsClass) { throw new IQException("You can't get ClassInfo for a value type."); } if (!ClassInfoCache.TryGetValue(type, out classInfo)) { classInfo = new DBClassInfo(); classInfo.MapClass(type, data); ClassInfoCache[type] = classInfo; } return(classInfo); }
protected void ProcessConstructorData(IQClassData data) { ISqlQuery query = data.Query; if (query != null) { _Query = query; // Sync the two table names -- TODO fix this, perhaps always create a query instead of having sep. // properties? if (String.IsNullOrEmpty(_Query.TableName)) { _Query.TableName = data.TableName; } else if (String.IsNullOrEmpty(data.TableName)) { data.TableName = _Query.TableName; } } if (!String.IsNullOrEmpty(data.TableName)) { if (!String.IsNullOrEmpty(TableName) && TableName.ToLower() != data.TableName.ToLower()) { throw new Exception("A table name was specified in the constructor, but another one was already indetified for the class."); } TableName = data.TableName; } if (!String.IsNullOrEmpty(data.PrimaryKey)) { string nameLower = data.PrimaryKey.ToLower(); Field fldTemp; if (!temporaryFieldInfo.TryGetValue(nameLower, out fldTemp)) { fldTemp = new Field(); temporaryFieldInfo[nameLower] = fldTemp; fldTemp.Name = data.PrimaryKey; } fldTemp.PK = true; } }
/// <summary> /// Main entry point /// </summary> /// <param name="type"></param> /// <param name="tableName"></param> /// <param name="mappedFields"></param> public void MapClass(Type type, IQClassData data=null) { ClassType = type; GetClassMetadata(); GetFieldInfoFromClassAttribute(); GetClassPropertiesMethods(); if (iqConstructor != null) { CallIQConstructor(); } // Data passed in to this will supercede anything else0 if (data != null) { ProcessConstructorData(data); } MapFromTemporaryFields(); if (fieldInfo.Count == 0) { throw new Exception("There were no databound fields in the object."); } if (PrimaryKey == null) { throw new Exception("No primary key was found in the object."); } }
public static DBClassInfo GetClassInfo(Type type, IQClassData data=null) { DBClassInfo classInfo; if (!type.IsClass) { throw new IQException("You can't get ClassInfo for a value type."); } if (!ClassInfoCache.TryGetValue(type, out classInfo)) { classInfo = new DBClassInfo(); classInfo.MapClass(type, data); ClassInfoCache[type] = classInfo; } return classInfo; }