private void ProcessArrayPropertyItem(XmlReader reader) { EntityPropertyInfo propInfo = this.stack.Peek().entityPropertyInfo; object value = DeserializeScalarValue(reader.Value, propInfo.EntityPropertyType, propInfo.Type.GetElementType()); arrayItems.Add(value); }
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 EndArrayProperty(XmlReader reader) { if (string.CompareOrdinal(XmlConvert.DecodeName(reader.LocalName), this.stack.Peek().elementName) != 0) { throw new InvalidOperationException(string.Format("Expecting </{0}> but encountered {1}", this.stack.Peek().elementName, reader.LocalName)); } StackFrame frame = this.stack.Pop(); EntityPropertyInfo propInfo = frame.entityPropertyInfo; Array values = Array.CreateInstance(propInfo.Type.GetElementType(), this.arrayItems.Count); for (int i = 0; i < values.Length; i++) { values.SetValue(this.arrayItems[i], i); } SetPropertyValue(frame, values); arrayItems.Clear(); this.state = frame.state; }
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; } }