Proxy that can turn extension methods into instance methods
Наследование: BaseForwarder
Пример #1
0
            internal Invoker(string name, Type[] genericParameters, Type[] genericMethodParameters, ExtensionToInstanceProxy parent, Type[] overloadTypes = null)
            {
                Name                    = name;
                Parent                  = parent;
                GenericParams           = genericParameters;
                GenericMethodParameters = genericMethodParameters;
                OverloadTypes           = new Dictionary <int, Type[]>();

                if (overloadTypes == null)
                {
                    foreach (var tGenInterface in parent.InstanceHints)
                    {
                        var tNewType = tGenInterface;

                        if (tNewType.GetTypeInfo().IsGenericType)
                        {
                            tNewType = tNewType.MakeGenericType(GenericParams);
                        }

                        var members = tNewType.GetTypeInfo().GetMethods(BindingFlags.Instance |
                                                                        BindingFlags.Public).Where(
                            it => it.Name == Name).ToList();
                        foreach (var tMethodInfo in members)
                        {
                            var tParams = tMethodInfo.GetParameters().Select(it => it.ParameterType).ToArray();

                            if (OverloadTypes.ContainsKey(tParams.Length))
                            {
                                OverloadTypes[tParams.Length] = new Type[] {};
                            }
                            else
                            {
                                OverloadTypes[tParams.Length] = tParams.Select(ReplaceGenericTypes).ToArray();
                            }
                        }

                        foreach (var tOverloadType in OverloadTypes.ToList())
                        {
                            if (tOverloadType.Value.Length == 0)
                            {
                                OverloadTypes.Remove(tOverloadType);
                            }
                        }
                    }
                }
                else
                {
                    OverloadTypes[overloadTypes.Length] = overloadTypes;
                }
            }
 internal OverloadInvoker(string name, Type[] genericParameters, Type[] genericMethodParameters, ExtensionToInstanceProxy parent)
     : base(name, genericParameters,genericMethodParameters, parent)
 {
 }
            internal Invoker(string name, Type[] genericParameters, Type[] genericMethodParameters, ExtensionToInstanceProxy parent, Type[] overloadTypes = null)
            {
                Name = name;
                Parent = parent;
                GenericParams = genericParameters;
                GenericMethodParameters = genericMethodParameters;
                OverloadTypes = new Dictionary<int,Type[]>();

                if (overloadTypes == null)
                {

                    foreach (var tGenInterface in parent.InstanceHints)
                    {
                        var tNewType = tGenInterface;

                        if (tNewType.IsGenericType)
                        {
                            tNewType = tNewType.MakeGenericType(GenericParams);
                        }

                        var members = tNewType.GetMethods(BindingFlags.Instance |
                                                                                   BindingFlags.Public).Where(
                                                                                       it => it.Name == Name).ToList();
                        foreach (var tMethodInfo in members)
                        {
                            var tParams = tMethodInfo.GetParameters().Select(it => it.ParameterType).ToArray();

                            if (OverloadTypes.ContainsKey(tParams.Length))
                            {
                                OverloadTypes[tParams.Length] = new Type[] {};
                            }
                            else
                            {
                                OverloadTypes[tParams.Length] = tParams.Select(ReplaceGenericTypes).ToArray();
                            }
                        }

                        foreach (var tOverloadType in OverloadTypes.ToList())
                        {
                            if (tOverloadType.Value.Length == 0)
                            {
                                OverloadTypes.Remove(tOverloadType);
                            }
                        }

                    }
                }
                else
                    {
                        OverloadTypes[overloadTypes.Length] = overloadTypes;
                    }
            }
Пример #4
0
 internal OverloadInvoker(string name, Type[] genericParameters, Type[] genericMethodParameters, ExtensionToInstanceProxy parent)
     : base(name, genericParameters, genericMethodParameters, parent)
 {
 }