Exemplo n.º 1
0
        internal XmlMapping(LogicalType lType, XmlSerializationReflector reflector, bool isSoap)
        {
            System.Diagnostics.Debug.Assert(null != reflector, "The reflector parameter can not be null.");
            System.Diagnostics.Debug.Assert(null != lType, "The logicalType parameter can not be null.");

            serializationReflector = reflector;
            logicalType            = lType;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructs the XmlSerializer using the XmlTypeMapping parameter
 /// to initialize the logical type(reflection data) of the object
 /// that will be serialized/de-serialized.
 /// </summary>
 /// <param name="xmlMapping"></param>
 /// <remarks>
 /// The XmlTypeMapping parameter has already reflected over the type,
 /// we just pull the reflection data from the <see cref="XmlTypeMapping"/> object.
 /// </remarks>
 public XmlSerializer(XmlTypeMapping xmlMapping)
 {
     if (xmlMapping == null)
     {
         throw new ArgumentNullException("xmlMapping");
     }
     _events.sender = this;
     _reflector     = xmlMapping.Reflector;
     _logicalType   = xmlMapping.LogicalType;
     _isEncoded     = xmlMapping.IsSoap;
     if (true /* AppDomain.CompatVersion >= AppDomain.Orcas */)
     {
         _reflector.ReflectionDisabled = true;
     }
 }
Exemplo n.º 3
0
 public XmlReflectionImporter(XmlAttributeOverrides attributeOverrides, string defaultNamespace)
 {
     if (defaultNamespace == null)
     {
         defaultNamespace = String.Empty;
     }
     if (attributeOverrides == null)
     {
         attributeOverrides = new XmlAttributeOverrides();
     }
     _attributeOverrides     = attributeOverrides;
     _defaultNs              = defaultNamespace;
     _defaultNs              = defaultNamespace;
     _attributeOverrides     = attributeOverrides;
     _serializationReflector = new XmlSerializationReflector(_attributeOverrides, _defaultNs);
 }
Exemplo n.º 4
0
 internal XmlMapping(LogicalType lType, XmlSerializationReflector reflector)
     :
     this(lType, reflector, false)
 {
 }
Exemplo n.º 5
0
 internal XmlTypeMapping(LogicalType logicalType, XmlSerializationReflector reflector) : base(logicalType, reflector)
 {
 }
Exemplo n.º 6
0
        /// <summary>
        /// Constructs the XmlSerializer, reflecting over the given
        /// types and any types that are statically referenced from them.
        /// Reflection overrides may be given.
        /// </summary>
        /// <param name="extraTypes">The additional types the serializer should be
        /// prepared to encounter during serialization of the primary <paramref name="type"/>.</param>
        /// <param name="defaultNamespace">The default namespace to use for all the XML elements.</param>
        public XmlSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (defaultNamespace == null)
            {
                defaultNamespace = "";
            }

            _events.sender = this;
            _isEncoded     = false;
            if (root != null)
            {
                if (overrides == null)
                {
                    overrides = new XmlAttributeOverrides();
                }
                // If we're dealing with a nullable type, we need to set the override
                // on the generic type argument as well.
                System.Collections.Generic.List <Type> typesToOverride = new System.Collections.Generic.List <Type>(2);
                typesToOverride.Add(type);
                if (type.GetTypeInfo().IsGenericType&& type.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    Type[] args = type.GetGenericArguments();
                    if (args.Length > 0)
                    { // just in case they passed in typeof(Nullable<>) with no generic arg
                        typesToOverride.Add(args[0]);
                    }
                }
                foreach (Type t in typesToOverride)
                {
                    XmlAttributes attrs = overrides[t];
                    if (attrs != null)
                    {
                        attrs.XmlRoot = root;
                    }
                    else
                    {
                        attrs         = new XmlAttributes();
                        attrs.XmlRoot = root;
                        // Preserve any XmlType that may be declared on the type itself,
                        // since by providing this XmlRoot override, we prevent any declared
                        // XmlTypeAttribute from being reflected.
                        object[] declaredAttributes = t.GetTypeInfo().GetCustomAttributes(typeof(XmlTypeAttribute), false).ToArray();
                        if (declaredAttributes.Length > 0)
                        {
                            // The user shouldn't have more than one defined, but just in case he does,
                            // we read the last reflected one, to emulate the behavior of the
                            // TypeAttributes class.
                            attrs.XmlType = (XmlTypeAttribute)declaredAttributes[declaredAttributes.Length - 1];
                        }
                        overrides.Add(t, attrs);
                    }
                }
            }

            _defaultNamespace = defaultNamespace;
            _reflector        = new XmlSerializationReflector(overrides, defaultNamespace);
            // Reflect over the main type.  Never search over intrinsics so we get a
            // LogicalType with a RootAccessor whose Namespace property reflects the defaultNamespace.
            // In fact, any type's RootAccessor.Namespace may not be set correctly given
            // the defaultNamespace if it was reflected over previously.  But since this
            // is the very first request we make of the m_Reflector, we're going to get
            // the right one.  And this is the only place where that is important.
            _logicalType = _reflector.FindTypeForRoot(type, _isEncoded, defaultNamespace);
            // Reflect over the extra types
            if (extraTypes != null && extraTypes.Length > 0)
            {
                _extraTypes = new LogicalType[extraTypes.Length];
                for (int typeNDX = 0; typeNDX < extraTypes.Length; ++typeNDX)
                {
                    _extraTypes[typeNDX] = findTypeByType(extraTypes[typeNDX], defaultNamespace);
                }
            }
            // Reflect over the included types
            _reflector.ReflectIncludedTypes();
            if (true /* AppDomain.CompatVersion >= AppDomain.Orcas */)
            {
                _reflector.ReflectionDisabled = true;
            }
        }