EnumDataContract ImportEnum(XmlQualifiedName typeName, XmlSchemaSimpleTypeRestriction restriction, bool isFlags, XmlSchemaAnnotation annotation) { EnumDataContract dataContract = new EnumDataContract(); dataContract.StableName = typeName; dataContract.BaseContractName = ImportActualType(annotation, SchemaExporter.DefaultEnumBaseTypeName, typeName); dataContract.IsFlags = isFlags; AddDataContract(dataContract); // CheckIfEnum has already checked if baseType of restriction is string dataContract.Values = new List<long>(); dataContract.Members = new List<DataMember>(); foreach (XmlSchemaFacet facet in restriction.Facets) { XmlSchemaEnumerationFacet enumFacet = facet as XmlSchemaEnumerationFacet; if (enumFacet == null) ThrowEnumTypeCannotBeImportedException(typeName.Name, typeName.Namespace, SR.GetString(SR.EnumOnlyEnumerationFacetsSupported)); if (enumFacet.Value == null) ThrowEnumTypeCannotBeImportedException(typeName.Name, typeName.Namespace, SR.GetString(SR.EnumEnumerationFacetsMustHaveValue)); string valueInnerText = GetInnerText(typeName, ImportAnnotation(enumFacet.Annotation, SchemaExporter.EnumerationValueAnnotationName)); if (valueInnerText == null) dataContract.Values.Add(SchemaExporter.GetDefaultEnumValue(isFlags, dataContract.Members.Count)); else dataContract.Values.Add(dataContract.GetEnumValueFromString(valueInnerText)); DataMember dataMember = new DataMember(enumFacet.Value); dataContract.Members.Add(dataMember); } return dataContract; }
private EnumDataContract ImportEnum(XmlQualifiedName typeName, XmlSchemaSimpleTypeRestriction restriction, bool isFlags, XmlSchemaAnnotation annotation) { EnumDataContract dataContract = new EnumDataContract { StableName = typeName, BaseContractName = ImportActualType(annotation, SchemaExporter.DefaultEnumBaseTypeName, typeName), IsFlags = isFlags }; this.AddDataContract(dataContract); dataContract.Values = new List<long>(); dataContract.Members = new List<DataMember>(); foreach (XmlSchemaFacet facet in restriction.Facets) { XmlSchemaEnumerationFacet facet2 = facet as XmlSchemaEnumerationFacet; if (facet2 == null) { ThrowEnumTypeCannotBeImportedException(typeName.Name, typeName.Namespace, System.Runtime.Serialization.SR.GetString("EnumOnlyEnumerationFacetsSupported")); } if (facet2.Value == null) { ThrowEnumTypeCannotBeImportedException(typeName.Name, typeName.Namespace, System.Runtime.Serialization.SR.GetString("EnumEnumerationFacetsMustHaveValue")); } string innerText = this.GetInnerText(typeName, ImportAnnotation(facet2.Annotation, SchemaExporter.EnumerationValueAnnotationName)); if (innerText == null) { dataContract.Values.Add(SchemaExporter.GetDefaultEnumValue(isFlags, dataContract.Members.Count)); } else { dataContract.Values.Add(dataContract.GetEnumValueFromString(innerText)); } DataMember item = new DataMember(facet2.Value); dataContract.Members.Add(item); } return dataContract; }