상속: SpecialMapping
예제 #1
0
 internal void SetBaseMapping(SerializableMapping mapping) {
     baseMapping = mapping;
     if (baseMapping != null) {
         nextDerivedMapping = baseMapping.derivedMappings;
         baseMapping.derivedMappings = this;
         if (this == nextDerivedMapping) {
             throw new InvalidOperationException(Res.GetString(Res.XmlCircularDerivation, TypeDesc.FullName));
         }
     }
 }
        void WriteDerivedSerializable(SerializableMapping head, SerializableMapping mapping, string source, bool isWrappedAny) {
            if (mapping == null)
                return;
            for (SerializableMapping derived = mapping.DerivedMappings; derived != null; derived = derived.NextDerivedMapping) {
                Writer.Write("else if (tser == null");
                Writer.Write(" || ");
                WriteQNameEqual("tser", derived.XsiType.Name, derived.XsiType.Namespace);

                Writer.WriteLine(") {");
                Writer.Indent++;

                if (derived.Type != null) {
                    if (head.Type.IsAssignableFrom(derived.Type)) {
                        WriteSourceBeginTyped(source, head.TypeDesc);
                        Writer.Write("ReadSerializable(( ");
                        Writer.Write(typeof(IXmlSerializable).FullName);
                        Writer.Write(")");
                        Writer.Write(RaCodeGen.GetStringForCreateInstance(derived.TypeDesc.CSharpName, derived.TypeDesc.UseReflection, derived.TypeDesc.CannotNew, false));
                        if (isWrappedAny) {
                            Writer.WriteLine(", true");
                        }
                        Writer.Write(")");
                        WriteSourceEnd(source);
                        Writer.WriteLine(";");
                    }
                    else {
                        Writer.Write("throw CreateBadDerivationException(");
                        WriteQuotedCSharpString(derived.XsiType.Name);
                        Writer.Write(", ");
                        WriteQuotedCSharpString(derived.XsiType.Namespace);
                        Writer.Write(", ");
                        WriteQuotedCSharpString(head.XsiType.Name);
                            Writer.Write(", ");
                        WriteQuotedCSharpString(head.XsiType.Namespace);
                        Writer.Write(", ");
                        WriteQuotedCSharpString(derived.Type.FullName);
                        Writer.Write(", ");
                        WriteQuotedCSharpString(head.Type.FullName);
                        Writer.WriteLine(");");
                    }
                }
                else {
                    Writer.WriteLine("// " + "missing real mapping for " + derived.XsiType);
                    Writer.Write("throw CreateMissingIXmlSerializableType(");
                    WriteQuotedCSharpString(derived.XsiType.Name);
                    Writer.Write(", ");
                    WriteQuotedCSharpString(derived.XsiType.Namespace);
                    Writer.Write(", ");
                    WriteQuotedCSharpString(head.Type.FullName);
                    Writer.WriteLine(");");
                }

                Writer.Indent--;
                Writer.WriteLine("}");

                WriteDerivedSerializable(head, derived, source, isWrappedAny);
            }
        }
        SpecialMapping ImportSpecialMapping(Type type, TypeDesc typeDesc, string ns, ImportContext context) {
            if (specials == null)
                specials = new Hashtable();
            SpecialMapping mapping = (SpecialMapping)specials[type];
            if (mapping != null) {
                CheckContext(mapping.TypeDesc, context);
                return mapping;
            }
            if (typeDesc.Kind == TypeKind.Serializable) {
                SerializableMapping serializableMapping = null;

                // get the schema method info
                object[] attrs = type.GetCustomAttributes(typeof(XmlSchemaProviderAttribute), false);

                if (attrs.Length > 0) {
                    // new IXmlSerializable
                    XmlSchemaProviderAttribute provider = (XmlSchemaProviderAttribute)attrs[0];
                    MethodInfo method = GetMethodFromSchemaProvider(provider, type);
                    serializableMapping = new SerializableMapping(method, provider.IsAny, ns);
                    XmlQualifiedName qname = serializableMapping.XsiType;
                    if (qname != null && !qname.IsEmpty) {
                        if (serializables == null)
                            serializables = new NameTable();
                        SerializableMapping existingMapping = (SerializableMapping)serializables[qname];
                        if (existingMapping != null) {
                            if (existingMapping.Type == null) {
                                serializableMapping = existingMapping;
                            }
                            else if (existingMapping.Type != type) {
                                SerializableMapping next = existingMapping.Next;
                                existingMapping.Next = serializableMapping;
                                serializableMapping.Next = next;
                            }
                        }
                        else {
                            XmlSchemaType xsdType = serializableMapping.XsdType;
                            if (xsdType != null)
                                SetBase(serializableMapping, xsdType.DerivedFrom);
                            serializables[qname] = serializableMapping;
                        }
                        serializableMapping.TypeName = qname.Name;
                        serializableMapping.Namespace = qname.Namespace;
                    }
                    serializableMapping.TypeDesc = typeDesc;
                    serializableMapping.Type = type;
                    IncludeTypes(type);
                }
                else {
                    // old IXmlSerializable
                    serializableMapping = new SerializableMapping();
                    serializableMapping.TypeDesc = typeDesc;
                    serializableMapping.Type = type;
                }
                mapping = serializableMapping;
            }
            else {
                mapping = new SpecialMapping();
                mapping.TypeDesc = typeDesc;
            }
            CheckContext(typeDesc, context);
            specials.Add(type, mapping);
            typeScope.AddTypeMapping(mapping);
            return mapping;
        }
        internal void SetBase(SerializableMapping mapping, XmlQualifiedName baseQname) {

            if (baseQname.IsEmpty) return;
            if (baseQname.Namespace == XmlSchema.Namespace) return;
            XmlSchemaSet schemas = mapping.Schemas;
            ArrayList srcSchemas = (ArrayList)schemas.Schemas(baseQname.Namespace);

            if (srcSchemas.Count == 0) {
                throw new InvalidOperationException(Res.GetString(Res.XmlMissingSchema, baseQname.Namespace));
            }
            if (srcSchemas.Count > 1) {
                throw new InvalidOperationException(Res.GetString(Res.XmlGetSchemaInclude, baseQname.Namespace, typeof(IXmlSerializable).Name, "GetSchema"));
            }
            XmlSchema s = (XmlSchema)srcSchemas[0];

            XmlSchemaType t = (XmlSchemaType)s.SchemaTypes[baseQname];
            t = t.Redefined != null ? t.Redefined : t;

            if (serializables[baseQname] == null) {
                SerializableMapping baseMapping = new SerializableMapping(baseQname, schemas);
                SetBase(baseMapping, t.DerivedFrom);
                serializables.Add(baseQname, baseMapping);
            }
            mapping.SetBaseMapping((SerializableMapping)serializables[baseQname]);
        }
