Exemplo n.º 1
0
        Dictionary <char, List <string> > _charToSimpleHighContrastNames; //this dictionary serves to link the first letter of the theme-dependent resource to the simple high contrast names that start with that letter.
        //The objective is to reduce the amount of strings we try to find in the resource (probably a minor improvement in performance but it's something)

        /// <summary>
        /// Tries to find the resourceKey in the Generic.xaml resources of the assembly. Note: the resource currently need to be defined in Project/Themes/generic.xaml
        /// </summary>
        /// <param name="assemblyWhereGenericXamlIsLocated">The assembly where we will look into.</param>
        /// <param name="resourceKey">The resource to find in the Assembly's resources.</param>
        /// <returns>The resource associated with the given key in the given assembly's resources.</returns>
        internal object TryFindResourceInGenericXaml(Assembly assemblyWhereGenericXamlIsLocated, object resourceKey)
        {
            ResourceDictionary resourceDictionary = null;

            if (_assemblyToResourceDictionary.ContainsKey(assemblyWhereGenericXamlIsLocated))
            {
                resourceDictionary = _assemblyToResourceDictionary[assemblyWhereGenericXamlIsLocated];
            }
            else
            {
#if !BRIDGE
                string assemblyName = assemblyWhereGenericXamlIsLocated.GetName().Name;
#else
                string assemblyName = INTERNAL_BridgeWorkarounds.GetAssemblyNameWithoutCallingGetNameMethod(assemblyWhereGenericXamlIsLocated);
#endif
                assemblyName = assemblyName.Replace(" ", "ǀǀ").Replace(".", "ǀǀ");
                string factoryTypeName = MakeTitleCase("ǀǀ" + assemblyName + "ǀǀComponentǀǀThemesǀǀGenericǀǀXamlǀǀFactory");
                Type   resourceDictionaryFactoryType = assemblyWhereGenericXamlIsLocated.GetType(factoryTypeName);
                if (resourceDictionaryFactoryType != null)
                {
                    resourceDictionary = (ResourceDictionary)resourceDictionaryFactoryType.GetMethod("Instantiate").Invoke(null, null);
                    _assemblyToResourceDictionary.Add(assemblyWhereGenericXamlIsLocated, resourceDictionary);
                }
            }

            if (resourceDictionary != null && resourceDictionary.ContainsKey(resourceKey))
            {
                return(resourceDictionary[resourceKey]);
            }

            return(null);
        }
