예제 #1
0
    public void NoShortCircuit(ValidateTypeCtor sut)
    {
        sut.ShouldSkip.ShouldSkip(Arg.Any <Type>()).Returns(true);

        sut.Validate(typeof(ValidClass));
        sut.Validate(typeof(ValidClass), new HashSet <string>()
        {
            "test"
        });
        sut.Validate(typeof(ValidClass), new HashSet <string>()
        {
            "test2"
        });

        sut.ShouldSkip.ReceivedWithAnyArgs(3).ShouldSkip(default !);
예제 #2
0
    public bool Check(Type type)
    {
        if (type.BaseType?.FullName != "System.MulticastDelegate")
        {
            return(false);
        }
        var invoke = type.GetMethod("Invoke");

        if (invoke == null)
        {
            return(false);
        }
        if (invoke.ReturnType == typeof(void))
        {
            return(false);
        }

        var typeToCheck = invoke.ReturnType;

        ValidateType.Validate(typeToCheck, validateCtor: false);

        if (Registrations.Items.TryGetValue(typeToCheck, out var registrations))
        {
            var register = registrations.FirstOrDefault();
            if (register != null)
            {
                if (!register.NeedsValidation)
                {
                    return(true);
                }
                typeToCheck = register.Type;
            }
        }

        var parameterNames = new HashSet <string>(invoke.GetParameters().Select(p => p.Name).NotNull());

        ValidateTypeCtor.Validate(typeToCheck, parameterNames);
        return(true);
    }