Exemplo n.º 1
0
        public TypeFowarder(string assemblyPath)
        {
            this.assemblyPath = assemblyPath;

            weaver = new AssemblyWeaver();
            fowardedTypes = new HashSet<Type>();
            fromAssembly = CecilUtils.GetAssemblyDef(assemblyPath);
        }
Exemplo n.º 2
0
 public FieldsToProperties(string assemblyPath)
 {
     weaver = new AssemblyWeaver(assemblyPath);
     fieldProperties = new Dictionary<FieldReference, PropertyDefinition>();
 }
Exemplo n.º 3
0
        public void Compile(string dllPath, bool createApi)
        {
            FieldsToProperties(dllPath);

            var apiPath = (createApi)? Path.ChangeExtension(dllPath, "API.dll") : dllPath;

            var references = AssemblyWeaver.GetReferences(dllPath);
            references.Remove(Path.GetFileName(apiPath));

            var apiTypes = ReferenceCollector.CollectReferences(dllPath, RpcTypes);

            using (var apiGenPaths = new TemporaryAssemblyPaths())
            {
                var apiReferences = references.Where(s => s.EndsWith(".API.dll")).ToList();

                AssemblyWeaver weaver;

                if (createApi)
                {
                    //Create assembly with required types by the generated API assembly
                    weaver = new AssemblyWeaver();

                    weaver.AddReference(dllPath, "EngineManaged");
                    weaver.AddReference(dllPath, "EngineBindings");
                    weaver.AddReference(dllPath, "System");
                    weaver.AddReference(dllPath, "System.Core");
                    foreach (var apiReference in apiReferences)
                        weaver.AddReference(dllPath, Path.GetFileNameWithoutExtension(apiReference));

                    weaver.CopyTypes(dllPath, apiTypes);
                    weaver.Write(apiPath);
                }

                //API generated assembly
                var apiGenReferences = apiReferences.ToList();
                apiGenReferences.Add("EngineManaged.dll");
                apiGenReferences.Add(apiPath);
                DotNetCompiler.CompileIntoAssembly(apiGenPaths.DllPath, apiGenReferences, apiWriter.GeneratedFiles);

                //Add API generated assembly to API assembly
                weaver = new AssemblyWeaver(apiPath);
                weaver.CloneMembers(GenerationContext.MemberClones);
                weaver.AddMemberOptions(GenerationContext.MemberOptions);
                //Merge some generated files.
                weaver.MergeTypes(apiGenPaths.DllPath, GenerationContext.DataObjectsMap);
                //Add all the other generated types.
                weaver.CopyAssembly(apiGenPaths.DllPath);

                if (createApi)
                {
                    //Add attribute InternalsVisibleToAttribute
                    var dllName = Path.GetFileNameWithoutExtension(dllPath);
                    weaver.AddAttribute(typeof(InternalsVisibleToAttribute), new []{typeof(string)}, new object[]{dllName});
                }

                weaver.Write(apiPath);
            }

            if (!createApi)
                return;

            var typeFowarder = new TypeFowarder(dllPath);
            typeFowarder.FowardTypes(apiPath, apiTypes);
            typeFowarder.Write(dllPath);
        }