public override MapValue[] GetMapValues(ObjectMapper mapper, MemberAccessor member, out bool isSet) { AttributeExtensionCollection extList = mapper.Extension[member.Name]["MapValue"]; if (extList == AttributeExtensionCollection.Null) { return(GetMapValues(mapper.Extension, member.Type, out isSet)); } List <MapValue> list = new List <MapValue>(extList.Count); foreach (AttributeExtension ext in extList) { object origValue = ext["OrigValue"]; if (origValue != null) { origValue = TypeExtension.ChangeType(origValue, member.Type); list.Add(new MapValue(origValue, ext.Value)); } } isSet = true; return(list.ToArray()); }
public override Association GetAssociation(TypeExtension typeExtension, MemberAccessor member) { if (typeExtension == TypeExtension.Null) { return(null); } MemberExtension mex = typeExtension[member.Name]; if (mex == MemberExtension.Null) { return(null); } AttributeExtensionCollection attrs = mex.Attributes[TypeExtension.NodeName.Association]; if (attrs == AttributeExtensionCollection.Null) { return(null); } return(new Association( member, Association.ParseKeys(attrs[0]["ThisKey", string.Empty].ToString()), Association.ParseKeys(attrs[0]["OtherKey", string.Empty].ToString()), attrs[0]["Storage", string.Empty].ToString(), TypeExtension.ToBoolean(attrs[0]["Storage", "True"], true))); }
public Join(AttributeExtension ext) { _tableName = (string)ext["TableName"]; _alias = (string)ext["Alias"]; AttributeExtensionCollection col = ext.Attributes["On"]; foreach (AttributeExtension ae in col) { _joinOns.Add(new JoinOn(ae)); } }
static void FillRelationIndex(string[] index, AttributeExtension attributeExtension, string indexName) { if (index.Any()) { var collection = new AttributeExtensionCollection(); foreach (var s in index) { var ae = new AttributeExtension(); ae.Values.Add(TypeExtension.AttrName.Name, s); collection.Add(ae); } attributeExtension.Attributes.Add(indexName, collection); } }
protected void FillMemberMapperExtension(AttributeNameCollection attributeCollection, Type memberType, Type memberMapperType) { AttributeExtensionCollection attrs; if (!attributeCollection.TryGetValue(Attributes.MemberMapper.Name, out attrs)) { attrs = new AttributeExtensionCollection(); attributeCollection.Add(Attributes.MemberMapper.Name, attrs); } var attributeExtension = new AttributeExtension(); attributeExtension.Values.Add(Attributes.MemberMapper.MemberType, memberType); attributeExtension.Values.Add(Attributes.MemberMapper.MemberMapperType, memberMapperType); attrs.Add(attributeExtension); }
private void MapFieldOnType(string origName, string mapName) { AttributeExtensionCollection attrs; if (!this._typeExtension.Attributes.TryGetValue(Attributes.MapField.Name, out attrs)) { attrs = new AttributeExtensionCollection(); this._typeExtension.Attributes.Add(Attributes.MapField.Name, attrs); } var attributeExtension = new AttributeExtension(); attributeExtension.Values.Add(Attributes.MapField.OrigName, origName); attributeExtension.Values.Add(Attributes.MapField.MapName, mapName); attrs.Add(attributeExtension); }
/// <summary> /// Associations the specified prop name. /// </summary> /// <param name="propName">Name of the prop.</param> /// <param name="canBeNull">if set to <c>true</c> [can be null].</param> /// <param name="thisKeys">The this keys.</param> /// <param name="otherKeys">The other keys.</param> void IFluentMap.Association(string propName, bool canBeNull, string thisKeys, string otherKeys) { var member = this.GetMemberExtension(propName); AttributeExtensionCollection attrs; if (!member.Attributes.TryGetValue(TypeExtension.NodeName.Association, out attrs)) { attrs = new AttributeExtensionCollection(); member.Attributes.Add(TypeExtension.NodeName.Association, attrs); } attrs.Clear(); var attributeExtension = new AttributeExtension(); attributeExtension.Values.Add(Attributes.Association.ThisKey, thisKeys); attributeExtension.Values.Add(Attributes.Association.OtherKey, otherKeys); attributeExtension.Values.Add(Attributes.Association.Storage, this.ToString(canBeNull)); attrs.Add(attributeExtension); this.EachChilds(m => m.Association(propName, canBeNull, thisKeys, otherKeys)); }
static List <MapValue> GetEnumMapValues(TypeExtension typeExt, Type type) { List <MapValue> mapValues = null; FieldInfo[] fields = type.GetFields(); foreach (FieldInfo fi in fields) { if ((fi.Attributes & EnumField) == EnumField) { AttributeExtensionCollection attrExt = typeExt[fi.Name]["MapValue"]; if (attrExt.Count == 0) { continue; } ArrayList list = new ArrayList(attrExt.Count); object origValue = Enum.Parse(type, fi.Name); foreach (AttributeExtension ae in attrExt) { if (ae.Value != null) { list.Add(ae.Value); } } if (list.Count > 0) { if (mapValues == null) { mapValues = new List <MapValue>(fields.Length); } mapValues.Add(new MapValue(origValue, list.ToArray())); } } } return(mapValues); }
/// <summary> /// Inheritances the mapping. /// </summary> /// <param name="type">The type.</param> /// <param name="code">The code.</param> /// <param name="isDefault">The is default.</param> void IFluentMap.InheritanceMapping(Type type, object code, bool?isDefault) { AttributeExtensionCollection extList; if (!this._typeExtension.Attributes.TryGetValue(Attributes.InheritanceMapping.Name, out extList)) { extList = new AttributeExtensionCollection(); this._typeExtension.Attributes.Add(Attributes.InheritanceMapping.Name, extList); } var attr = new AttributeExtension(); attr.Values.Add(Attributes.InheritanceMapping.Type, type.AssemblyQualifiedName); if (null != code) { attr.Values.Add(Attributes.InheritanceMapping.Code, code); } if (null != isDefault) { attr.Values.Add(Attributes.InheritanceMapping.IsDefault, isDefault.Value); } extList.Add(attr); this.EachChilds(m => m.InheritanceMapping(type, code, isDefault)); }
public override InheritanceMappingAttribute[] GetInheritanceMapping(Type type, TypeExtension typeExtension) { AttributeExtensionCollection extList = typeExtension.Attributes["InheritanceMapping"]; if (extList == AttributeExtensionCollection.Null) { return(Array <InheritanceMappingAttribute> .Empty); } InheritanceMappingAttribute[] attrs = new InheritanceMappingAttribute[extList.Count]; for (int i = 0; i < extList.Count; i++) { AttributeExtension ext = extList[i]; attrs[i] = new InheritanceMappingAttribute(); attrs[i].Code = ext["Code"]; attrs[i].IsDefault = TypeExtension.ToBoolean(ext["IsDefault", "False"], false); attrs[i].Type = Type.GetType(Convert.ToString(ext["Type"])); } return(attrs); }
/// <summary> /// Relations the specified prop name. /// </summary> /// <param name="propName">Name of the prop.</param> /// <param name="destinationType">Type of the destination.</param> /// <param name="slaveIndex">Index of the slave.</param> /// <param name="masterIndex">Index of the master.</param> void IFluentMap.Relation(string propName, Type destinationType, string[] slaveIndex, string[] masterIndex) { if (TypeHelper.IsSameOrParent(typeof(IEnumerable), destinationType)) { destinationType = destinationType.GetGenericArguments().Single(); } var member = this.GetMemberExtension(propName); AttributeExtensionCollection attrs; if (!member.Attributes.TryGetValue(TypeExtension.NodeName.Relation, out attrs)) { attrs = new AttributeExtensionCollection(); member.Attributes.Add(TypeExtension.NodeName.Relation, attrs); } attrs.Clear(); var attributeExtension = new AttributeExtension(); attributeExtension.Values.Add(TypeExtension.AttrName.DestinationType, destinationType.AssemblyQualifiedName); attrs.Add(attributeExtension); FillRelationIndex(slaveIndex, attributeExtension, TypeExtension.NodeName.SlaveIndex); FillRelationIndex(masterIndex, attributeExtension, TypeExtension.NodeName.MasterIndex); this.EachChilds(m => m.Relation(propName, destinationType, slaveIndex, masterIndex)); }
static List <MapValue> GetTypeMapValues(TypeExtension typeExt, Type type) { AttributeExtensionCollection extList = typeExt.Attributes["MapValue"]; if (extList == AttributeExtensionCollection.Null) { return(null); } List <MapValue> attrs = new List <MapValue>(extList.Count); foreach (AttributeExtension ext in extList) { object origValue = ext["OrigValue"]; if (origValue != null) { origValue = TypeExtension.ChangeType(origValue, type); attrs.Add(new MapValue(origValue, ext.Value)); } } return(attrs); }
protected void FillMapValueExtension <TR, TV>(AttributeNameCollection attributeCollection, TR origValue, TV value, TV[] values) { AttributeExtensionCollection list; if (!attributeCollection.TryGetValue(Attributes.MapValue.Name, out list)) { list = new AttributeExtensionCollection(); attributeCollection.Add(Attributes.MapValue.Name, list); } var allValues = new List <TV>(values); allValues.Insert(0, value); var tvFullName = typeof(TV).FullName; foreach (var val in allValues) { var attributeExtension = new AttributeExtension(); attributeExtension.Values.Add(Attributes.MapValue.OrigValue, origValue); attributeExtension.Values.Add(TypeExtension.ValueName.Value, Convert.ToString(val)); attributeExtension.Values.Add(TypeExtension.ValueName.Value + TypeExtension.ValueName.TypePostfix, tvFullName); list.Add(attributeExtension); } }
public override List <MapRelationBase> GetRelations(MappingSchema schema, ExtensionList typeExt, Type master, Type slave, out bool isSet) { List <MapRelationBase> relations = new List <MapRelationBase>(); TypeExtension ext = typeExt != null ? typeExt[master] : TypeExtension.Null; isSet = ext != TypeExtension.Null; if (!isSet) { return(relations); } TypeAccessor ta = TypeAccessor.GetAccessor(master); foreach (MemberExtension mex in ext.Members) { AttributeExtensionCollection relationInfos = mex.Attributes[TypeExtension.NodeName.Relation]; if (relationInfos == AttributeExtensionCollection.Null) { continue; } string destinationTypeName = relationInfos[0][TypeExtension.AttrName.DestinationType, string.Empty].ToString(); Type destinationType = slave; MemberAccessor ma = ta[mex.Name]; bool toMany = TypeHelper.IsSameOrParent(typeof(IEnumerable), ma.Type); if (destinationTypeName == string.Empty) { if (toMany) { throw new InvalidOperationException("Destination type should be set for enumerable relations: " + ma.Type.FullName + "." + ma.Name); } destinationType = ma.Type; } else { if (!destinationTypeName.Contains(",")) { destinationTypeName += ", " + ta.OriginalType.Assembly.FullName; } try { destinationType = Type.GetType(destinationTypeName, true); } catch (TypeLoadException ex) { throw new InvalidOperationException( "Unable to load type by name: " + destinationTypeName + "\n may be assembly is not specefied, please see Type.GetType(string typeName) documentation", ex); } } if (slave != null && !TypeHelper.IsSameOrParent(slave, destinationType)) { continue; } List <string> masterIndexFields = new List <string>(); List <string> slaveIndexFields = new List <string>(); foreach (AttributeExtension ae in relationInfos[0].Attributes[TypeExtension.NodeName.MasterIndex]) { masterIndexFields.Add(ae[TypeExtension.AttrName.Name].ToString()); } foreach (AttributeExtension ae in relationInfos[0].Attributes[TypeExtension.NodeName.SlaveIndex]) { slaveIndexFields.Add(ae[TypeExtension.AttrName.Name].ToString()); } if (slaveIndexFields.Count == 0) { TypeAccessor accessor = toMany ? ta : TypeAccessor.GetAccessor(destinationType); TypeExtension tex = TypeExtension.GetTypeExtension(accessor.Type, typeExt); slaveIndexFields = GetPrimaryKeyFields(schema, accessor, tex); } if (slaveIndexFields.Count == 0) { throw new InvalidOperationException("Slave index is not set for relation: " + ma.Type.FullName + "." + ma.Name); } MapIndex slaveIndex = new MapIndex(slaveIndexFields.ToArray()); MapIndex masterIndex = masterIndexFields.Count > 0 ? new MapIndex(masterIndexFields.ToArray()) : slaveIndex; MapRelationBase mapRelation = new MapRelationBase(destinationType, slaveIndex, masterIndex, mex.Name); relations.Add(mapRelation); } isSet = relations.Count > 0; return(relations); }
private static void MergeExtensions(AttributeExtensionCollection fromExt, ref AttributeExtensionCollection toExt) { toExt.AddRange(fromExt); }