public static void GetEntryPoint(string pathOfAssemblyThatContainsEntryPoint, List <Mono.Cecil.AssemblyDefinition> assemblyDefinitions, out Mono.Cecil.MethodDefinition outputMethodDefinition)
        {
            // Get the assembly that is supposed to contain the entry point, ie. a class that inherits from "Application":
            string applicationClassFullName;
            string assemblyName;
            string assemblyFullName;

            ApplicationEntryPointFinder.GetFullNameOfClassThatInheritsFromApplication(pathOfAssemblyThatContainsEntryPoint, out applicationClassFullName, out assemblyName, out assemblyFullName);

            // Then, find the constructor of that EntryPoint in the AssemblyDefinitions:
            outputMethodDefinition = null;
            foreach (Mono.Cecil.AssemblyDefinition assemblyDefinition in assemblyDefinitions)
            {
                if (assemblyDefinition.FullName == assemblyFullName)
                {
                    foreach (Mono.Cecil.ModuleDefinition moduleDefinition in assemblyDefinition.Modules)
                    {
                        foreach (Mono.Cecil.TypeDefinition typeDefinition in moduleDefinition.Types)
                        {
                            if (typeDefinition.FullName == applicationClassFullName)
                            {
                                foreach (Mono.Cecil.MethodDefinition methodDefinition in typeDefinition.Methods)
                                {
                                    if (methodDefinition.IsConstructor)
                                    {
                                        outputMethodDefinition = methodDefinition;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        static string GenerateStartupCode(string pathOfAssemblyThatContainsEntryPoint)
        {
            // Get the assembly that is supposed to contain the entry point, ie. a class that inherits from "Application":
            string applicationClassFullName;
            string assemblyName;
            string assemblyFullName;

            ApplicationEntryPointFinder.GetFullNameOfClassThatInheritsFromApplication(pathOfAssemblyThatContainsEntryPoint, out applicationClassFullName, out assemblyName, out assemblyFullName);

            //Generate the JavaScript code for instantiating the application:
            string generatedCode = string.Format(@"
                JSIL.LocalStorage.Initialize(""{0}"");
                var asm = JSIL.GetAssembly(""{1}"", true);
                var app = new asm.{2}();
                ", assemblyName, assemblyFullName, applicationClassFullName);

            // Return the generated code:
            return(generatedCode);
        }