public static AssemblyDefinition CreateMultiModuleAssemblyDefinition()
        {
            AssemblyDefinition corlib = AssemblyDefinition.ReadAssembly (typeof (object).Module.FullyQualifiedName);

              AssemblyDefinition assemblyDefinition = AssemblyDefinitionObjectMother.CreateAssemblyDefinition ("TestAssembly");
              assemblyDefinition.MainModule.AssemblyReferences.Add (corlib.Name);
              assemblyDefinition.Name.Version = new Version ("1.0.0.0");

              ModuleDefinition secondModule = ModuleDefinition.CreateModule ("TestSecondModule.netmodule", ModuleKind.NetModule);
              TypeReference typereference = secondModule.Import (typeof (void));
              TypeReference typereferenceObject = secondModule.Import (typeof (object));

              TypeDefinition type = new TypeDefinition ("TestSpace", "TestType", TypeAttributes.Public | TypeAttributes.Class, assemblyDefinition.MainModule.Import(typeof(object)));
              MethodDefinition method = new MethodDefinition ("TestMethod", MethodAttributes.Public | MethodAttributes.HideBySig, typereference);
              var il = method.Body.GetILProcessor ();
              il.Emit (OpCodes.Ret);

              type.Methods.Add (method);
              method.DeclaringType = type;
              assemblyDefinition.MainModule.Types.Add (type);

              TypeDefinition secondType = new TypeDefinition ("TestSpace", "TestSecondType", TypeAttributes.Public | TypeAttributes.Class, secondModule.Import(typeof(object)));
              MethodDefinition secondMethod = new MethodDefinition ("TestSecondMethod", MethodAttributes.Public | MethodAttributes.HideBySig, typereference);
              il = secondMethod.Body.GetILProcessor ();
              il.Emit (OpCodes.Ret);

              secondType.Methods.Add (secondMethod);
              secondModule.Types.Add (secondType);
              secondMethod.DeclaringType = secondType;
              assemblyDefinition.Modules.Add (secondModule);
              assemblyDefinition.MainModule.ModuleReferences.Add (secondModule);

              ExportedType e = new ExportedType ("TestSpace", "TestSecondType", secondModule, secondModule);
              assemblyDefinition.MainModule.ExportedTypes.Add (e);

              var testingDirectory = Path.Combine (AppDomain.CurrentDomain.BaseDirectory, @"temp\testing");
              if (!Directory.Exists (testingDirectory))
            Directory.CreateDirectory (testingDirectory);

              assemblyDefinition.Write (Path.Combine (testingDirectory, "test.mainmodule"));
              secondModule.Write (Path.Combine (testingDirectory, "test.module"));
              assemblyDefinition = AssemblyDefinition.ReadAssembly (Path.Combine (testingDirectory, "test.mainmodule"));

              return assemblyDefinition;
        }
Exemplo n.º 2
0
            private TypeReference LookupTypeForwarded(string @namespace, string name)
            {
                if (!base.module.HasExportedTypes)
                {
                    return(null);
                }
                Collection <ExportedType> exportedTypes = base.module.ExportedTypes;

                for (int i = 0; i < exportedTypes.Count; i++)
                {
                    ExportedType exportedType = exportedTypes[i];
                    if (exportedType.Name == name && exportedType.Namespace == @namespace)
                    {
                        return(exportedType.CreateReference());
                    }
                }
                return(null);
            }
Exemplo n.º 3
0
        private static TypeDefinition GetType(ModuleDefinition module, TypeReference reference)
        {
            TypeDefinition typeDefinition = GetTypeDefinition(module, reference);

            if (typeDefinition != null)
            {
                return(typeDefinition);
            }
            if (module.HasExportedTypes)
            {
                Collection <ExportedType> exportedTypes = module.ExportedTypes;
                for (int i = 0; i < exportedTypes.Count; i++)
                {
                    ExportedType type = exportedTypes[i];
                    if ((type.Name == reference.Name) && (type.Namespace == reference.Namespace))
                    {
                        return(type.Resolve());
                    }
                }
            }
            return(null);
        }
        private static TypeDefinition GetType(ModuleDefinition module, TypeReference reference)
        {
            TypeDefinition typeDefinition = MetadataResolver.GetTypeDefinition(module, reference);

            if (typeDefinition != null)
            {
                return(typeDefinition);
            }
            if (!module.HasExportedTypes)
            {
                return(null);
            }
            Collection <ExportedType> exportedTypes = module.ExportedTypes;

            for (int i = 0; i < exportedTypes.Count; i++)
            {
                ExportedType item = exportedTypes[i];
                if (!(item.Name != reference.Name) && !(item.Namespace != reference.Namespace))
                {
                    return(item.Resolve());
                }
            }
            return(null);
        }
Exemplo n.º 5
0
 public PseudoCecilAttribute(ExportedType type)
     : base(typeof (TypeForwardedToAttribute).FullName)
 {
     ExtraInfo = "[assembly: TypeForwardedToAttribute (typeof (" + type.ToString () + "))]";
 }
Exemplo n.º 6
0
 private TypeReference CreateReference(ExportedType type)
 {
     return new TypeReference(type.Namespace, type.Name, _repackContext.TargetAssemblyMainModule, _repackContext.MergeScope(type.Scope))
     {
         DeclaringType = type.DeclaringType != null ? CreateReference(type.DeclaringType) : null,
     };
 }
Exemplo n.º 7
0
        public static string EnsureWellName(ExportedType et, ref string name)
        {
            if (name == null)
            {
                if (IGNORE_WELLNAMING)
                {
                    name = et.Name;
                    return name;
                }

                name = et.Resolve().WellName;
            }
            return name;
        }
Exemplo n.º 8
0
 public static string EnsureWellNamespace(ExportedType et, ref string ns)
 {
     if (ns == null) ns = ToWellNamespace(et.Namespace);
     return ns;
 }
        protected override void ProcessExportedType(ExportedType exportedType)
        {
            var exportedTypeDef = exportedType.TryResolve();
            if (exportedTypeDef != null) {
                AddDependency(exportedTypeDef, new ExportedTypeDependency(exportedType, exportedTypeDef.Module));
            } else {
                Trace.WriteLine(string.Format("Strange: Couldn't resolve the exported type {0}.", exportedType), "CollectTypesDependencies");
            }

            base.ProcessExportedType(exportedType);
        }
		public static CustomAttribute GetExportedTypeAttribute(ExportedType exportedType, ModuleDefinition module)
		{
			MethodReference ctor = Utilities.GetEmptyConstructor(typeof(System.Runtime.CompilerServices.TypeForwardedToAttribute), module, new[] { typeof(System.Type) });

			CustomAttribute exportedTypeAttribute = new CustomAttribute(ctor);
			TypeReference systemType = Utilities.GetCorlibTypeReference(typeof(Type), module);
			TypeReference type = exportedType.CreateReference();
			exportedTypeAttribute.ConstructorArguments.Add(new CustomAttributeArgument(systemType, type));

			return exportedTypeAttribute;
		}
Exemplo n.º 11
0
 protected override void ProcessExportedType(ExportedType exportedType)
 {
     var exportedTypeDef = exportedType.TryResolve();
     if (exportedTypeDef != null) {
         ProcessFoundType(exportedTypeDef);
     } else {
         Trace.WriteLine(string.Format("Strange: Couldn't resolve the exported type {0}.", exportedType), "CollectUsedTypes");
     }
     base.ProcessExportedType(exportedType);
 }
Exemplo n.º 12
0
 protected virtual void ProcessExportedType(ExportedType exportedType)
 {
 }