Esempio n. 1
0
        static IList <string> PrefixesToIgnore(IList <KeyValuePair <string, string> > xmlns)
        {
            var prefixes = new List <string>();

            foreach (var kvp in xmlns)
            {
                var prefix = kvp.Key;

                string typeName = null, ns = null, asm = null, targetPlatform = null;
                XmlnsHelper.ParseXmlns(kvp.Value, out typeName, out ns, out asm, out targetPlatform);
                if (targetPlatform == null)
                {
                    continue;
                }
                try {
                    if (targetPlatform != Device.RuntimePlatform)
                    {
                        // Special case for Windows backward compatibility
                        if (targetPlatform == "Windows" && Device.RuntimePlatform == Device.UWP)
                        {
                            continue;
                        }

                        prefixes.Add(prefix);
                    }
                } catch (InvalidOperationException) {
                    prefixes.Add(prefix);
                }
            }
            return(prefixes);
        }
Esempio n. 2
0
        static IList <string> PrefixesToIgnore(IList <KeyValuePair <string, string> > xmlns)
        {
            var prefixes = new List <string>();

            foreach (var kvp in xmlns)
            {
                var prefix = kvp.Key;

                string typeName = null, ns = null, asm = null;
                XmlnsHelper.ParseXmlns(kvp.Value, out typeName, out ns, out asm);
            }
            return(prefixes);
        }
Esempio n. 3
0
        public static Type GetElementType(XmlType xmlType, IXmlLineInfo xmlInfo, Assembly currentAssembly,
                                          out XamlParseException exception)
        {
            if (s_xmlnsDefinitions == null)
            {
                GatherXmlnsDefinitionAttributes(currentAssembly);
            }

            var namespaceURI  = xmlType.NamespaceUri;
            var elementName   = xmlType.Name;
            var typeArguments = xmlType.TypeArguments;

            exception = null;

            if (elementName.Contains("-"))
            {
                elementName = elementName.Replace('-', '+');
            }

            var lookupAssemblies = new List <XmlnsDefinitionAttribute>();
            var lookupNames      = new List <string>();

            foreach (var xmlnsDef in s_xmlnsDefinitions)
            {
                if (xmlnsDef.XmlNamespace != namespaceURI)
                {
                    continue;
                }
                lookupAssemblies.Add(xmlnsDef);
            }

            if (lookupAssemblies.Count == 0)
            {
                string ns, asmstring, _;
                XmlnsHelper.ParseXmlns(namespaceURI, out _, out ns, out asmstring);
                lookupAssemblies.Add(new XmlnsDefinitionAttribute(namespaceURI, ns)
                {
                    AssemblyName = asmstring ?? currentAssembly.FullName
                });
            }

            lookupNames.Add(elementName);
            lookupNames.Add(elementName + "Extension");

            for (var i = 0; i < lookupNames.Count; i++)
            {
                var name = lookupNames[i];
                if (name.Contains(":"))
                {
                    name = name.Substring(name.LastIndexOf(':') + 1);
                }
                if (typeArguments != null)
                {
                    name += "`" + typeArguments.Count; //this will return an open generic Type
                }
                lookupNames[i] = name;
            }

            Type type = null;

            foreach (var asm in lookupAssemblies)
            {
                foreach (var name in lookupNames)
                {
                    if ((type = Type.GetType($"{asm.ClrNamespace}.{name}, {asm.AssemblyName}")) != null)
                    {
                        break;
                    }

                    if ('?' == name.Last())
                    {
                        string nameOfNotNull = name.Substring(0, name.Length - 1);
                        Type   typeofNotNull = Type.GetType($"{asm.ClrNamespace}.{nameOfNotNull}, {asm.AssemblyName}");

                        if (null != typeofNotNull)
                        {
                            type = typeof(Nullable <>).MakeGenericType(new Type[] { typeofNotNull });
                            break;
                        }
                    }
                }

                if (type != null)
                {
                    break;
                }
            }

            if (type != null && typeArguments != null)
            {
                XamlParseException innerexception = null;
                var args = typeArguments.Select(delegate(XmlType xmltype)
                {
                    XamlParseException xpe;
                    var t = GetElementType(xmltype, xmlInfo, currentAssembly, out xpe);
                    if (xpe != null)
                    {
                        innerexception = xpe;
                        return(null);
                    }
                    return(t);
                }).ToArray();
                if (innerexception != null)
                {
                    exception = innerexception;
                    return(null);
                }
                type = type.MakeGenericType(args);
            }

            if (type == null)
            {
                var message = $"Type {elementName} not found in xmlns {namespaceURI}\n";
                message  += "\n  - Make sure the all used assemblies (e.g. Tizen.NUI.Components) are included in the application project.";
                message  += "\n  - Make sure the type and namespace are correct.\n";
                exception = new XamlParseException($"message", xmlInfo);
            }

            return(type);
        }
