TryGetMethod() public method

Searches the specified hub">Hub for the specified In the case that there are multiple overloads of the specified method, the parameter set helps determine exactly which instance of the overload should be resolved. If there are multiple overloads found with the same number of matching parameters, none of the methods will be returned because it is not possible to determine which overload of the method was intended to be resolved.
public TryGetMethod ( HubDescriptor hub, string method, MethodDescriptor &descriptor, IList parameters ) : bool
hub HubDescriptor Hub to search for the specified on.
method string The method name to search for.
descriptor MethodDescriptor If successful, the that was resolved.
parameters IList The set of parameters that will be used to help locate a specific overload of the specified .
return bool
        public void ResolveActionExcludesEvents()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo1;
            MethodDescriptor actionInfo2;

            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(MyHubWithEvents), Name = "TestHub" }, "add_MyEvent", out actionInfo1, new IJsonValue[] { JTokenify("x") });
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(MyHubWithEvents), Name = "TestHub" }, "remove_MyEvent", out actionInfo2, new IJsonValue[] { JTokenify("x") });

            Assert.Null(actionInfo1);
            Assert.Null(actionInfo2);
        }
        public void ResolveActionExcludesHubMethods()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo1;
            MethodDescriptor actionInfo2;
            MethodDescriptor actionInfo3;
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(HubWithOverrides), Name = "TestHub" }, "OnDisconnected", out actionInfo1, new IJsonValue[] { });
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(HubWithOverrides), Name = "TestHub" }, "OnReconnected", out actionInfo2, new IJsonValue[] { });
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(HubWithOverrides), Name = "TestHub" }, "OnConnected", out actionInfo3, new IJsonValue[] { });

            Assert.Null(actionInfo1);
            Assert.Null(actionInfo2);
            Assert.Null(actionInfo3);
        }
        public void ResolveActionExcludesObjectMethods()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo1;
            MethodDescriptor actionInfo2;
            MethodDescriptor actionInfo3;
            MethodDescriptor actionInfo4;
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(MyHubWithObjectMethods), Name = "TestHub" }, "GetHashCode", out actionInfo1, new IJsonValue[] { });
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(MyHubWithObjectMethods), Name = "TestHub" }, "Equals", out actionInfo2, new IJsonValue[] { JTokenify("test") });
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(MyHubWithObjectMethods), Name = "TestHub" }, "ToString", out actionInfo3, new IJsonValue[] { });
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(MyHubWithObjectMethods), Name = "TestHub" }, "Dispose", out actionInfo4, new IJsonValue[] { JTokenify(false) });

            Assert.Null(actionInfo1);
            Assert.Null(actionInfo2);
            Assert.Null(actionInfo3);
            Assert.Null(actionInfo4);
        }
        public void ResolveActionBindsByteArray()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            var binder = new DefaultParameterResolver();

            var arg = JTokenify(Encoding.UTF8.GetBytes("Hello World!"));

            MethodDescriptor actionInfo;
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestHub), Name = "TestHub" }, "MethodWithByteArray", out actionInfo, new IJsonValue[] { arg });

            Assert.NotNull(actionInfo);
            var arg0 = (byte[])binder.ResolveMethodParameters(actionInfo, arg)[0];
            Assert.Equal("Hello World!", Encoding.UTF8.GetString(arg0));
        }
        public void ResolveActionBindsComplexArguments()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            var binder = new DefaultParameterResolver();

            var arg = new JObject(new JProperty("Age", 1),
                                  new JProperty("Address",
                                      new JObject(
                                          new JProperty("Street", "The street"),
                                          new JProperty("Zip", "34567"))));

            MethodDescriptor actionInfo;
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestHub), Name = "TestHub" }, "MethodWithComplex", out actionInfo, new IJsonValue[] { new JTokenValue(arg) });

            Assert.NotNull(actionInfo);
            var complex = binder.ResolveMethodParameters(actionInfo, new JTokenValue(arg))[0] as Complex;
            Assert.NotNull(complex);
            Assert.Equal(1, complex.Age);
            Assert.NotNull(complex.Address);
            Assert.Equal("The street", complex.Address.Street);
            Assert.Equal(34567, complex.Address.Zip);
        }
        public void ResolveActionExcludesPropertiesOnDeclaredType()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo;
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestHub), Name = "TestHub" }, "get_Value", out actionInfo, new IJsonValue[] { });

            Assert.Null(actionInfo);
        }
        public void ResolveActionOnDerivedHubFindsMethodOnBasedType()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo;
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestDerivedHub), Name = "TestHub" }, "Foo", out actionInfo, new IJsonValue[] { });

            Assert.NotNull(actionInfo);
            Assert.Equal("Foo", actionInfo.Name);
            Assert.Equal(0, actionInfo.Parameters.Count);
        }
        public void ResolveActionBindsNullables()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            var binder = new DefaultParameterResolver();

            var arg1 = JTokenify(null);
            var arg2 = JTokenify(null);

            MethodDescriptor actionInfo;
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestHub), Name = "TestHub" }, "MethodWithNullables", out actionInfo, new IJsonValue[] { arg1, arg2 });

            Assert.NotNull(actionInfo);
            var args = binder.ResolveMethodParameters(actionInfo, new[] { arg1, arg2 });
            Assert.Null(args[0]);
            Assert.Null(args[1]);
        }
        public void ResolveActionBindsGuid()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            var binder = new DefaultParameterResolver();

            var arg = JTokenify(new Guid("1d6a1d30-599f-4495-ace7-303fd87204bb"));

            MethodDescriptor actionInfo;
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestHub), Name = "TestHub" }, "MethodWithGuid", out actionInfo, new IJsonValue[] { arg });

            Assert.NotNull(actionInfo);
            var arg0 = (Guid)binder.ResolveMethodParameters(actionInfo, new[] { arg })[0];
            Assert.Equal(new Guid("1d6a1d30-599f-4495-ace7-303fd87204bb"), arg0);
        }
        public void ResolveActionBindsSimpleArrayArgument()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            var binder = new DefaultParameterResolver();

            var arg = new JArray(new[] { 1, 2, 3 });

            MethodDescriptor actionInfo;
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestHub), Name = "TestHub" }, "MethodWithArray", out actionInfo, new IJsonValue[] { new JTokenValue(arg) });

            Assert.NotNull(actionInfo);
            var args = binder.ResolveMethodParameters(actionInfo, new[] { new JTokenValue(arg) })[0] as int[];
            Assert.Equal(1, args[0]);
            Assert.Equal(2, args[1]);
            Assert.Equal(3, args[2]);
        }
        public void ResolveActionPicksMethodWithMatchingArguments()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo;
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestHub), Name = "TestHub" }, "Foo", out actionInfo, new[] { JTokenify(1) });

            Assert.NotNull(actionInfo);
            Assert.Equal("Foo", actionInfo.Name);
            Assert.Equal(1, actionInfo.Parameters.Count);
        }
        public void ResolveActionReturnsNullIfMethodAmbiguous()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo;
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestHub), Name = "TestHub" }, "Bar", out actionInfo, new[] { JTokenify(1) });

            Assert.Null(actionInfo);
        }
示例#13
0
        public void ResolveActionExcludeHubMethods()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo1;
            MethodDescriptor actionInfo2;
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestHub), Name = "TestHub" }, "AddToGroup", out actionInfo1, new[] { JTokenify("admin") });
            resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestHub), Name = "TestHub" }, "RemoveFromGroup", out actionInfo2, new[] { JTokenify("admin") });

            Assert.Null(actionInfo1);
            Assert.Null(actionInfo2);
        }
        public void ResolveActionLocatesPublicMethodsOnHub()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo;
            resolver.TryGetMethod(new HubDescriptor { Type = typeof(TestHub), Name = "TestHub" }, "Foo", out actionInfo, new IJsonValue[] { });

            Assert.NotNull(actionInfo);
            Assert.Equal("Foo", actionInfo.Name);
            Assert.Equal(0, actionInfo.Parameters.Count);
        }