System.Runtime.Serialization.XsdDataContractImporter.ImportEnum C# (CSharp) Method

ImportEnum() private method

private ImportEnum ( CodeTypeDeclaration td, XmlSchemaSet schemas, XmlSchemaSimpleTypeRestriction r, XmlSchemaType type, XmlQualifiedName qname, bool isFlag ) : void
td System.CodeDom.CodeTypeDeclaration
schemas System.Xml.Schema.XmlSchemaSet
r System.Xml.Schema.XmlSchemaSimpleTypeRestriction
type System.Xml.Schema.XmlSchemaType
qname System.Xml.XmlQualifiedName
isFlag bool
return void
		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);
			}
		}