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(); }
public static bool AllowsNull(this PropertyDefinition property, NullGuardMode mode) { if (mode == NullGuardMode.Explicit) { return(ExplicitMode.AllowsNull(property)); } return(property.ImplicitAllowsNull()); }
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)); }
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(); }
public static bool AllowsNull(this ParameterDefinition parameter, MethodDefinition method, NullGuardMode mode) { if (mode == NullGuardMode.Explicit) { return(ExplicitMode.AllowsNull(parameter, method)); } return(parameter.ImplicitAllowsNull()); }
public static bool MayNotBeNull(this ParameterDefinition arg, MethodDefinition method, NullGuardMode mode) { return(!arg.AllowsNull(method, mode) && !arg.IsOptionalArgumentWithNullDefaultValue() && arg.ParameterType.IsRefType() && !arg.IsOut); }