System.Xml.Serialization.CodeIdentifiers.ToArray C# (CSharp) Method

ToArray() public method

public ToArray ( Type type ) : object
type System.Type
return object
        public object ToArray(Type type)
        {
            //Array array = Array.CreateInstance(type, identifiers.Values.Count);
            //identifiers.Values.CopyTo(array, 0);
            Array array = Array.CreateInstance(type, _list.Count);
            _list.CopyTo(array, 0);
            return array;
        }

Usage Example

Example #1
0
        private TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, bool isList)
        {
            TypeMapping mapping = (TypeMapping)base.ImportedMappings[dataType];

            if (mapping != null)
            {
                return(mapping);
            }
            XmlSchemaSimpleType type     = this.FindDataType(dataType.DerivedFrom);
            TypeDesc            typeDesc = base.Scope.GetTypeDesc(type);

            if ((typeDesc != null) && (typeDesc != base.Scope.GetTypeDesc(typeof(string))))
            {
                return(this.ImportPrimitiveDataType(dataType));
            }
            identifier = Accessor.UnescapeName(identifier);
            string      name     = base.GenerateUniqueTypeName(identifier);
            EnumMapping mapping2 = new EnumMapping {
                IsReference = base.Schemas.IsReference(dataType),
                TypeDesc    = new TypeDesc(name, name, TypeKind.Enum, null, TypeFlags.None),
                TypeName    = identifier,
                Namespace   = typeNs,
                IsFlags     = isList
            };
            CodeIdentifiers identifiers = new CodeIdentifiers();

            if (!(dataType.Content is XmlSchemaSimpleTypeRestriction))
            {
                throw new InvalidOperationException(Res.GetString("XmlInvalidEnumContent", new object[] { dataType.Content.GetType().Name, identifier }));
            }
            XmlSchemaSimpleTypeRestriction content = (XmlSchemaSimpleTypeRestriction)dataType.Content;

            for (int i = 0; i < content.Facets.Count; i++)
            {
                object obj2 = content.Facets[i];
                if (obj2 is XmlSchemaEnumerationFacet)
                {
                    XmlSchemaEnumerationFacet facet    = (XmlSchemaEnumerationFacet)obj2;
                    ConstantMapping           mapping3 = new ConstantMapping();
                    string str2 = CodeIdentifier.MakeValid(facet.Value);
                    mapping3.Name    = identifiers.AddUnique(str2, mapping3);
                    mapping3.XmlName = facet.Value;
                    mapping3.Value   = i;
                }
            }
            mapping2.Constants = (ConstantMapping[])identifiers.ToArray(typeof(ConstantMapping));
            if (isList && (mapping2.Constants.Length > 0x3f))
            {
                mapping = new PrimitiveMapping {
                    TypeDesc = base.Scope.GetTypeDesc(typeof(string)),
                    TypeName = mapping.TypeDesc.DataType.Name
                };
                base.ImportedMappings.Add(dataType, mapping);
                return(mapping);
            }
            base.ImportedMappings.Add(dataType, mapping2);
            base.Scope.AddTypeMapping(mapping2);
            return(mapping2);
        }
All Usage Examples Of System.Xml.Serialization.CodeIdentifiers::ToArray