Esempio n. 4
0
        public static Type GetElementType(XmlType xmlType, IXmlLineInfo xmlInfo, Assembly currentAssembly,
                                          out XamlParseException exception)
        {
            if (s_xmlnsDefinitions == null)
            {
                GatherXmlnsDefinitionAttributes();
            }

            var namespaceURI  = xmlType.NamespaceUri;
            var elementName   = xmlType.Name;
            var typeArguments = xmlType.TypeArguments;

            exception = null;

            if (elementName.Contains("-"))
            {
                elementName = elementName.Replace('-', '+');
            }

            var lookupAssemblies = new List <XmlnsDefinitionAttribute>();
            var lookupNames      = new List <string>();

            foreach (var xmlnsDef in s_xmlnsDefinitions)
            {
                if (xmlnsDef.XmlNamespace != namespaceURI)
                {
                    continue;
                }
                lookupAssemblies.Add(xmlnsDef);
            }

            if (lookupAssemblies.Count == 0)
            {
                string ns, asmstring, _;
                XmlnsHelper.ParseXmlns(namespaceURI, out _, out ns, out asmstring, out _);
                lookupAssemblies.Add(new XmlnsDefinitionAttribute(namespaceURI, ns, 0)
                {
                    AssemblyName = asmstring ?? currentAssembly.FullName
                });
            }

            lookupNames.Add(elementName);
            lookupNames.Add(elementName + "Extension");

            for (var i = 0; i < lookupNames.Count; i++)
            {
                var name = lookupNames[i];
                if (name.Contains(":"))
                {
                    name = name.Substring(name.LastIndexOf(':') + 1);
                }
                if (typeArguments != null)
                {
                    name += "`" + typeArguments.Count; //this will return an open generic Type
                }
                lookupNames[i] = name;
            }

            Type type = null;

            foreach (var asm in lookupAssemblies)
            {
                foreach (var name in lookupNames)
                {
                    if ((type = Type.GetType($"{asm.ClrNamespace}.{name}, {asm.AssemblyName}")) != null)
                    {
                        break;
                    }
                }
                if (type != null)
                {
                    break;
                }
            }

            if (type != null && typeArguments != null)
            {
                XamlParseException innerexception = null;
                var args = typeArguments.Select(delegate(XmlType xmltype)
                {
                    XamlParseException xpe;
                    var t = GetElementType(xmltype, xmlInfo, currentAssembly, out xpe);
                    if (xpe != null)
                    {
                        innerexception = xpe;
                        return(null);
                    }
                    return(t);
                }).ToArray();
                if (innerexception != null)
                {
                    exception = innerexception;
                    return(null);
                }
                type = type.MakeGenericType(args);
            }

            if (type == null)
            {
                exception = new XamlParseException($"Type {elementName} not found in xmlns {namespaceURI}", xmlInfo);
            }

            return(type);
        }
