ConstantMapping ImportConstantMapping(ConstantModel model) { SoapAttributes a = GetAttributes(model.FieldInfo); if (a.SoapIgnore) { return(null); } if ((a.SoapFlags & ~SoapAttributeFlags.Enum) != 0) { throw new InvalidOperationException(Res.GetString(Res.XmlInvalidEnumAttribute)); } if (a.SoapEnum == null) { a.SoapEnum = new SoapEnumAttribute(); } ConstantMapping constant = new ConstantMapping(); constant.XmlName = a.SoapEnum.Name.Length == 0 ? model.Name : a.SoapEnum.Name; constant.Name = model.Name; constant.Value = model.Value; return(constant); }
internal void WriteEnumCase(string fullTypeName, ConstantMapping c, bool useReflection) { writer.Write("case "); if (useReflection){ writer.Write(c.Value.ToString(CultureInfo.InvariantCulture)); } else{ writer.Write(fullTypeName); writer.Write(".@"); CodeIdentifier.CheckValidIdentifier(c.Name); writer.Write(c.Name); } writer.Write(": "); }
void WriteEnumCase(string fullTypeName, ConstantMapping c, bool useReflection){ RaCodeGen.WriteEnumCase(fullTypeName, c, useReflection); }
ConstantMapping ImportConstantMapping(ConstantModel model) { SoapAttributes a = GetAttributes(model.FieldInfo); if (a.SoapIgnore) return null; if ((a.SoapFlags & ~SoapAttributeFlags.Enum) != 0) throw new InvalidOperationException(Res.GetString(Res.XmlInvalidEnumAttribute)); if (a.SoapEnum == null) a.SoapEnum = new SoapEnumAttribute(); ConstantMapping constant = new ConstantMapping(); constant.XmlName = a.SoapEnum.Name.Length == 0 ? model.Name : a.SoapEnum.Name; constant.Name = model.Name; constant.Value = model.Value; return constant; }
internal static void ExportConstant(CodeTypeDeclaration codeClass, ConstantMapping constant, Type type, bool init, long enumValue) { CodeMemberField field = new CodeMemberField(typeof(int).FullName, constant.Name); field.Comments.Add(new CodeCommentStatement(Res.GetString(Res.XmlRemarks), true)); if (init) field.InitExpression = new CodePrimitiveExpression(enumValue); codeClass.Members.Add(field); if (constant.XmlName != constant.Name) { CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(type.FullName); attribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(constant.XmlName))); field.CustomAttributes.Add(attribute); } }
TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, bool isList) { TypeMapping mapping = (TypeMapping)ImportedMappings[dataType]; if (mapping != null) return mapping; XmlSchemaSimpleType sourceDataType = FindDataType(dataType.DerivedFrom); TypeDesc sourceTypeDesc = Scope.GetTypeDesc(sourceDataType); if (sourceTypeDesc != null && sourceTypeDesc != Scope.GetTypeDesc(typeof(string))) return ImportPrimitiveDataType(dataType); identifier = Accessor.UnescapeName(identifier); string typeName = GenerateUniqueTypeName(identifier); EnumMapping enumMapping = new EnumMapping(); enumMapping.IsReference = Schemas.IsReference(dataType); enumMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Enum, null, 0); enumMapping.TypeName = identifier; enumMapping.Namespace = typeNs; enumMapping.IsFlags = isList; CodeIdentifiers constants = new CodeIdentifiers(); if (!(dataType.Content is XmlSchemaSimpleTypeRestriction)) throw new InvalidOperationException(Res.GetString(Res.XmlInvalidEnumContent, dataType.Content.GetType().Name, identifier)); XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)dataType.Content; for (int i = 0; i < restriction.Facets.Count; i++) { object facet = restriction.Facets[i]; if (!(facet is XmlSchemaEnumerationFacet)) continue; XmlSchemaEnumerationFacet enumeration = (XmlSchemaEnumerationFacet)facet; ConstantMapping constant = new ConstantMapping(); string constantName = CodeIdentifier.MakeValid(enumeration.Value); constant.Name = constants.AddUnique(constantName, constant); constant.XmlName = enumeration.Value; constant.Value = i; } enumMapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping)); if (isList && enumMapping.Constants.Length > 63) { // if we have 64+ flag constants we cannot map the type to long enum, we will use string mapping instead. mapping = new PrimitiveMapping(); mapping.TypeDesc = Scope.GetTypeDesc(typeof(string)); mapping.TypeName = mapping.TypeDesc.DataType.Name; ImportedMappings.Add(dataType, mapping); return mapping; } ImportedMappings.Add(dataType, enumMapping); Scope.AddTypeMapping(enumMapping); return enumMapping; }
private TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, bool isList) { TypeMapping mapping = (TypeMapping)ImportedMappings[dataType]; if (mapping != null) { return(mapping); } XmlSchemaSimpleType sourceDataType = FindDataType(dataType.DerivedFrom); TypeDesc sourceTypeDesc = Scope.GetTypeDesc(sourceDataType); if (sourceTypeDesc != null && sourceTypeDesc != Scope.GetTypeDesc(typeof(string))) { return(ImportPrimitiveDataType(dataType)); } identifier = Accessor.UnescapeName(identifier); string typeName = GenerateUniqueTypeName(identifier); EnumMapping enumMapping = new EnumMapping(); enumMapping.IsReference = Schemas.IsReference(dataType); enumMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Enum, null, 0); enumMapping.TypeName = identifier; enumMapping.Namespace = typeNs; enumMapping.IsFlags = isList; CodeIdentifiers constants = new CodeIdentifiers(); if (!(dataType.Content is XmlSchemaSimpleTypeRestriction)) { throw new InvalidOperationException(SR.Format(SR.XmlInvalidEnumContent, dataType.Content.GetType().Name, identifier)); } XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)dataType.Content; for (int i = 0; i < restriction.Facets.Count; i++) { object facet = restriction.Facets[i]; if (!(facet is XmlSchemaEnumerationFacet)) { continue; } XmlSchemaEnumerationFacet enumeration = (XmlSchemaEnumerationFacet)facet; ConstantMapping constant = new ConstantMapping(); string constantName = CodeIdentifier.MakeValid(enumeration.Value); constant.Name = constants.AddUnique(constantName, constant); constant.XmlName = enumeration.Value; constant.Value = i; } enumMapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping)); if (isList && enumMapping.Constants.Length > 63) { // if we have 64+ flag constants we cannot map the type to long enum, we will use string mapping instead. mapping = new PrimitiveMapping(); mapping.TypeDesc = Scope.GetTypeDesc(typeof(string)); mapping.TypeName = mapping.TypeDesc.DataType.Name; ImportedMappings.Add(dataType, mapping); return(mapping); } ImportedMappings.Add(dataType, enumMapping); Scope.AddTypeMapping(enumMapping); return(enumMapping); }
void ExportConstant(CodeTypeDeclaration codeClass, ConstantMapping constant) { CodeMemberField field = new CodeMemberField(typeof(int).FullName, constant.Name); codeClass.Members.Add(field); field.CustomAttributes = new CodeAttributeDeclarationCollection(); field.Comments.Add(new CodeCommentStatement("<remarks/>", true)); if (constant.XmlName != constant.Name) { CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(SoapEnumAttribute).FullName); attribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(constant.XmlName))); field.CustomAttributes.Add(attribute); } }
EnumMapping ImportEnumeratedChoice(ElementAccessor[] choice, string typeNs, string typeName) { typeName = GenerateUniqueTypeName(typeName, typeNs); EnumMapping enumMapping = new EnumMapping(); enumMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Enum, null, 0); enumMapping.TypeName = typeName; enumMapping.Namespace = typeNs; enumMapping.IsFlags = false; enumMapping.IncludeInSchema = false; CodeIdentifiers constants = new CodeIdentifiers(); for (int i = 0; i < choice.Length; i++) { ElementAccessor element = choice[i]; ConstantMapping constant = new ConstantMapping(); string constantName = CodeIdentifier.MakeValid(element.Name); constant.Name = constants.AddUnique(constantName, constant); constant.XmlName = element.Namespace == typeNs ? element.Name : element.Namespace + ":" + element.Name; constant.Value = i; } enumMapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping)); scope.AddTypeMapping(enumMapping); return enumMapping; }
TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier) { EnumMapping enumMapping = (EnumMapping)mappings[dataType]; if (enumMapping != null) return enumMapping; XmlSchemaType sourceType = FindType(dataType.DerivedFrom); if (sourceType is XmlSchemaComplexType) return null; TypeDesc sourceTypeDesc = scope.GetTypeDesc((XmlSchemaSimpleType)sourceType); if (sourceTypeDesc != null && sourceTypeDesc.FullName != typeof(string).FullName) return ImportPrimitiveDataType(dataType); string typeName = GenerateUniqueTypeName(identifier); enumMapping = new EnumMapping(); enumMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Enum, null, 0); enumMapping.TypeName = identifier; enumMapping.Namespace = typeNs; enumMapping.IsFlags = false; mappings.Add(dataType, enumMapping); CodeIdentifiers constants = new CodeIdentifiers(); XmlSchemaSimpleTypeContent content = dataType.Content; if (content is XmlSchemaSimpleTypeRestriction) { XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)content; for (int i = 0; i < restriction.Facets.Count; i++) { object facet = restriction.Facets[i]; if (!(facet is XmlSchemaEnumerationFacet)) continue; XmlSchemaEnumerationFacet enumeration = (XmlSchemaEnumerationFacet)facet; // validate the enumeration value if (sourceTypeDesc != null && sourceTypeDesc.HasCustomFormatter) { XmlCustomFormatter.ToDefaultValue(enumeration.Value, sourceTypeDesc.FormatterName); } ConstantMapping constant = new ConstantMapping(); string constantName = CodeIdentifier.MakeValid(enumeration.Value); constant.Name = constants.AddUnique(constantName, constant); constant.XmlName = enumeration.Value; constant.Value = i; } } enumMapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping)); scope.AddTypeMapping(enumMapping); return enumMapping; }
private TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, TypeFlags flags, bool isList) { TypeMapping mapping = (TypeMapping)ImportedMappings[dataType]; if (mapping != null) return mapping; XmlSchemaType sourceType = dataType; while (!sourceType.DerivedFrom.IsEmpty) { sourceType = FindType(sourceType.DerivedFrom, TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue); } if (sourceType is XmlSchemaComplexType) return null; TypeDesc sourceTypeDesc = Scope.GetTypeDesc((XmlSchemaSimpleType)sourceType); if (sourceTypeDesc != null && sourceTypeDesc.FullName != typeof(string).FullName) return ImportPrimitiveDataType(dataType, flags); identifier = Accessor.UnescapeName(identifier); string typeName = GenerateUniqueTypeName(identifier); EnumMapping enumMapping = new EnumMapping(); enumMapping.IsReference = Schemas.IsReference(dataType); enumMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Enum, null, 0); if (dataType.Name != null && dataType.Name.Length > 0) enumMapping.TypeName = identifier; enumMapping.Namespace = typeNs; enumMapping.IsFlags = isList; CodeIdentifiers constants = new CodeIdentifiers(); XmlSchemaSimpleTypeContent content = dataType.Content; if (content is XmlSchemaSimpleTypeRestriction) { XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)content; for (int i = 0; i < restriction.Facets.Count; i++) { object facet = restriction.Facets[i]; if (!(facet is XmlSchemaEnumerationFacet)) continue; XmlSchemaEnumerationFacet enumeration = (XmlSchemaEnumerationFacet)facet; // validate the enumeration value if (sourceTypeDesc != null && sourceTypeDesc.HasCustomFormatter) { XmlCustomFormatter.ToDefaultValue(enumeration.Value, sourceTypeDesc.FormatterName); } ConstantMapping constant = new ConstantMapping(); string constantName = CodeIdentifier.MakeValid(enumeration.Value); constant.Name = constants.AddUnique(constantName, constant); constant.XmlName = enumeration.Value; constant.Value = i; } } enumMapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping)); if (isList && enumMapping.Constants.Length > 63) { // if we have 64+ flag constants we cannot map the type to long enum, we will use string mapping instead. mapping = GetDefaultMapping(TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue | TypeFlags.CanBeAttributeValue); ImportedMappings.Add(dataType, mapping); return mapping; } ImportedMappings.Add(dataType, enumMapping); Scope.AddTypeMapping(enumMapping); return enumMapping; }
private ConstantMapping ImportConstantMapping(ConstantModel model) { XmlAttributes a = GetAttributes(model.FieldInfo); if (a.XmlIgnore) return null; if ((a.XmlFlags & ~XmlAttributeFlags.Enum) != 0) throw new InvalidOperationException(SR.XmlInvalidConstantAttribute); if (a.XmlEnum == null) a.XmlEnum = new XmlEnumAttribute(); ConstantMapping constant = new ConstantMapping(); constant.XmlName = a.XmlEnum.Name == null ? model.Name : a.XmlEnum.Name; constant.Name = model.Name; constant.Value = model.Value; return constant; }
private TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, TypeFlags flags, bool isList) { TypeMapping defaultMapping = (TypeMapping) base.ImportedMappings[dataType]; if (defaultMapping != null) { return defaultMapping; } XmlSchemaType type = dataType; while (!type.DerivedFrom.IsEmpty) { type = this.FindType(type.DerivedFrom, TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue); } if (type is XmlSchemaComplexType) { return null; } TypeDesc typeDesc = base.Scope.GetTypeDesc((XmlSchemaSimpleType) type); if ((typeDesc != null) && (typeDesc.FullName != typeof(string).FullName)) { return this.ImportPrimitiveDataType(dataType, flags); } identifier = Accessor.UnescapeName(identifier); string name = base.GenerateUniqueTypeName(identifier); EnumMapping mapping2 = new EnumMapping { IsReference = base.Schemas.IsReference(dataType), TypeDesc = new TypeDesc(name, name, TypeKind.Enum, null, TypeFlags.None) }; if ((dataType.Name != null) && (dataType.Name.Length > 0)) { mapping2.TypeName = identifier; } mapping2.Namespace = typeNs; mapping2.IsFlags = isList; CodeIdentifiers identifiers = new CodeIdentifiers(); XmlSchemaSimpleTypeContent content = dataType.Content; if (content is XmlSchemaSimpleTypeRestriction) { XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content; for (int i = 0; i < restriction.Facets.Count; i++) { object obj2 = restriction.Facets[i]; if (obj2 is XmlSchemaEnumerationFacet) { XmlSchemaEnumerationFacet facet = (XmlSchemaEnumerationFacet) obj2; if ((typeDesc != null) && typeDesc.HasCustomFormatter) { XmlCustomFormatter.ToDefaultValue(facet.Value, typeDesc.FormatterName); } ConstantMapping mapping3 = new ConstantMapping(); string str2 = CodeIdentifier.MakeValid(facet.Value); mapping3.Name = identifiers.AddUnique(str2, mapping3); mapping3.XmlName = facet.Value; mapping3.Value = i; } } } mapping2.Constants = (ConstantMapping[]) identifiers.ToArray(typeof(ConstantMapping)); if (isList && (mapping2.Constants.Length > 0x3f)) { defaultMapping = this.GetDefaultMapping(TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue | TypeFlags.CanBeAttributeValue); base.ImportedMappings.Add(dataType, defaultMapping); return defaultMapping; } base.ImportedMappings.Add(dataType, mapping2); base.Scope.AddTypeMapping(mapping2); return mapping2; }
private EnumMapping ImportEnumeratedChoice(ElementAccessor[] choice, string typeNs, string typeName) { typeName = this.GenerateUniqueTypeName(Accessor.UnescapeName(typeName), typeNs); EnumMapping typeMapping = new EnumMapping { TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Enum, null, TypeFlags.None), TypeName = typeName, Namespace = typeNs, IsFlags = false, IncludeInSchema = false }; if (this.GenerateOrder) { Array.Sort(choice, new ElementComparer()); } CodeIdentifiers identifiers = new CodeIdentifiers(); for (int i = 0; i < choice.Length; i++) { ElementAccessor accessor = choice[i]; ConstantMapping mapping2 = new ConstantMapping(); string identifier = CodeIdentifier.MakeValid(accessor.Name); mapping2.Name = identifiers.AddUnique(identifier, mapping2); mapping2.XmlName = accessor.ToString(typeNs); mapping2.Value = i; } typeMapping.Constants = (ConstantMapping[]) identifiers.ToArray(typeof(ConstantMapping)); base.Scope.AddTypeMapping(typeMapping); return typeMapping; }
TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier) { EnumMapping enumMapping = (EnumMapping)mappings[dataType]; if (enumMapping != null) return enumMapping; XmlSchemaSimpleType sourceDataType = FindDataType(dataType.DerivedFrom); TypeDesc sourceTypeDesc = scope.GetTypeDesc(sourceDataType); if (sourceTypeDesc != null && sourceTypeDesc != scope.GetTypeDesc(typeof(string))) return ImportPrimitiveDataType(dataType); string typeName = GenerateUniqueTypeName(identifier); enumMapping = new EnumMapping(); enumMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Enum, null, 0); enumMapping.TypeName = identifier; enumMapping.Namespace = typeNs; enumMapping.IsFlags = false; mappings.Add(dataType, enumMapping); CodeIdentifiers constants = new CodeIdentifiers(); if (!(dataType.Content is XmlSchemaSimpleTypeRestriction)) throw new InvalidOperationException(Res.GetString(Res.XmlInvalidEnumContent, dataType.Content.GetType().Name, identifier)); XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)dataType.Content; for (int i = 0; i < restriction.Facets.Count; i++) { object facet = restriction.Facets[i]; if (!(facet is XmlSchemaEnumerationFacet)) continue; XmlSchemaEnumerationFacet enumeration = (XmlSchemaEnumerationFacet)facet; ConstantMapping constant = new ConstantMapping(); string constantName = CodeIdentifier.MakeValid(enumeration.Value); constant.Name = constants.AddUnique(constantName, constant); constant.XmlName = enumeration.Value; constant.Value = i; } enumMapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping)); scope.AddTypeMapping(enumMapping); return enumMapping; }
private TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, bool isList) { TypeMapping mapping = (TypeMapping) base.ImportedMappings[dataType]; if (mapping != null) { return mapping; } XmlSchemaSimpleType type = this.FindDataType(dataType.DerivedFrom); TypeDesc typeDesc = base.Scope.GetTypeDesc(type); if ((typeDesc != null) && (typeDesc != base.Scope.GetTypeDesc(typeof(string)))) { return this.ImportPrimitiveDataType(dataType); } identifier = Accessor.UnescapeName(identifier); string name = base.GenerateUniqueTypeName(identifier); EnumMapping mapping2 = new EnumMapping { IsReference = base.Schemas.IsReference(dataType), TypeDesc = new TypeDesc(name, name, TypeKind.Enum, null, TypeFlags.None), TypeName = identifier, Namespace = typeNs, IsFlags = isList }; CodeIdentifiers identifiers = new CodeIdentifiers(); if (!(dataType.Content is XmlSchemaSimpleTypeRestriction)) { throw new InvalidOperationException(Res.GetString("XmlInvalidEnumContent", new object[] { dataType.Content.GetType().Name, identifier })); } XmlSchemaSimpleTypeRestriction content = (XmlSchemaSimpleTypeRestriction) dataType.Content; for (int i = 0; i < content.Facets.Count; i++) { object obj2 = content.Facets[i]; if (obj2 is XmlSchemaEnumerationFacet) { XmlSchemaEnumerationFacet facet = (XmlSchemaEnumerationFacet) obj2; ConstantMapping mapping3 = new ConstantMapping(); string str2 = CodeIdentifier.MakeValid(facet.Value); mapping3.Name = identifiers.AddUnique(str2, mapping3); mapping3.XmlName = facet.Value; mapping3.Value = i; } } mapping2.Constants = (ConstantMapping[]) identifiers.ToArray(typeof(ConstantMapping)); if (isList && (mapping2.Constants.Length > 0x3f)) { mapping = new PrimitiveMapping { TypeDesc = base.Scope.GetTypeDesc(typeof(string)), TypeName = mapping.TypeDesc.DataType.Name }; base.ImportedMappings.Add(dataType, mapping); return mapping; } base.ImportedMappings.Add(dataType, mapping2); base.Scope.AddTypeMapping(mapping2); return mapping2; }