GetApplicableAttributes() public method

public GetApplicableAttributes ( Type types ) : Platform.Xml.Serialization.XmlSerializationAttribute[]
types System.Type
return Platform.Xml.Serialization.XmlSerializationAttribute[]
        private void Scan(SerializationMemberInfo memberInfo, TypeSerializerCache cache, SerializerOptions options)
        {
            XmlSerializationAttribute[] attribs;

            var attributes = new List<Attribute>();

            // Get the ElementType attributes specified on the type itself as long
            // as we're not the type itself!

            if (memberInfo.MemberInfo != memberInfo.ReturnType)
            {
                var smi = new SerializationMemberInfo(memberInfo.ReturnType, options, cache);

                attribs = smi.GetApplicableAttributes(typeof(XmlDictionaryElementTypeAttribute));

                foreach (XmlSerializationAttribute a in attribs)
                {
                    attributes.Add(a);
                }
            }

            // Get the ElementType attributes specified on the member.

            attribs = memberInfo.GetApplicableAttributes(typeof(XmlDictionaryElementTypeAttribute));

            foreach (var a in attribs)
            {
                attributes.Add(a);
            }

            foreach (XmlDictionaryElementTypeAttribute attribute in attributes)
            {
                var dictionaryItem = new DictionaryItem();

                var smi2 = new SerializationMemberInfo(attribute.ElementType, options, cache);

                if (attribute.TypeAlias == null)
                {
                    attribute.TypeAlias = smi2.SerializedName;
                }

                dictionaryItem.attribute = attribute;
                dictionaryItem.typeAlias = attribute.TypeAlias;

                // Check if a specific type of serializer is specified.

                if (attribute.SerializerType == null)
                {
                    // Figure out the serializer based on the type of the element.

                    dictionaryItem.serializer = cache.GetTypeSerializerBySupportedType(attribute.ElementType, smi2);
                }
                else
                {
                    // Get the type of serializer they specify.

                    dictionaryItem.serializer = cache.GetTypeSerializerBySerializerType(attribute.SerializerType, smi2);
                }

                primaryDictionaryItem = dictionaryItem;

                typeToItemMap[attribute.ElementType] = dictionaryItem;
                aliasToItemMap[attribute.TypeAlias] = dictionaryItem;
            }

            if (aliasToItemMap.Count != 1)
            {
                primaryDictionaryItem = null;
            }
        }
 public RuntimeTypeTypeSerializer(SerializationMemberInfo memberInfo, TypeSerializerCache cache, SerializerOptions options)
 {
     verifyAttributes = (XmlSerializationAttribute[])memberInfo.GetApplicableAttributes(typeof(XmlVerifyRuntimeTypeAttribute));
 }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="memberInfo"></param>
        /// <param name="cache"></param>
        /// <param name="options"></param>
        private void Scan(SerializationMemberInfo memberInfo, TypeSerializerCache cache, SerializerOptions options)
        {
            IList attributes;
            SerializationMemberInfo smi;

            XmlSerializationAttribute[] attribs;

            attributes = new ArrayList(10);

            // Get the ElementType attributes specified on the type itself as long
            // as we're not the type itself!

            if (memberInfo.MemberInfo != memberInfo.LogicalType)
            {
                smi = new SerializationMemberInfo(memberInfo.LogicalType, options, cache);

                attribs = smi.GetApplicableAttributes(typeof(XmlListElementAttribute));

                foreach (Attribute a in attribs)
                {
                    attributes.Add(a);
                }
            }

            // Get the ElementType attributes specified on the member.

            attribs = memberInfo.GetApplicableAttributes(typeof(XmlListElementAttribute));

            foreach (Attribute a in attribs)
            {
                attributes.Add(a);
            }


            foreach (XmlListElementAttribute attribute in attributes)
            {
                SerializationMemberInfo smi2;
                ListItem listItem = new ListItem();

                smi2 = new SerializationMemberInfo(attribute.ItemType, options, cache);

                if (attribute.Alias == null)
                {
                    attribute.Alias = smi2.SerializedName;
                }

                listItem.Attribute = attribute;
                listItem.Alias     = attribute.Alias;

                // Check if a specific type of serializer is specified.

                if (attribute.SerializerType == null)
                {
                    // Figure out the serializer based on the type of the element.

                    listItem.Serializer = cache.GetTypeSerializerBySupportedType(attribute.ItemType, smi2);
                }
                else
                {
                    // Get the type of serializer they specify.

                    listItem.Serializer = cache.GetTypeSerializerBySerializerType(attribute.SerializerType, smi2);
                }

                m_TypeToItemMap[attribute.ItemType] = listItem;
                m_AliasToItemMap[attribute.Alias]   = listItem;
            }

            if (m_TypeToItemMap.Count == 0)
            {
                if (memberInfo.LogicalType.IsArray)
                {
                    ListItem listItem;
                    Type     elementType;

                    listItem = new ListItem();

                    elementType    = memberInfo.LogicalType.GetElementType();
                    listItem.Alias = elementType.Name;

                    listItem.Serializer = cache.GetTypeSerializerBySupportedType(elementType, new SerializationMemberInfo(elementType, options, cache));

                    m_TypeToItemMap[elementType]     = listItem;
                    m_AliasToItemMap[listItem.Alias] = listItem;
                }
            }

            if (m_TypeToItemMap.Count == 0)
            {
                throw new InvalidOperationException("Must specify at least one XmlListElementype.");
            }

            m_ListType = memberInfo.LogicalType;

            if (m_ListType.IsAbstract)
            {
                m_ListType = typeof(ArrayList);
            }
        }
