Пример #1
0
        private void CreateDefinitions(ModelMapping modelMapping)
        {
            IDictionary <Model.Assembly, AssemblyDefinition> assembliesMap = modelMapping.AssembliesMap;

            foreach (KeyValuePair <Model.Assembly, AssemblyDefinition> keyval in assembliesMap)
            {
                AssemblyDefinition cecilAssembly       = keyval.Value;
                Model.Assembly     analysisNetAssembly = keyval.Key;

                ReferenceGenerator referenceGen = new ReferenceGenerator(new Context(cecilAssembly.MainModule, modelMapping, Host));

                // TraverseTypes returns every nested type in A before returning A
                // this is assumed by the TypeGenerator and MethodGenerator
                foreach (Model.Types.TypeDefinition analysisNetType in analysisNetAssembly.TraverseTypes())
                {
                    TypeGenerator             typeGenerator = new TypeGenerator(referenceGen);
                    Mono.Cecil.TypeDefinition cecilTypeDef  = typeGenerator.TypeDefinition(analysisNetType);

                    // nested types are not added directly to the main module
                    // instead they are added to their enclosing type (that's the way cecil works)
                    if (cecilTypeDef.DeclaringType == null)
                    {
                        cecilAssembly.MainModule.Types.Add(cecilTypeDef);
                    }

                    foreach (Model.Types.MethodDefinition analysisNetMethod in analysisNetType.Methods)
                    {
                        MethodGenerator methodGenerator = new MethodGenerator(referenceGen);
                        cecilTypeDef.Methods.Add(methodGenerator.MethodDefinition(analysisNetMethod));
                    }

                    // we need to have every method definition created
                    typeGenerator.PropertyDefinitions(analysisNetType, cecilTypeDef);
                }
            }
        }
Пример #2
0
 public Context(Cecil.ModuleDefinition current, ModelMapping modelMapping, Model.Host host)
 {
     CurrentModule = current;
     ModelMapping  = modelMapping;
     Host          = host;
 }