internal virtual TypeDefinition GetInjecteeCecilType(ModuleDefinition module)
        {
            if (_injecteeCecilDef == null)
                _injecteeCecilDef = module.FindMatchingType(InjecteeType, true);

            return _injecteeCecilDef;
        }
Пример #2
0
        internal TypeReference Import(ModuleDefinition module, IMetadataScope scope, IInjector injector)
        {
            var reference = new TypeReference(
                ParentType == null ? Attr.Namespace : "",
                InjecteeType.Name,
                module,
                module.ImportScope(injector.MapMetadataScope(scope)),
                InjecteeType.IsValueType);

            MetadataSystem.TryProcessPrimitiveTypeReference(reference);

            if (ParentType != null)
            {
                var declDef = module.FindMatchingType(ParentType, true);
                reference.DeclaringType = CreateDeclRef(declDef, module, injector);
            }

            if (InjecteeType.ContainsGenericParameters)
                CecilHelpers.ImportGenericParameters(reference, InjecteeType);

            return reference;
        }
        internal virtual TypeDefinition GetTargetCecilType(ModuleDefinition module)
        {
            if (_targetCecilDef == null)
                _targetCecilDef = module.FindMatchingType(TargetType, true);

            return _targetCecilDef;
        }
Пример #4
0
        private TypeDefinition CloneType(ModuleDefinition module, string nameSpace, TypeDefinition source, Type parentType)
        {
            TypeDefinition parentDef = null;
            if (parentType != null)
            {
                nameSpace = "";
                parentDef = module.FindMatchingType(parentType, true);
            }

            var clone = new TypeDefinition(nameSpace, source.Name, source.Attributes);
            clone.IsValueType = source.IsValueType;

            if (parentDef != null)
                parentDef.NestedTypes.Add(clone);
            else
                module.Types.Add(clone);

            foreach (var g in source.GenericParameters)
                clone.GenericParameters.Add(CloneGenericParameter(clone, g));

            foreach (var i in source.Interfaces)
                clone.Interfaces.Add(FixTypeImport(module, i));

            foreach (var f in source.Fields)
                clone.Fields.Add(CloneField(clone, f));

            foreach (var e in source.Events)
                clone.Events.Add(CloneEvent(clone, e));

            foreach (var p in source.Properties)
                clone.Properties.Add(CloneProperty(clone, p));

            foreach (var m in source.Methods)
            {
                var cloneMethod = CloneMethodWithoutBody(clone, m);
                CloneMethodBody(m, cloneMethod);
            }

            clone.BaseType = FixTypeImport(module, source.BaseType);

            return clone;
        }