예제 #5
0
        SerializableMapping ImportSerializable(XmlSchemaType type, string identifier, string ns) {
            // we expecting type with one base group (all) for the dataset
            TypeItems items = GetTypeItems(type);
            if (items.Particle == null) return null;
            if (!(items.Particle is XmlSchemaAll || items.Particle is XmlSchemaSequence)) return null;
            XmlSchemaGroupBase group = (XmlSchemaGroupBase)items.Particle;
            if (group.Items.Count == 2) {
                if (!(group.Items[0] is XmlSchemaElement && group.Items[1] is XmlSchemaAny)) return null;
                XmlSchemaElement schema = (XmlSchemaElement)group.Items[0];
                if (!(schema.RefName.Name == "schema" && schema.RefName.Namespace == XmlSchema.Namespace)) return null;
                SerializableMapping specialMapping = new SerializableMapping();
                specialMapping.TypeDesc = new TypeDesc("System.Data.DataSet", "System.Data.DataSet", TypeKind.Serializable, null,
                        TypeFlags.Special | TypeFlags.CanBeElementValue | TypeFlags.Reference);
                specialMapping.TypeName = specialMapping.TypeDesc.Name;
                return specialMapping;
            }
            else if (group.Items.Count == 1) {
                if (!(group.Items[0] is XmlSchemaAny)) return null;
                XmlSchemaAny any = (XmlSchemaAny)group.Items[0];
                if (any.Namespace == null) return null;
                if (any.Namespace.IndexOf('#') >= 0) return null; // special syntax (##any, ##other, ...)
                if (any.Namespace.IndexOf(' ') >= 0) return null; // more than one Uri present
                XmlSchema schema = schemas[any.Namespace];
                if (schema == null) return null;

                SerializableMapping mapping = (SerializableMapping)mappings[schema];
                if (mapping == null) {
                    string typeName = CodeIdentifier.MakeValid(schema.Id);
                    TypeDesc typeDesc = new TypeDesc(typeName, typeName, TypeKind.Serializable, null,
                        TypeFlags.Special | TypeFlags.CanBeElementValue | TypeFlags.Reference);
                    mapping = new SerializableMapping();
                    mapping.Schema = schema;
                    mapping.TypeDesc = typeDesc;
                    mapping.TypeName = typeDesc.Name;
                    mappings.Add(schema, mapping);
                }
                return mapping;
            }
            else {
                return null;
            }
        }
