Пример #1
0
 public static ITypeId SniffRootNodeType(Stream stream, IDocumentContext documentContext, out string xamlClassAttribute)
 {
     xamlClassAttribute = (string)null;
     try
     {
         ITypeResolver typeResolver = documentContext.TypeResolver;
         using (XmlReader xmlReader = XmlReader.Create(stream))
         {
             ClrNamespaceUriParseCache documentNamespaces = new ClrNamespaceUriParseCache(typeResolver);
             while (xmlReader.Read())
             {
                 if (xmlReader.MoveToContent() == XmlNodeType.Element)
                 {
                     xamlClassAttribute = xmlReader.GetAttribute("Class", "http://schemas.microsoft.com/winfx/2006/xaml");
                     string str = xmlReader.LookupNamespace(xmlReader.Prefix);
                     if (!string.IsNullOrEmpty(str))
                     {
                         return((ITypeId)XamlTypeHelper.GetTypeId(typeResolver, documentNamespaces, XmlNamespace.ToNamespace(str, XmlNamespace.GetNamespaceCanonicalization(typeResolver)), xmlReader.LocalName, false, false));
                     }
                 }
             }
         }
     }
     catch (XmlException ex)
     {
     }
     return((ITypeId)null);
 }
Пример #2
0
        internal static IType GetTypeId(ITypeResolver typeResolver, ClrNamespaceUriParseCache documentNamespaces, XmlNamespace xmlNamespace, string typeName, bool instantiateUnrecognizedTypes, bool inMarkupExtension)
        {
            IType designTimeType = typeResolver.PlatformMetadata.GetDesignTimeType(typeResolver, (IXmlNamespace)xmlNamespace, typeName);

            if (designTimeType != null)
            {
                return(designTimeType);
            }
            AssemblyNamespace assemblyNamespace;

            documentNamespaces.GetNamespace((IXmlNamespace)xmlNamespace, out assemblyNamespace);
            IType type;

            if (assemblyNamespace != null)
            {
                type = XamlTypeHelper.ResolveType(typeResolver, (IXmlNamespaceTypeResolver)documentNamespaces, xmlNamespace, typeName, inMarkupExtension);
                if (type == null && instantiateUnrecognizedTypes)
                {
                    IAssembly assembly     = assemblyNamespace.Assembly;
                    string    clrNamespace = assemblyNamespace.ClrNamespace;
                    type = typeResolver.GetType(assembly.Name, TypeHelper.CombineNamespaceAndTypeName(clrNamespace, typeName)) ?? typeResolver.PlatformMetadata.CreateUnknownType(typeResolver, assembly, clrNamespace, typeName);
                }
            }
            else
            {
                type = XamlTypeHelper.ResolveType(typeResolver, typeResolver.ProjectNamespaces, xmlNamespace, typeName, inMarkupExtension);
                if (type == null && instantiateUnrecognizedTypes)
                {
                    type = typeResolver.PlatformMetadata.CreateUnknownType(typeResolver, (IXmlNamespace)xmlNamespace, typeName);
                }
            }
            return(type);
        }
Пример #3
0
 public XamlParserContext(IDocumentContext documentContext, ClassAttributes rootAttributes)
 {
     if (documentContext == null)
     {
         throw new ArgumentNullException("documentContext");
     }
     this.documentContext = documentContext;
     this.namespaces      = new ClrNamespaceUriParseCache(this.TypeResolver);
     this.rootAttributes  = rootAttributes;
     this.errors          = (IList <XamlParseError>) new List <XamlParseError>();
 }
Пример #4
0
 public XamlSerializerContext(PersistenceSettings persistenceSettings, IDocumentContext documentContext, CultureInfo cultureInfo, IAssembly projectAssembly, bool removeProjectRootFromUri)
 {
     this.persistenceSettings = persistenceSettings;
     this.documentContext     = documentContext;
     this.cultureInfo         = cultureInfo;
     this.root      = new RootNode();
     this.container = (ContainerNode)this.root;
     this.clrNamespaceUriParseCache     = new ClrNamespaceUriParseCache(this.TypeResolver);
     this.clrNamespaceUriSerializeCache = new XamlSerializerContext.ClrNamespaceUriSerializeCache(this.documentContext, projectAssembly);
     this.removeProjectRootFromUri      = removeProjectRootFromUri;
 }
            public ClrNamespaceDeclaration(ClrNamespaceUriParseCache namespaces, string assemblyName, string clrNamespace)
            {
                this.namespaces   = namespaces;
                this.assemblyName = ClrNamespaceUriParseCache.ClrNamespaceDeclaration.Normalize(assemblyName);
                this.clrNamespace = ClrNamespaceUriParseCache.ClrNamespaceDeclaration.Normalize(clrNamespace);
                if (this.assemblyName == null || !this.namespaces.typeResolver.IsCapabilitySet(PlatformCapability.AllowExtensionInClrNamespace))
                {
                    return;
                }
                string extension = Path.GetExtension(this.assemblyName);

                if (string.IsNullOrEmpty(extension))
                {
                    return;
                }
                switch (extension.ToUpperInvariant())
                {
                case ".DLL":
                case ".EXE":
                    this.assemblyName = Path.GetFileNameWithoutExtension(this.assemblyName);
                    break;
                }
            }