本文整理汇总了C#中System.Xml.Serialization.ImportContext类的典型用法代码示例。如果您正苦于以下问题:C# ImportContext类的具体用法?C# ImportContext怎么用?C# ImportContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImportContext类属于System.Xml.Serialization命名空间,在下文中一共展示了ImportContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SchemaImporter
internal SchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, ImportContext context)
{
if (!schemas.Contains(XmlSchema.Namespace))
{
schemas.AddReference(XmlSchemas.XsdSchema);
schemas.SchemaSet.Add(XmlSchemas.XsdSchema);
}
if (!schemas.Contains(XmlReservedNs.NsXml))
{
schemas.AddReference(XmlSchemas.XmlSchema);
schemas.SchemaSet.Add(XmlSchemas.XmlSchema);
}
_schemas = schemas;
_options = options;
_context = context;
Schemas.SetCache(Context.Cache, Context.ShareTypes);
}
示例2: SchemaImporter
internal SchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, CodeDomProvider codeProvider, ImportContext context) {
if (!schemas.Contains(XmlSchema.Namespace)) {
schemas.AddReference(XmlSchemas.XsdSchema);
schemas.SchemaSet.Add(XmlSchemas.XsdSchema);
}
if (!schemas.Contains(XmlReservedNs.NsXml)) {
schemas.AddReference(XmlSchemas.XmlSchema);
schemas.SchemaSet.Add(XmlSchemas.XmlSchema);
}
this.schemas = schemas;
this.options = options;
this.codeProvider = codeProvider;
this.context = context;
Schemas.SetCache(Context.Cache, Context.ShareTypes);
SchemaImporterExtensionsSection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.SchemaImporterExtensionsSectionPath) as SchemaImporterExtensionsSection;
if (section != null)
extensions = section.SchemaImporterExtensionsInternal;
else
extensions = new SchemaImporterExtensionCollection();
}
示例3: Import
private ServiceDescriptionImportWarnings Import(CodeNamespace codeNamespace, ImportContext importContext, Hashtable exportContext, StringCollection warnings) {
allSchemas = new XmlSchemas();
foreach (XmlSchema schema in schemas) {
allSchemas.Add(schema);
}
foreach (ServiceDescription description in serviceDescriptions) {
foreach (XmlSchema schema in description.Types.Schemas) {
allSchemas.Add(schema);
}
}
Hashtable references = new Hashtable();
if (!allSchemas.Contains(ServiceDescription.Namespace)) {
allSchemas.AddReference(ServiceDescription.Schema);
references[ServiceDescription.Schema] = ServiceDescription.Schema;
}
if (!allSchemas.Contains(Soap.Encoding)) {
allSchemas.AddReference(ServiceDescription.SoapEncodingSchema);
references[ServiceDescription.SoapEncodingSchema] = ServiceDescription.SoapEncodingSchema;
}
allSchemas.Compile(null, false);
// Segregate the schemas containing abstract types from those
// containing regular XML definitions. This is important because
// when you import something returning the ur-type (object), then
// you need to import ALL types/elements within ALL schemas. We
// don't want the RPC-based types leaking over into the XML-based
// element definitions. This also occurs when you have derivation:
// we need to search the schemas for derived types: but WHICH schemas
// should we search.
foreach (ServiceDescription description in serviceDescriptions) {
foreach (Message message in description.Messages) {
foreach (MessagePart part in message.Parts) {
bool isEncoded;
bool isLiteral;
FindUse(part, out isEncoded, out isLiteral);
if (part.Element != null && !part.Element.IsEmpty) {
if (isEncoded) throw new InvalidOperationException(Res.GetString(Res.CanTSpecifyElementOnEncodedMessagePartsPart, part.Name, message.Name));
XmlSchemaElement element = (XmlSchemaElement)allSchemas.Find(part.Element, typeof(XmlSchemaElement));
if (element != null) {
AddSchema(element.Parent as XmlSchema, isEncoded, isLiteral, abstractSchemas, concreteSchemas, references);
if (element.SchemaTypeName != null && !element.SchemaTypeName.IsEmpty) {
XmlSchemaType type = (XmlSchemaType)allSchemas.Find(element.SchemaTypeName, typeof(XmlSchemaType));
if (type != null) {
AddSchema(type.Parent as XmlSchema, isEncoded, isLiteral, abstractSchemas, concreteSchemas, references);
}
}
}
}
if (part.Type != null && !part.Type.IsEmpty) {
XmlSchemaType type = (XmlSchemaType)allSchemas.Find(part.Type, typeof(XmlSchemaType));
if (type != null) {
AddSchema(type.Parent as XmlSchema, isEncoded, isLiteral, abstractSchemas, concreteSchemas, references);
}
}
}
}
}
Hashtable imports;
foreach (XmlSchemas xmlschemas in new XmlSchemas[] { abstractSchemas, concreteSchemas }) {
// collect all imports
imports = new Hashtable();
foreach (XmlSchema schema in xmlschemas) {
AddImport(schema, imports);
}
// make sure we add them to the corresponding schema collections
foreach (XmlSchema schema in imports.Keys) {
if (references[schema] == null && !xmlschemas.Contains(schema)) {
xmlschemas.Add(schema);
}
}
}
// If a schema was not referenced by either a literal or an encoded message part,
// add it to both collections. There's no way to tell which it should be.
imports = new Hashtable();
foreach (XmlSchema schema in allSchemas) {
if (!abstractSchemas.Contains(schema) && !concreteSchemas.Contains(schema)) {
AddImport(schema, imports);
}
}
// make sure we add them to the corresponding schema collections
foreach (XmlSchema schema in imports.Keys) {
if (references[schema] != null)
continue;
if (!abstractSchemas.Contains(schema)) {
abstractSchemas.Add(schema);
}
if (!concreteSchemas.Contains(schema)) {
concreteSchemas.Add(schema);
}
}
if (abstractSchemas.Count > 0) {
foreach (XmlSchema schema in references.Values) {
abstractSchemas.AddReference(schema);
}
StringCollection schemaWarnings = SchemaCompiler.Compile(abstractSchemas);
foreach (string warning in schemaWarnings)
warnings.Add(warning);
//.........这里部分代码省略.........
示例4: XmlSchemaImporter
public XmlSchemaImporter (XmlSchemas schemas, CodeGenerationOptions options, ImportContext context)
{
this.schemas = schemas;
this.options = options;
if (context != null) {
typeIdentifiers = context.TypeIdentifiers;
InitSharedData (context);
}
else
typeIdentifiers = new CodeIdentifiers ();
InitializeExtensions ();
}
示例5: SoapSchemaImporter
/// <include file='doc\SoapSchemaImporter.uex' path='docs/doc[@for="SoapSchemaImporter.SoapSchemaImporter3"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public SoapSchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, ImportContext context) : base(schemas, options, null, context){}
示例6: ImportPrimitiveMapping
PrimitiveMapping ImportPrimitiveMapping(PrimitiveModel model, ImportContext context, string dataType, bool repeats) {
PrimitiveMapping mapping = new PrimitiveMapping();
if (dataType.Length > 0) {
mapping.TypeDesc = typeScope.GetTypeDesc(dataType, XmlSchema.Namespace);
if (mapping.TypeDesc == null) {
// try it as a non-Xsd type
mapping.TypeDesc = typeScope.GetTypeDesc(dataType, UrtTypes.Namespace);
if (mapping.TypeDesc == null) {
throw new InvalidOperationException(Res.GetString(Res.XmlUdeclaredXsdType, dataType));
}
}
}
else {
mapping.TypeDesc = model.TypeDesc;
}
mapping.TypeName = mapping.TypeDesc.DataType.Name;
mapping.Namespace = mapping.TypeDesc.IsXsdType ? XmlSchema.Namespace : UrtTypes.Namespace;
mapping.IsList = repeats;
CheckContext(mapping.TypeDesc, context);
return mapping;
}
示例7: UnsupportedException
static Exception UnsupportedException(TypeDesc typeDesc, ImportContext context) {
return new InvalidOperationException(Res.GetString(Res.XmlIllegalTypeContext, typeDesc.FullName, GetContextName(context)));
}
示例8: ImportSpecialMapping
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;
}
示例9: ImportTypeMapping
TypeMapping ImportTypeMapping(TypeModel model, string ns, ImportContext context, string dataType, XmlAttributes a) {
return ImportTypeMapping(model, ns, context, dataType, a, false, false);
}
示例10: ImportSpecialMapping
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;
}
示例11: GetContextName
private static string GetContextName(ImportContext context)
{
switch (context)
{
case ImportContext.Element: return "element";
case ImportContext.Attribute: return "attribute";
case ImportContext.Text: return "text";
default:
throw new ArgumentException(SR.XmlInternalError, nameof(context));
}
}
示例12: UnsupportedException
private static Exception UnsupportedException(TypeDesc typeDesc, ImportContext context)
{
return new InvalidOperationException(Res.GetString("XmlIllegalTypeContext", new object[] { typeDesc.FullName, GetContextName(context) }));
}
示例13: ImportTypeMapping
private TypeMapping ImportTypeMapping(TypeModel model, string ns, ImportContext context, string dataType, XmlAttributes a, bool repeats, bool openModel, RecursionLimiter limiter)
{
TypeMapping mapping3;
try
{
if (dataType.Length > 0)
{
TypeDesc desc = TypeScope.IsOptionalValue(model.Type) ? model.TypeDesc.BaseTypeDesc : model.TypeDesc;
if (!desc.IsPrimitive)
{
throw new InvalidOperationException(Res.GetString("XmlInvalidDataTypeUsage", new object[] { dataType, "XmlElementAttribute.DataType" }));
}
TypeDesc typeDesc = this.typeScope.GetTypeDesc(dataType, "http://www.w3.org/2001/XMLSchema");
if (typeDesc == null)
{
throw new InvalidOperationException(Res.GetString("XmlInvalidXsdDataType", new object[] { dataType, "XmlElementAttribute.DataType", new XmlQualifiedName(dataType, "http://www.w3.org/2001/XMLSchema").ToString() }));
}
if (desc.FullName != typeDesc.FullName)
{
throw new InvalidOperationException(Res.GetString("XmlDataTypeMismatch", new object[] { dataType, "XmlElementAttribute.DataType", desc.FullName }));
}
}
if (a == null)
{
a = this.GetAttributes(model.Type, false);
}
if ((a.XmlFlags & ~(XmlAttributeFlags.Type | XmlAttributeFlags.Root)) != ((XmlAttributeFlags) 0))
{
throw new InvalidOperationException(Res.GetString("XmlInvalidTypeAttributes", new object[] { model.Type.FullName }));
}
switch (model.TypeDesc.Kind)
{
case TypeKind.Root:
case TypeKind.Struct:
case TypeKind.Class:
if (context != ImportContext.Element)
{
throw UnsupportedException(model.TypeDesc, context);
}
goto Label_0216;
case TypeKind.Primitive:
if (a.XmlFlags != ((XmlAttributeFlags) 0))
{
throw InvalidAttributeUseException(model.Type);
}
return this.ImportPrimitiveMapping((PrimitiveModel) model, context, dataType, repeats);
case TypeKind.Enum:
return this.ImportEnumMapping((EnumModel) model, ns, repeats);
case TypeKind.Array:
case TypeKind.Collection:
case TypeKind.Enumerable:
if (context != ImportContext.Element)
{
throw UnsupportedException(model.TypeDesc, context);
}
break;
default:
goto Label_02E5;
}
this.arrayNestingLevel++;
ArrayMapping mapping = this.ImportArrayLikeMapping((ArrayModel) model, ns, limiter);
this.arrayNestingLevel--;
return mapping;
Label_0216:
if (model.TypeDesc.IsOptionalValue)
{
TypeDesc desc3 = string.IsNullOrEmpty(dataType) ? model.TypeDesc.BaseTypeDesc : this.typeScope.GetTypeDesc(dataType, "http://www.w3.org/2001/XMLSchema");
string typeName = (desc3.DataType == null) ? desc3.Name : desc3.DataType.Name;
TypeMapping baseMapping = this.GetTypeMapping(typeName, ns, desc3, this.types, null);
if (baseMapping == null)
{
baseMapping = this.ImportTypeMapping(this.modelScope.GetTypeModel(model.TypeDesc.BaseTypeDesc.Type), ns, context, dataType, null, repeats, openModel, limiter);
}
return this.CreateNullableMapping(baseMapping, model.TypeDesc.Type);
}
return this.ImportStructLikeMapping((StructModel) model, ns, openModel, a, limiter);
Label_02E5:
if (model.TypeDesc.Kind == TypeKind.Serializable)
{
if ((a.XmlFlags & ~XmlAttributeFlags.Root) != ((XmlAttributeFlags) 0))
{
throw new InvalidOperationException(Res.GetString("XmlSerializableAttributes", new object[] { model.TypeDesc.FullName, typeof(XmlSchemaProviderAttribute).Name }));
}
}
else if (a.XmlFlags != ((XmlAttributeFlags) 0))
{
throw InvalidAttributeUseException(model.Type);
}
if (!model.TypeDesc.IsSpecial)
{
throw UnsupportedException(model.TypeDesc, context);
}
mapping3 = this.ImportSpecialMapping(model.Type, model.TypeDesc, ns, context, limiter);
}
catch (Exception exception)
{
//.........这里部分代码省略.........
示例14: ImportSpecialMapping
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;
}
示例15: ImportPrimitiveMapping
private PrimitiveMapping ImportPrimitiveMapping(PrimitiveModel model, ImportContext context, string dataType, bool repeats)
{
PrimitiveMapping mapping = new PrimitiveMapping();
if (dataType.Length > 0)
{
mapping.TypeDesc = this.typeScope.GetTypeDesc(dataType, "http://www.w3.org/2001/XMLSchema");
if (mapping.TypeDesc == null)
{
mapping.TypeDesc = this.typeScope.GetTypeDesc(dataType, "http://microsoft.com/wsdl/types/");
if (mapping.TypeDesc == null)
{
throw new InvalidOperationException(Res.GetString("XmlUdeclaredXsdType", new object[] { dataType }));
}
}
}
else
{
mapping.TypeDesc = model.TypeDesc;
}
mapping.TypeName = mapping.TypeDesc.DataType.Name;
mapping.Namespace = mapping.TypeDesc.IsXsdType ? "http://www.w3.org/2001/XMLSchema" : "http://microsoft.com/wsdl/types/";
mapping.IsList = repeats;
this.CheckContext(mapping.TypeDesc, context);
return mapping;
}