public static XmlAttributeOverrides Create(Type objectType) { XmlAttributeOverrides xOver = null; if (!table.TryGetValue(objectType, out xOver)) { // Create XmlAttributeOverrides object. xOver = new XmlAttributeOverrides(); /* Create an XmlTypeAttribute and change the name of the XML type. */ XmlTypeAttribute xType = new XmlTypeAttribute(); xType.TypeName = objectType.Name; // Set the XmlTypeAttribute to the XmlType property. XmlAttributes attrs = new XmlAttributes(); attrs.XmlType = xType; /* Add the XmlAttributes to the XmlAttributeOverrides, specifying the member to override. */ xOver.Add(objectType, attrs); table.MergeSafe(objectType, xOver); } return xOver; }
public XmlMetadata(Type type, XmlTypeAttribute xmlType, XmlRootAttribute xmlRoot, IEnumerable<Type> xmlIncludes) { Type = type; XmlType = xmlType; XmlRoot = xmlRoot; XmlIncludes = xmlIncludes; }
public void TypeNameDefault () { XmlTypeAttribute attr = new XmlTypeAttribute (); Assert.AreEqual (string.Empty, attr.TypeName, "#1"); attr.TypeName = null; Assert.AreEqual (string.Empty, attr.TypeName, "#2"); }
void IDictionaryMetaInitializer.Initialize(IDictionaryAdapterFactory factory, DictionaryAdapterMeta dictionaryMeta) { var type = dictionaryMeta.Type; bool? qualified = null; bool? isNullable = null; string defaultNamespace = null; XmlTypeAttribute xmlType = null; XmlRootAttribute xmlRoot = null; List<Type> xmlIncludes = null; new BehaviorVisitor() .OfType<XmlTypeAttribute>(attrib => xmlType = attrib) .OfType<XmlRootAttribute>(attrib => xmlRoot = attrib) .OfType<XmlDefaultsAttribute>(attrib => { qualified = attrib.Qualified; isNullable = attrib.IsNullable; }) .OfType<XmlNamespaceAttribute>(attrib => { if (attrib.Default) { defaultNamespace = attrib.NamespaceUri; } }) .OfType<XmlIncludeAttribute>(attrib => { xmlIncludes = xmlIncludes ?? new List<Type>(); if (type != attrib.Type && type.IsAssignableFrom(attrib.Type)) { xmlIncludes.Add(attrib.Type); } }) .Apply(dictionaryMeta.Behaviors); if (xmlType == null) { xmlType = new XmlTypeAttribute(); } if (string.IsNullOrEmpty(xmlType.TypeName)) { xmlType.TypeName = type.Name; if (xmlType.TypeName.StartsWith("I")) { xmlType.TypeName = xmlType.TypeName.Substring(1); } } if (xmlType.Namespace == null) { xmlType.Namespace = defaultNamespace; } dictionaryMeta.SetXmlMeta(new XmlMetadata(type, qualified, isNullable, xmlType, xmlRoot, xmlIncludes)); }
public XmlMetadata(Type type, bool? qualified, bool? isNullable, XmlTypeAttribute xmlType, XmlRootAttribute xmlRoot, IEnumerable<Type> xmlIncludes) { Type = type; Qualified = qualified; IsNullable = isNullable; XmlType = xmlType; XmlRoot = xmlRoot; XmlIncludes = xmlIncludes; }
void IDictionaryMetaInitializer.Initialize(IDictionaryAdapterFactory factory, DictionaryAdapterMeta dictionaryMeta) { var type = dictionaryMeta.Type; string defaultNamespace = null; XmlTypeAttribute xmlType = null; XmlRootAttribute xmlRoot = null; List<Type> xmlIncludes = null; new BehaviorVisitor() .OfType<XmlTypeAttribute>(attrib => { xmlType = attrib; }) .OfType<XmlRootAttribute>(attrib => { xmlRoot = attrib; }) .OfType<XmlNamespaceAttribute>(attrib => { if (attrib.Default) defaultNamespace = attrib.NamespaceUri; }) .OfType<XmlIncludeAttribute>(attrib => { xmlIncludes = xmlIncludes ?? new List<Type>(); if (type != attrib.Type && type.IsAssignableFrom(attrib.Type)) { xmlIncludes.Add(attrib.Type); } }) .Apply(dictionaryMeta.Behaviors); if (xmlType == null) { xmlType = new XmlTypeAttribute { TypeName = type.Name, Namespace = defaultNamespace }; if (xmlType.TypeName.StartsWith("I")) { xmlType.TypeName = xmlType.TypeName.Substring(1); } } else if (xmlType.Namespace == null) xmlType.Namespace = defaultNamespace; dictionaryMeta.SetXmlMeta(new XmlMetadata(type, xmlType, xmlRoot, xmlIncludes)); }
public XmlTypeAttribute GetTypeAttribute() { XmlTypeAttribute type = new XmlTypeAttribute(); if (!string.IsNullOrWhiteSpace(this.TypeName)) { type.TypeName = this.TypeName; } if (!string.IsNullOrWhiteSpace(this.Namespace)) { type.Namespace = this.Namespace; } return type; }
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlAttributes1"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public XmlAttributes(ICustomAttributeProvider provider) { xmlIgnore = GetAttr(provider, typeof(XmlIgnoreAttribute)) != null; if (!xmlIgnore) { object[] attrs = provider.GetCustomAttributes(typeof(XmlElementAttribute), false); for (int i = 0; i < attrs.Length; i++) { this.xmlElements.Add((XmlElementAttribute)attrs[i]); } attrs = provider.GetCustomAttributes(typeof(XmlArrayItemAttribute), false); for (int i = 0; i < attrs.Length; i++) { this.xmlArrayItems.Add((XmlArrayItemAttribute)attrs[i]); } attrs = provider.GetCustomAttributes(typeof(XmlAnyElementAttribute), false); for (int i = 0; i < attrs.Length; i++) { this.xmlAnyElements.Add((XmlAnyElementAttribute)attrs[i]); } DefaultValueAttribute defaultValueAttribute = (DefaultValueAttribute)GetAttr(provider, typeof(DefaultValueAttribute)); if (defaultValueAttribute != null) { xmlDefaultValue = defaultValueAttribute.Value; } xmlAttribute = (XmlAttributeAttribute)GetAttr(provider, typeof(XmlAttributeAttribute)); xmlArray = (XmlArrayAttribute)GetAttr(provider, typeof(XmlArrayAttribute)); xmlText = (XmlTextAttribute)GetAttr(provider, typeof(XmlTextAttribute)); xmlEnum = (XmlEnumAttribute)GetAttr(provider, typeof(XmlEnumAttribute)); xmlRoot = (XmlRootAttribute)GetAttr(provider, typeof(XmlRootAttribute)); xmlType = (XmlTypeAttribute)GetAttr(provider, typeof(XmlTypeAttribute)); xmlAnyAttribute = (XmlAnyAttributeAttribute)GetAttr(provider, typeof(XmlAnyAttributeAttribute)); xmlChoiceIdentifier = (XmlChoiceIdentifierAttribute)GetAttr(provider, typeof(XmlChoiceIdentifierAttribute)); xmlns = GetAttr(provider, typeof(XmlNamespaceDeclarationsAttribute)) != null; } }
public void DifferentTypesSameXmlTypes() { XmlAttributeOverrides ov1 = new XmlAttributeOverrides(); XmlAttributeOverrides ov2 = new XmlAttributeOverrides(); XmlTypeAttribute att1 = new XmlTypeAttribute("myType"); XmlTypeAttribute att2 = new XmlTypeAttribute("myType"); XmlAttributes atts1 = new XmlAttributes(); atts1.XmlType = att1; XmlAttributes atts2 = new XmlAttributes(); atts2.XmlType = att2; ov1.Add(typeof(SerializeMe), atts1); ov2.Add(typeof(SerializeMeToo), atts2); ThumbprintHelpers.DifferentThumbprint(ov1, ov2); }
public void SameXmlTypeDifferentObjects() { XmlAttributeOverrides ov1 = new XmlAttributeOverrides(); XmlAttributeOverrides ov2 = new XmlAttributeOverrides(); XmlTypeAttribute att = new XmlTypeAttribute("myType"); XmlAttributes atts1 = new XmlAttributes(); atts1.XmlType = att; XmlAttributes atts2 = new XmlAttributes(); atts2.XmlType = att; ov1.Add(typeof(SerializeMe), atts1); ov2.Add(typeof(SerializeMe), atts2); ThumbprintHelpers.SameThumbprint(ov1, ov2); }
public void SameXmlTypeTwice() { XmlAttributeOverrides ov = new XmlAttributeOverrides(); XmlTypeAttribute att = new XmlTypeAttribute("myType"); XmlAttributes atts = new XmlAttributes(); atts.XmlType = att; ov.Add(typeof(SerializeMe), atts); ThumbprintHelpers.SameThumbprint(ov, ov); }
public XmlAttributes (ICustomAttributeProvider provider) { object[] attributes = provider.GetCustomAttributes(false); foreach(object obj in attributes) { if(obj is XmlAnyAttributeAttribute) xmlAnyAttribute = (XmlAnyAttributeAttribute) obj; else if(obj is XmlAnyElementAttribute) xmlAnyElements.Add((XmlAnyElementAttribute) obj); else if(obj is XmlArrayAttribute) xmlArray = (XmlArrayAttribute) obj; else if(obj is XmlArrayItemAttribute) xmlArrayItems.Add((XmlArrayItemAttribute) obj); else if(obj is XmlAttributeAttribute) xmlAttribute = (XmlAttributeAttribute) obj; else if(obj is XmlChoiceIdentifierAttribute) xmlChoiceIdentifier = (XmlChoiceIdentifierAttribute) obj; else if(obj is DefaultValueAttribute) xmlDefaultValue = ((DefaultValueAttribute)obj).Value; else if(obj is XmlElementAttribute ) xmlElements.Add((XmlElementAttribute ) obj); else if(obj is XmlEnumAttribute) xmlEnum = (XmlEnumAttribute) obj; else if(obj is XmlIgnoreAttribute) xmlIgnore = true; else if(obj is XmlNamespaceDeclarationsAttribute) xmlns = true; else if(obj is XmlRootAttribute) xmlRoot = (XmlRootAttribute) obj; else if(obj is XmlTextAttribute) xmlText = (XmlTextAttribute) obj; else if(obj is XmlTypeAttribute) xmlType = (XmlTypeAttribute) obj; } }
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlAttributes1"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public XmlAttributes(MemberInfo memberInfo) { object[] attrs = memberInfo.GetCustomAttributes(false).ToArray(); // most generic <any/> matches everithig XmlAnyElementAttribute wildcard = null; for (int i = 0; i < attrs.Length; i++) { if (attrs[i] is XmlIgnoreAttribute || attrs[i] is ObsoleteAttribute || attrs[i].GetType() == IgnoreAttribute) { _xmlIgnore = true; break; } else if (attrs[i] is XmlElementAttribute) { _xmlElements.Add((XmlElementAttribute)attrs[i]); } else if (attrs[i] is XmlArrayItemAttribute) { _xmlArrayItems.Add((XmlArrayItemAttribute)attrs[i]); } else if (attrs[i] is XmlAnyElementAttribute) { XmlAnyElementAttribute any = (XmlAnyElementAttribute)attrs[i]; if ((any.Name == null || any.Name.Length == 0) && any.NamespaceSpecified && any.Namespace == null) { // ignore duplicate wildcards wildcard = any; } else { _xmlAnyElements.Add((XmlAnyElementAttribute)attrs[i]); } } else if (attrs[i] is DefaultValueAttribute) { _xmlDefaultValue = ((DefaultValueAttribute)attrs[i]).Value; } else if (attrs[i] is XmlAttributeAttribute) { _xmlAttribute = (XmlAttributeAttribute)attrs[i]; } else if (attrs[i] is XmlArrayAttribute) { _xmlArray = (XmlArrayAttribute)attrs[i]; } else if (attrs[i] is XmlTextAttribute) { _xmlText = (XmlTextAttribute)attrs[i]; } else if (attrs[i] is XmlEnumAttribute) { _xmlEnum = (XmlEnumAttribute)attrs[i]; } else if (attrs[i] is XmlRootAttribute) { _xmlRoot = (XmlRootAttribute)attrs[i]; } else if (attrs[i] is XmlTypeAttribute) { _xmlType = (XmlTypeAttribute)attrs[i]; } else if (attrs[i] is XmlAnyAttributeAttribute) { _xmlAnyAttribute = (XmlAnyAttributeAttribute)attrs[i]; } else if (attrs[i] is XmlChoiceIdentifierAttribute) { _xmlChoiceIdentifier = (XmlChoiceIdentifierAttribute)attrs[i]; } else if (attrs[i] is XmlNamespaceDeclarationsAttribute) { _xmlns = true; } } if (_xmlIgnore) { _xmlElements.Clear(); _xmlArrayItems.Clear(); _xmlAnyElements.Clear(); _xmlDefaultValue = null; _xmlAttribute = null; _xmlArray = null; _xmlText = null; _xmlEnum = null; _xmlType = null; _xmlAnyAttribute = null; _xmlChoiceIdentifier = null; _xmlns = false; } else { if (wildcard != null) { _xmlAnyElements.Add(wildcard); } } }
public void ExportClass_TestDefault_Overrides () { XmlAttributeOverrides overrides = new XmlAttributeOverrides (); XmlAttributes attr = new XmlAttributes (); XmlTypeAttribute xmlType = new XmlTypeAttribute ("flagenum"); xmlType.Namespace = "yetanother:urn"; attr.XmlType = xmlType; overrides.Add (typeof (FlagEnum_Encoded), attr); XmlSchemas schemas = Export (typeof (TestDefault), overrides, "NSTestDefault"); Assert.AreEqual (2, schemas.Count, "#1"); StringWriter sw = new StringWriter (); schemas [0].Write (sw); Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" + "<xs:schema xmlns:tns=\"urn:myNS\" elementFormDefault=\"qualified\" targetNamespace=\"urn:myNS\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" + " <xs:import namespace=\"yetanother:urn\" />{0}" + " <xs:element name=\"testDefault\" type=\"tns:TestDefault\" />{0}" + " <xs:complexType name=\"TestDefault\">{0}" + " <xs:sequence>{0}" + " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" + " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"Default Value\" name=\"strDefault\" type=\"xs:string\" />{0}" + " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"true\" name=\"boolT\" type=\"xs:boolean\" />{0}" + " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"false\" name=\"boolF\" type=\"xs:boolean\" />{0}" + " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"10\" name=\"decimalval\" type=\"xs:decimal\" />{0}" + " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"one four\" name=\"flag\" type=\"tns:FlagEnum\" />{0}" + " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"e1 e4\" name=\"flagencoded\" xmlns:q1=\"yetanother:urn\" type=\"q1:flagenum\" />{0}" + " </xs:sequence>{0}" + " </xs:complexType>{0}" + " <xs:simpleType name=\"FlagEnum\">{0}" + " <xs:list>{0}" + " <xs:simpleType>{0}" + " <xs:restriction base=\"xs:string\">{0}" + " <xs:enumeration value=\"one\" />{0}" + " <xs:enumeration value=\"two\" />{0}" + " <xs:enumeration value=\"four\" />{0}" + " </xs:restriction>{0}" + " </xs:simpleType>{0}" + " </xs:list>{0}" + " </xs:simpleType>{0}" + "</xs:schema>", Environment.NewLine), sw.ToString (), "#2"); sw.GetStringBuilder ().Length = 0; schemas [1].Write (sw); Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" + "<xs:schema xmlns:tns=\"yetanother:urn\" elementFormDefault=\"qualified\" targetNamespace=\"yetanother:urn\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" + " <xs:simpleType name=\"flagenum\">{0}" + " <xs:list>{0}" + " <xs:simpleType>{0}" + " <xs:restriction base=\"xs:string\">{0}" + " <xs:enumeration value=\"e1\" />{0}" + " <xs:enumeration value=\"e2\" />{0}" + " <xs:enumeration value=\"e4\" />{0}" + " </xs:restriction>{0}" + " </xs:simpleType>{0}" + " </xs:list>{0}" + " </xs:simpleType>{0}" + "</xs:schema>", Environment.NewLine), sw.ToString (), "#3"); }
/// <summary> /// Adds new attribute to the node decorations. /// </summary> /// <param name="attr">An attriubute.</param> protected void Add( object attr ) { if( attr is NodePolicyAttribute ) { if( _nodePolicy == null ) _nodePolicy = (NodePolicyAttribute)attr; } else if( attr is ConverterAttribute ) { if( _converter == null ) _converter = (ConverterAttribute)attr; } else if( attr is TransparentAttribute ) { _transparent = (TransparentAttribute)attr; } else if( attr is SkipNavigableRootAttribute ) { _skipNavigableRoot = (SkipNavigableRootAttribute)attr; } else if( attr is ChildXmlElementAttribute ) { _childXmlElementName = (ChildXmlElementAttribute)attr; } else if( attr is XmlRootAttribute ) { if( _xmlRoot == null ) _xmlRoot = (XmlRootAttribute)attr; } else if( attr is XmlAttributeAttribute ) { if( NodeTypeUndefined() ) _xmlAttribute = (XmlAttributeAttribute)attr; } else if( attr is XmlElementAttribute ) { if( NodeTypeUndefined() ) { _xmlElement = (XmlElementAttribute)attr; _isNullable = _xmlElement.IsNullable; } } else if( attr is XmlAnyElementAttribute ) { if( NodeTypeUndefined() ) _xmlAnyElement = (XmlAnyElementAttribute)attr; } else if( attr is XmlTextAttribute ) { if( NodeTypeUndefined() ) _xmlText = (XmlTextAttribute)attr; } else if( attr is XmlIgnoreAttribute ) { _xmlIgnore = (XmlIgnoreAttribute)attr; } else if( attr is XmlTypeAttribute ) { _xmlType = (XmlTypeAttribute)attr; } }
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlAttributes1"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public XmlAttributes(ICustomAttributeProvider provider) { xmlIgnore = GetAttr(provider, typeof(XmlIgnoreAttribute)) != null; if (!xmlIgnore) { object[] attrs = provider.GetCustomAttributes(typeof(XmlElementAttribute), false); for (int i = 0; i < attrs.Length; i++) this.xmlElements.Add((XmlElementAttribute)attrs[i]); attrs = provider.GetCustomAttributes(typeof(XmlArrayItemAttribute), false); for (int i = 0; i < attrs.Length; i++) this.xmlArrayItems.Add((XmlArrayItemAttribute)attrs[i]); attrs = provider.GetCustomAttributes(typeof(XmlAnyElementAttribute), false); for (int i = 0; i < attrs.Length; i++) this.xmlAnyElements.Add((XmlAnyElementAttribute)attrs[i]); DefaultValueAttribute defaultValueAttribute = (DefaultValueAttribute)GetAttr(provider, typeof(DefaultValueAttribute)); if (defaultValueAttribute != null) xmlDefaultValue = defaultValueAttribute.Value; xmlAttribute = (XmlAttributeAttribute)GetAttr(provider, typeof(XmlAttributeAttribute)); xmlArray = (XmlArrayAttribute)GetAttr(provider, typeof(XmlArrayAttribute)); xmlText = (XmlTextAttribute)GetAttr(provider, typeof(XmlTextAttribute)); xmlEnum = (XmlEnumAttribute)GetAttr(provider, typeof(XmlEnumAttribute)); xmlRoot = (XmlRootAttribute)GetAttr(provider, typeof(XmlRootAttribute)); xmlType = (XmlTypeAttribute)GetAttr(provider, typeof(XmlTypeAttribute)); xmlAnyAttribute = (XmlAnyAttributeAttribute)GetAttr(provider, typeof(XmlAnyAttributeAttribute)); xmlChoiceIdentifier = (XmlChoiceIdentifierAttribute)GetAttr(provider, typeof(XmlChoiceIdentifierAttribute)); xmlns = GetAttr(provider, typeof(XmlNamespaceDeclarationsAttribute)) != null; } }
public XmlAttributes(ICustomAttributeProvider provider) { this.xmlElements = new XmlElementAttributes(); this.xmlArrayItems = new XmlArrayItemAttributes(); this.xmlAnyElements = new XmlAnyElementAttributes(); object[] customAttributes = provider.GetCustomAttributes(false); XmlAnyElementAttribute attribute = null; for (int i = 0; i < customAttributes.Length; i++) { if (((customAttributes[i] is XmlIgnoreAttribute) || (customAttributes[i] is ObsoleteAttribute)) || (customAttributes[i].GetType() == IgnoreAttribute)) { this.xmlIgnore = true; break; } if (customAttributes[i] is XmlElementAttribute) { this.xmlElements.Add((XmlElementAttribute)customAttributes[i]); } else if (customAttributes[i] is XmlArrayItemAttribute) { this.xmlArrayItems.Add((XmlArrayItemAttribute)customAttributes[i]); } else if (customAttributes[i] is XmlAnyElementAttribute) { XmlAnyElementAttribute attribute2 = (XmlAnyElementAttribute)customAttributes[i]; if (((attribute2.Name == null) || (attribute2.Name.Length == 0)) && (attribute2.NamespaceSpecified && (attribute2.Namespace == null))) { attribute = attribute2; } else { this.xmlAnyElements.Add((XmlAnyElementAttribute)customAttributes[i]); } } else if (customAttributes[i] is DefaultValueAttribute) { this.xmlDefaultValue = ((DefaultValueAttribute)customAttributes[i]).Value; } else if (customAttributes[i] is XmlAttributeAttribute) { this.xmlAttribute = (XmlAttributeAttribute)customAttributes[i]; } else if (customAttributes[i] is XmlArrayAttribute) { this.xmlArray = (XmlArrayAttribute)customAttributes[i]; } else if (customAttributes[i] is XmlTextAttribute) { this.xmlText = (XmlTextAttribute)customAttributes[i]; } else if (customAttributes[i] is XmlEnumAttribute) { this.xmlEnum = (XmlEnumAttribute)customAttributes[i]; } else if (customAttributes[i] is XmlRootAttribute) { this.xmlRoot = (XmlRootAttribute)customAttributes[i]; } else if (customAttributes[i] is XmlTypeAttribute) { this.xmlType = (XmlTypeAttribute)customAttributes[i]; } else if (customAttributes[i] is XmlAnyAttributeAttribute) { this.xmlAnyAttribute = (XmlAnyAttributeAttribute)customAttributes[i]; } else if (customAttributes[i] is XmlChoiceIdentifierAttribute) { this.xmlChoiceIdentifier = (XmlChoiceIdentifierAttribute)customAttributes[i]; } else if (customAttributes[i] is XmlNamespaceDeclarationsAttribute) { this.xmlns = true; } } if (this.xmlIgnore) { this.xmlElements.Clear(); this.xmlArrayItems.Clear(); this.xmlAnyElements.Clear(); this.xmlDefaultValue = null; this.xmlAttribute = null; this.xmlArray = null; this.xmlText = null; this.xmlEnum = null; this.xmlType = null; this.xmlAnyAttribute = null; this.xmlChoiceIdentifier = null; this.xmlns = false; } else if (attribute != null) { this.xmlAnyElements.Add(attribute); } }
private static void AddXmlTypePrint(XmlTypeAttribute att, StringBuilder printBuilder) { if (null != att) { printBuilder.Append(att.IncludeInSchema); printBuilder.Append("/"); printBuilder.Append(att.Namespace); printBuilder.Append("/"); printBuilder.Append(att.TypeName); } printBuilder.Append("%%"); }
public void AddTypeAttributes(string messageName, string typeNS, CodeAttributeDeclarationCollection typeAttributes, bool isEncoded) { // we do not need top-level attibutes for the encoded SOAP if (isEncoded) return; XmlTypeAttribute xmlType = new XmlTypeAttribute(); xmlType.Namespace = typeNS; typeAttributes.Add(OperationGenerator.GenerateAttributeDeclaration(context.Contract.ServiceContractGenerator, xmlType)); }
public XmlAttributes(ICustomAttributeProvider provider) { object[] attributes = provider.GetCustomAttributes(false); foreach (object obj in attributes) { if (obj is XmlAnyAttributeAttribute) { xmlAnyAttribute = (XmlAnyAttributeAttribute)obj; } else if (obj is XmlAnyElementAttribute) { xmlAnyElements.Add((XmlAnyElementAttribute)obj); } else if (obj is XmlArrayAttribute) { xmlArray = (XmlArrayAttribute)obj; } else if (obj is XmlArrayItemAttribute) { xmlArrayItems.Add((XmlArrayItemAttribute)obj); } else if (obj is XmlAttributeAttribute) { xmlAttribute = (XmlAttributeAttribute)obj; } else if (obj is XmlChoiceIdentifierAttribute) { xmlChoiceIdentifier = (XmlChoiceIdentifierAttribute)obj; } else if (obj is DefaultValueAttribute) { xmlDefaultValue = ((DefaultValueAttribute)obj).Value; } else if (obj is XmlElementAttribute) { xmlElements.Add((XmlElementAttribute )obj); } else if (obj is XmlEnumAttribute) { xmlEnum = (XmlEnumAttribute)obj; } else if (obj is XmlIgnoreAttribute) { xmlIgnore = true; } else if (obj is XmlNamespaceDeclarationsAttribute) { xmlns = true; } else if (obj is XmlRootAttribute) { xmlRoot = (XmlRootAttribute)obj; } else if (obj is XmlTextAttribute) { xmlText = (XmlTextAttribute)obj; } else if (obj is XmlTypeAttribute) { xmlType = (XmlTypeAttribute)obj; } } if (xmlIgnore) { xmlAnyAttribute = null; xmlAnyElements.Clear(); xmlArray = null; xmlArrayItems.Clear(); xmlAttribute = null; xmlChoiceIdentifier = null; xmlDefaultValue = null; xmlElements.Clear(); xmlEnum = null; xmlns = false; xmlRoot = null; xmlText = null; xmlType = null; } }
public void IncludeInSchemaDefault () { XmlTypeAttribute attr = new XmlTypeAttribute (); Assert.AreEqual (true, attr.IncludeInSchema); }
public void TestSerializeDefaultValueAttribute () { XmlAttributeOverrides overrides = new XmlAttributeOverrides (); XmlAttributes attr = new XmlAttributes (); string defaultValueInstance = "nothing"; attr.XmlDefaultValue = defaultValueInstance; overrides.Add (typeof (SimpleClass), "something", attr); // use the default SimpleClass simple = new SimpleClass (); Serialize (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#A1"); // same value as default simple.something = defaultValueInstance; Serialize (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#A2"); // some other value simple.something = "hello"; Serialize (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something>hello</something></SimpleClass>"), WriterText, "#A3"); overrides = new XmlAttributeOverrides (); attr = new XmlAttributes (); attr.XmlAttribute = new XmlAttributeAttribute (); attr.XmlDefaultValue = defaultValueInstance; overrides.Add (typeof (SimpleClass), "something", attr); // use the default simple = new SimpleClass (); Serialize (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#B1"); // same value as default simple.something = defaultValueInstance; Serialize (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#B2"); // some other value simple.something = "hello"; Serialize (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass something='hello' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#B3"); overrides = new XmlAttributeOverrides (); attr = new XmlAttributes (); attr.XmlAttribute = new XmlAttributeAttribute ("flagenc"); overrides.Add (typeof (TestDefault), "flagencoded", attr); // use the default TestDefault testDefault = new TestDefault (); Serialize (testDefault); Assert.AreEqual (Infoset ("<testDefault xmlns='urn:myNS' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#C1"); // use the default with overrides Serialize (testDefault, overrides); Assert.AreEqual (Infoset ("<testDefault flagenc='e1 e4' xmlns='urn:myNS' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#C2"); overrides = new XmlAttributeOverrides (); attr = new XmlAttributes (); attr.XmlAttribute = new XmlAttributeAttribute ("flagenc"); attr.XmlDefaultValue = (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e4); // add default again overrides.Add (typeof (TestDefault), "flagencoded", attr); // use the default with overrides Serialize (testDefault, overrides); Assert.AreEqual (Infoset ("<testDefault xmlns='urn:myNS' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#C3"); // use the default with overrides and default namspace Serialize (testDefault, overrides, AnotherNamespace); Assert.AreEqual (Infoset ("<testDefault xmlns='urn:myNS' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#C4"); // non-default values testDefault.strDefault = "Some Text"; testDefault.boolT = false; testDefault.boolF = true; testDefault.decimalval = 20m; testDefault.flag = FlagEnum.e2; testDefault.flagencoded = FlagEnum_Encoded.e2 | FlagEnum_Encoded.e1; Serialize (testDefault); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<testDefault xmlns='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault>Some Text</strDefault>" + " <boolT>false</boolT>" + " <boolF>true</boolF>" + " <decimalval>20</decimalval>" + " <flag>two</flag>" + " <flagencoded>e1 e2</flagencoded>" + "</testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)), WriterText, "#C5"); Serialize (testDefault, overrides); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<testDefault flagenc='e1 e2' xmlns='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault>Some Text</strDefault>" + " <boolT>false</boolT>" + " <boolF>true</boolF>" + " <decimalval>20</decimalval>" + " <flag>two</flag>" + "</testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)), WriterText, "#C6"); Serialize (testDefault, overrides, AnotherNamespace); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<testDefault flagenc='e1 e2' xmlns='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault>Some Text</strDefault>" + " <boolT>false</boolT>" + " <boolF>true</boolF>" + " <decimalval>20</decimalval>" + " <flag>two</flag>" + "</testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)), WriterText, "#C7"); attr = new XmlAttributes (); XmlTypeAttribute xmlType = new XmlTypeAttribute ("flagenum"); xmlType.Namespace = "yetanother:urn"; attr.XmlType = xmlType; overrides.Add (typeof (FlagEnum_Encoded), attr); Serialize (testDefault, overrides, AnotherNamespace); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<testDefault flagenc='e1 e2' xmlns='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault>Some Text</strDefault>" + " <boolT>false</boolT>" + " <boolF>true</boolF>" + " <decimalval>20</decimalval>" + " <flag>two</flag>" + "</testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)), WriterText, "#C8"); attr = new XmlAttributes (); attr.XmlType = new XmlTypeAttribute ("testDefault"); overrides.Add (typeof (TestDefault), attr); Serialize (testDefault, overrides, AnotherNamespace); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<testDefault flagenc='e1 e2' xmlns='{2}' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault>Some Text</strDefault>" + " <boolT>false</boolT>" + " <boolF>true</boolF>" + " <decimalval>20</decimalval>" + " <flag>two</flag>" + "</testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace, AnotherNamespace)), WriterText, "#C9"); }
public static void AddTypeMemberMapping(XmlAttributeOverrideMappingArgs mappings, Type type, string typeName, string namespaces) { XmlAttributes at = new XmlAttributes(); XmlTypeAttribute att = new XmlTypeAttribute(typeName); att.Namespace = namespaces; at.XmlType = att; mappings.XmlMemberOverrides.Add(type, at); }
public void NamespaceDefault () { XmlTypeAttribute attr = new XmlTypeAttribute (); Assert.IsNull (attr.Namespace); }