Пример #1
0
 public SubstitutedInterfaceMethod(IInterfaceMethod original, ImmutableArrayDictionary <ITypeParameter, IType> substitutions, Dictionary <IType, IType> substituted)
 {
     _original   = original;
     _returnType = new Lazy <IType>(_original.ReturnType.Substitute(substitutions, substituted));
     _parameters = new Lazy <ImmutableArray <IParameter> >(
         () => _original.Parameters.Select(x => x.Substitute(substitutions, substituted)).ToImmutableArray());
 }
Пример #2
0
        public void GlobalSetup()
        {
            _request      = 1;
            _staticMethod = typeof(StaticMethod).GetMethod(nameof(StaticMethod.Parameters));
            if (_staticMethod == null)
            {
                throw new InvalidOperationException("Could not get static method with parameters.");
            }

            // non-virtual
            _nonVirtualMethod = new NonVirtualMethod();

            // interface
            _interfaceMethod = new InterfaceMethod();

            // delegates
            _delegate = StaticMethod.Parameters;

            // reflection delegates
            _reflectionDelegate = (Func <int, int>)_staticMethod.CreateDelegate(typeof(Func <int, int>));

            // compiled expression tree
            int response = 1;
            Expression <Func <int, int> > expressionTree = request => response;

            _compiledExpressionTreeDelegate = expressionTree.Compile(preferInterpretation: false);

            // compiled code
            CompiledCodeGenerator.CompileCode();
            _compiledCodeDelegate = CompiledCodeGenerator.CompiledMethodParameters;

            // emitted code
            EmittedCodeGenerator.EmitCode();
            _emittedCodeDelegate = EmittedCodeGenerator.EmittedMethodParameters;

            // slow reflection
            _slowArgs = new object[] { 1 };
        }
        public void GlobalSetup()
        {
            _staticMethod = typeof(StaticMethod).GetMethod(nameof(StaticMethod.Void));
            if (_staticMethod == null)
            {
                throw new InvalidOperationException("Could not get static method void.");
            }

            // non-virtual
            _nonVirtualMethod = new NonVirtualMethod();

            // interface
            _interfaceMethod = new InterfaceMethod();

            // delegates
            _delegate = StaticMethod.Void;

            // reflection delegates
            _reflectionDelegate = (Action)_staticMethod.CreateDelegate(typeof(Action));

            // compiled expression tree
            Expression <Action> expressionTree = () => EmptyMethod();

            _compiledExpressionTreeDelegate = expressionTree.Compile(preferInterpretation: false);

            // compiled code
            CompiledCodeGenerator.CompileCode();
            _compiledCodeDelegate = CompiledCodeGenerator.CompiledMethodVoid;

            // emitted code
            EmittedCodeGenerator.EmitCode();
            _emittedCodeDelegate = EmittedCodeGenerator.EmittedMethodVoid;

            // slow reflection
            _slowArgs = new object[0];
        }
Пример #4
0
 public bool TryGetInterfaceMethod([MaybeNullWhen(false)] out IInterfaceMethod interfaceMethod)
 {
     interfaceMethod = _interfaceMethod;
     return(interfaceMethod != null);
 }
Пример #5
0
 public MethodOrInterfaceMethod(IInterfaceMethod interfaceMethod) : this()
 {
     _interfaceMethod = interfaceMethod;
     _typeArguments   = ImmutableArray <ITypeParameter> .Empty;
 }