• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Schema.XmlSchemaSimpleTypeRestriction类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Xml.Schema.XmlSchemaSimpleTypeRestriction的典型用法代码示例。如果您正苦于以下问题:C# XmlSchemaSimpleTypeRestriction类的具体用法?C# XmlSchemaSimpleTypeRestriction怎么用?C# XmlSchemaSimpleTypeRestriction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



XmlSchemaSimpleTypeRestriction类属于System.Xml.Schema命名空间,在下文中一共展示了XmlSchemaSimpleTypeRestriction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetSchema

        public XmlSchemaElement GetSchema()
        {
            var type = new XmlSchemaComplexType();

            type.Attributes.Add(new XmlSchemaAttribute
                                    {
                                        Name = "refValue",
                                        Use = XmlSchemaUse.Required,
                                        SchemaTypeName =
                                            new XmlQualifiedName("positiveInteger", "http://www.w3.org/2001/XMLSchema")
                                    });

            type.Attributes.Add(new XmlSchemaAttribute
                                    {
                                        Name = "test",
                                        Use = XmlSchemaUse.Optional,
                                        SchemaTypeName =
                                            new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
                                    });

            
            var restriction = new XmlSchemaSimpleTypeRestriction
                                  {
                                      BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
                                  };

            restriction.Facets.Add(new XmlSchemaEnumerationFacet {Value = "years"});
            restriction.Facets.Add(new XmlSchemaEnumerationFacet {Value = "weeks"});
            restriction.Facets.Add(new XmlSchemaEnumerationFacet {Value = "days"});

            var simpleType = new XmlSchemaSimpleType {Content = restriction};


            type.Attributes.Add(new XmlSchemaAttribute
                                    {
                                        Name = "units",
                                        Use = XmlSchemaUse.Required,
                                        SchemaType = simpleType
                                    });


            type.Attributes.Add(new XmlSchemaAttribute
                                    {
                                        Name = "expressionLanguage",
                                        Use = XmlSchemaUse.Optional,
                                        SchemaTypeName =
                                            new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
                                    });

            var element = new XmlSchemaElement
                              {
                                  Name = "dicom-age-less-than",
                                  SchemaType = type
                              };

            return element;
        }
开发者ID:nhannd,项目名称:Xian,代码行数:57,代码来源:DicomAgeLessThanSpecification.cs


示例2: CreateSimpletypeLength

    private void CreateSimpletypeLength(string length, string minLength, string maxLength, bool expected) {
      passed = true;

      XmlSchema schema = new XmlSchema();

      XmlSchemaSimpleType testType = new XmlSchemaSimpleType();
      testType.Name = "TestType";

      XmlSchemaSimpleTypeRestriction testTypeRestriction = new XmlSchemaSimpleTypeRestriction();
      testTypeRestriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

      if (length != "-") {
        XmlSchemaLengthFacet _length = new XmlSchemaLengthFacet();
        _length.Value = length;
        testTypeRestriction.Facets.Add(_length);
      }
      if (minLength != "-") {
        XmlSchemaMinLengthFacet _minLength = new XmlSchemaMinLengthFacet();
        _minLength.Value = minLength;
        testTypeRestriction.Facets.Add(_minLength);
      }
      if (maxLength != "-") {
        XmlSchemaMaxLengthFacet _maxLength = new XmlSchemaMaxLengthFacet();
        _maxLength.Value = maxLength;
        testTypeRestriction.Facets.Add(_maxLength);
      }

      testType.Content = testTypeRestriction;
      schema.Items.Add(testType);
      schema.Compile(new ValidationEventHandler(ValidationCallbackOne));

      Assert.IsTrue (expected == passed, (passed ? "Test passed, should have failed" : "Test failed, should have passed") + ": " + length + " " + minLength + " " + maxLength);
      
    }
开发者ID:nobled,项目名称:mono,代码行数:34,代码来源:XmlSchemaLengthFacetTests.cs


示例3: Visit

        protected override void Visit(XmlSchemaSimpleTypeRestriction restriction)
        {
            PushNode(SimpleTypeStructureNodeType.Restriction, restriction);

            var baseType = _schemaSet.ResolveType(restriction.BaseType, restriction.BaseTypeName);
            Traverse(baseType);
            Traverse(restriction.Facets);

            PopNode();
        }
