internal TypeModel GetTypeModel(Type type, bool directReference) { TypeModel model; if (_models.TryGetValue(type, out model)) return model; TypeDesc typeDesc = _typeScope.GetTypeDesc(type, null, directReference); switch (typeDesc.Kind) { case TypeKind.Enum: model = new EnumModel(type, typeDesc, this); break; case TypeKind.Primitive: model = new PrimitiveModel(type, typeDesc, this); break; case TypeKind.Array: case TypeKind.Collection: case TypeKind.Enumerable: model = new ArrayModel(type, typeDesc, this); break; case TypeKind.Root: case TypeKind.Class: case TypeKind.Struct: model = new StructModel(type, typeDesc, this); break; default: if (!typeDesc.IsSpecial) throw new NotSupportedException(SR.Format(SR.XmlUnsupportedTypeKind, type.FullName)); model = new SpecialModel(type, typeDesc, this); break; } _models.Add(type, model); return model; }
public TypeModel GetTypeModel(Type type) { TypeModel model = (TypeModel)models[type]; if (model != null) return model; TypeDesc typeDesc = typeScope.GetTypeDesc(type); switch (typeDesc.Kind) { case TypeKind.Enum: model = new EnumModel(type, typeDesc, this); break; case TypeKind.Primitive: model = new PrimitiveModel(type, typeDesc, this); break; case TypeKind.Array: case TypeKind.Collection: case TypeKind.Enumerable: model = new ArrayModel(type, typeDesc, this); break; case TypeKind.Root: case TypeKind.Class: case TypeKind.Struct: case TypeKind.Interface: model = new StructModel(type, typeDesc, this); break; default: if (!typeDesc.IsSpecial) throw new NotSupportedException(Res.GetString(Res.XmlUnsupportedTypeKind, type.FullName)); model = new SpecialModel(type, typeDesc, this); break; } models.Add(type, model); return model; }
EnumMapping ImportEnumMapping(EnumModel model) { SoapAttributes a = GetAttributes(model.Type); string typeNs = defaultNs; if (a.SoapType != null && a.SoapType.Namespace != null) { typeNs = a.SoapType.Namespace; } string typeName = string.Empty; if (a.SoapType != null) { typeName = a.SoapType.TypeName; } if (typeName.Length == 0) { typeName = model.TypeDesc.Name; } EnumMapping mapping = (EnumMapping)GetTypeMapping(typeName, typeNs, model.TypeDesc); if (mapping == null) { mapping = new EnumMapping(); mapping.IsSoap = true; mapping.TypeDesc = model.TypeDesc; mapping.TypeName = typeName; mapping.Namespace = typeNs; mapping.IsFlags = model.Type.IsDefined(typeof(FlagsAttribute), false); typeScope.AddTypeMapping(mapping); types.Add(typeName, typeNs, mapping); ArrayList constants = new ArrayList(); for (int i = 0; i < model.Constants.Length; i++) { ConstantMapping constant = ImportConstantMapping(model.Constants[i]); if (constant != null) { constants.Add(constant); } } if (constants.Count == 0) { throw new InvalidOperationException(Res.GetString(Res.XmlNoSerializableMembers, model.TypeDesc.FullName)); } mapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping)); } return(mapping); }
public TypeModel GetTypeModel(Type type) { TypeModel model = (TypeModel)models[type]; if (model != null) { return(model); } TypeDesc typeDesc = typeScope.GetTypeDesc(type); switch (typeDesc.Kind) { case TypeKind.Enum: model = new EnumModel(type, typeDesc, this); break; case TypeKind.Primitive: model = new PrimitiveModel(type, typeDesc, this); break; case TypeKind.Array: case TypeKind.Collection: case TypeKind.Enumerable: model = new ArrayModel(type, typeDesc, this); break; case TypeKind.Root: case TypeKind.Class: case TypeKind.Struct: case TypeKind.Interface: model = new StructModel(type, typeDesc, this); break; default: if (!typeDesc.IsSpecial) { throw new NotSupportedException(Res.GetString(Res.XmlUnsupportedTypeKind, type.FullName)); } model = new SpecialModel(type, typeDesc, this); break; } models.Add(type, model); return(model); }
internal TypeModel GetTypeModel(Type type, bool directReference) { TypeModel?model; if (_models.TryGetValue(type, out model)) { return(model); } TypeDesc typeDesc = _typeScope.GetTypeDesc(type, null, directReference); switch (typeDesc.Kind) { case TypeKind.Enum: model = new EnumModel(type, typeDesc, this); break; case TypeKind.Primitive: model = new PrimitiveModel(type, typeDesc, this); break; case TypeKind.Array: case TypeKind.Collection: case TypeKind.Enumerable: model = new ArrayModel(type, typeDesc, this); break; case TypeKind.Root: case TypeKind.Class: case TypeKind.Struct: model = new StructModel(type, typeDesc, this); break; default: if (!typeDesc.IsSpecial) { throw new NotSupportedException(SR.Format(SR.XmlUnsupportedTypeKind, type.FullName)); } model = new SpecialModel(type, typeDesc, this); break; } _models.Add(type, model); return(model); }
internal TypeModel GetTypeModel(Type type, bool directReference) { TypeModel model = (TypeModel)this.models[type]; if (model == null) { TypeDesc typeDesc = this.typeScope.GetTypeDesc(type, null, directReference); switch (typeDesc.Kind) { case TypeKind.Root: case TypeKind.Struct: case TypeKind.Class: model = new StructModel(type, typeDesc, this); break; case TypeKind.Primitive: model = new PrimitiveModel(type, typeDesc, this); break; case TypeKind.Enum: model = new EnumModel(type, typeDesc, this); break; case TypeKind.Array: case TypeKind.Collection: case TypeKind.Enumerable: model = new ArrayModel(type, typeDesc, this); break; default: if (!typeDesc.IsSpecial) { throw new NotSupportedException(Res.GetString("XmlUnsupportedTypeKind", new object[] { type.FullName })); } model = new SpecialModel(type, typeDesc, this); break; } this.models.Add(type, model); } return(model); }
internal TypeModel GetTypeModel(Type type, bool directReference) { TypeModel model = (TypeModel) this.models[type]; if (model == null) { TypeDesc typeDesc = this.typeScope.GetTypeDesc(type, null, directReference); switch (typeDesc.Kind) { case TypeKind.Root: case TypeKind.Struct: case TypeKind.Class: model = new StructModel(type, typeDesc, this); break; case TypeKind.Primitive: model = new PrimitiveModel(type, typeDesc, this); break; case TypeKind.Enum: model = new EnumModel(type, typeDesc, this); break; case TypeKind.Array: case TypeKind.Collection: case TypeKind.Enumerable: model = new ArrayModel(type, typeDesc, this); break; default: if (!typeDesc.IsSpecial) { throw new NotSupportedException(Res.GetString("XmlUnsupportedTypeKind", new object[] { type.FullName })); } model = new SpecialModel(type, typeDesc, this); break; } this.models.Add(type, model); } return model; }
private EnumMapping ImportEnumMapping(EnumModel model) { SoapAttributes a = this.GetAttributes(model.Type); string defaultNs = this.defaultNs; if ((a.SoapType != null) && (a.SoapType.Namespace != null)) { defaultNs = a.SoapType.Namespace; } string typeName = XmlConvert.EncodeLocalName(this.XsdTypeName(model.Type, a, model.TypeDesc.Name)); EnumMapping typeMapping = (EnumMapping)this.GetTypeMapping(typeName, defaultNs, model.TypeDesc); if (typeMapping == null) { typeMapping = new EnumMapping { IsSoap = true, TypeDesc = model.TypeDesc, TypeName = typeName, Namespace = defaultNs, IsFlags = model.Type.IsDefined(typeof(FlagsAttribute), false) }; this.typeScope.AddTypeMapping(typeMapping); this.types.Add(typeName, defaultNs, typeMapping); ArrayList list = new ArrayList(); for (int i = 0; i < model.Constants.Length; i++) { ConstantMapping mapping2 = this.ImportConstantMapping(model.Constants[i]); if (mapping2 != null) { list.Add(mapping2); } } if (list.Count == 0) { throw new InvalidOperationException(Res.GetString("XmlNoSerializableMembers", new object[] { model.TypeDesc.FullName })); } typeMapping.Constants = (ConstantMapping[])list.ToArray(typeof(ConstantMapping)); } return(typeMapping); }
EnumMapping ImportEnumMapping(EnumModel model) { SoapAttributes a = GetAttributes(model.Type); string typeNs = defaultNs; if (a.SoapType != null && a.SoapType.Namespace != null) typeNs = a.SoapType.Namespace; string typeName = XsdTypeName(model.Type, a, model.TypeDesc.Name); typeName = XmlConvert.EncodeLocalName(typeName); EnumMapping mapping = (EnumMapping)GetTypeMapping(typeName, typeNs, model.TypeDesc); if (mapping == null) { mapping = new EnumMapping(); mapping.IsSoap = true; mapping.TypeDesc = model.TypeDesc; mapping.TypeName = typeName; mapping.Namespace = typeNs; mapping.IsFlags = model.Type.IsDefined(typeof(FlagsAttribute), false); typeScope.AddTypeMapping(mapping); types.Add(typeName, typeNs, mapping); ArrayList constants = new ArrayList(); for (int i = 0; i < model.Constants.Length; i++) { ConstantMapping constant = ImportConstantMapping(model.Constants[i]); if (constant != null) constants.Add(constant); } if (constants.Count == 0) { throw new InvalidOperationException(Res.GetString(Res.XmlNoSerializableMembers, model.TypeDesc.FullName)); } mapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping)); } return mapping; }
EnumMapping ImportEnumMapping(EnumModel model, string ns, bool repeats) { XmlAttributes a = GetAttributes(model.Type, false); string typeNs = ns; if (a.XmlType != null && a.XmlType.Namespace != null) typeNs = a.XmlType.Namespace; string typeName = XsdTypeName(model.Type, a, model.TypeDesc.Name); typeName = XmlConvert.EncodeLocalName(typeName); EnumMapping mapping = (EnumMapping)GetTypeMapping(typeName, typeNs, model.TypeDesc, types, model.Type); if (mapping == null) { mapping = new EnumMapping(); mapping.TypeDesc = model.TypeDesc; mapping.TypeName = typeName; mapping.Namespace = typeNs; mapping.IsFlags = model.Type.IsDefined(typeof(FlagsAttribute), false); if (mapping.IsFlags && repeats) throw new InvalidOperationException(Res.GetString(Res.XmlIllegalAttributeFlagsArray, model.TypeDesc.FullName)); mapping.IsList = repeats; mapping.IncludeInSchema = a.XmlType == null ? true : a.XmlType.IncludeInSchema; if (!mapping.IsAnonymousType) types.Add(typeName, typeNs, mapping); else anonymous[model.Type] = mapping; ArrayList constants = new ArrayList(); for (int i = 0; i < model.Constants.Length; i++) { ConstantMapping constant = ImportConstantMapping(model.Constants[i]); if (constant != null) constants.Add(constant); } if (constants.Count == 0) { throw new InvalidOperationException(Res.GetString(Res.XmlNoSerializableMembers, model.TypeDesc.FullName)); } mapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping)); typeScope.AddTypeMapping(mapping); } return mapping; }
private EnumMapping ImportEnumMapping(EnumModel model, string ns, bool repeats) { XmlAttributes a = this.GetAttributes(model.Type, false); string str = ns; if ((a.XmlType != null) && (a.XmlType.Namespace != null)) { str = a.XmlType.Namespace; } string name = IsAnonymousType(a, ns) ? null : this.XsdTypeName(model.Type, a, model.TypeDesc.Name); name = XmlConvert.EncodeLocalName(name); EnumMapping mapping = (EnumMapping) this.GetTypeMapping(name, str, model.TypeDesc, this.types, model.Type); if (mapping == null) { mapping = new EnumMapping { TypeDesc = model.TypeDesc, TypeName = name, Namespace = str, IsFlags = model.Type.IsDefined(typeof(FlagsAttribute), false) }; if (mapping.IsFlags && repeats) { throw new InvalidOperationException(Res.GetString("XmlIllegalAttributeFlagsArray", new object[] { model.TypeDesc.FullName })); } mapping.IsList = repeats; mapping.IncludeInSchema = (a.XmlType == null) || a.XmlType.IncludeInSchema; if (!mapping.IsAnonymousType) { this.types.Add(name, str, mapping); } else { this.anonymous[model.Type] = mapping; } ArrayList list = new ArrayList(); for (int i = 0; i < model.Constants.Length; i++) { ConstantMapping mapping2 = this.ImportConstantMapping(model.Constants[i]); if (mapping2 != null) { list.Add(mapping2); } } if (list.Count == 0) { throw new InvalidOperationException(Res.GetString("XmlNoSerializableMembers", new object[] { model.TypeDesc.FullName })); } mapping.Constants = (ConstantMapping[]) list.ToArray(typeof(ConstantMapping)); this.typeScope.AddTypeMapping(mapping); } return mapping; }