示例#1
0
		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;
			}
		}
示例#2
0
		public void DataTypeDefault ()
		{
			XmlAttributeAttribute attr = new XmlAttributeAttribute ();
			Assert.AreEqual (string.Empty, attr.DataType, "#1");

			attr.DataType = null;
			Assert.AreEqual (string.Empty, attr.DataType, "#2");
		}
示例#3
0
		public void AttributeNameDefault ()
		{
			XmlAttributeAttribute attr = new XmlAttributeAttribute ();
			Assert.AreEqual (string.Empty, attr.AttributeName, "#1");

			attr.AttributeName = null;
			Assert.AreEqual (string.Empty, attr.AttributeName, "#2");
		}
示例#4
0
        //attributes have to be simple types, either enum, string, int, double, bool
        private static void AddXMLAttributte(FileLevelInfo info, XmlAttributeAttribute xa, ClassSnippet snip, FieldInfo finfo)
        {
            string fieldName = xa.AttributeName;
              string dtype = SetupSimpleType(info, snip, xa.DataType, fieldName, finfo.FieldType.Name);

              snip.fromXml += "\t"+fieldName+" = FromString_" + dtype +"(pEm, pEm->Attribute(\"" + fieldName + "\"));\n";
              snip.toXml += "\tpEm->SetAttribute(\"" + fieldName + "\", ToString_" + dtype + "(" + fieldName + "));\n";

              snip.declarations += "\t" + dtype + " " + fieldName + ";\n";
        }
		public void XmlArraySameName()
		{
			XmlAttributeAttribute attribute1 = new XmlAttributeAttribute("myname");
			XmlAttributeAttribute attribute2 = new XmlAttributeAttribute("myname");

			atts1.XmlAttribute = attribute1;
			atts2.XmlAttribute = attribute2;

			ov1.Add(typeof(SerializeMe), atts1);
			ov2.Add(typeof(SerializeMe), atts2);

			ThumbprintHelpers.SameThumbprint(ov1, ov2);
		}
		public void XmlArrayDifferentNames()
		{
			XmlAttributeAttribute attribute1 = new XmlAttributeAttribute("myname");
			XmlAttributeAttribute attribute2 = new XmlAttributeAttribute("myothername");

			atts1.XmlAttribute = attribute1;
			atts2.XmlAttribute = attribute2;

			ov1.Add(typeof(SerializeMe), atts1);
			ov2.Add(typeof(SerializeMe), atts2);

			ThumbprintHelpers.DifferentThumbprint(ov1, ov2);
		}
        public XmlAttributeAttribute GetAttributeAttribute()
        {
            XmlAttributeAttribute attr = new XmlAttributeAttribute();

            if (!string.IsNullOrWhiteSpace(this.AttributeName))
            {
                attr.AttributeName = this.AttributeName;
            }

            if (!string.IsNullOrWhiteSpace(this.DataType))
            {
                attr.DataType = this.DataType;
            }

            return attr;
        }
示例#8
0
        public XmlSerializer CreateOverrider( )
        {
            // Create the XmlAttributeOverrides and XmlAttributes objects.
            XmlAttributeOverrides xOver = new XmlAttributeOverrides( );
            XmlAttributes xAttrs = new XmlAttributes( );

            /* Create an overriding XmlAttributeAttribute set it to
            the XmlAttribute property of the XmlAttributes object.*/
            XmlAttributeAttribute xAttribute = new XmlAttributeAttribute( "NameTest" );
            xAttrs.XmlAttribute = xAttribute;

            // Add to the XmlAttributeOverrides. Specify the member name.
            xOver.Add( typeof( Data ) , "Category" , xAttrs );

            // Create the XmlSerializer and return it.
            return new XmlSerializer( typeof( Data ) , xOver );
        }