开发者ID:sergey-steinvil,项目名称:xsddoc,代码行数:10,代码来源:SimpleTypeStructureBuilder.cs


示例4: CreateGuidType

        private XmlSchemaSimpleType CreateGuidType()
        {
            var type = new XmlSchemaSimpleType { Name = "Guid" };

            var restriction = new XmlSchemaSimpleTypeRestriction { BaseType = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String) };
            restriction.Facets.Add(new XmlSchemaPatternFacet
            {
                Value =
                    @"[{(]?[0-9A-Fa-f]{8}\-?[0-9A-Fa-f]{4}\-?[0-9A-Fa-f]{4}\-?[0-9A-Fa-f]{4}\-?[0-9A-Fa-f]{12}[})]?|([!$])(\(var|\(loc|\(wix)\.[_A-Za-z][0-9A-Za-z_.]*\)"
            });
            type.Content = restriction;
            return type;
        }
开发者ID:kayanme,项目名称:Dataspace,代码行数:13,代码来源:DataSchemaBuilder.cs


示例5: Write

        protected internal override void Write(XmlSchemaObject obj)
        {
            var simpleType = (XmlSchemaSimpleType) obj;
            var restriction = new XmlSchemaSimpleTypeRestriction();

            foreach (var facet in Facets)
            {
                restriction.Facets.Add(facet);
            }

            simpleType.Content = restriction;
            base.Write(obj);
        }
开发者ID:kodefuguru,项目名称:SDataCSharpClientLib,代码行数:13,代码来源:SDataSchemaSimpleType.cs


