/// <summary> Write a Id XML Element from attributes in a member. </summary> public virtual void WriteId(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, IdAttribute attribute, BaseAttribute parentAttribute, System.Type mappedClass) { writer.WriteStartElement( "id" ); // Attribute: <name> if(attribute.Name != null) writer.WriteAttributeString("name", GetAttributeValue(attribute.Name, mappedClass)); // Attribute: <node> if(attribute.Node != null) writer.WriteAttributeString("node", GetAttributeValue(attribute.Node, mappedClass)); // Attribute: <access> if(attribute.Access != null) writer.WriteAttributeString("access", GetAttributeValue(attribute.Access, mappedClass)); // Attribute: <column> if(attribute.Column != null) writer.WriteAttributeString("column", GetAttributeValue(attribute.Column, mappedClass)); // Attribute: <type> if(attribute.Type != null) writer.WriteAttributeString("type", GetAttributeValue(attribute.Type, mappedClass)); // Attribute: <length> if(attribute.Length != -1) writer.WriteAttributeString("length", attribute.Length.ToString()); // Attribute: <unsaved-value> if(attribute.UnsavedValue != null) writer.WriteAttributeString("unsaved-value", GetAttributeValue(attribute.UnsavedValue, mappedClass)); WriteUserDefinedContent(writer, member, null, attribute); System.Collections.ArrayList memberAttribs = GetSortedAttributes(member); int attribPos; // Find the position of the IdAttribute (its <sub-element>s must be after it) for(attribPos=0; attribPos<memberAttribs.Count; attribPos++) if( memberAttribs[attribPos] is IdAttribute && ((BaseAttribute)memberAttribs[attribPos]).Position == attribute.Position ) break; // found int i = attribPos + 1; // Element: <meta> for(; i<memberAttribs.Count; i++) { BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute; if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType()) || IsNextElement(memberAttrib, attribute, typeof(MetaAttribute)) ) break; // next attributes are 'elements' of the same level OR for 'sub-elements' else { if( memberAttrib is IdAttribute ) break; // Following attributes are for this Id if( memberAttrib is MetaAttribute ) WriteMeta(writer, member, memberAttrib as MetaAttribute, attribute, mappedClass); } } WriteUserDefinedContent(writer, member, typeof(MetaAttribute), attribute); // 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 IdAttribute ) break; // Following attributes are for this Id if( memberAttrib is ColumnAttribute ) WriteColumn(writer, member, memberAttrib as ColumnAttribute, attribute, mappedClass); } } WriteUserDefinedContent(writer, member, typeof(ColumnAttribute), attribute); // Element: <type> for(; i<memberAttribs.Count; i++) { BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute; if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType()) || IsNextElement(memberAttrib, attribute, typeof(TypeAttribute)) ) break; // next attributes are 'elements' of the same level OR for 'sub-elements' else { if( memberAttrib is IdAttribute ) break; // Following attributes are for this Id if( memberAttrib is TypeAttribute ) WriteType(writer, member, memberAttrib as TypeAttribute, attribute, mappedClass); } } WriteUserDefinedContent(writer, member, typeof(TypeAttribute), attribute); // Element: <generator> for(; i<memberAttribs.Count; i++) { BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute; if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType()) || IsNextElement(memberAttrib, attribute, typeof(GeneratorAttribute)) ) break; // next attributes are 'elements' of the same level OR for 'sub-elements' else { if( memberAttrib is IdAttribute ) break; // Following attributes are for this Id if( memberAttrib is GeneratorAttribute ) WriteGenerator(writer, member, memberAttrib as GeneratorAttribute, attribute, mappedClass); } } WriteUserDefinedContent(writer, member, typeof(GeneratorAttribute), attribute); writer.WriteEndElement(); }
protected bool Equals(IdAttribute other) { return(base.Equals(other) && string.Equals(Reference, other.Reference)); }
private void ApplyIdMappings(IModelInspector modelInspector, System.Type type, IClassAttributesMapper classCustomizer) { var member = MembersProvider.GetEntityMembersForPoid(type).FirstOrDefault(m => modelInspector.IsPersistentId(m)); if (member != null) { var idAttr = member.GetCustomAttributes(typeof(IdAttribute), false).OfType<IdAttribute>().FirstOrDefault(); // If IdAttribute is not specified for persistent id property, then use the default id mapping strategy if (idAttr == null) { idAttr = new IdAttribute(); } var context = new MappingContext(modelInspector, Conventions); foreach (var mapper in _attributeMapperFactory.GetIdAttributeMappers(idAttr)) { mapper.ApplyMapping(idAttr, member, type, classCustomizer, context); } } }
public static TableInfo GetTableInfo(object entity, DbOperateType dbOpType, PropertyInfo[] properties) { bool breakForeach = false; string strPrimaryKey = string.Empty; TableInfo tableInfo = new TableInfo(); Type type = entity.GetType(); tableInfo.TableName = GetTableName(type, dbOpType); if (dbOpType == DbOperateType.COUNT) { return(tableInfo); } foreach (PropertyInfo property in properties) { object propvalue = null; string columnName = string.Empty; string propName = columnName = property.Name; propvalue = ReflectionHelper.GetPropertyValue(entity, property); object[] propertyAttrs = property.GetCustomAttributes(false); for (int i = 0; i < propertyAttrs.Length; i++) { object propertyAttr = propertyAttrs[i]; if (EntityHelper.IsCaseColumn(propertyAttr, dbOpType)) { breakForeach = true; break; } string tempVal = GetColumnName(propertyAttr); columnName = tempVal == string.Empty ? propName : tempVal; if (propertyAttr is IdAttribute) { if (dbOpType == DbOperateType.INSERT || dbOpType == DbOperateType.DELETE) { IdAttribute idAttr = propertyAttr as IdAttribute; tableInfo.Strategy = idAttr.Strategy; if (CommonUtils.IsNullOrEmpty(propvalue)) { strPrimaryKey = EntityHelper.GetPrimaryKey(propertyAttr, dbOpType); if (!string.IsNullOrEmpty(strPrimaryKey)) { propvalue = strPrimaryKey; } } } tableInfo.Id.Key = columnName; tableInfo.Id.Value = propvalue; tableInfo.PropToColumn.Put(propName, columnName); breakForeach = true; } } if (breakForeach && dbOpType == DbOperateType.DELETE) { break; } if (breakForeach) { breakForeach = false; continue; } tableInfo.Columns.Put(columnName, propvalue); tableInfo.PropToColumn.Put(propName, columnName); } if (dbOpType == DbOperateType.UPDATE) { tableInfo.Columns.Put(tableInfo.Id.Key, tableInfo.Id.Value); } return(tableInfo); }
public void IdAttribute_InitializingConstructorWithNull() { idAttribute = new IdAttribute(null); }
private static int GetBondId(IdAttribute idAttr) { PropertyInfo valuePropery = typeof(IdAttribute).GetProperty("Value", BindingFlags.NonPublic | BindingFlags.Instance); return((ushort)valuePropery.GetValue(idAttr, BindingFlags.GetProperty | BindingFlags.NonPublic, null, null, null)); }
/// <summary> /// Determines whether the specified <see cref="IdAttribute" />, is equal to this instance. /// </summary> /// <param name="other">The other.</param> /// <returns>true if equal; otherwise, false</returns> protected bool Equals(IdAttribute other) => base.Equals(other) && string.Equals(Reference, other.Reference);
public static CodeGeneratorRequest Create(global::System.Type type) { if (type == null) { throw new ArgumentNullException(); } Message msg = null; try { CodeGeneratorRequest req = msg.Allocate <CodeGeneratorRequest>(); msg.Root = msg; Dictionary <System.Type, Node> map = new Dictionary <System.Type, Node>(); Queue <System.Type> pending = new Queue <System.Type>(); pending.Enqueue(type); var nodes = new List <Node>(); // in discovery order // first just get everything without configuring all the nodes; this avoids a number of cyclic issues while (pending.Count != 0) { System.Type next = pending.Dequeue(); if (next != null && !map.ContainsKey(next)) { ulong id = 0; string name = next.Name; IdAttribute idAttrib = (IdAttribute)Attribute.GetCustomAttribute(next, typeof(IdAttribute)); if (idAttrib != null) { id = idAttrib.Id; if (!string.IsNullOrWhiteSpace(idAttrib.Name)) { name = idAttrib.Name; } } var node = new Node { id = id, displayName = Text.Create(msg, name) }; map.Add(next, node); nodes.Add(node); Cascade(next, pending); } } foreach (var pair in map) { ConfigureNode(pair.Key, pair.Value, map); } req.nodes = msg.AllocateList <Node>(nodes); req.requestedFiles = msg.AllocateList <RequestedFile>(0); return(req); } finally { if (msg != null) { msg.Dispose(); } } }