Esempio n. 4
0
		protected virtual void Scan(SerializationMemberInfo memberInfo, TypeSerializerCache cache, SerializerOptions options)
		{
			XmlSerializationAttribute[] attribs;

			var attributes = new List<Attribute>();

			// Get the ElementType attributes specified on the type itself as long
			// as we're not the type itself!

			if (memberInfo.MemberInfo != memberInfo.ReturnType)
			{
				var smi = new SerializationMemberInfo(memberInfo.ReturnType, options, cache);

				attribs = smi.GetApplicableAttributes(typeof(XmlListElementAttribute));

				foreach (var a in attribs)
				{
					attributes.Add(a);
				}
			}
			
			// Get the ElementType attributes specified on the member.

			attribs = memberInfo.GetApplicableAttributes(typeof(XmlListElementAttribute));

			foreach (var a in attribs)
			{
				attributes.Add(a);
			}
			
			foreach (XmlListElementAttribute attribute in attributes)
			{
				var listItem = new ListItem();
				
				if (attribute.Type == null)
				{
					if (serializationMemberInfo.ReturnType.IsArray)
					{
						attribute.Type = serializationMemberInfo.ReturnType.GetElementType();
					}
					else if (serializationMemberInfo.ReturnType.IsGenericType)
					{
						attribute.Type = serializationMemberInfo.ReturnType.GetGenericArguments()[0];
					}
				}
			
				var smi2 = new SerializationMemberInfo(attribute.ItemType, options, cache);

				if (attribute.Alias == null)
				{
					attribute.Alias = smi2.SerializedName;
				}

				listItem.Attribute = attribute;
				listItem.Alias = attribute.Alias;

				// Check if a specific type of serializer is specified.

				if (attribute.SerializerType == null)
				{
					// Figure out the serializer based on the type of the element.

					listItem.Serializer = cache.GetTypeSerializerBySupportedType(attribute.ItemType, smi2);
				}
				else
				{
					// Get the type of serializer they specify.

					listItem.Serializer = cache.GetTypeSerializerBySerializerType(attribute.SerializerType, smi2);
				}

				typeToItemMap[attribute.ItemType] = listItem;
				aliasToItemMap[attribute.Alias] = listItem;
			}

			if (typeToItemMap.Count == 0)
			{
				if (memberInfo.ReturnType.IsArray)
				{
					var listItem = new ListItem();
					var elementType = memberInfo.ReturnType.GetElementType();
					var sm = new SerializationMemberInfo(elementType, options, cache);

					listItem.Alias = sm.SerializedName;

					listItem.Serializer = cache.GetTypeSerializerBySupportedType(elementType, new SerializationMemberInfo(elementType, options, cache));

					typeToItemMap[elementType] = listItem;
					aliasToItemMap[listItem.Alias] = listItem;
				}
			}

			if (memberInfo.ReturnType.IsGenericType)
			{
				var elementType = memberInfo.ReturnType.GetGenericArguments()[0];

				if (!typeToItemMap.ContainsKey(elementType) && dynamicTypeResolver == null && !(elementType.IsAbstract || elementType.IsInterface))
				{
					var listItem = new ListItem();
					var sm = new SerializationMemberInfo(elementType, options, cache);

					listItem.Alias = sm.SerializedName;

					listItem.Serializer = cache.GetTypeSerializerBySupportedType(elementType, new SerializationMemberInfo(elementType, options, cache));

					typeToItemMap[elementType] = listItem;
					aliasToItemMap[listItem.Alias] = listItem;
				}
			}

			if (typeToItemMap.Count == 0 && this.dynamicTypeResolver == null)
			{
			    throw new InvalidOperationException(
			        string.Format(
			            "Must specify at least one XmlListElemenType or an XmlListElementTypeSerializerProvider for field {0}",
			             ((Type)memberInfo.MemberInfo).FullName));
			}

			listType = memberInfo.ReturnType;		
		}
        protected virtual void Scan(SerializationMemberInfo memberInfo, TypeSerializerCache cache, SerializerOptions options)
        {
            XmlSerializationAttribute[] attribs;

            var attributes = new List<Attribute>();

            // Get the ElementType attributes specified on the type itself as long
            // as we're not the type itself!

            if (memberInfo.MemberInfo != memberInfo.ReturnType)
            {
                var smi = new SerializationMemberInfo(memberInfo.ReturnType, options, cache);

                attribs = smi.GetApplicableAttributes(typeof(XmlListElementAttribute));

                foreach (var a in attribs)
                {
                    attributes.Add(a);
                }
            }

            // Get the ElementType attributes specified on the member.

            attribs = memberInfo.GetApplicableAttributes(typeof(XmlListElementAttribute));

            foreach (var a in attribs)
            {
                attributes.Add(a);
            }

            foreach (var attribute1 in attributes)
            {
                var attribute = (XmlListElementAttribute)attribute1;
                var listItem = new ListItem();

                if (attribute.Type == null)
                {
                    if (serializationMemberInfo.ReturnType.IsArray)
                    {
                        attribute.Type = serializationMemberInfo.ReturnType.GetElementType();
                    }
                    else if (serializationMemberInfo.ReturnType.IsGenericType)
                    {
                        attribute.Type = serializationMemberInfo.ReturnType.GetGenericArguments()[0];
                    }
                }

                var smi2 = new SerializationMemberInfo(attribute.ItemType, options, cache);

                if (attribute.Alias == null)
                {
                    attribute.Alias = smi2.SerializedName;
                }

                listItem.Attribute = attribute;
                listItem.Alias = attribute.Alias;

                // Check if a specific type of serializer is specified.

                if (attribute.SerializerType == null)
                {
                    // Figure out the serializer based on the type of the element.

                    listItem.Serializer = cache.GetTypeSerializerBySupportedType(attribute.ItemType, smi2);
                }
                else
                {
                    // Get the type of serializer they specify.

                    listItem.Serializer = cache.GetTypeSerializerBySerializerType(attribute.SerializerType, smi2);
                }

                typeToItemMap[attribute.ItemType] = listItem;
                aliasToItemMap[attribute.Alias] = listItem;
            }

            if (typeToItemMap.Count == 0)
            {
                if (memberInfo.ReturnType.IsArray)
                {
                    var listItem = new ListItem();
                    var elementType = memberInfo.ReturnType.GetElementType();
                    var sm = new SerializationMemberInfo(elementType, options, cache);

                    listItem.Alias = sm.SerializedName;

                    listItem.Serializer = cache.GetTypeSerializerBySupportedType(elementType, new SerializationMemberInfo(elementType, options, cache));

                    typeToItemMap[elementType] = listItem;
                    aliasToItemMap[listItem.Alias] = listItem;
                }
            }

            if (memberInfo.ReturnType.IsGenericType)
            {
                var elementType = memberInfo.ReturnType.GetGenericArguments()[0];

                if (!typeToItemMap.ContainsKey(elementType) && dynamicTypeResolver == null && !(elementType.IsAbstract || elementType.IsInterface))
                {
                    var listItem = new ListItem();
                    var sm = new SerializationMemberInfo(elementType, options, cache);

                    listItem.Alias = sm.SerializedName;

                    listItem.Serializer = cache.GetTypeSerializerBySupportedType(elementType, new SerializationMemberInfo(elementType, options, cache));

                    typeToItemMap[elementType] = listItem;
                    aliasToItemMap[listItem.Alias] = listItem;
                }
            }

            if (typeToItemMap.Count == 0 && this.dynamicTypeResolver == null)
            {
                throw new InvalidOperationException(
                    $"Must specify at least one XmlListElemenType or an XmlListElementTypeSerializerProvider for field {((Type)memberInfo.MemberInfo).FullName}");
            }

            listType = memberInfo.ReturnType;
        }
 public RuntimeTypeTypeSerializer(SerializationMemberInfo memberInfo, TypeSerializerCache cache, SerializerOptions options)
 {
     verifyAttributes = (XmlSerializationAttribute[])memberInfo.GetApplicableAttributes(typeof(XmlVerifyRuntimeTypeAttribute));
 }
