Exemplo n.º 1
0
        public void Swap <T>(ref T v1, ref T v2)
        {
            var genericArgumentT = GenericArgumentInfo.Create(typeof(T), nameof(T));
            var invocationInfo   = InvocationInfo.Create(
                typeof(RefUtilsAopProxy),
                nameof(Swap),
                new[]
            {
                ArgumentInfo.Create(typeof(T), nameof(v1), v1, ArgumentSpecialType.Ref, genericArgumentT),
                ArgumentInfo.Create(typeof(T), nameof(v2), v2, ArgumentSpecialType.Ref, genericArgumentT)
            },
                new[]
            {
                genericArgumentT
            },
                Swap <T>);

            var result = _interceptionHandler.Invoke(invocationInfo);

            const int v1Index = 0;
            const int v2Index = 1;

            v1 = (T)result.Arguments[v1Index].Value;
            v2 = (T)result.Arguments[v2Index].Value;
        }
Exemplo n.º 2
0
        public void DoSomething(List <IEnumerable <string> > list)
        {
            var invocationInfo = InvocationInfo.Create(
                typeof(TestInterfaceAopProxy),
                nameof(DoSomething),
                new[]
            {
                ArgumentInfo.Create(typeof(List <IEnumerable <string> >), nameof(list), list)
            },
                DoSomethingListOfIEnumerableOfString);

            _interceptionHandler.Invoke(invocationInfo);
        }
Exemplo n.º 3
0
        public void SetDictionary(Dictionary <string, string> dict)
        {
            var invocationInfo = InvocationInfo.Create(
                typeof(TestInterfaceAopProxy),
                nameof(DoSomething),
                new[]
            {
                ArgumentInfo.Create(typeof(Dictionary <string, string>), nameof(dict), dict)
            },
                SetDictionary);

            _interceptionHandler.Invoke(invocationInfo);
        }
Exemplo n.º 4
0
        public void DoSomething(string[] array)
        {
            var invocationInfo = InvocationInfo.Create(
                typeof(TestInterfaceAopProxy),
                nameof(DoSomething),
                new[]
            {
                ArgumentInfo.Create(typeof(string[]), nameof(array), array)
            },
                DoSomethingArrayOfString);

            _interceptionHandler.Invoke(invocationInfo);
        }
Exemplo n.º 5
0
        public void DoSomething(string s, int x)
        {
            var invocationInfo = InvocationInfo.Create(
                typeof(TestInterfaceAopProxy),
                nameof(DoSomething),
                new[]
            {
                ArgumentInfo.Create(typeof(string), nameof(s), s),
                ArgumentInfo.Create(typeof(int), nameof(x), x)
            },
                DoSomethingStringInt32);

            _interceptionHandler.Invoke(invocationInfo);
        }
Exemplo n.º 6
0
        public Task <List <int> > DoSomething(int parameter)
        {
            var invocationInfo = InvocationInfo.Create(
                typeof(TestInterfaceAopProxy),
                nameof(DoSomething),
                new[]
            {
                ArgumentInfo.Create(typeof(int), nameof(parameter), parameter)
            },
                ResultInfo.Create(typeof(Task <List <int> >)),
                DoSomethingInt32);

            var result = _interceptionHandler.Invoke(invocationInfo);

            return((Task <List <int> >)result.Result.Value);
        }
Exemplo n.º 7
0
        public long GetContactPhoneNumber(string firstName, string lastName)
        {
            var invocationInfo = InvocationInfo.Create(
                typeof(PhoneBookAopProxy),
                nameof(GetContactPhoneNumber),
                new[]
                {
                    ArgumentInfo.Create(typeof (string), nameof(firstName), firstName),
                    ArgumentInfo.Create(typeof (string), nameof(lastName), lastName)
                },
                ResultInfo.Create(typeof(long)),
                GetContactPhoneNumber);

            var result = _interceptionHandler.Invoke(invocationInfo);

            return (long)result.Result.Value;
        }
Exemplo n.º 8
0
        public void SetGenericValue <T>(T value)
        {
            var genericArgumentT = GenericArgumentInfo.Create(typeof(T), nameof(T));
            var invocationInfo   = InvocationInfo.Create(
                typeof(ContainerAopProxy),
                nameof(GetGenericList),
                new[]
            {
                ArgumentInfo.Create(typeof(T), nameof(value), value, genericArgumentT),
            },
                new[]
            {
                genericArgumentT
            },
                SetGenericValue <T>);

            _interceptionHandler.Invoke(invocationInfo);
        }
Exemplo n.º 9
0
        public void SetElement <T>(int index, T value)
        {
            var genericArgumentT = GenericArgumentInfo.Create(typeof(T), nameof(T));
            var invocationInfo   = InvocationInfo.Create(
                typeof(ContainerAopProxy),
                nameof(SetElement),
                new[]
            {
                ArgumentInfo.Create(typeof(int), nameof(index), index),
                ArgumentInfo.Create(typeof(T), nameof(value), value, genericArgumentT)
            },
                new[]
            {
                genericArgumentT
            },
                SetElement <T>);

            _interceptionHandler.Invoke(invocationInfo);
        }
Exemplo n.º 10
0
        public bool GetElement(int index, out object value)
        {
            var invocationInfo = InvocationInfo.Create(
                typeof(ContainerAopProxy),
                nameof(GetElement),
                new[]
            {
                ArgumentInfo.Create(typeof(int), nameof(index), index),
                ArgumentInfo.Create(typeof(object), nameof(value), default(object), ArgumentSpecialType.Out)
            },
                ResultInfo.Create(typeof(bool)),
                GetElement);

            var       result     = _interceptionHandler.Invoke(invocationInfo);
            const int valueIndex = 1;

            value = result.Arguments[valueIndex].Value;

            return((bool)result.Result.Value);
        }
Exemplo n.º 11
0
        public T GetElement <T>(int index)
        {
            var genericArgumentT = GenericArgumentInfo.Create(typeof(T), nameof(T));
            var invocationInfo   = InvocationInfo.Create(
                typeof(ContainerAopProxy),
                nameof(GetElement),
                new[]
            {
                ArgumentInfo.Create(typeof(int), nameof(index), index, genericArgumentT)
            },
                new[]
            {
                genericArgumentT
            },
                ResultInfo.Create(typeof(T), genericArgumentT),
                GetElement <T>);

            var result = _interceptionHandler.Invoke(invocationInfo);

            return((T)result.Result.Value);
        }
        public void SetBoo <T, TA>(T t, TA a)
            where T : class, IDisposable, new()
            where TA : new()
        {
            var genericArgumentT = GenericArgumentInfo.Create(
                typeof(T),
                nameof(T),
                new[]
            {
                GenericArgumentRestriction.Create(GenericArgumentRestrictionType.Class),
                GenericArgumentRestriction.Create(typeof(IDisposable)),
                GenericArgumentRestriction.Create(GenericArgumentRestrictionType.New)
            });

            var genericArgumentTa = GenericArgumentInfo.Create(
                typeof(TA),
                nameof(TA),
                new[] { GenericArgumentRestriction.Create(GenericArgumentRestrictionType.New) });

            var invocationInfo = InvocationInfo.Create(
                typeof(InterfaceWithGenericMethodAopProxy),
                nameof(GetBar),
                new[]
            {
                ArgumentInfo.Create(typeof(T), nameof(t), t, genericArgumentT),
                ArgumentInfo.Create(typeof(TA), nameof(a), a, genericArgumentTa),
            },
                new[]
            {
                genericArgumentT,
                genericArgumentTa
            },
                SetBoo <T, TA>);

            _interceptionHandler.Invoke(invocationInfo);
        }