예제 #6
0
 SpecialMapping ImportSpecialMapping(Type type, TypeDesc typeDesc, string ns, ImportContext context) {
     SpecialMapping mapping = (SpecialMapping)specials[type];
     if (mapping != null) {
         CheckContext(mapping.TypeDesc, context);
         return mapping;
     }
     if (typeDesc.Kind == TypeKind.Serializable) {
         SerializableMapping serializableMapping = new SerializableMapping();
         serializableMapping.Type = type;
         mapping = serializableMapping;
     }
     else {
         mapping = new SpecialMapping();
     }
     mapping.TypeDesc = typeDesc;
     mapping.TypeName = typeDesc.Name;
     CheckContext(typeDesc, context);
     specials.Add(type, mapping);
     return mapping;
 }
예제 #7
0
        private SpecialMapping ImportSpecialMapping(Type type, TypeDesc typeDesc, string ns, ImportContext context, RecursionLimiter limiter)
        {
            if (_specials == null)
                _specials = new Hashtable();
            SpecialMapping mapping = (SpecialMapping)_specials[type];
            if (mapping != null)
            {
                CheckContext(mapping.TypeDesc, context);
                return mapping;
            }
            if (typeDesc.Kind == TypeKind.Serializable)
            {
                SerializableMapping serializableMapping = null;

                // get the schema method info
                object[] attrs = type.GetTypeInfo().GetCustomAttributes(typeof(XmlSchemaProviderAttribute), false).ToArray();

                if (attrs.Length > 0)
                {
                    // new IXmlSerializable
                    XmlSchemaProviderAttribute provider = (XmlSchemaProviderAttribute)attrs[0];
                    MethodInfo method = GetMethodFromSchemaProvider(provider, type);
                    serializableMapping = new SerializableMapping(method, provider.IsAny, ns);
                    XmlQualifiedName qname = serializableMapping.XsiType;
                    if (qname != null && !qname.IsEmpty)
                    {
                        serializableMapping.TypeName = qname.Name;
                        serializableMapping.Namespace = qname.Namespace;
                    }
                    serializableMapping.TypeDesc = typeDesc;
                    serializableMapping.Type = type;
                    IncludeTypes(type.GetTypeInfo());
                }
                else
                {
                    // old IXmlSerializable
                    serializableMapping = new SerializableMapping();
                    serializableMapping.TypeDesc = typeDesc;
                    serializableMapping.Type = type;
                }
                mapping = serializableMapping;
            }
            else
            {
                mapping = new SpecialMapping();
                mapping.TypeDesc = typeDesc;
            }
            CheckContext(typeDesc, context);
            _specials.Add(type, mapping);
            _typeScope.AddTypeMapping(mapping);
            return mapping;
        }
        void WriteDerivedSerializable(SerializableMapping head, SerializableMapping mapping, string source, bool isWrappedAny) {
            if (mapping == null)
                return;
            for (SerializableMapping derived = mapping.DerivedMappings; derived != null; derived = derived.NextDerivedMapping) {
                Label labelTrue = ilg.DefineLabel();
                Label labelEnd = ilg.DefineLabel();
                LocalBuilder tserLoc = ilg.GetLocal("tser");
                ilg.InitElseIf();
                ilg.Ldloc(tserLoc);
                ilg.Load(null);
                ilg.Ceq();
                ilg.Brtrue(labelTrue);
                WriteQNameEqual("tser", derived.XsiType.Name, derived.XsiType.Namespace);

                ilg.Br_S(labelEnd);
                ilg.MarkLabel(labelTrue);
                ilg.Ldc(true);
                ilg.MarkLabel(labelEnd);
                ilg.AndIf();

                if (derived.Type != null) {
                    if (head.Type.IsAssignableFrom(derived.Type)) {
                        WriteSourceBeginTyped(source, head.TypeDesc);
                        MethodInfo XmlSerializationReader_ReadSerializable = typeof(XmlSerializationReader).GetMethod(
                             "ReadSerializable",
                             CodeGenerator.InstanceBindingFlags,
                             null,
                             isWrappedAny ? new Type[] { typeof(IXmlSerializable), typeof(Boolean) } : new Type[] { typeof(IXmlSerializable) },
                             null
                             );
                        ilg.Ldarg(0);
                        RaCodeGen.ILGenForCreateInstance(ilg, derived.TypeDesc.Type, derived.TypeDesc.CannotNew, false);
                        if (derived.TypeDesc.CannotNew)
                            ilg.ConvertValue(typeof(object), typeof(IXmlSerializable));
                        if (isWrappedAny)
                            ilg.Ldc(true);
                        ilg.Call(XmlSerializationReader_ReadSerializable);
                        // See logic in WriteSourceBeginTyped whether or not to castclass.
                        if (head.TypeDesc != null)
                            ilg.ConvertValue(typeof(IXmlSerializable), head.TypeDesc.Type);
                        WriteSourceEnd(source, head.TypeDesc.Type);
                    }
                    else {
                        MethodInfo XmlSerializationReader_CreateBadDerivationException = typeof(XmlSerializationReader).GetMethod(
                           "CreateBadDerivationException",
                           CodeGenerator.InstanceBindingFlags,
                           null,
                           new Type[] { typeof(String), typeof(String), typeof(String), typeof(String), typeof(String), typeof(String) },
                           null
                           );
                        ilg.Ldarg(0);
                        ilg.Ldstr(derived.XsiType.Name);
                        ilg.Ldstr(derived.XsiType.Namespace);
                        ilg.Ldstr(head.XsiType.Name);
                        ilg.Ldstr(head.XsiType.Namespace);
                        ilg.Ldstr(derived.Type.FullName);
                        ilg.Ldstr(head.Type.FullName);
                        ilg.Call(XmlSerializationReader_CreateBadDerivationException);
                        ilg.Throw();
                    }
                }
                else {
                    MethodInfo XmlSerializationReader_CreateMissingIXmlSerializableType = typeof(XmlSerializationReader).GetMethod(
                       "CreateMissingIXmlSerializableType",
                       CodeGenerator.InstanceBindingFlags,
                       null,
                       new Type[] { typeof(String), typeof(String), typeof(String) },
                       null
                       );
                    ilg.Ldarg(0);
                    ilg.Ldstr(derived.XsiType.Name);
                    ilg.Ldstr(derived.XsiType.Namespace);
                    ilg.Ldstr(head.Type.FullName);
                    ilg.Call(XmlSerializationReader_CreateMissingIXmlSerializableType);
                    ilg.Throw();
                }


                WriteDerivedSerializable(head, derived, source, isWrappedAny);
            }
        }
