public override CodeTypeReference GetReferenceFor(NamespaceModel referencingNamespace, bool collection, bool forInit = false)
        {
            var type = ValueType;

            if (XmlSchemaType != null)
            {
                // some types are not mapped in the same way between XmlSerializer and XmlSchema >(
                // http://msdn.microsoft.com/en-us/library/aa719879(v=vs.71).aspx
                // http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlelementattribute.datatype(v=vs.110).aspx
                // XmlSerializer is inconsistent: maps xs:decimal to decimal but xs:integer to string,
                // even though xs:integer is a restriction of xs:decimal
                type = XmlSchemaType.GetEffectiveType(Configuration);
                UseDataTypeAttribute = XmlSchemaType.IsDataTypeAttributeAllowed(Configuration) ?? UseDataTypeAttribute;
            }

            if (collection)
            {
                if (forInit)
                    type = (Configuration.CollectionImplementationType ?? Configuration.CollectionType).MakeGenericType(type);
                else
                    type = Configuration.CollectionType.MakeGenericType(type);
            }

            return new CodeTypeReference(type);
        }
 public virtual CodeTypeReference GetReferenceFor(NamespaceModel referencingNamespace, bool collection, bool forInit = false)
 {
     var name = referencingNamespace == Namespace ? Name : string.Format("{2}{0}.{1}", Namespace.Name, Name, ((referencingNamespace ?? Namespace).IsAmbiguous ? "global::" : string.Empty));
     if (collection)
         name = forInit ? SimpleModel.GetCollectionImplementationName(name, Configuration) : SimpleModel.GetCollectionDefinitionName(name, Configuration);
     return new CodeTypeReference(name);
 }
 private NamespaceModel CreateNamespaceModel(Uri source, XmlQualifiedName qualifiedName)
 {
     NamespaceModel namespaceModel = null;
     if (!qualifiedName.IsEmpty && qualifiedName.Namespace != XmlSchema.Namespace)
     {
         var key = new NamespaceKey(source, qualifiedName.Namespace);
         if (!Namespaces.TryGetValue(key, out namespaceModel))
         {
             var namespaceName = BuildNamespace(source, qualifiedName.Namespace);
             namespaceModel = new NamespaceModel(key, _configuration) { Name = namespaceName };
             Namespaces.Add(key, namespaceModel);
         }
     }
     return namespaceModel;
 }