示例#1
0
 string ExportDefaultValue(TypeData typeData, XmlTypeMapping map, object defaultValue)
 {
     if (typeData.SchemaType == SchemaTypes.Enum)
     {
         EnumMap enumMap = (EnumMap)map.ObjectMap;
         // get corresponding xml name
         return(enumMap.GetXmlName(map.TypeFullName, defaultValue));
     }
     return(XmlCustomFormatter.ToXmlString(typeData, defaultValue));
 }
        string GetEnumXmlValue(XmlTypeMapping typeMap, object ob)
        {
            if (ob == null)
            {
                return(null);
            }
            EnumMap map = (EnumMap)typeMap.ObjectMap;

            return(map.GetXmlName(typeMap.TypeFullName, ob));
        }
示例#3
0
        void ExportEnumCode(XmlTypeMapping map, bool isTopLevel)
        {
            if (IsMapExported(map))
            {
                return;
            }

            CodeTypeDeclaration codeEnum = new CodeTypeDeclaration(map.TypeData.TypeName);

            SetMapExported(map, codeEnum);

            codeEnum.Attributes = MemberAttributes.Public;
            codeEnum.IsEnum     = true;
            AddCodeType(codeEnum, map.Documentation);

            EnumMap emap = (EnumMap)map.ObjectMap;

            if (emap.IsFlags)
            {
                codeEnum.CustomAttributes.Add(new CodeAttributeDeclaration("System.FlagsAttribute"));
            }

#if NET_2_0
            CodeAttributeDeclaration generatedCodeAttribute = new CodeAttributeDeclaration(
                new CodeTypeReference(typeof(GeneratedCodeAttribute)));
            generatedCodeAttribute.Arguments.Add(new CodeAttributeArgument(
                                                     new CodePrimitiveExpression("System.Xml")));
            generatedCodeAttribute.Arguments.Add(new CodeAttributeArgument(
                                                     new CodePrimitiveExpression(Consts.FxFileVersion)));
            codeEnum.CustomAttributes.Add(generatedCodeAttribute);

            codeEnum.CustomAttributes.Add(new CodeAttributeDeclaration(
                                              new CodeTypeReference(typeof(SerializableAttribute))));
#endif

            GenerateEnum(map, codeEnum, isTopLevel);

            int flag = 1;
            foreach (EnumMap.EnumMapMember emem in emap.Members)
            {
                CodeMemberField codeField = new CodeMemberField("", emem.EnumName);
                if (emap.IsFlags)
                {
                    codeField.InitExpression = new CodePrimitiveExpression(flag);
                    flag *= 2;
                }

                AddComments(codeField, emem.Documentation);

                GenerateEnumItem(codeField, emem);
                codeEnum.Members.Add(codeField);
            }
        }
        object GetEnumValue(XmlTypeMapping typeMap, string val)
        {
            if (val == null)
            {
                return(null);
            }
            EnumMap map = (EnumMap)typeMap.ObjectMap;
            string  ev  = map.GetEnumName(typeMap.TypeFullName, val);

            if (ev == null)
            {
                throw CreateUnknownConstantException(val, typeMap.TypeData.Type);
            }
            return(Enum.Parse(typeMap.TypeData.Type, ev));
        }
示例#5
0
        void ExportEnumSchema(XmlTypeMapping map)
        {
            if (IsMapExported(map))
            {
                return;
            }
            SetMapExported(map);

            XmlSchema           schema = GetSchema(map.XmlTypeNamespace);
            XmlSchemaSimpleType stype  = new XmlSchemaSimpleType();

            stype.Name = map.ElementName;
            schema.Items.Add(stype);

            XmlSchemaSimpleTypeRestriction rest = new XmlSchemaSimpleTypeRestriction();

            rest.BaseTypeName = new XmlQualifiedName("string", XmlSchema.Namespace);
            EnumMap emap = (EnumMap)map.ObjectMap;

            foreach (EnumMap.EnumMapMember emem in emap.Members)
            {
                XmlSchemaEnumerationFacet ef = new XmlSchemaEnumerationFacet();
                ef.Value = emem.XmlName;
                rest.Facets.Add(ef);
            }

            if (emap.IsFlags)
            {
                XmlSchemaSimpleTypeList slist           = new XmlSchemaSimpleTypeList();
                XmlSchemaSimpleType     restrictionType = new XmlSchemaSimpleType();
                restrictionType.Content = rest;
                slist.ItemType          = restrictionType;
                stype.Content           = slist;
            }
            else
            {
                stype.Content = rest;
            }
        }