示例6: AddNonXsdPrimitive

 private static void AddNonXsdPrimitive(Type type, string dataTypeName, string ns, string formatterName, XmlQualifiedName baseTypeName, XmlSchemaFacet[] facets, TypeFlags flags)
 {
     XmlSchemaSimpleType dataType = new XmlSchemaSimpleType {
         Name = dataTypeName
     };
     XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction {
         BaseTypeName = baseTypeName
     };
     foreach (XmlSchemaFacet facet in facets)
     {
         restriction.Facets.Add(facet);
     }
     dataType.Content = restriction;
     TypeDesc desc = new TypeDesc(type, false, dataType, formatterName, flags);
     if (primitiveTypes[type] == null)
     {
         primitiveTypes.Add(type, desc);
     }
     primitiveDataTypes.Add(dataType, desc);
     primitiveNames.Add(dataTypeName, ns, desc);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:21,代码来源:TypeScope.cs


示例7: GetSimpleType

        /// <summary>
        ///     Returns a SimpleType restricted by the datatype only
        /// </summary>
        public override XmlSchemaSimpleType GetSimpleType(string attributeDataType)
        {
            var retVal = new XmlSchemaSimpleType();

            // <xs:restriction base="<whatever xs:datatype is required>" />
            var dataTypeRestriction = new XmlSchemaSimpleTypeRestriction
            {
                BaseTypeName = new XmlQualifiedName(attributeDataType)
            };
            retVal.Content = dataTypeRestriction;

            //  if the property type is an enum then add an enumeration facet to the simple type
            if (Property.PropertyType.IsEnum)
            {
                // <xs:enumeration value="123" />
                foreach (var enumValue in Enum.GetNames(Property.PropertyType))
                {
                    var enumFacet = new XmlSchemaEnumerationFacet { Value = enumValue };
                    dataTypeRestriction.Facets.Add(enumFacet);
                }
            }

            return retVal;
        }
开发者ID:flcdrg,项目名称:XSDExtractor,代码行数:27,代码来源:NoValidatorParser.cs


示例8: AddSimpleType

 private static void AddSimpleType(XmlSchema schema, string typeName, string baseXsdType) {
     XmlSchemaSimpleType type = new XmlSchemaSimpleType();
     type.Name = typeName;
     XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
     restriction.BaseTypeName = new XmlQualifiedName(baseXsdType, XmlSchema.Namespace);
     type.Content = restriction;
     schema.Items.Add(type);
 }
开发者ID:ArildF,项目名称:masters,代码行数:8,代码来源:xsd.cs


示例9: ExportEnumMapping

        XmlSchemaType ExportEnumMapping(EnumMapping mapping, string ns) {
            if (!mapping.IncludeInSchema) throw new InvalidOperationException(Res.GetString(Res.XmlCannotIncludeInSchema, mapping.TypeDesc.Name));
            XmlSchemaSimpleType dataType = (XmlSchemaSimpleType)types[mapping];
            if (dataType == null) {
                CheckForDuplicateType(mapping, mapping.Namespace);
                dataType = new XmlSchemaSimpleType();
                dataType.Name = mapping.TypeName;
                if (!mapping.IsAnonymousType) {
                    types.Add(mapping, dataType);
                    AddSchemaItem(dataType, mapping.Namespace, ns);
                }
                XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
                restriction.BaseTypeName = new XmlQualifiedName("string", XmlSchema.Namespace);

                for (int i = 0; i < mapping.Constants.Length; i++) {
                    ConstantMapping constant = mapping.Constants[i];
                    XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet();
                    enumeration.Value = constant.XmlName;
                    restriction.Facets.Add(enumeration);
                }
                if (!mapping.IsFlags) {
                    dataType.Content = restriction;
                }
                else {
                    XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
                    XmlSchemaSimpleType enumType = new XmlSchemaSimpleType();
                    enumType.Content =  restriction;
                    list.ItemType = enumType;
                    dataType.Content =  list;
                }
            }
            if (!mapping.IsAnonymousType) {
                AddSchemaImport(mapping.Namespace, ns);
            }
            return dataType;
        }
开发者ID:uQr,项目名称:referencesource,代码行数:36,代码来源:XmlSchemaExporter.cs


示例10: GetBuildInSchema

 internal static XmlSchema GetBuildInSchema()
 {
     if (builtInSchemaForXmlNS == null)
     {
         XmlSchema schema = new XmlSchema {
             TargetNamespace = "http://www.w3.org/XML/1998/namespace"
         };
         schema.Namespaces.Add("xml", "http://www.w3.org/XML/1998/namespace");
         XmlSchemaAttribute item = new XmlSchemaAttribute {
             Name = "lang",
             SchemaTypeName = new XmlQualifiedName("language", "http://www.w3.org/2001/XMLSchema")
         };
         schema.Items.Add(item);
         XmlSchemaAttribute attribute2 = new XmlSchemaAttribute {
             Name = "base",
             SchemaTypeName = new XmlQualifiedName("anyURI", "http://www.w3.org/2001/XMLSchema")
         };
         schema.Items.Add(attribute2);
         XmlSchemaAttribute attribute3 = new XmlSchemaAttribute {
             Name = "space"
         };
         XmlSchemaSimpleType type = new XmlSchemaSimpleType();
         XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction {
             BaseTypeName = new XmlQualifiedName("NCName", "http://www.w3.org/2001/XMLSchema")
         };
         XmlSchemaEnumerationFacet facet = new XmlSchemaEnumerationFacet {
             Value = "default"
         };
         restriction.Facets.Add(facet);
         XmlSchemaEnumerationFacet facet2 = new XmlSchemaEnumerationFacet {
             Value = "preserve"
         };
         restriction.Facets.Add(facet2);
         type.Content = restriction;
         attribute3.SchemaType = type;
         attribute3.DefaultValue = "preserve";
         schema.Items.Add(attribute3);
         XmlSchemaAttributeGroup group = new XmlSchemaAttributeGroup {
             Name = "specialAttrs"
         };
         XmlSchemaAttribute attribute4 = new XmlSchemaAttribute {
             RefName = new XmlQualifiedName("lang", "http://www.w3.org/XML/1998/namespace")
         };
         group.Attributes.Add(attribute4);
         XmlSchemaAttribute attribute5 = new XmlSchemaAttribute {
             RefName = new XmlQualifiedName("space", "http://www.w3.org/XML/1998/namespace")
         };
         group.Attributes.Add(attribute5);
         XmlSchemaAttribute attribute6 = new XmlSchemaAttribute {
             RefName = new XmlQualifiedName("base", "http://www.w3.org/XML/1998/namespace")
         };
         group.Attributes.Add(attribute6);
         schema.Items.Add(group);
         schema.IsPreprocessed = true;
         schema.CompileSchemaInSet(new NameTable(), null, null);
         Interlocked.CompareExchange<XmlSchema>(ref builtInSchemaForXmlNS, schema, null);
     }
     return builtInSchemaForXmlNS;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:59,代码来源:Preprocessor.cs


示例11: WriteEnumType

                public XmlSchemaType WriteEnumType (Type type)
                {
                        if (type.IsEnum == false)
                                throw new Exception (String.Format ("{0} is not an enumeration.", type.Name));

                        if (generatedSchemaTypes.Contains (type.FullName)) // Caching
                                return null;

                        XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType ();
                        simpleType.Name = type.Name;
                        FieldInfo [] fields = type.GetFields ();

                        XmlSchemaSimpleTypeRestriction simpleRestriction = new XmlSchemaSimpleTypeRestriction ();
                        simpleType.Content = simpleRestriction;
                        simpleRestriction.BaseTypeName = new XmlQualifiedName ("string", xs);

                        foreach (FieldInfo field in fields) {
                                if (field.IsSpecialName)
                                        continue;

                                XmlSchemaEnumerationFacet e = new XmlSchemaEnumerationFacet ();
                                e.Value = field.Name;
                                simpleRestriction.Facets.Add (e);
                        }

                        generatedSchemaTypes.Add (type.FullName, simpleType);
                        return simpleType;
                }
开发者ID:symform,项目名称:mono,代码行数:28,代码来源:MonoXSD.cs


示例12: GetAttributeValueCompletionData

		XmlCompletionDataCollection GetAttributeValueCompletionData(XmlSchemaSimpleTypeRestriction simpleTypeRestriction)
		{
			XmlCompletionDataCollection data = new XmlCompletionDataCollection();
			
			foreach (XmlSchemaObject schemaObject in simpleTypeRestriction.Facets) {
				XmlSchemaEnumerationFacet enumFacet = schemaObject as XmlSchemaEnumerationFacet;
				if (enumFacet != null) {
					AddAttributeValue(data, enumFacet.Value, enumFacet.Annotation);
				}
			}

			return data;
		}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:13,代码来源:XmlSchemaCompletionData.cs


示例13: FinishBuiltinType

        /// <summary>
        /// Finish constructing built-in types by setting up derivation and list links.
        /// </summary>
        internal static void FinishBuiltinType(XmlSchemaSimpleType derivedType, XmlSchemaSimpleType baseType) {
            Debug.Assert(derivedType != null && baseType != null);

            // Create link from the derived type to the base type
            derivedType.SetBaseSchemaType(baseType);
            derivedType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
            if (derivedType.Datatype.Variety == XmlSchemaDatatypeVariety.Atomic) { //Content is restriction
                XmlSchemaSimpleTypeRestriction restContent = new XmlSchemaSimpleTypeRestriction();
                restContent.BaseTypeName = baseType.QualifiedName;
                derivedType.Content = restContent;
            }

            // Create link from a list type to its member type
            if (derivedType.Datatype.Variety == XmlSchemaDatatypeVariety.List) {
                XmlSchemaSimpleTypeList listContent = new XmlSchemaSimpleTypeList();
                derivedType.SetDerivedBy(XmlSchemaDerivationMethod.List);
                switch (derivedType.Datatype.TypeCode) {
                    case XmlTypeCode.NmToken:
                        listContent.ItemType = listContent.BaseItemType = enumToTypeCode[(int) XmlTypeCode.NmToken];
                        break;

                    case XmlTypeCode.Entity:
                        listContent.ItemType = listContent.BaseItemType = enumToTypeCode[(int) XmlTypeCode.Entity];
                        break;

                    case XmlTypeCode.Idref:
                        listContent.ItemType = listContent.BaseItemType = enumToTypeCode[(int) XmlTypeCode.Idref];
                        break;
                }
                derivedType.Content = listContent;
            }
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:35,代码来源:DataTypeImplementation.cs


示例14: GetBuildInSchema

        internal static XmlSchema GetBuildInSchema() {
            if (builtInSchemaForXmlNS == null) {
                XmlSchema tempSchema = new XmlSchema();
                tempSchema.TargetNamespace = XmlReservedNs.NsXml;
                tempSchema.Namespaces.Add("xml", XmlReservedNs.NsXml);
                
                XmlSchemaAttribute lang = new XmlSchemaAttribute();
                lang.Name = "lang";
                lang.SchemaTypeName = new XmlQualifiedName("language", XmlReservedNs.NsXs);
                tempSchema.Items.Add(lang);

                XmlSchemaAttribute xmlbase = new XmlSchemaAttribute();
                xmlbase.Name = "base";
                xmlbase.SchemaTypeName = new XmlQualifiedName("anyURI", XmlReservedNs.NsXs);
                tempSchema.Items.Add(xmlbase);

                XmlSchemaAttribute space = new XmlSchemaAttribute();
                space.Name = "space";
                    XmlSchemaSimpleType type = new XmlSchemaSimpleType();
                    XmlSchemaSimpleTypeRestriction r = new XmlSchemaSimpleTypeRestriction();
                    r.BaseTypeName = new XmlQualifiedName("NCName", XmlReservedNs.NsXs);
                    XmlSchemaEnumerationFacet space_default = new XmlSchemaEnumerationFacet();
                    space_default.Value = "default";
                    r.Facets.Add(space_default);
                    XmlSchemaEnumerationFacet space_preserve = new XmlSchemaEnumerationFacet();
                    space_preserve.Value = "preserve";
                    r.Facets.Add(space_preserve);
                    type.Content = r;
                    space.SchemaType = type;
                space.DefaultValue = "preserve";
                tempSchema.Items.Add(space);

                XmlSchemaAttributeGroup attributeGroup = new XmlSchemaAttributeGroup();
                attributeGroup.Name = "specialAttrs";
                XmlSchemaAttribute langRef = new XmlSchemaAttribute();
                langRef.RefName = new XmlQualifiedName("lang", XmlReservedNs.NsXml);
                attributeGroup.Attributes.Add(langRef);
                XmlSchemaAttribute spaceRef = new XmlSchemaAttribute();
                spaceRef.RefName = new XmlQualifiedName("space", XmlReservedNs.NsXml);
                attributeGroup.Attributes.Add(spaceRef);
                XmlSchemaAttribute baseRef = new XmlSchemaAttribute();
                baseRef.RefName = new XmlQualifiedName("base", XmlReservedNs.NsXml);
                attributeGroup.Attributes.Add(baseRef);
                tempSchema.Items.Add(attributeGroup);
                tempSchema.IsPreprocessed = true;
                tempSchema.CompileSchemaInSet(new NameTable(), null, null); //compile built-in schema

                Interlocked.CompareExchange<XmlSchema>(ref builtInSchemaForXmlNS, tempSchema, null);
            }
            return builtInSchemaForXmlNS; 
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:51,代码来源:Preprocessor.cs


示例15: ExportStreamBody

 protected void ExportStreamBody(WsdlNS.Message message, string wrapperName, string wrapperNs, string partName, string partNs, bool isRpc, bool skipSchemaExport)
 {
     XmlSchemaSet schemas = this.exporter.GeneratedXmlSchemas;
     XmlSchema schema = SchemaHelper.GetSchema(DataContractSerializerMessageContractImporter.StreamBodyTypeName.Namespace, schemas);
     if (!schema.SchemaTypes.Contains(DataContractSerializerMessageContractImporter.StreamBodyTypeName))
     {
         XmlSchemaSimpleType streamBodyType = new XmlSchemaSimpleType();
         streamBodyType.Name = DataContractSerializerMessageContractImporter.StreamBodyTypeName.Name;
         XmlSchemaSimpleTypeRestriction contentRestriction = new XmlSchemaSimpleTypeRestriction();
         contentRestriction.BaseTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Base64Binary).QualifiedName;
         streamBodyType.Content = contentRestriction;
         SchemaHelper.AddTypeToSchema(streamBodyType, schema, schemas);
     }
     XmlSchemaSequence wrapperSequence = null;
     if (!isRpc && wrapperName != null)
         wrapperSequence = ExportWrappedPart(message, wrapperName, wrapperNs, schemas, skipSchemaExport);
     MessagePartDescription streamPart = new MessagePartDescription(partName, partNs);
     ExportMessagePart(message, streamPart, DataContractSerializerMessageContractImporter.StreamBodyTypeName, null/*xsdType*/, false/*isOptional*/, false/*isNillable*/, skipSchemaExport, !isRpc, wrapperNs, wrapperSequence, schemas);
 }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:19,代码来源:MessageContractExporter.cs


示例16: createEnum

        private static void createEnum(PropertyInfo pi, Dictionary<Type, XmlSchemaType> xmlTypes, XmlSchema xmlSchema)
        {
            // Create enum
            var res = new XmlSchemaSimpleTypeRestriction();
            res.BaseTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.NmToken).QualifiedName;

            foreach (var o in Enum.GetNames(pi.PropertyType))
            {
                res.Facets.Add(new XmlSchemaEnumerationFacet
                    {
                        Value = (o.Substring(0, 1).ToLower() + o.Substring(1))
                });
            }

            XmlSchemaSimpleType st = new XmlSchemaSimpleType
            {
                Content = res
            };

            // For flags must create a union of the values & string
            if (CustomAttributeHelper.Has<System.FlagsAttribute>(pi.PropertyType))
            {
                XmlSchemaSimpleType st2 = new XmlSchemaSimpleType();
                st2.Name = getXmlTypeName(pi.PropertyType);

                var union = new XmlSchemaSimpleTypeUnion();

                XmlSchemaSimpleType st3 = new XmlSchemaSimpleType();
                var res3 = new XmlSchemaSimpleTypeRestriction();
                res3.BaseTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).QualifiedName;
                st3.Content = res3;

                union.BaseTypes.Add(st);
                union.BaseTypes.Add(st3);

                st2.Content = union;
                xmlSchema.Items.Add(st2);
                xmlTypes[pi.PropertyType] = st2;
            }
            else
            {
                st.Name = getXmlTypeName(pi.PropertyType);
                xmlSchema.Items.Add(st);
                xmlTypes[pi.PropertyType] = st;
            }
        }
开发者ID:xsharper,项目名称:xsharper,代码行数:46,代码来源:XsXsdGenerator.cs


示例17: HasEnumFacets

 private bool HasEnumFacets(XmlSchemaSimpleTypeRestriction restriction)
 {
     foreach (XmlSchemaFacet facet in restriction.Facets)
     {
         if (facet is XmlSchemaEnumerationFacet)
             return true;
     }
     return false;
 }
开发者ID:awakegod,项目名称:NETMF-LPC,代码行数:9,代码来源:DCCodeGen.cs


示例18: CreateEnumeration

        private void CreateEnumeration(XmlSchemaSimpleTypeRestriction restriction, CodeTypeDeclaration codeType)
        {
            Logger.WriteLine("\tRestriction base type: " + restriction.BaseTypeName, LogLevel.Verbose);

            // Process facets
            foreach (XmlSchemaFacet facet in restriction.Facets)
            {
                int enumValue = -1;
                bool IsEnum = false;

                Logger.WriteLine("\t\tFacet Type: " + facet.GetType().ToString(), LogLevel.Verbose);
                Logger.WriteLine("\t\tFacet Value: " + facet.Value, LogLevel.Verbose);

                // If this is an Enum facet
                if (facet is XmlSchemaEnumerationFacet)
                {
                    IsEnum = true;
                    if (facet.Annotation != null)
                    {
                        foreach (XmlSchemaObject item in facet.Annotation.Items)
                        {
                            if (item is XmlSchemaAppInfo)
                            {
                                enumValue = Convert.ToInt32(((XmlSchemaAppInfo)item).Markup[0].InnerText);
                                break;
                            }
                            enumValue = -1;
                        }
                    }

                    // Validate the enum string. If the first char is numeric or any character is not Alpha Numeric throw
                    string enumTestValue = facet.Value.ToLower();
                    string enumFacet = "";
                    if (enumTestValue.Length < 64 && (enumTestValue[0] >= 'a' && facet.Value[0] <= 'z' || enumTestValue[0] == '_'))
                    {
                        for (int i = 0; i < enumTestValue.Length; ++i)
                        {
                            if ((enumTestValue[i] < '0' || (enumTestValue[i] > '9' && enumTestValue[i] < 'a') || enumTestValue[i] > 'z') && enumTestValue[i] != '_')
                                continue;
                            enumFacet += facet.Value[i];
                        }
                    }
                    else
                        throw new XmlException("Invalid enumeration value. " + facet.Value);
                    
                    // Add enum member to data contract
                    CodeMemberField codeMember = new CodeMemberField(enumFacet, enumFacet);

                    // Since valid XMLSchema enum values may contain values that cannot be used as real C# enum values a mechanism
                    // is required to map XmlSchema value names to real enum value names. If an XmlSchema enum value name cannot be
                    // used for a real enum value, a UserData dictionary entry is created containing the real facet value
                    // (the XmlSchema value name) that is used by serializers to map between the real enum and the XmlSchema enum.
                    if (enumFacet != facet.Value)
                    {
                        codeMember.UserData.Add(typeof(XmlSchemaEnumerationFacet), facet);
                    }
                    if (Convert.ToInt32(enumValue) >= 0)
                        codeMember.InitExpression = new CodePrimitiveExpression(enumValue);
                    CodeAttributeDeclaration fieldAttrDecl = new CodeAttributeDeclaration("EnumMember");
                    codeMember.CustomAttributes.Add(fieldAttrDecl);
                    codeMember.Attributes = MemberAttributes.Public;
                    codeType.Members.Add(codeMember);
                }
                else
                {
                    // Per WCF DataContract processing rules, length, minlength, maxlength,
                    // whitespace and pattern are are forbidden elements in a simple type enumeration
                    // If this is not an enumeration only restriction and simple type are supported
                    // all others are ignored.
                    Type facetType = facet.GetType();
                    if (IsEnum && (facetType == typeof(XmlSchemaLengthFacet) ||
                        facetType == typeof(XmlSchemaMinLengthFacet) ||
                        facetType == typeof(XmlSchemaMaxLengthFacet) ||
                        facetType == typeof(XmlSchemaWhiteSpaceFacet) ||
                        facetType == typeof(XmlSchemaPatternFacet)))
                    {
                        Logger.WriteLine("SimpleType facet " + facetType.ToString() +
                            " was ingnored in the enumeration.", LogLevel.Normal);
                        continue;
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            return;
        }
开发者ID:awakegod,项目名称:NETMF-LPC,代码行数:88,代码来源:DCCodeGen.cs


示例19: ImportEnum

		void ImportEnum (CodeTypeDeclaration td, XmlSchemaSet schemas, XmlSchemaSimpleTypeRestriction r, XmlSchemaType type, XmlQualifiedName qname, bool isFlag)
		{
			if (isFlag && !r.BaseTypeName.Equals (new XmlQualifiedName ("string", XmlSchema.Namespace)))
				throw new InvalidDataContractException (String.Format ("For flags enumeration '{0}', the base type for the simple type restriction must be XML schema string", qname));

			td.IsEnum = true;
			AddTypeAttributes (td, type);
			if (isFlag)
				td.CustomAttributes.Add (new CodeAttributeDeclaration (new CodeTypeReference (typeof (FlagsAttribute))));

			foreach (var facet in r.Facets) {
				var e = facet as XmlSchemaEnumerationFacet;
				if (e == null)
					throw new InvalidDataContractException (String.Format ("Invalid simple type restriction (type {0}). Only enumeration is allowed.", qname));
				var em = new CodeMemberField () { Name = CodeIdentifier.MakeValid (e.Value) };
				var ea = new CodeAttributeDeclaration (enum_member_att_ref);
				if (e.Value != em.Name)
					ea.Arguments.Add (new CodeAttributeArgument ("Value", new CodePrimitiveExpression (e.Value)));
				em.CustomAttributes.Add (ea);
				td.Members.Add (em);
			}
		}
开发者ID:shana,项目名称:mono,代码行数:22,代码来源:XsdDataContractImporter.cs


示例20: ExportDerivedSchema

		void ExportDerivedSchema(XmlTypeMapping map) {
			if (IsMapExported (map)) return;
			SetMapExported (map);

			XmlSchema schema = GetSchema (map.XmlTypeNamespace);
			for (int i = 0; i < schema.Items.Count; i++) {
			        XmlSchemaSimpleType item = schema.Items [i] as XmlSchemaSimpleType;
			        if (item != null && item.Name == map.ElementName)
			                return;
			}
			XmlSchemaSimpleType stype = new XmlSchemaSimpleType ();
			stype.Name = map.ElementName;
			schema.Items.Add (stype);

			XmlSchemaSimpleTypeRestriction rest = new XmlSchemaSimpleTypeRestriction ();
			rest.BaseTypeName = new XmlQualifiedName (map.TypeData.MappedType.XmlType, XmlSchema.Namespace);
			XmlSchemaPatternFacet facet = map.TypeData.XmlSchemaPatternFacet;
			if (facet != null)
				rest.Facets.Add(facet);
			stype.Content = rest;
		}
开发者ID:Profit0004,项目名称:mono,代码行数:21,代码来源:XmlSchemaExporter.cs



注:本文中的System.Xml.Schema.XmlSchemaSimpleTypeRestriction类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Schema.XmlSchemaType类代码示例发布时间:2022-05-26
下一篇:
C# Schema.XmlSchemaSimpleType类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap