예제 #1
0
    public override void Execute()
    {
        ReadConfig();

        if (nullGuardMode == NullGuardMode.AutoDetect)
        {
            nullGuardMode = ModuleDefinition.AutoDetectMode();
        }

        var nullGuardAttribute = ModuleDefinition.GetNullGuardAttribute();

        if (nullGuardAttribute == null)
        {
            nullGuardAttribute = ModuleDefinition.Assembly.GetNullGuardAttribute();
        }

        if (nullGuardAttribute != null)
        {
            ValidationFlags = (ValidationFlags)nullGuardAttribute.ConstructorArguments[0].Value;
        }

        LogInfo($"Mode={nullGuardMode}, ValidationFlags={ValidationFlags}");

        FindReferences();
        var types = GetTypesToProcess();

        CheckForBadAttributes(types);
        ProcessAssembly(types);
        RemoveAttributes(types);
        RemoveReference();
    }
예제 #2
0
    public static bool AllowsNull(this PropertyDefinition property, NullGuardMode mode)
    {
        if (mode == NullGuardMode.Explicit)
        {
            return(ExplicitMode.AllowsNull(property));
        }

        return(property.ImplicitAllowsNull());
    }
예제 #3
0
    public static bool AllowsNullReturnValue(this MethodDefinition methodDefinition, NullGuardMode mode)
    {
        if (mode == NullGuardMode.Explicit)
        {
            // ReSharper uses a *method* attribute for NotNull for the return value
            return(ExplicitMode.AllowsNull(methodDefinition));
        }

        return(methodDefinition.MethodReturnType.CustomAttributes.Any(a => a.AttributeType.Name == AllowNullAttributeTypeName) ||
               // ReSharper uses a *method* attribute for CanBeNull for the return value
               methodDefinition.CustomAttributes.Any(a => a.AttributeType.Name == CanBeNullAttributeTypeName));
    }
예제 #4
0
    public override void Execute()
    {
        ReadConfig();

        if (nullGuardMode == NullGuardMode.AutoDetect)
        {
            nullGuardMode = ModuleDefinition.AutoDetectMode();
        }

        switch (nullGuardMode)
        {
        case NullGuardMode.Explicit:
            nullabilityAnalyzer = new ExplicitModeAnalyzer();
            break;

        case NullGuardMode.NullableReferenceTypes:
            nullabilityAnalyzer = new NullableReferenceTypesModeAnalyzer();
            break;
        }

        var nullGuardAttribute = ModuleDefinition.GetNullGuardAttribute();

        if (nullGuardAttribute == null)
        {
            nullGuardAttribute = ModuleDefinition.Assembly.GetNullGuardAttribute();
        }

        if (nullGuardAttribute != null)
        {
            ValidationFlags = (ValidationFlags)nullGuardAttribute.ConstructorArguments[0].Value;
        }

        WriteInfo($"Mode={nullGuardMode}, ValidationFlags={ValidationFlags}");

        FindReferences();
        var types = GetTypesToProcess();

        nullabilityAnalyzer.CheckForBadAttributes(types, WriteError);
        ProcessAssembly(types);
        RemoveAttributes(types);
        RemoveReference();
    }
예제 #5
0
    public static bool AllowsNull(this ParameterDefinition parameter, MethodDefinition method, NullGuardMode mode)
    {
        if (mode == NullGuardMode.Explicit)
        {
            return(ExplicitMode.AllowsNull(parameter, method));
        }

        return(parameter.ImplicitAllowsNull());
    }
예제 #6
0
 public static bool MayNotBeNull(this ParameterDefinition arg, MethodDefinition method, NullGuardMode mode)
 {
     return(!arg.AllowsNull(method, mode) && !arg.IsOptionalArgumentWithNullDefaultValue() && arg.ParameterType.IsRefType() && !arg.IsOut);
 }