示例#9
0
        /// <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 DifferentMemberName()
		{
			XmlAttributeAttribute attribute1 = new XmlAttributeAttribute("myname");
			XmlAttributeAttribute attribute2 = new XmlAttributeAttribute("myname");

			atts1.XmlAttribute = attribute1;
			atts2.XmlAttribute = attribute2;

			ov1.Add(typeof(SerializeMe), "TheMember", atts1);
			ov2.Add(typeof(SerializeMe), "TheOtherMember", atts2);

			ThumbprintHelpers.DifferentThumbprint(ov1, ov2);
		}
		public void XmlArrayDifferentForm()
		{
			XmlAttributeAttribute attribute1 = new XmlAttributeAttribute("myname");
			attribute1.Form = System.Xml.Schema.XmlSchemaForm.Qualified;
			XmlAttributeAttribute attribute2 = new XmlAttributeAttribute("myname");
			attribute2.Form = System.Xml.Schema.XmlSchemaForm.Unqualified;

			atts1.XmlAttribute = attribute1;
			atts2.XmlAttribute = attribute2;

			ov1.Add(typeof(SerializeMe), atts1);
			ov2.Add(typeof(SerializeMe), atts2);

			ThumbprintHelpers.DifferentThumbprint(ov1, ov2);
		}
