private void ReadStructAttributes(object obj, StructMapping mapping) { if (!m_reader.HasAttributes) { return; } string text = null; foreach (MemberMapping value in mapping.Attributes.Values) { if (value.Type == typeof(string)) { text = 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 (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; WriteMember(writer, obj, member.GetValue(obj), member, member.Name, ns2); } } }
private static StructMapping ImportStructMapping(Type type) { StructMapping structMapping = new StructMapping(type); foreach (XmlElementAttribute item in (IEnumerable)type.GetCustomAttributes(typeof(XmlElementClassAttribute), inherit: true)) { if (item.Type == null || type == item.Type) { if (item.Namespace != null) { structMapping.Namespace = item.Namespace; } if (item.ElementName != null) { structMapping.Name = item.ElementName; } break; } } ImportTypeMembers(structMapping, type); structMapping.ResolveChildAttributes(); return(structMapping); }
private void WriteStructure(XmlWriter writer, object component, object obj, string name, string ns, MemberMapping member, StructMapping mapping) { if (obj != null) { WriteStartElement(writer, component, name, ns, member); WriteStructContent(writer, obj, mapping, ns); writer.WriteEndElement(); } }
private void ReadStructContent(object obj, StructMapping mapping) { m_reader.MoveToContent(); string name = m_reader.Name; string namespaceURI = m_reader.NamespaceURI; ReadStructAttributes(obj, mapping); if (m_reader.IsEmptyElement) { m_reader.Skip(); return; } m_reader.ReadStartElement(); m_reader.MoveToContent(); while (m_reader.NodeType != XmlNodeType.EndElement && m_reader.NodeType != 0) { string localName = m_reader.LocalName; string namespaceURI2 = 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) { ReadChildAttribute(obj, mapping, childAttribute); } } if (memberMapping.IsReadOnly) { if (!TypeMapper.IsPrimitiveType(type)) { object value = memberMapping.GetValue(obj); if (value != null) { ReadObjectContent(value, memberMapping, 0); } else { m_reader.Skip(); } } else { m_reader.Skip(); } } else { object obj2 = ReadObject(type, memberMapping, 0); if (obj2 != null) { memberMapping.SetValue(obj, obj2); } } } else { if (namespaceURI2 != string.Empty && m_validNamespaces.Contains(namespaceURI2)) { IXmlLineInfo xmlLineInfo = (IXmlLineInfo)m_reader; throw new XmlException(RDLValidatingReaderStrings.rdlValidationInvalidMicroVersionedElement(m_reader.Name, name, xmlLineInfo.LineNumber.ToString(CultureInfo.InvariantCulture.NumberFormat), xmlLineInfo.LinePosition.ToString(CultureInfo.InvariantCulture.NumberFormat))); } m_reader.Skip(); } m_reader.MoveToContent(); } m_reader.ReadEndElement(); }
private static void ImportPropertyInfo(StructMapping mapping, PropertyInfo prop) { Type type = prop.PropertyType; bool flag = false; if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>)) { flag = true; type = type.GetGenericArguments()[0]; } bool flag2 = false; XmlAttributes xmlAttributes = new XmlAttributes(); object[] array = type.GetCustomAttributes(inherit: true); object[] customAttributes = prop.GetCustomAttributes(inherit: true); bool flag3 = false; int num = array.Length; Array.Resize(ref array, num + customAttributes.Length); customAttributes.CopyTo(array, num); object[] array2 = array; foreach (object obj in array2) { 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 tagName = prop.Name; string ns = string.Empty; if (!flag2) { GetMemberName(xmlAttributes, ref tagName, ref ns); } if (mapping.GetElement(tagName, ns) != null || mapping.GetAttribute(tagName, ns) != null) { return; } PropertyMapping propertyMapping = new PropertyMapping(type, tagName, ns, prop); propertyMapping.XmlAttributes = xmlAttributes; mapping.Members.Add(propertyMapping); if (xmlAttributes.XmlAttribute != null) { if (xmlAttributes.XmlAttribute is XmlChildAttributeAttribute) { mapping.AddChildAttribute(propertyMapping); } else { mapping.Attributes[tagName, ns] = propertyMapping; } } else { mapping.Elements[tagName, ns] = propertyMapping; if (flag2) { mapping.AddUseTypeInfo(tagName, ns); } } Type declaringType = prop.DeclaringType; if (!declaringType.IsSubclassOf(typeof(ReportObject))) { return; } Type type3 = declaringType.Assembly.GetType(declaringType.FullName + "+Definition+Properties", throwOnError: 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", throwOnError: false); propertyMapping.Definition = (IPropertyDefinition)type3.InvokeMember("GetProperty", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.InvokeMethod, null, null, new object[1] { propertyMapping.Index }, CultureInfo.InvariantCulture); } } }