Exemplo n.º 2
0
        Dictionary <char, List <string> > _charToSimpleHighContrastNames; //this dictionary serves to link the first letter of the theme-dependent resource to the simple high contrast names that start with that letter.
        //The objective is to reduce the amount of strings we try to find in the resource (probably a minor improvement in performance but it's something)

        /// <summary>
        /// Tries to find the resourceKey in the Generic.xaml resources of the assembly. Note: the resource currently need to be defined in Project/Themes/generic.xaml
        /// </summary>
        /// <param name="assemblyWhereGenericXamlIsLocated">The assembly where we will look into.</param>
        /// <param name="resourceKey">The resource to find in the Assembly's resources.</param>
        /// <returns>The resource associated with the given key in the given assembly's resources.</returns>
        internal object TryFindResourceInGenericXaml(Assembly assemblyWhereGenericXamlIsLocated, object resourceKey)
        {
            ResourceDictionary resourceDictionary = null;

            if (_assemblyToResourceDictionary.ContainsKey(assemblyWhereGenericXamlIsLocated))
            {
                resourceDictionary = _assemblyToResourceDictionary[assemblyWhereGenericXamlIsLocated];
            }
            else
            {
#if !BRIDGE
                string assemblyName = assemblyWhereGenericXamlIsLocated.GetName().Name;
                // todo: instead of the following if, make it so that the Core project can generate the .g.cs files by itself (JSIL version, Bridge works fine) instead of relying on an external project (called DotNetForHtml5.Core.Styles). Note: given what the name of the assembly is, it should still be shortened to remove everything after the first comma.
                //Fixing the assemblyName so that the default styles can be found (the generic.xaml file that contains the default styles is located in a different project with a different namespace):
                if (assemblyName == "SLMigration.CSharpXamlForHtml5" || assemblyName == "CSharpXamlForHtml5" ||
                    assemblyName == "SLMigration.CSharpXamlForHtml5, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" || assemblyName == "CSharpXamlForHtml5, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
                {
                    assemblyName = "DotNetForHtml5.Core.Styles"; //Note: this is the name of the assembly where the default styles are defined (project DotNetForHtml5.Core.Styles in the DotNetForHtml5 solution).
                }
#else
                string assemblyName = INTERNAL_BridgeWorkarounds.GetAssemblyNameWithoutCallingGetNameMethod(assemblyWhereGenericXamlIsLocated);
#endif
                assemblyName = assemblyName.Replace(" ", "ǀǀ").Replace(".", "ǀǀ");
                string factoryTypeName = MakeTitleCase("ǀǀ" + assemblyName + "ǀǀComponentǀǀThemesǀǀGenericǀǀXamlǀǀFactory");
                Type   resourceDictionaryFactoryType = assemblyWhereGenericXamlIsLocated.GetType(factoryTypeName);
#if CSHTML5BLAZOR
                if (resourceDictionaryFactoryType == null)
                {
                    if (assemblyName == "OpenSilver") //We do this part because OpenSilver uses the generic.xaml.g.cs of the CSHTML5 Migration edition which in consequence has a different namespace than it would have if it was directly defined as xaml in OpenSilver.
                    {
                        assemblyName    = "Cshtml5ǀǀMigration";
                        factoryTypeName = MakeTitleCase("ǀǀ" + assemblyName + "ǀǀComponentǀǀThemesǀǀGenericǀǀXamlǀǀFactory");
                        resourceDictionaryFactoryType = assemblyWhereGenericXamlIsLocated.GetType(factoryTypeName);
                    }
                    else if (assemblyName == "OpenSilverǀǀUwpCompatible") //We do this part because OpenSilver uses the generic.xaml.g.cs of the CSHTML5 Migration edition which in consequence has a different namespace than it would have if it was directly defined as xaml in OpenSilver.
                    {
                        assemblyName    = "Cshtml5";
                        factoryTypeName = MakeTitleCase("ǀǀ" + assemblyName + "ǀǀComponentǀǀThemesǀǀGenericǀǀXamlǀǀFactory");
                        resourceDictionaryFactoryType = assemblyWhereGenericXamlIsLocated.GetType(factoryTypeName);
                    }
                }
#endif

                if (resourceDictionaryFactoryType != null)
                {
                    resourceDictionary = (ResourceDictionary)resourceDictionaryFactoryType.GetMethod("Instantiate").Invoke(null, null);
                    _assemblyToResourceDictionary.Add(assemblyWhereGenericXamlIsLocated, resourceDictionary);
                }
            }

            if (resourceDictionary != null && resourceDictionary.ContainsKey(resourceKey))
            {
                return(resourceDictionary[resourceKey]);
            }

            return(null);
        }
Exemplo n.º 3
0
        static object FindPage(Uri uri)
        {
            string assemblyName;
            string instancierName;

            GetXamlFileAssociatedClassInstancierName(uri, out assemblyName, out instancierName); //this method should only accept .xaml files (imo), it returns the name of the class we generated during the compilation, built from the assembly(gotten from either the uri, or the startingAssembly) and the file name.
#if BRIDGE
            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (INTERNAL_BridgeWorkarounds.GetAssemblyNameWithoutCallingGetNameMethod(assembly) == assemblyName)
                {
                    Type type = assembly.GetType(instancierName);
                    if (type != null)
                    {
                        MethodInfo methodInfo = type.GetMethod("Instantiate");
                        return(methodInfo.Invoke(null, null));
                    }
                    break;
                }
            }
#else
#if OPENSILVER
            if (true)
#elif BRIDGE
            if (CSHTML5.Interop.IsRunningInTheSimulator)
#endif
            {
                foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    if (assembly.GetName().Name == assemblyName)
                    {
                        Type type = assembly.GetType(instancierName);
                        if (type != null)
                        {
                            MethodInfo methodInfo = type.GetMethod("Instantiate");
                            return(methodInfo.Invoke(null, null));
                        }
                        break;
                    }
                }
            }
            else
            {
                object assembly = CSHTML5.Interop.ExecuteJavaScript(@"JSIL.GetAssembly($0, true)", assemblyName);
                object type     = CSHTML5.Interop.ExecuteJavaScript(@"JSIL.GetTypeFromAssembly($0, $1)", assembly, instancierName);
                if (!IsNullOrUndefined(type))
                {
                    object method = CSHTML5.Interop.ExecuteJavaScript(@"$0.GetMethod('Instantiate')", type);
                    return(CSHTML5.Interop.ExecuteJavaScript("$0.Invoke(null, null)", method));
                }
            }
#endif
            return(null);
        }
Exemplo n.º 4
0
        static string[] GetListOfLoadedAssemblies()
        {
            string[] listOfAssemblies;
            if (CSHTML5.Interop.IsRunningInTheSimulator)
            {
#if !BRIDGE
                listOfAssemblies = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetName().Name).ToArray();
#else
                listOfAssemblies = AppDomain.CurrentDomain.GetAssemblies().Select(a => INTERNAL_BridgeWorkarounds.GetAssemblyNameWithoutCallingGetNameMethod(a)).ToArray();
#endif
            }
            else
            {
#if !BRIDGE
                listOfAssemblies = JSIL.Verbatim.Expression("Object.keys(JSIL.AssemblyShortNames)");
#else
                listOfAssemblies = AppDomain.CurrentDomain.GetAssemblies().Select(a => GetAssemblyName(a.FullName)).ToArray();//Script.Write<string[]>("Object.keys(JSIL.AssemblyShortNames);");
#endif
            }
            return(listOfAssemblies);
        }