private void ReadStructAttributes(object obj, StructMapping mapping) { if (this.m_reader.HasAttributes) { string text = null; foreach (MemberMapping value in mapping.Attributes.Values) { if (value.Type == typeof(string)) { text = this.m_reader.GetAttribute(value.Name, value.Namespace); if (text != null) { value.SetValue(obj, text); } } } } }
private void WriteStructContent(XmlWriter writer, object obj, StructMapping mapping, string ns) { foreach (MemberMapping value2 in mapping.Attributes.Values) { if (value2.Type == typeof(string) && value2.XmlAttributes.XmlElements.Count == 0) { object value = value2.GetValue(obj); if (this.ShouldSerializeValue(obj, value, value2)) { writer.WriteAttributeString(value2.Name, value2.Namespace, (value != null) ? ((string)value) : ""); } } } foreach (MemberMapping member in mapping.Members) { if (member.XmlAttributes.XmlAttribute == null) { string ns2 = (member.Namespace != string.Empty) ? member.Namespace : ns; this.WriteMember(writer, obj, member.GetValue(obj), member, member.Name, ns2); } } }
private static void ImportPropertyInfo(StructMapping mapping, PropertyInfo prop) { Type type = prop.PropertyType; bool flag = false; if (type.IsGenericType) { Type genericTypeDefinition = type.GetGenericTypeDefinition(); if (genericTypeDefinition == typeof(Nullable <>)) { flag = true; type = type.GetGenericArguments()[0]; } } bool flag2 = false; XmlAttributes xmlAttributes = new XmlAttributes(); object[] customAttributes = type.GetCustomAttributes(true); object[] customAttributes2 = prop.GetCustomAttributes(true); bool flag3 = false; int num = customAttributes.Length; Array.Resize(ref customAttributes, num + customAttributes2.Length); customAttributes2.CopyTo(customAttributes, num); object[] array = customAttributes; foreach (object obj in array) { Type type2 = obj.GetType(); if (type2 == typeof(XmlIgnoreAttribute)) { return; } if (typeof(DefaultValueAttribute).IsAssignableFrom(type2)) { xmlAttributes.XmlDefaultValue = ((DefaultValueAttribute)obj).Value; } else if (typeof(XmlElementAttribute).IsAssignableFrom(type2)) { XmlElementAttribute xmlElementAttribute = (XmlElementAttribute)obj; xmlAttributes.XmlElements.Add(xmlElementAttribute); if (xmlElementAttribute.Type != null) { if (string.IsNullOrEmpty(xmlElementAttribute.ElementName)) { type = xmlElementAttribute.Type; } else { flag2 = true; } } } else if (type2 == typeof(XmlArrayItemAttribute)) { XmlArrayItemAttribute xmlArrayItemAttribute = (XmlArrayItemAttribute)obj; int j; for (j = 0; j < xmlAttributes.XmlArrayItems.Count && xmlAttributes.XmlArrayItems[j].NestingLevel <= xmlArrayItemAttribute.NestingLevel; j++) { } xmlAttributes.XmlArrayItems.Insert(j, xmlArrayItemAttribute); } else if (typeof(XmlAttributeAttribute).IsAssignableFrom(type2)) { xmlAttributes.XmlAttribute = (XmlAttributeAttribute)obj; } else if (type2 == typeof(ValidValuesAttribute) || type2 == typeof(ValidEnumValuesAttribute)) { flag3 = true; } } string name = prop.Name; string empty = string.Empty; if (!flag2) { TypeMapper.GetMemberName(xmlAttributes, ref name, ref empty); } if (mapping.GetElement(name, empty) == null && mapping.GetAttribute(name, empty) == null) { PropertyMapping propertyMapping = new PropertyMapping(type, name, empty, prop); propertyMapping.XmlAttributes = xmlAttributes; mapping.Members.Add(propertyMapping); if (xmlAttributes.XmlAttribute != null) { if (xmlAttributes.XmlAttribute is XmlChildAttributeAttribute) { mapping.AddChildAttribute(propertyMapping); } else { mapping.Attributes[name, empty] = propertyMapping; } } else { mapping.Elements[name, empty] = propertyMapping; if (flag2) { mapping.AddUseTypeInfo(name, empty); } } Type declaringType = prop.DeclaringType; if (declaringType.IsSubclassOf(typeof(ReportObject))) { Type type3 = declaringType.Assembly.GetType(declaringType.FullName + "+Definition+Properties", false); FieldInfo field; if (type3 != null && type3.IsEnum && (field = type3.GetField(prop.Name)) != null) { propertyMapping.Index = (int)field.GetRawConstantValue(); propertyMapping.TypeCode = PropertyMapping.PropertyTypeCode.Object; if (flag) { propertyMapping.TypeCode = PropertyMapping.PropertyTypeCode.Object; } else if (type.IsSubclassOf(typeof(IContainedObject))) { propertyMapping.TypeCode = PropertyMapping.PropertyTypeCode.ContainedObject; } else if (type == typeof(bool)) { propertyMapping.TypeCode = PropertyMapping.PropertyTypeCode.Boolean; } else if (type == typeof(int)) { propertyMapping.TypeCode = PropertyMapping.PropertyTypeCode.Integer; } else if (type == typeof(ReportSize)) { propertyMapping.TypeCode = PropertyMapping.PropertyTypeCode.Size; } else if (type.IsEnum) { propertyMapping.TypeCode = PropertyMapping.PropertyTypeCode.Enum; } else if (type.IsValueType) { propertyMapping.TypeCode = PropertyMapping.PropertyTypeCode.ValueType; } if (flag3) { type3 = declaringType.Assembly.GetType(declaringType.FullName + "+Definition", false); propertyMapping.Definition = (IPropertyDefinition)type3.InvokeMember("GetProperty", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.InvokeMethod, null, null, new object[1] { propertyMapping.Index }, CultureInfo.InvariantCulture); } } } } }
private void ReadStructContent(object obj, StructMapping mapping) { this.m_reader.MoveToContent(); string name = this.m_reader.Name; string namespaceURI = this.m_reader.NamespaceURI; this.ReadStructAttributes(obj, mapping); if (this.m_reader.IsEmptyElement) { this.m_reader.Skip(); } else { this.m_reader.ReadStartElement(); this.m_reader.MoveToContent(); while (this.m_reader.NodeType != XmlNodeType.EndElement && this.m_reader.NodeType != 0) { string localName = this.m_reader.LocalName; string namespaceURI2 = this.m_reader.NamespaceURI; namespaceURI2 = ((namespaceURI == namespaceURI2) ? string.Empty : namespaceURI2); MemberMapping memberMapping = mapping.GetElement(localName, namespaceURI2); Type type = null; if (memberMapping != null) { type = memberMapping.Type; } else { List <MemberMapping> typeNameElements = mapping.GetTypeNameElements(); if (typeNameElements != null) { bool flag = false; for (int i = 0; i < typeNameElements.Count; i++) { memberMapping = typeNameElements[i]; XmlElementAttributes xmlElements = memberMapping.XmlAttributes.XmlElements; if (base.XmlOverrides != null) { XmlAttributes xmlAttributes = base.XmlOverrides[obj.GetType()]; if (xmlAttributes == null) { xmlAttributes = base.XmlOverrides[memberMapping.Type]; } if (xmlAttributes != null && xmlAttributes.XmlElements != null) { xmlElements = xmlAttributes.XmlElements; } } foreach (XmlElementAttribute item in xmlElements) { if (item.ElementName == localName && item.Type != null) { type = item.Type; flag = true; break; } } if (flag) { break; } } } } if (type != null) { if (memberMapping.ChildAttributes != null) { foreach (MemberMapping childAttribute in memberMapping.ChildAttributes) { this.ReadChildAttribute(obj, mapping, childAttribute); } } if (memberMapping.IsReadOnly) { if (!TypeMapper.IsPrimitiveType(type)) { object value = memberMapping.GetValue(obj); if (value != null) { this.ReadObjectContent(value, memberMapping, 0); } else { this.m_reader.Skip(); } } else { this.m_reader.Skip(); } } else { object obj2 = this.ReadObject(type, memberMapping, 0); if (obj2 != null) { memberMapping.SetValue(obj, obj2); } } } else { if (namespaceURI2 != string.Empty && this.m_validNamespaces.Contains(namespaceURI2)) { IXmlLineInfo xmlLineInfo = (IXmlLineInfo)this.m_reader; string message = RDLValidatingReaderStrings.rdlValidationInvalidMicroVersionedElement(this.m_reader.Name, name, xmlLineInfo.LineNumber.ToString(CultureInfo.InvariantCulture.NumberFormat), xmlLineInfo.LinePosition.ToString(CultureInfo.InvariantCulture.NumberFormat)); throw new XmlException(message); } this.m_reader.Skip(); } this.m_reader.MoveToContent(); } this.m_reader.ReadEndElement(); } }
private void WriteStructure(XmlWriter writer, object component, object obj, string name, string ns, MemberMapping member, StructMapping mapping) { if (obj != null) { this.WriteStartElement(writer, component, name, ns, member); this.WriteStructContent(writer, obj, mapping, ns); writer.WriteEndElement(); } }