示例#12
0
        public static T FromXML <T>(XmlNode Xml, IFormatProvider Provider) where T : new()
        {
            Type TypeEntity = typeof(T);

            T Entity = new T();


            //List<> of Types
            if (TypeEntity.IsGenericType && typeof(System.Collections.IList).IsAssignableFrom(TypeEntity.GetGenericTypeDefinition()))
            {
                foreach (XmlNode node in Xml.ChildNodes)
                {
                    object ret = node.InnerXml;
                    if (node.NodeType != XmlNodeType.XmlDeclaration)
                    {
                        Type UnderlyingType = TypeEntity.GetGenericArguments()[0];

                        Type[] BasicTypes = { typeof(String), typeof(Int16), typeof(Int32), typeof(Int64), typeof(Boolean), typeof(DateTime), typeof(System.Char), typeof(System.Decimal), typeof(System.Double), typeof(System.Single), typeof(System.TimeSpan), typeof(System.Byte) };


                        //If not a basic Type , try to deep more in the dom tree deserializing the inner XML Value
                        if (BasicTypes.SingleOrDefault((t) => { return(t == UnderlyingType); }) == null)
                        {
                            //Otherwise of arrays convert to XML to send
                            var fromXMLMethods = typeof(Gale.Serialization).GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
                            System.Reflection.MethodInfo fromXMLMethodInfo = fromXMLMethods.FirstOrDefault(mi => mi.Name == "FromXML" && mi.GetGenericArguments().Count() == 1 && mi.GetParameters()[0].ParameterType == typeof(XmlNode));

                            System.Reflection.MethodInfo method = fromXMLMethodInfo.MakeGenericMethod(new Type[] { UnderlyingType });
                            ret = method.Invoke(null, new object[] { node });
                        }

                        (Entity as System.Collections.IList).Add(Convert.ChangeType(ret, UnderlyingType));
                    }
                }
                return((T)Entity);
            }

            List <PropertyInfo> setterProperties = (from PropertyInfo p in TypeEntity.GetProperties() where p.GetIndexParameters().Count() == 0 select p).ToList();

            //Delegate
            Action <PropertyInfo, object> setValue = (Property, Value) =>
            {
                try
                {
                    Property.SetValue(Entity, Value, null);
                }
                catch
                {
                    throw new Gale.Exception.GaleException("InvalidSetValueInXMLDeserialization", Value.ToString(), Property.Name, Property.PropertyType.ToString());
                }
            };

            //For Each
            setterProperties.ForEach((prop) =>
            {
                if (object.ReferenceEquals(prop.DeclaringType, TypeEntity))
                {
                    System.Xml.Serialization.XmlAttributeAttribute customAttribute = (System.Xml.Serialization.XmlAttributeAttribute)prop.GetCustomAttributes(typeof(System.Xml.Serialization.XmlAttributeAttribute), false).FirstOrDefault();
                    Type propertyType          = prop.PropertyType;
                    string nodeValue           = null;
                    System.Xml.XmlNode noderef = null;

                    if (customAttribute != null)
                    {
                        XmlAttribute attrib = Xml.Attributes[customAttribute.AttributeName];
                        if (attrib != null)
                        {
                            nodeValue = attrib.InnerXml;
                        }
                    }
                    else
                    {
                        System.Xml.Serialization.XmlElementAttribute xmlattrib = (System.Xml.Serialization.XmlElementAttribute)prop.GetCustomAttributes(typeof(System.Xml.Serialization.XmlElementAttribute), false).FirstOrDefault();
                        XmlNode propertyNode = Xml.SelectSingleNode((xmlattrib != null) ? xmlattrib.ElementName : prop.Name);
                        if (propertyNode != null)
                        {
                            noderef   = propertyNode;
                            nodeValue = propertyNode.InnerXml;
                        }
                    }

                    if (nodeValue != null && nodeValue != String.Empty)
                    {
                        if (Type.Equals(propertyType, typeof(decimal)))
                        {
                            setValue(prop, System.Convert.ToDecimal(nodeValue, Provider));
                        }
                        else if (Type.Equals(propertyType, typeof(double)))
                        {
                            setValue(prop, System.Convert.ToDouble(nodeValue, Provider));
                        }
                        else if (Type.Equals(propertyType, typeof(Int16)))
                        {
                            setValue(prop, System.Convert.ToInt16(nodeValue, Provider));
                        }
                        else if (Type.Equals(propertyType, typeof(Int32)))
                        {
                            setValue(prop, System.Convert.ToInt32(nodeValue, Provider));
                        }
                        else if (Type.Equals(propertyType, typeof(Int64)))
                        {
                            setValue(prop, System.Convert.ToInt64(nodeValue, Provider));
                        }
                        else if (Type.Equals(propertyType, typeof(bool)))
                        {
                            setValue(prop, System.Convert.ToBoolean(nodeValue, Provider));
                        }
                        else if (Type.Equals(propertyType, typeof(DateTime)))
                        {
                            setValue(prop, System.Convert.ToDateTime(nodeValue, Provider));
                        }
                        else if (Type.Equals(propertyType, typeof(string)))
                        {
                            setValue(prop, System.Convert.ToString(nodeValue, Provider));
                        }
                        else if (propertyType.IsArray)
                        {
                            if (nodeValue != string.Empty)
                            {
                                Type UnderlyingType = propertyType.GetElementType();  //Array or a Generic List (Almost the same things)
                                // Creates and initializes a new Array of type Int32.
                                Array typedArray = Array.CreateInstance(UnderlyingType, noderef.ChildNodes.Count);

                                int arrayIndex = 0;
                                foreach (XmlNode node in noderef.ChildNodes)
                                {
                                    object ret = node.InnerXml;
                                    if (node.NodeType != XmlNodeType.XmlDeclaration)
                                    {
                                        //If not a basic Type , try to deep more in the dom tree deserializing the inner XML Value
                                        Type[] BasicTypes = { typeof(String), typeof(Int16), typeof(Int32), typeof(Int64), typeof(Boolean), typeof(DateTime), typeof(System.Char), typeof(System.Decimal), typeof(System.Double), typeof(System.Single), typeof(System.TimeSpan), typeof(System.Byte) };
                                        if (BasicTypes.SingleOrDefault((t) => { return(t == UnderlyingType); }) == null)
                                        {
                                            //Otherwise of arrays convert to XML to send
                                            var fromXMLMethods = typeof(Gale.Serialization).GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
                                            System.Reflection.MethodInfo fromXMLMethodInfo = fromXMLMethods.FirstOrDefault(mi => mi.Name == "FromXML" && mi.GetGenericArguments().Count() == 1 && mi.GetParameters()[0].ParameterType == typeof(XmlNode));

                                            System.Reflection.MethodInfo method = fromXMLMethodInfo.MakeGenericMethod(new Type[] { UnderlyingType });
                                            ret = method.Invoke(null, new object[] { node });
                                        }

                                        typedArray.SetValue(Convert.ChangeType(ret, UnderlyingType), arrayIndex);
                                    }
                                    arrayIndex++;
                                }

                                setValue(prop, typedArray);
                            }
                        }
                        else if (propertyType.IsGenericType)
                        {
                            //If a Parameter Type is Nullable, create the nullable type dinamycally and set it's value
                            Type UnderlyingType    = propertyType.GetGenericArguments()[0];
                            Type GenericDefinition = propertyType.GetGenericTypeDefinition();

                            Type GenericType = GenericDefinition.MakeGenericType(new Type[] { UnderlyingType });

                            object value = null;
                            if (nodeValue != string.Empty)
                            {
                                if (GenericDefinition == typeof(System.Nullable <>))
                                {
                                    value = Convert.ChangeType(nodeValue, UnderlyingType);
                                }
                                else
                                {
                                    //Complex Node Type, (Maybe it's a List of Other Complex Type and go on in the deepest level
                                    //So call the fromXML itself, again and again

                                    //Otherwise of arrays convert to XML to send
                                    var fromXMLMethods = typeof(Gale.Serialization).GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
                                    System.Reflection.MethodInfo fromXMLMethodInfo = fromXMLMethods.FirstOrDefault(mi => mi.Name == "FromXML" && mi.GetGenericArguments().Count() == 1 && mi.GetParameters()[0].ParameterType == typeof(XmlNode));

                                    System.Reflection.MethodInfo method = fromXMLMethodInfo.MakeGenericMethod(new Type[] { GenericType });

                                    value = method.Invoke(null, new object[] { noderef });
                                }
                                setValue(prop, Activator.CreateInstance(GenericType, new object[] { value }));
                            }
                        }
                        else
                        {
                            try
                            {
                                //Its a more complex type ( not generic but yes a object with properties and setter's)
                                if (noderef.ChildNodes.Count > 0)
                                {
                                    //Otherwise of arrays convert to XML to send
                                    var fromXMLMethods = typeof(Gale.Serialization).GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
                                    System.Reflection.MethodInfo fromXMLMethodInfo = fromXMLMethods.FirstOrDefault(mi => mi.Name == "FromXML" && mi.GetGenericArguments().Count() == 1 && mi.GetParameters()[0].ParameterType == typeof(XmlNode));

                                    System.Reflection.MethodInfo method = fromXMLMethodInfo.MakeGenericMethod(new Type[] { propertyType });

                                    var value = method.Invoke(null, new object[] { noderef });

                                    setValue(prop, Convert.ChangeType(value, propertyType));  //try to set into the variable anyways , if throw error then throw invalid cast exception
                                }
                                else
                                {
                                    setValue(prop, Convert.ChangeType(nodeValue, propertyType));  //try to set into the variable anyways , if throw error then throw invalid cast exception
                                }
                            }
                            catch
                            {
                                //TODO: Perform this Section, To Support Non Primitive Object Type
                                throw new Gale.Exception.GaleException("InvalidCastInXMLDeserialization", prop.Name);
                            }
                        }
                    }
                }
            });

            return((T)(Entity));
        }
