Наследование: ObjectMap
Пример #1
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);
            }
            stype.Content = rest;
        }
 private string ExportDefaultValue(TypeData typeData, XmlTypeMapping map, object defaultValue)
 {
     if (typeData.SchemaType == SchemaTypes.Enum)
     {
         EnumMap enumMap = (EnumMap)map.ObjectMap;
         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));
        }
Пример #4
0
        object GetEnumValue(XmlTypeMapping typeMap, string val)
        {
            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 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);
            }
        }
Пример #6
0
        private object GetEnumValue(XmlTypeMapping typeMap, string val)
        {
            if (val == null)
            {
                return(null);
            }
            EnumMap enumMap  = (EnumMap)typeMap.ObjectMap;
            string  enumName = enumMap.GetEnumName(typeMap.TypeFullName, val);

            if (enumName == null)
            {
                throw base.CreateUnknownConstantException(val, typeMap.TypeData.Type);
            }
            return(Enum.Parse(typeMap.TypeData.Type, enumName));
        }
Пример #7
0
        void ExportEnumCode(XmlTypeMapping map)
        {
            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);

            GenerateEnum(map, codeEnum);
            EnumMap emap = (EnumMap)map.ObjectMap;

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

            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);
            }
        }
        private void ExportEnumSchema(XmlTypeMapping map)
        {
            if (this.IsMapExported(map))
            {
                return;
            }
            this.SetMapExported(map);
            XmlSchema           schema = this.GetSchema(map.XmlTypeNamespace);
            XmlSchemaSimpleType xmlSchemaSimpleType = new XmlSchemaSimpleType();

            xmlSchemaSimpleType.Name = map.ElementName;
            schema.Items.Add(xmlSchemaSimpleType);
            XmlSchemaSimpleTypeRestriction xmlSchemaSimpleTypeRestriction = new XmlSchemaSimpleTypeRestriction();

            xmlSchemaSimpleTypeRestriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
            EnumMap enumMap = (EnumMap)map.ObjectMap;

            foreach (EnumMap.EnumMapMember enumMapMember in enumMap.Members)
            {
                XmlSchemaEnumerationFacet xmlSchemaEnumerationFacet = new XmlSchemaEnumerationFacet();
                xmlSchemaEnumerationFacet.Value = enumMapMember.XmlName;
                xmlSchemaSimpleTypeRestriction.Facets.Add(xmlSchemaEnumerationFacet);
            }
            if (enumMap.IsFlags)
            {
                xmlSchemaSimpleType.Content = new XmlSchemaSimpleTypeList
                {
                    ItemType = new XmlSchemaSimpleType
                    {
                        Content = xmlSchemaSimpleTypeRestriction
                    }
                };
            }
            else
            {
                xmlSchemaSimpleType.Content = xmlSchemaSimpleTypeRestriction;
            }
        }
		protected override void GenerateEnumItem (CodeMemberField codeField, EnumMap.EnumMapMember emem)
		{
			if (emem.EnumName != emem.XmlName)
			{
				CodeAttributeDeclaration xatt = new CodeAttributeDeclaration ("System.Xml.Serialization.SoapEnum");
				xatt.Arguments.Add (GetArg ("Name", emem.XmlName));
				AddCustomAttribute (codeField, xatt, true);
			}
		}		
		protected virtual void GenerateEnumItem (CodeMemberField codeField, EnumMap.EnumMapMember emem)
		{
		}
        string GetEnumXmlValue(XmlTypeMapping typeMap, object ob)
        {
            EnumMap map = (EnumMap)typeMap.ObjectMap;

            return(map.GetXmlName(ob));
        }