private void BeginProperty(XmlReader reader) { StackFrame topFrame = stack.Peek(); string localName = XmlConvert.DecodeName(reader.LocalName); EntityPropertyInfo entityPropertyInfo = topFrame.entity.Properties[localName]; PropertyInfo property; if (!topFrame.dynamic && (property = topFrame.instanceType.GetProperty(localName)) != null) { // Assumptions: // - No type conversion is performed to assign the variable // Improvements: // - Process this validation when the metadata has been processed. if (!property.PropertyType.IsAssignableFrom(stack.Peek().entity.Properties[localName].Type)) { throw new InvalidOperationException(string.Format("Property {0} cannot be assigned from type {1}", localName, entityInfo.Properties[localName].TypeName)); } StackFrame frame = topFrame.Clone(); frame.elementName = localName; frame.property = property; frame.state = state; stack.Push(frame); } else { StackFrame frame = topFrame.Clone(); frame.elementName = localName; frame.state = state; if (hasAddMethod) { frame.iAddInstance = (IEntityPropertySetter)frame.instance; } else { MethodInfo addMethod = topFrame.instanceType.GetMethod("Add"); frame.addMethod = addMethod; } stack.Push(frame); } if (entityPropertyInfo.IsArray) { this.state = ParserState.ArrayProperty; } else { this.state = ParserState.Property; } }
private void BeginNestedEntity(XmlReader reader) { EntityInfo nestedEntity = stack.Peek().entitySet.Entities[reader.LocalName]; StackFrame topFrame = stack.Peek(); StackFrame frame = topFrame.Clone(); frame.entity = nestedEntity; frame.elementName = reader.LocalName; if (frame.property != null) { frame.instance = Activator.CreateInstance(topFrame.instanceType); } else //keep reference to current instance - for non mapped properties { frame.instance = topFrame.instance; } frame.state = state; frame.dynamic = nestedEntity.Dynamic; stack.Push(frame); state = ParserState.Entity; }
private void BeginEntitySet(XmlReader reader) { string localName = XmlConvert.DecodeName(reader.LocalName); EntitySetInfo entitySet = stack.Peek().entity.EntitySets[localName]; StackFrame topFrame = stack.Peek(); Type instanceType = topFrame.instance.GetType(); PropertyInfo property = instanceType.GetProperty(localName); Type[] arguments; //if(property==null) //{ // property = instanceType.GetProperty("NonMappedProperties"); //} StackFrame frame = topFrame.Clone(); if (property != null) { if (!property.PropertyType.IsGenericType) { throw new InvalidOperationException(string.Format("Property {0}.{1} is not a generic type", instanceType.Name, localName)); } // figure out what type of elements are allowed in the collection arguments = property.PropertyType.GetGenericArguments(); // Only support generic ICollection<T> for nested entities Type collType = typeof(ICollection <>).MakeGenericType(arguments[0]); if (!collType.IsAssignableFrom(property.PropertyType)) { throw new InvalidOperationException(string.Format("Property {0} is not an ICollection<T>", property.Name)); } frame.instanceType = arguments[0]; //frame.instance = property.PropertyType; } //throw new InvalidOperationException(string.Format("Property {0} does not exist on type {1}", reader.LocalName, instanceType.Name)); frame.entitySet = entitySet; frame.elementName = localName; frame.property = property; frame.state = state; stack.Push(frame); state = ParserState.EntitySet; }
private void BeginNestedEntity(XmlReader reader) { EntityInfo nestedEntity = stack.Peek().entitySet.Entities[reader.LocalName]; StackFrame topFrame = this.stack.Peek(); StackFrame frame = topFrame.Clone(); frame.entity = nestedEntity; frame.elementName = reader.LocalName; frame.instance = Activator.CreateInstance(topFrame.instanceType); frame.state = this.state; frame.dynamic = nestedEntity.Dynamic; stack.Push(frame); this.state = ParserState.Entity; }
private void BeginProperty(XmlReader reader) { StackFrame topFrame = this.stack.Peek(); EntityPropertyInfo entityPropertyInfo = topFrame.entity.Properties[reader.LocalName]; if (!topFrame.dynamic) { // Assumptions: // - expecting property to match exactly XML element name // - only public members looked for // Improvement: // - Process this validation when the metadata has been processed. PropertyInfo property = topFrame.instanceType.GetProperty(reader.LocalName); if (property == null) { throw new InvalidOperationException(string.Format("Property {0} does not exist on typeName {1}", reader.LocalName, topFrame.instanceType.Name)); } // Assumptions: // - No type conversion is performed to assign the variable // Improvements: // - Process this validation when the metadata has been processed. if (!property.PropertyType.IsAssignableFrom(entityPropertyInfo.Type)) { throw new InvalidOperationException(string.Format("Property {0} cannot be assigned from type {1}", reader.LocalName, this.entityInfo.Properties[reader.LocalName].TypeName)); } StackFrame frame = topFrame.Clone(); frame.elementName = XmlConvert.DecodeName(reader.LocalName); frame.property = property; frame.entityPropertyInfo = entityPropertyInfo; frame.state = this.state; stack.Push(frame); } else { StackFrame frame = topFrame.Clone(); frame.elementName = XmlConvert.DecodeName(reader.LocalName); frame.entityPropertyInfo = entityPropertyInfo; frame.state = this.state; if (hasAddMethod) { frame.iAddInstance = (IEntityPropertySetter)frame.instance; } else { MethodInfo addMethod = topFrame.instanceType.GetMethod("Add"); frame.addMethod = addMethod; } stack.Push(frame); } if (entityPropertyInfo.IsArray) { this.state = ParserState.ArrayProperty; } else { this.state = ParserState.Property; } }