private void AddPropertyMapKey(PropertyInfo property, PropertyAuditingData propertyData) { MapKeyAttribute mapKey = (MapKeyAttribute)Attribute.GetCustomAttribute(property, typeof(MapKeyAttribute)); if (mapKey != null) { propertyData.MapKey = mapKey.Name; } }
/// <summary> Write a MapKey XML Element from attributes in a member. </summary> public virtual void WriteMapKey(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, MapKeyAttribute attribute, BaseAttribute parentAttribute, System.Type mappedClass) { writer.WriteStartElement( "map-key" ); // Attribute: <column> if(attribute.Column != null) writer.WriteAttributeString("column", GetAttributeValue(attribute.Column, mappedClass)); // Attribute: <formula> if(attribute.Formula != null) writer.WriteAttributeString("formula", GetAttributeValue(attribute.Formula, mappedClass)); // Attribute: <type> writer.WriteAttributeString("type", attribute.Type==null ? DefaultHelper.Get_MapKey_Type_DefaultValue(member) : GetAttributeValue(attribute.Type, mappedClass)); // Attribute: <length> if(attribute.Length != -1) writer.WriteAttributeString("length", attribute.Length.ToString()); // Attribute: <node> if(attribute.Node != null) writer.WriteAttributeString("node", GetAttributeValue(attribute.Node, mappedClass)); WriteUserDefinedContent(writer, member, null, attribute); System.Collections.ArrayList memberAttribs = GetSortedAttributes(member); int attribPos; // Find the position of the MapKeyAttribute (its <sub-element>s must be after it) for(attribPos=0; attribPos<memberAttribs.Count; attribPos++) if( memberAttribs[attribPos] is MapKeyAttribute && ((BaseAttribute)memberAttribs[attribPos]).Position == attribute.Position ) break; // found int i = attribPos + 1; // Element: <column> for(; i<memberAttribs.Count; i++) { BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute; if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType()) || IsNextElement(memberAttrib, attribute, typeof(ColumnAttribute)) ) break; // next attributes are 'elements' of the same level OR for 'sub-elements' else { if( memberAttrib is MapKeyAttribute ) break; // Following attributes are for this MapKey if( memberAttrib is ColumnAttribute ) WriteColumn(writer, member, memberAttrib as ColumnAttribute, attribute, mappedClass); } } WriteUserDefinedContent(writer, member, typeof(ColumnAttribute), attribute); // Element: <formula> for(; i<memberAttribs.Count; i++) { BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute; if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType()) || IsNextElement(memberAttrib, attribute, typeof(FormulaAttribute)) ) break; // next attributes are 'elements' of the same level OR for 'sub-elements' else { if( memberAttrib is MapKeyAttribute ) break; // Following attributes are for this MapKey if( memberAttrib is FormulaAttribute ) WriteFormula(writer, member, memberAttrib as FormulaAttribute, attribute, mappedClass); } } WriteUserDefinedContent(writer, member, typeof(FormulaAttribute), attribute); writer.WriteEndElement(); }