Esempio n. 5
0
        public static Type GetElementType(XmlType xmlType, IXmlLineInfo xmlInfo, Assembly currentAssembly,
                                          out XamlParseException exception)
        {
            if (s_xmlnsDefinitions == null)
            {
                GatherXmlnsDefinitionAttributes();
            }

            var namespaceURI  = xmlType.NamespaceUri;
            var elementName   = xmlType.Name;
            var typeArguments = xmlType.TypeArguments;

            exception = null;

            var lookupAssemblies = new List <XmlnsDefinitionAttribute>();
            var lookupNames      = new List <string>();

            foreach (var xmlnsDef in s_xmlnsDefinitions)
            {
                if (xmlnsDef.XmlNamespace != namespaceURI)
                {
                    continue;
                }
                lookupAssemblies.Add(xmlnsDef);
            }

            if (lookupAssemblies.Count == 0)
            {
                string ns, asmstring, _;
                XmlnsHelper.ParseXmlns(namespaceURI, out _, out ns, out asmstring, out _);
                lookupAssemblies.Add(new XmlnsDefinitionAttribute(namespaceURI, ns)
                {
                    AssemblyName = asmstring ?? currentAssembly.FullName
                });
            }

            lookupNames.Add(elementName);
            lookupNames.Add(elementName + "Extension");

            for (var i = 0; i < lookupNames.Count; i++)
            {
                var name = lookupNames[i];
                if (name.Contains(":"))
                {
                    name = name.Substring(name.LastIndexOf(':') + 1);
                }
                if (typeArguments != null)
                {
                    name += "`" + typeArguments.Count;                     //this will return an open generic Type
                }
                lookupNames[i] = name;
            }

            Type type = null;

            foreach (var asm in lookupAssemblies)
            {
                foreach (var name in lookupNames)
                {
                    if ((type = Type.GetType($"{asm.ClrNamespace}.{name}, {asm.AssemblyName}")) != null)
                    {
                        break;
                    }
                }
                if (type != null)
                {
                    break;
                }
            }

            if (type == null)
            {
                List <Tuple <string, Assembly> > lookupAssemblies2 = new List <Tuple <string, Assembly> >();
                if (namespaceURI == NUI2018Uri)
                {
                    // Got the type of Tizen.NUI wiedget here, then CreateValueVisitor will create the instance of Tizen.NUI widget
                    lookupAssemblies2.Add(new Tuple <string, Assembly>("Tizen.NUI", typeof(Tizen.NUI.BaseComponents.View).GetTypeInfo().Assembly));
                    lookupAssemblies2.Add(new Tuple <string, Assembly>("Tizen.NUI.BaseComponents", typeof(Tizen.NUI.BaseComponents.View).GetTypeInfo().Assembly));
                    lookupAssemblies2.Add(new Tuple <string, Assembly>("Tizen.NUI.UIComponents", typeof(Tizen.NUI.BaseComponents.View).GetTypeInfo().Assembly));
                    lookupAssemblies2.Add(new Tuple <string, Assembly>("Tizen.NUI.Xaml", typeof(XamlLoader).GetTypeInfo().Assembly));
                    lookupAssemblies2.Add(new Tuple <string, Assembly>("Tizen.NUI.Binding", typeof(Tizen.NUI.BaseComponents.View).GetTypeInfo().Assembly));
                }
                else if (namespaceURI == X2009Uri || namespaceURI == X2006Uri)
                {
                    lookupAssemblies2.Add(new Tuple <string, Assembly>("Tizen.NUI.Xaml", typeof(XamlLoader).GetTypeInfo().Assembly));
                    lookupAssemblies2.Add(new Tuple <string, Assembly>("System", typeof(object).GetTypeInfo().Assembly));
                    lookupAssemblies2.Add(new Tuple <string, Assembly>("System", typeof(Uri).GetTypeInfo().Assembly)); //System.dll
                }
                else
                {
                    string   ns;
                    string   typename;
                    string   asmstring;
                    Assembly asm;
                    XmlnsHelper.ParseXmlns(namespaceURI, out typename, out ns, out asmstring, out _);
                    asm = asmstring == null ? currentAssembly : Assembly.Load(new AssemblyName(asmstring));
                    lookupAssemblies2.Add(new Tuple <string, Assembly>(ns, asm));
                }

                foreach (var asm in lookupAssemblies2)
                {
                    if (type != null)
                    {
                        break;
                    }
                    foreach (var name in lookupNames)
                    {
                        if (type != null)
                        {
                            break;
                        }
                        type = asm.Item2.GetType(asm.Item1 + "." + name);
                    }
                }
            }

            if (type != null && typeArguments != null)
            {
                XamlParseException innerexception = null;
                var args = typeArguments.Select(delegate(XmlType xmltype)
                {
                    XamlParseException xpe;
                    var t = GetElementType(xmltype, xmlInfo, currentAssembly, out xpe);
                    if (xpe != null)
                    {
                        innerexception = xpe;
                        return(null);
                    }
                    return(t);
                }).ToArray();
                if (innerexception != null)
                {
                    exception = innerexception;
                    return(null);
                }
                type = type.MakeGenericType(args);
            }

            if (type == null)
            {
                exception = new XamlParseException($"Type {elementName} not found in xmlns {namespaceURI}", xmlInfo);
            }

            return(type);
        }