Esempio n. 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="memberInfo"></param>
        /// <param name="cache"></param>
        /// <param name="options"></param>
        private void Scan(SerializationMemberInfo memberInfo, TypeSerializerCache cache, SerializerOptions options)
        {
            IList attributes;
            SerializationMemberInfo smi;
            XmlSerializationAttribute[] attribs;

            attributes = new ArrayList(10);

            // Get the ElementType attributes specified on the type itself as long
            // as we're not the type itself!

            if (memberInfo.MemberInfo != memberInfo.LogicalType)
            {
                smi = new SerializationMemberInfo(memberInfo.LogicalType, options, cache);

                attribs = smi.GetApplicableAttributes(typeof(XmlListElementAttribute));

                foreach (Attribute a in attribs)
                {
                    attributes.Add(a);
                }
            }

            // Get the ElementType attributes specified on the member.

            attribs = memberInfo.GetApplicableAttributes(typeof(XmlListElementAttribute));

            foreach (Attribute a in attribs)
            {
                attributes.Add(a);
            }

            foreach (XmlListElementAttribute attribute in attributes)
            {
                SerializationMemberInfo smi2;
                ListItem listItem = new ListItem();

                smi2 = new SerializationMemberInfo(attribute.ItemType, options, cache);

                if (attribute.Alias == null)
                {
                    attribute.Alias = smi2.SerializedName;
                }

                listItem.Attribute = attribute;
                listItem.Alias = attribute.Alias;

                // Check if a specific type of serializer is specified.

                if (attribute.SerializerType == null)
                {
                    // Figure out the serializer based on the type of the element.

                    listItem.Serializer = cache.GetTypeSerializerBySupportedType(attribute.ItemType, smi2);
                }
                else
                {
                    // Get the type of serializer they specify.

                    listItem.Serializer = cache.GetTypeSerializerBySerializerType(attribute.SerializerType, smi2);
                }

                m_TypeToItemMap[attribute.ItemType] = listItem;
                m_AliasToItemMap[attribute.Alias] = listItem;
            }

            if (m_TypeToItemMap.Count == 0)
            {
                if (memberInfo.LogicalType.IsArray)
                {
                    ListItem listItem;
                    Type elementType;

                    listItem = new ListItem();

                    elementType = memberInfo.LogicalType.GetElementType();
                    listItem.Alias = elementType.Name;

                    listItem.Serializer = cache.GetTypeSerializerBySupportedType(elementType, new SerializationMemberInfo(elementType, options, cache));

                    m_TypeToItemMap[elementType] = listItem;
                    m_AliasToItemMap[listItem.Alias] = listItem;
                }
            }

            if (m_TypeToItemMap.Count == 0)
            {
                throw new InvalidOperationException("Must specify at least one XmlListElementype.");
            }

            m_ListType = memberInfo.LogicalType;

            if (m_ListType.IsAbstract)
            {
                m_ListType = typeof(ArrayList);
            }
        }
        private void Scan(SerializationMemberInfo memberInfo, TypeSerializerCache cache, SerializerOptions options)
        {
            XmlSerializationAttribute[] attribs;

            var attributes = new List <Attribute>();

            // Get the ElementType attributes specified on the type itself as long
            // as we're not the type itself!

            if (memberInfo.MemberInfo != memberInfo.ReturnType)
            {
                var smi = new SerializationMemberInfo(memberInfo.ReturnType, options, cache);

                attribs = smi.GetApplicableAttributes(typeof(XmlDictionaryElementTypeAttribute));

                foreach (XmlSerializationAttribute a in attribs)
                {
                    attributes.Add(a);
                }
            }

            // Get the ElementType attributes specified on the member.

            attribs = memberInfo.GetApplicableAttributes(typeof(XmlDictionaryElementTypeAttribute));

            foreach (var a in attribs)
            {
                attributes.Add(a);
            }

            foreach (XmlDictionaryElementTypeAttribute attribute in attributes)
            {
                var dictionaryItem = new DictionaryItem();

                var smi2 = new SerializationMemberInfo(attribute.ElementType, options, cache);

                if (attribute.TypeAlias == null)
                {
                    attribute.TypeAlias = smi2.SerializedName;
                }

                dictionaryItem.attribute = attribute;
                dictionaryItem.typeAlias = attribute.TypeAlias;

                // Check if a specific type of serializer is specified.

                if (attribute.SerializerType == null)
                {
                    // Figure out the serializer based on the type of the element.

                    dictionaryItem.serializer = cache.GetTypeSerializerBySupportedType(attribute.ElementType, smi2);
                }
                else
                {
                    // Get the type of serializer they specify.

                    dictionaryItem.serializer = cache.GetTypeSerializerBySerializerType(attribute.SerializerType, smi2);
                }

                primaryDictionaryItem = dictionaryItem;

                typeToItemMap[attribute.ElementType] = dictionaryItem;
                aliasToItemMap[attribute.TypeAlias]  = dictionaryItem;
            }

            if (aliasToItemMap.Count != 1)
            {
                primaryDictionaryItem = null;
            }
        }