示例#13
0
		public void TypeDefault ()
		{
			XmlAttributeAttribute attr = new XmlAttributeAttribute ();
			Assert.IsNull (attr.Type);
		}
示例#14
0
		public void NamespaceDefault ()
		{
			XmlAttributeAttribute attr = new XmlAttributeAttribute ();
			Assert.IsNull (attr.Namespace);
		}
示例#15
0
		public void FormDefault ()
		{
			XmlAttributeAttribute attr = new XmlAttributeAttribute ();
			Assert.AreEqual (XmlSchemaForm.None, attr.Form);
		}
 public static void AddAttributeMemberMapping(XmlAttributeOverrideMappingArgs mappings, Type type, string member, string attributeName, string attributeNamespace)
 {
     XmlAttributes at = new XmlAttributes();
     XmlAttributeAttribute att = new XmlAttributeAttribute(attributeName);
     att.Namespace = attributeNamespace;
     at.XmlAttribute = att;
     mappings.XmlMemberOverrides.Add(type, member, at);
 }
		private static void AddXmlAttributePrint(XmlAttributeAttribute att, StringBuilder printBuilder)
		{
			if (null != att)
			{
				printBuilder.Append(att.AttributeName);
				printBuilder.Append("/");
				printBuilder.Append(att.DataType);
				printBuilder.Append("/");
				printBuilder.Append(att.Form);
				printBuilder.Append("/");
				printBuilder.Append(att.Namespace);
				printBuilder.Append("/");
				if (null != att.Type)
				{
					printBuilder.Append(att.Type.AssemblyQualifiedName);
				}
			}
			printBuilder.Append("%%");
		}
示例#18
0
        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;
            }
        }
示例#19
0
        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);
            }
        }
示例#20
0
        /// <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);
                }
            }
        }
示例#21
0
        /// <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;
            }
        }
示例#22
0
        /// <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);
                }
            }
        }
示例#23
0
		/// <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;
			}
		}