Beispiel #1
0
        public MethodDefinition AddMethod(TypeDefinition targetType,
                                          MethodReference originalMethod)
        {
            if (originalMethod.Name == ".ctor")
            {
                return(null);
            }

            MethodDefinition result = _finder.FindMethod(targetType, originalMethod);;

            if (result != null)
            {
                return(result);
            }

            result = _newMethodBuilder.AddMethod(targetType, originalMethod);

            // Map the interface method to the current method
            _methodMap[originalMethod] = result;

            return(result);
        }
        public TypeDefinition CreateType(string interfaceName,
                                         string targetNamespace,
                                         Dictionary <MethodReference, MethodReference> methodMap)
        {
            var targetMethods = _methodFilter.GetMethods(_scope.Methods, _targetDependency);

            // Step 6
            const TypeAttributes attributes = TypeAttributes.Interface |
                                              TypeAttributes.Abstract | TypeAttributes.Public;

            var interfaceType = new TypeDefinition(interfaceName, targetNamespace, attributes, null);

            interfaceType.Constructors.Clear();

            _module.Types.Add(interfaceType);

            foreach (var method in targetMethods)
            {
                _methodBuilder.AddMethod(interfaceType, method);
            }

            return(interfaceType);
        }