protected ArrayDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, INestedDataField parent, int length, IProducer arrProducer) : base(dataHolder, name, accessor, mappedMember, parent) { m_length = length; m_arrProducer = arrProducer; }
protected DataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, INestedDataField parent) : base(dataHolder, accessor, parent) { this.m_mappedMember = mappedMember; this.m_name = name; }
public NestedPersistor(INestedDataField dataField) { this.m_DataField = dataField; this.m_UnderlyingPersistors = new IBinaryPersistor[this.m_DataField.InnerFields.Count]; this.m_accessors = new IGetterSetter[this.m_DataField.InnerFields.Count]; int index = 0; foreach (IDataField field in this.m_DataField.InnerFields.Values) { IBinaryPersistor persistor = BinaryPersistors.GetPersistor(field); this.m_UnderlyingPersistors[index] = persistor; this.m_accessors[index] = field.Accessor; ++index; } }
public NestedPersistor( INestedDataField dataField) { m_DataField = dataField; m_UnderlyingPersistors = new IBinaryPersistor[m_DataField.InnerFields.Count]; m_accessors = new IGetterSetter[m_DataField.InnerFields.Count]; var i = 0; foreach (var field in m_DataField.InnerFields.Values) { var persistor = BinaryPersistors.GetPersistor(field); m_UnderlyingPersistors[i] = persistor; m_accessors[i] = field.Accessor; i++; } }
public void Set(IDataHolder obj, object value) { object key = this.GetTargetObject(obj); this.m_accessor.Set(key, value); if (!key.GetType().IsValueType) { return; } INestedDataField parent = this.m_parent; while (parent != null) { object targetObject = parent.GetTargetObject(obj); parent.Accessor.Set(targetObject, key); key = targetObject; parent = parent.Parent; if (!targetObject.GetType().IsValueType) { break; } } }
public override IDataField Copy(INestedDataField parent) { return new FlatArrayDataField(m_DataHolderDefinition, m_name, m_accessor, m_mappedMember, m_length, m_arrProducer, parent); }
public override IDataField Copy(INestedDataField parent) { return((IDataField) new FlatArrayDataField(this.m_DataHolderDefinition, this.m_name, this.m_accessor, this.m_mappedMember, this.m_length, this.m_arrProducer, parent)); }
public NestedPersistor( INestedDataField dataField) { m_DataField = dataField; m_UnderlyingPersistors = new IBinaryPersistor[m_DataField.InnerFields.Count]; m_accessors = new IGetterSetter[m_DataField.InnerFields.Count]; var i = 0; foreach (var field in m_DataField.InnerFields.Values) { var persistor = BinaryPersistors.GetPersistor(field); m_UnderlyingPersistors[i] = persistor; m_accessors[i] = field.Accessor; i++; } }
public override IDataField Copy(INestedDataField parent) { return((IDataField) new NestedSimpleDataField(this.m_DataHolderDefinition, this.m_name, this.m_accessor, this.m_mappedMember, this.m_Producer, parent)); }
public override IDataField Copy(INestedDataField parent) { return(new NestedArrayDataField(m_DataHolderDefinition, m_name, m_accessor, m_mappedMember, m_Producer, m_arrProducer, m_length, parent)); }
public abstract IDataField Copy(INestedDataField parent);
protected NestedDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, IProducer producer, INestedDataField parent) : base(dataHolder, name, accessor, mappedMember, parent) { m_Producer = producer; }
protected ArrayDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, INestedDataField parent, int length, IProducer arrProducer) : base(dataHolder, name, accessor, mappedMember, parent) { m_length = length; m_arrProducer = arrProducer; }
private void GetDataFields(Type type, IDictionary <string, IDataField> fields, INestedDataField parent) { var members = type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetField | BindingFlags.SetProperty); var count = members.Length; Dictionary <MemberInfo, IGetterSetter> accessors; if (count < DynamicMaximumMembers && type.IsClass) { // only create dynamic accessors if there are less than x members accessors = AccessorMgr.GetOrCreateAccessors(type); } else { accessors = null; } foreach (var member in members) { if (member.IsReadonly()) { continue; } if (member.GetCustomAttributes <NotPersistentAttribute>().Length > 0) { continue; } var dbAttrs = member.GetCustomAttributes <DBAttribute>(); var persistentAttribute = dbAttrs.Where(attribute => attribute is PersistentAttribute).FirstOrDefault() as PersistentAttribute; if (persistentAttribute == null && m_Attribute.RequirePersistantAttr) { // DataHolder only maps fields/properties with PersistantAttribute continue; } var rawType = member.GetVariableType(); var isArr = rawType.IsArray; string varName; IGetterSetter accessor; IFieldReader reader; Type memberType; if (persistentAttribute != null) { // persistent attribute memberType = persistentAttribute.ActualType ?? member.GetActualType(); varName = persistentAttribute.Name ?? member.Name; if (persistentAttribute.AccessorType != null) { var accessorObj = Activator.CreateInstance(persistentAttribute.AccessorType); if (!(accessorObj is IGetterSetter)) { throw new DataHolderException("Accessor for Persistent members must be of type IGetterSetter - " + "Found accessor of type {0} for member {1}", accessorObj.GetType(), member.GetFullMemberName()); } accessor = (IGetterSetter)accessorObj; } else { accessor = accessors != null ? accessors[member] : new DefaultVariableAccessor(member); } reader = Converters.GetReader(persistentAttribute.ReadType ?? memberType); } else { memberType = member.GetActualType(); varName = member.Name; //accessor = new DefaultVariableAccessor(member); accessor = (accessors != null ? accessors[member] : new DefaultVariableAccessor(member)); reader = Converters.GetReader(memberType); } // check array constraints if (isArr) { if (rawType.GetArrayRank() > 1 || memberType.IsArray) { throw new DataHolderException("Cannot define Type {0} of {1} because its a multi-dimensional Array.", rawType, member.GetFullMemberName()); } } IDataField field; if (reader == null) { // create reader if (type.IsAbstract) { throw new DataHolderException( "Cannot define member \"{0}\" of DataHolder \"{1}\" because it's Type ({2}) is abstract.", member.GetFullMemberName(), this, memberType.FullName); } IProducer producer; if (memberType.IsClass) { producer = CreateProducer(memberType); } else { // value type does not need a producer producer = null; } if (isArr) { // complex (nested) type var length = GetArrayLengthByAttr(persistentAttribute, member); var nestedField = new NestedArrayDataField(this, varName, accessor, member, producer, CreateArrayProducer(memberType, length), length, parent); var dataFields = new Dictionary <string, IDataField>(StringComparer.InvariantCultureIgnoreCase); //Console.WriteLine("Getting field for: " + nestedField); GetDataFields(memberType, dataFields, nestedField); foreach (var dataField in dataFields.Values) { for (var i = 0; i < nestedField.ArrayAccessors.Length; i++) { var arrAccessor = (NestedArrayAccessor)nestedField.ArrayAccessors[i]; var newField = ((DataFieldBase)dataField).Copy(arrAccessor); arrAccessor.InnerFields.Add(newField.Name, newField); } } field = nestedField; } else { // simple nested type var nestedField = new NestedSimpleDataField(this, varName, accessor, member, producer, parent); //Console.WriteLine("Getting field for: " + nestedField); GetDataFields(memberType, nestedField.InnerFields, nestedField); if (nestedField.InnerFields.Count == 0) { throw new DataHolderException("Cannot define " + member.GetFullMemberName() + " as Nested because it does not have any inner fields."); } else { field = nestedField; } } } else { if (isArr) { //var nestedField = new (this, varName, accessor, member, producer, parent); var length = GetArrayLengthByAttr(persistentAttribute, member); field = new FlatArrayDataField(this, varName, accessor, member, length, CreateArrayProducer(memberType, length), parent); } else { field = new FlatSimpleDataField(this, varName, accessor, member, parent); if (varName == m_DependingFieldName) { m_DependingField = (FlatSimpleDataField)field; } } } fields.Add(field.Name, field); } if (fields.Count() - count == 0) { throw new ArgumentException("Invalid data Type has no persistent members: " + type.FullName); } }
public abstract IDataField Copy(INestedDataField parent);
protected DataFieldBase(DataHolderDefinition dataHolder, IGetterSetter accessor, INestedDataField parent) { m_DataHolderDefinition = dataHolder; m_parent = parent; m_accessor = accessor; }
protected DataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, INestedDataField parent) : base(dataHolder, accessor, parent) { m_mappedMember = mappedMember; m_name = name; //m_fullName = parent; }
private void GetDataFields(Type type, IDictionary <string, IDataField> fields, INestedDataField parent) { MemberInfo[] members = type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetField | BindingFlags.SetProperty); int length = members.Length; Dictionary <MemberInfo, IGetterSetter> dictionary1 = length >= 80 || !type.IsClass ? (Dictionary <MemberInfo, IGetterSetter>)null : AccessorMgr.GetOrCreateAccessors(type); foreach (MemberInfo index1 in members) { if (!index1.IsReadonly() && index1.GetCustomAttributes <NotPersistentAttribute>().Length <= 0) { PersistentAttribute attr = ((IEnumerable <DBAttribute>)index1.GetCustomAttributes <DBAttribute>()) .Where <DBAttribute>((Func <DBAttribute, bool>)(attribute => attribute is PersistentAttribute)) .FirstOrDefault <DBAttribute>() as PersistentAttribute; if (attr != null || !this.m_Attribute.RequirePersistantAttr) { Type variableType = index1.GetVariableType(); bool isArray = variableType.IsArray; Type type1; string name; IGetterSetter accessor; IFieldReader reader; if (attr != null) { Type actualType = attr.ActualType; if ((object)actualType == null) { actualType = index1.GetActualType(); } type1 = actualType; name = attr.Name ?? index1.Name; if (attr.AccessorType != (Type)null) { object instance = Activator.CreateInstance(attr.AccessorType); if (!(instance is IGetterSetter)) { throw new DataHolderException( "Accessor for Persistent members must be of type IGetterSetter - Found accessor of type {0} for member {1}", new object[2] { (object)instance.GetType(), (object)index1.GetFullMemberName() }); } accessor = (IGetterSetter)instance; } else { accessor = dictionary1 != null ? dictionary1[index1] : (IGetterSetter) new DefaultVariableAccessor(index1); } Type type2 = attr.ReadType; if ((object)type2 == null) { type2 = type1; } reader = Converters.GetReader(type2); } else { type1 = index1.GetActualType(); name = index1.Name; accessor = dictionary1 != null ? dictionary1[index1] : (IGetterSetter) new DefaultVariableAccessor(index1); reader = Converters.GetReader(type1); } if (isArray && (variableType.GetArrayRank() > 1 || type1.IsArray)) { throw new DataHolderException( "Cannot define Type {0} of {1} because its a multi-dimensional Array.", new object[2] { (object)variableType, (object)index1.GetFullMemberName() }); } IDataField dataField1; if (reader == null) { if (type.IsAbstract) { throw new DataHolderException( "Cannot define member \"{0}\" of DataHolder \"{1}\" because it's Type ({2}) is abstract.", new object[3] { (object)index1.GetFullMemberName(), (object)this, (object)type1.FullName }); } IProducer producer = !type1.IsClass ? (IProducer)null : DataHolderDefinition.CreateProducer(type1); if (isArray) { int arrayLengthByAttr = DataHolderDefinition.GetArrayLengthByAttr(attr, index1); NestedArrayDataField nestedArrayDataField = new NestedArrayDataField(this, name, accessor, index1, producer, DataHolderDefinition.CreateArrayProducer(type1, arrayLengthByAttr), arrayLengthByAttr, parent); Dictionary <string, IDataField> dictionary2 = new Dictionary <string, IDataField>( (IEqualityComparer <string>)StringComparer.InvariantCultureIgnoreCase); this.GetDataFields(type1, (IDictionary <string, IDataField>)dictionary2, (INestedDataField)nestedArrayDataField); foreach (IDataField dataField2 in dictionary2.Values) { for (int index2 = 0; index2 < nestedArrayDataField.ArrayAccessors.Length; ++index2) { NestedArrayAccessor arrayAccessor = (NestedArrayAccessor)nestedArrayDataField.ArrayAccessors[index2]; IDataField dataField3 = ((DataFieldBase)dataField2).Copy((INestedDataField)arrayAccessor); arrayAccessor.InnerFields.Add(dataField3.Name, dataField3); } } dataField1 = (IDataField)nestedArrayDataField; } else { NestedSimpleDataField nestedSimpleDataField = new NestedSimpleDataField(this, name, accessor, index1, producer, parent); this.GetDataFields(type1, (IDictionary <string, IDataField>)nestedSimpleDataField.InnerFields, (INestedDataField)nestedSimpleDataField); if (nestedSimpleDataField.InnerFields.Count == 0) { throw new DataHolderException( "Cannot define " + index1.GetFullMemberName() + " as Nested because it does not have any inner fields.", new object[0]); } dataField1 = (IDataField)nestedSimpleDataField; } } else if (isArray) { int arrayLengthByAttr = DataHolderDefinition.GetArrayLengthByAttr(attr, index1); dataField1 = (IDataField) new FlatArrayDataField(this, name, accessor, index1, arrayLengthByAttr, DataHolderDefinition.CreateArrayProducer(type1, arrayLengthByAttr), parent); } else { dataField1 = (IDataField) new FlatSimpleDataField(this, name, accessor, index1, parent); if (name == this.m_DependingFieldName) { this.m_DependingField = (FlatSimpleDataField)dataField1; } } fields.Add(dataField1.Name, dataField1); } } } if (fields.Count <KeyValuePair <string, IDataField> >() - length == 0) { throw new ArgumentException("Invalid data Type has no persistent members: " + type.FullName); } }
public NestedArrayDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, IProducer producer, IProducer arrayProducer, int length, INestedDataField parent) : base(dataHolder, name, accessor, mappedMember, parent, length, arrayProducer) { m_Producer = producer; m_ArrayAccessors = new NestedArrayAccessor[m_length]; for (var i = 0; i < m_length; i++) { m_ArrayAccessors[i] = new NestedArrayAccessor(this, i); } }
protected DataFieldBase(DataHolderDefinition dataHolder, IGetterSetter accessor, INestedDataField parent) { m_DataHolderDefinition = dataHolder; m_parent = parent; m_accessor = accessor; }
protected NestedDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, IProducer producer, INestedDataField parent) : base(dataHolder, name, accessor, mappedMember, parent) { m_Producer = producer; }
public override IDataField Copy(INestedDataField parent) { return(new FlatSimpleDataField(m_DataHolderDefinition, m_name, m_accessor, m_mappedMember, parent)); }
public NestedSimpleDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, IProducer producer, INestedDataField parent) : base(dataHolder, name, accessor, mappedMember, producer, parent) { }
public NestedSimpleDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, IProducer producer, INestedDataField parent) : base(dataHolder, name, accessor, mappedMember, producer, parent) { }
public override IDataField Copy(INestedDataField parent) { return new NestedSimpleDataField(m_DataHolderDefinition, m_name, m_accessor, m_mappedMember, m_Producer, parent); }
public NestedArrayDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, IProducer producer, IProducer arrayProducer, int length, INestedDataField parent) : base(dataHolder, name, accessor, mappedMember, parent, length, arrayProducer) { m_Producer = producer; m_ArrayAccessors = new NestedArrayAccessor[m_length]; for (var i = 0; i < m_length; i++) { m_ArrayAccessors[i] = new NestedArrayAccessor(this, i); } }
public NestedArrayDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, IProducer producer, IProducer arrayProducer, int length, INestedDataField parent) : base(dataHolder, name, accessor, mappedMember, parent, length, arrayProducer) { this.m_Producer = producer; this.m_ArrayAccessors = (IDataFieldAccessor[])new NestedArrayAccessor[this.m_length]; for (int index = 0; index < this.m_length; ++index) { this.m_ArrayAccessors[index] = (IDataFieldAccessor) new NestedArrayAccessor(this, index); } }
private void GetDataFields(Type type, IDictionary<string, IDataField> fields, INestedDataField parent) { var members = type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetField | BindingFlags.SetProperty); var count = members.Length; Dictionary<MemberInfo, IGetterSetter> accessors; if (count < DynamicMaximumMembers && type.IsClass) { // only create dynamic accessors if there are less than x members accessors = AccessorMgr.GetOrCreateAccessors(type); } else { accessors = null; } foreach (var member in members) { if (member.IsReadonly()) { continue; } if (member.GetCustomAttributes<NotPersistentAttribute>().Length > 0) { continue; } var dbAttrs = member.GetCustomAttributes<DBAttribute>(); var persistentAttribute = dbAttrs.Where(attribute => attribute is PersistentAttribute).FirstOrDefault() as PersistentAttribute; if (persistentAttribute == null && m_Attribute.RequirePersistantAttr) { // DataHolder only maps fields/properties with PersistantAttribute continue; } var rawType = member.GetVariableType(); var isArr = rawType.IsArray; string varName; IGetterSetter accessor; IFieldReader reader; Type memberType; if (persistentAttribute != null) { // persistent attribute memberType = persistentAttribute.ActualType ?? member.GetActualType(); varName = persistentAttribute.Name ?? member.Name; if (persistentAttribute.AccessorType != null) { var accessorObj = Activator.CreateInstance(persistentAttribute.AccessorType); if (!(accessorObj is IGetterSetter)) { throw new DataHolderException("Accessor for Persistent members must be of type IGetterSetter - " + "Found accessor of type {0} for member {1}", accessorObj.GetType(), member.GetFullMemberName()); } accessor = (IGetterSetter)accessorObj; } else { accessor = accessors != null ? accessors[member] : new DefaultVariableAccessor(member); } reader = Converters.GetReader(persistentAttribute.ReadType ?? memberType); } else { memberType = member.GetActualType(); varName = member.Name; //accessor = new DefaultVariableAccessor(member); accessor = (accessors != null ? accessors[member] : new DefaultVariableAccessor(member)); reader = Converters.GetReader(memberType); } // check array constraints if (isArr) { if (rawType.GetArrayRank() > 1 || memberType.IsArray) { throw new DataHolderException("Cannot define Type {0} of {1} because its a multi-dimensional Array.", rawType, member.GetFullMemberName()); } } IDataField field; if (reader == null) { // create reader if (type.IsAbstract) { throw new DataHolderException( "Cannot define member \"{0}\" of DataHolder \"{1}\" because it's Type ({2}) is abstract.", member.GetFullMemberName(), this, memberType.FullName); } IProducer producer; if (memberType.IsClass) { producer = CreateProducer(memberType); } else { // value type does not need a producer producer = null; } if (isArr) { // complex (nested) type var length = GetArrayLengthByAttr(persistentAttribute, member); var nestedField = new NestedArrayDataField(this, varName, accessor, member, producer, CreateArrayProducer(memberType, length), length, parent); var dataFields = new Dictionary<string, IDataField>(StringComparer.InvariantCultureIgnoreCase); //Console.WriteLine("Getting field for: " + nestedField); GetDataFields(memberType, dataFields, nestedField); foreach (var dataField in dataFields.Values) { for (var i = 0; i < nestedField.ArrayAccessors.Length; i++) { var arrAccessor = (NestedArrayAccessor)nestedField.ArrayAccessors[i]; var newField = ((DataFieldBase)dataField).Copy(arrAccessor); arrAccessor.InnerFields.Add(newField.Name, newField); } } field = nestedField; } else { // simple nested type var nestedField = new NestedSimpleDataField(this, varName, accessor, member, producer, parent); //Console.WriteLine("Getting field for: " + nestedField); GetDataFields(memberType, nestedField.InnerFields, nestedField); if (nestedField.InnerFields.Count == 0) { throw new DataHolderException("Cannot define " + member.GetFullMemberName() + " as Nested because it does not have any inner fields."); } else { field = nestedField; } } } else { if (isArr) { //var nestedField = new (this, varName, accessor, member, producer, parent); var length = GetArrayLengthByAttr(persistentAttribute, member); field = new FlatArrayDataField(this, varName, accessor, member, length, CreateArrayProducer(memberType, length), parent); } else { field = new FlatSimpleDataField(this, varName, accessor, member, parent); if (varName == m_DependingFieldName) { m_DependingField = (FlatSimpleDataField)field; } } } fields.Add(field.Name, field); } if (fields.Count() - count == 0) { throw new ArgumentException("Invalid data Type has no persistent members: " + type.FullName); } }
public FlatArrayDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, int length, IProducer arrProducer, INestedDataField parent) : base(dataHolder, name, accessor, mappedMember, parent, length, arrProducer) { m_ArrayAccessors = new FlatArrayAccessor[m_length]; for (int index = 0; index < m_length; ++index) { m_ArrayAccessors[index] = new FlatArrayAccessor(this, index); } }