예제 #9
0
 internal void SetBaseMapping(SerializableMapping mapping)
 {
     _baseMapping = mapping;
     if (_baseMapping != null)
     {
         _nextDerivedMapping = _baseMapping._derivedMappings;
         _baseMapping._derivedMappings = this;
         if (this == _nextDerivedMapping)
         {
             throw new InvalidOperationException(SR.Format(SR.XmlCircularDerivation, TypeDesc.FullName));
         }
     }
 }
 internal void SetBase(SerializableMapping mapping, XmlQualifiedName baseQname)
 {
     if (!baseQname.IsEmpty && (baseQname.Namespace != "http://www.w3.org/2001/XMLSchema"))
     {
         XmlSchemaSet schemas = mapping.Schemas;
         ArrayList list = (ArrayList) schemas.Schemas(baseQname.Namespace);
         if (list.Count == 0)
         {
             throw new InvalidOperationException(Res.GetString("XmlMissingSchema", new object[] { baseQname.Namespace }));
         }
         if (list.Count > 1)
         {
             throw new InvalidOperationException(Res.GetString("XmlGetSchemaInclude", new object[] { baseQname.Namespace, typeof(IXmlSerializable).Name, "GetSchema" }));
         }
         XmlSchema schema = (XmlSchema) list[0];
         XmlSchemaType type = (XmlSchemaType) schema.SchemaTypes[baseQname];
         type = (type.Redefined != null) ? type.Redefined : type;
         if (this.serializables[baseQname] == null)
         {
             SerializableMapping mapping2 = new SerializableMapping(baseQname, schemas);
             this.SetBase(mapping2, type.DerivedFrom);
             this.serializables.Add(baseQname, mapping2);
         }
         mapping.SetBaseMapping((SerializableMapping) this.serializables[baseQname]);
     }
 }
 private SpecialMapping ImportSpecialMapping(Type type, TypeDesc typeDesc, string ns, ImportContext context, RecursionLimiter limiter)
 {
     if (this.specials == null)
     {
         this.specials = new Hashtable();
     }
     SpecialMapping mapping = (SpecialMapping) this.specials[type];
     if (mapping != null)
     {
         this.CheckContext(mapping.TypeDesc, context);
         return mapping;
     }
     if (typeDesc.Kind == TypeKind.Serializable)
     {
         SerializableMapping mapping2 = null;
         object[] customAttributes = type.GetCustomAttributes(typeof(XmlSchemaProviderAttribute), false);
         if (customAttributes.Length > 0)
         {
             XmlSchemaProviderAttribute provider = (XmlSchemaProviderAttribute) customAttributes[0];
             mapping2 = new SerializableMapping(GetMethodFromSchemaProvider(provider, type), provider.IsAny, ns);
             XmlQualifiedName xsiType = mapping2.XsiType;
             if ((xsiType != null) && !xsiType.IsEmpty)
             {
                 if (this.serializables == null)
                 {
                     this.serializables = new System.Xml.Serialization.NameTable();
                 }
                 SerializableMapping mapping3 = (SerializableMapping) this.serializables[xsiType];
                 if (mapping3 != null)
                 {
                     if (mapping3.Type == null)
                     {
                         mapping2 = mapping3;
                     }
                     else if (mapping3.Type != type)
                     {
                         SerializableMapping next = mapping3.Next;
                         mapping3.Next = mapping2;
                         mapping2.Next = next;
                     }
                 }
                 else
                 {
                     XmlSchemaType xsdType = mapping2.XsdType;
                     if (xsdType != null)
                     {
                         this.SetBase(mapping2, xsdType.DerivedFrom);
                     }
                     this.serializables[xsiType] = mapping2;
                 }
                 mapping2.TypeName = xsiType.Name;
                 mapping2.Namespace = xsiType.Namespace;
             }
             mapping2.TypeDesc = typeDesc;
             mapping2.Type = type;
             this.IncludeTypes(type);
         }
         else
         {
             mapping2 = new SerializableMapping {
                 TypeDesc = typeDesc,
                 Type = type
             };
         }
         mapping = mapping2;
     }
     else
     {
         mapping = new SpecialMapping {
             TypeDesc = typeDesc
         };
     }
     this.CheckContext(typeDesc, context);
     this.specials.Add(type, mapping);
     this.typeScope.AddTypeMapping(mapping);
     return mapping;
 }
 internal void SetBaseMapping(SerializableMapping mapping)
 {
     this.baseMapping = mapping;
     if (this.baseMapping != null)
     {
         this.nextDerivedMapping = this.baseMapping.derivedMappings;
         this.baseMapping.derivedMappings = this;
         if (this == this.nextDerivedMapping)
         {
             throw new InvalidOperationException(Res.GetString("XmlCircularDerivation", new object[] { base.TypeDesc.FullName }));
         }
     }
 }
 private void WriteDerivedSerializable(SerializableMapping head, SerializableMapping mapping, string source, bool isWrappedAny)
 {
     if (mapping != null)
     {
         for (SerializableMapping mapping2 = mapping.DerivedMappings; mapping2 != null; mapping2 = mapping2.NextDerivedMapping)
         {
             base.Writer.Write("else if (tser == null");
             base.Writer.Write(" || ");
             this.WriteQNameEqual("tser", mapping2.XsiType.Name, mapping2.XsiType.Namespace);
             base.Writer.WriteLine(") {");
             IndentedWriter writer = base.Writer;
             writer.Indent++;
             if (mapping2.Type != null)
             {
                 if (head.Type.IsAssignableFrom(mapping2.Type))
                 {
                     this.WriteSourceBeginTyped(source, head.TypeDesc);
                     base.Writer.Write("ReadSerializable(( ");
                     base.Writer.Write(typeof(IXmlSerializable).FullName);
                     base.Writer.Write(")");
                     base.Writer.Write(base.RaCodeGen.GetStringForCreateInstance(mapping2.TypeDesc.CSharpName, mapping2.TypeDesc.UseReflection, mapping2.TypeDesc.CannotNew, false));
                     if (isWrappedAny)
                     {
                         base.Writer.WriteLine(", true");
                     }
                     base.Writer.Write(")");
                     this.WriteSourceEnd(source);
                     base.Writer.WriteLine(";");
                 }
                 else
                 {
                     base.Writer.Write("throw CreateBadDerivationException(");
                     base.WriteQuotedCSharpString(mapping2.XsiType.Name);
                     base.Writer.Write(", ");
                     base.WriteQuotedCSharpString(mapping2.XsiType.Namespace);
                     base.Writer.Write(", ");
                     base.WriteQuotedCSharpString(head.XsiType.Name);
                     base.Writer.Write(", ");
                     base.WriteQuotedCSharpString(head.XsiType.Namespace);
                     base.Writer.Write(", ");
                     base.WriteQuotedCSharpString(mapping2.Type.FullName);
                     base.Writer.Write(", ");
                     base.WriteQuotedCSharpString(head.Type.FullName);
                     base.Writer.WriteLine(");");
                 }
             }
             else
             {
                 base.Writer.WriteLine("// missing real mapping for " + mapping2.XsiType);
                 base.Writer.Write("throw CreateMissingIXmlSerializableType(");
                 base.WriteQuotedCSharpString(mapping2.XsiType.Name);
                 base.Writer.Write(", ");
                 base.WriteQuotedCSharpString(mapping2.XsiType.Namespace);
                 base.Writer.Write(", ");
                 base.WriteQuotedCSharpString(head.Type.FullName);
                 base.Writer.WriteLine(");");
             }
             IndentedWriter writer2 = base.Writer;
             writer2.Indent--;
             base.Writer.WriteLine("}");
             this.WriteDerivedSerializable(head, mapping2, source, isWrappedAny);
         }
     }
 }