Exemplo n.º 1
0
        // ======================================================

        private Type TryGetType(string typeName)
        {
            Type type = SearchAssembliesForShortName(typeName);

            if (type == null && IsClrNamespace)
            {
                Debug.Assert(_assemblyNamespaces.Count == 1);
                type = XamlLanguage.LookupClrNamespaceType(_assemblyNamespaces[0], typeName);
            }
            if (type == null)
            {
                return(null);
            }

            // Discard private nested types
            Type currentType = type;

            while (currentType.IsNested)
            {
                if (currentType.IsNestedPrivate)
                {
                    return(null);
                }
                currentType = currentType.DeclaringType;
            }
            return(type);
        }
Exemplo n.º 2
0
        public static string ParseTypeName(this ITypeParser typeParser, XamlName name)
        {
            if (XamlLanguage.IsXamlType(name))
            {
                return(String.Empty);
            }

            string typeName;

            if (!typeParser.TryParseTypeName(name.LocalName, name.NamespaceName, out typeName))
            {
                throw new Granular.Exception("Type \"{0}\" wasn't found", name);
            }

            return(typeName);
        }
Exemplo n.º 3
0
        private Type TryGetType(string typeName)
        {
            Type clrNamespaceType = this.SearchAssembliesForShortName(typeName);

            if ((clrNamespaceType == null) && this.IsClrNamespace)
            {
                clrNamespaceType = XamlLanguage.LookupClrNamespaceType(this._assemblyNamespaces[0], typeName);
            }
            if (clrNamespaceType == null)
            {
                return(null);
            }
            for (Type type2 = clrNamespaceType; type2.IsNested; type2 = type2.DeclaringType)
            {
                if (type2.IsNestedPrivate)
                {
                    return(null);
                }
            }
            return(clrNamespaceType);
        }
Exemplo n.º 4
0
        public static bool TryParse(string typeName, IXamlNamespaceResolver namespaceResolver, out XamlTypeName result)
        {
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }
            if (namespaceResolver == null)
            {
                throw new ArgumentNullException("namespaceResolver");
            }

            result = null;
            IList <XamlTypeName> args = null;
            int nArray = 0;
            int idx;

            if (typeName.Length > 2 && typeName[typeName.Length - 1] == ']')
            {
                idx = typeName.LastIndexOf('[');
                if (idx < 0)
                {
                    return(false);                    // mismatch brace
                }
                nArray = 1;
                for (int i = idx + 1; i < typeName.Length - 1; i++)
                {
                    if (typeName[i] != ',')
                    {
                        return(false);                        // only ',' is expected
                    }
                    nArray++;
                }
                if (!TryParse(typeName.Substring(0, idx), namespaceResolver, out result))
                {
                    return(false);
                }
                // Weird result, but Name ends with '[]'
                result = new XamlTypeName(result.Namespace, result.Name + '[' + new string(',', nArray - 1) + ']', result.TypeArguments);
                return(true);
            }

            idx = typeName.IndexOf('(');
            if (idx >= 0)
            {
                if (typeName[typeName.Length - 1] != ')')
                {
                    return(false);
                }
                if (!TryParseList(typeName.Substring(idx + 1, typeName.Length - idx - 2), namespaceResolver, out args))
                {
                    return(false);
                }
                typeName = typeName.Substring(0, idx);
            }

            idx = typeName.IndexOf(':');
            string prefix, local;

            if (idx < 0)
            {
                prefix = String.Empty;
                local  = typeName;
            }
            else
            {
                prefix = typeName.Substring(0, idx);
                local  = typeName.Substring(idx + 1);
                if (!XamlLanguage.IsValidXamlName(prefix))
                {
                    return(false);
                }
            }
            if (!XamlLanguage.IsValidXamlName(local, true))
            {
                return(false);
            }
            string ns = namespaceResolver.GetNamespace(prefix);

            if (ns == null)
            {
                return(false);
            }

            result = new XamlTypeName(ns, local, args);
            return(true);
        }