Skip to content

Commit

Permalink
Merge pull request #555 from SteveDunn/use-is-isnot-null
Browse files Browse the repository at this point in the history
Use is and isnot null
  • Loading branch information
SteveDunn authored Jan 4, 2024
2 parents ad76425 + 0710eba commit 84a6d98
Show file tree
Hide file tree
Showing 27,665 changed files with 28,480 additions and 28,478 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ dotnet_style_require_accessibility_modifiers=for_non_interface_members:hint
csharp_indent_labels = one_less_than_current
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_namespace_declarations = file_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_expression_bodied_operators = false:silent
Expand Down
2 changes: 1 addition & 1 deletion src/Vogen/BuildConfigurationFromAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private void PopulateFromValueObjectAttributeArgs(ImmutableArray<TypedConstant>

private void BuildAnyIssuesWithTheException(INamedTypeSymbol? invalidExceptionType)
{
if (invalidExceptionType == null)
if (invalidExceptionType is null)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Vogen/BuildWorkItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private static void ThrowIfToStringOverrideOnRecordIsUnsealed(VoTarget target,
private static bool IsUnderlyingAValueType(VogenConfiguration config)
{
bool isValueType = true;
if (config.UnderlyingType != null)
if (config.UnderlyingType is not null)
{
isValueType = config.UnderlyingType.IsValueType;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Vogen/CompilationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public static IEnumerable<INamedTypeSymbol> GetTypesByMetadataName(this Compilat
foreach (var reference in compilation.References)
{
var assemblySymbol = compilation.GetAssemblyOrModuleSymbol(reference) as IAssemblySymbol;
if (assemblySymbol == null)
if (assemblySymbol is null)
continue;

symbol = assemblySymbol.GetTypeByMetadataName(typeMetadataName);
if (symbol != null)
if (symbol is not null)
yield return symbol;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Vogen/Extensions/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.cs]
dotnet_style_namespace_match_folder = false:suggestion
2 changes: 1 addition & 1 deletion src/Vogen/Extensions/IDictionaryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void AddKeyValueIfNotNull<TKey, TValue>(
where TKey : class
where TValue : class
{
if (key != null && value != null)
if (key is not null && value is not null)
{
dictionary.Add(key, value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Vogen/GenerateComparableCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static string GenerateIComparableImplementationIfNeeded(VoWorkItem item,
var s = $$"""
public int CompareTo({{primitive}} other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is {{primitive}} x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type {{primitive}}", nameof(other));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Vogen/Generators/RecordStructGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private readonly void EnsureInitialized()
{Util.GenerateAnyConversionBodies(tds, item)}
{Util.GenerateDebuggerProxyForStructs(tds, item)}
{Util.GenerateDebuggerProxyForStructs(item)}
}}
{GenerateEfCoreExtensions.GenerateIfNeeded(item)}
Expand Down
2 changes: 1 addition & 1 deletion src/Vogen/Generators/StructGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private readonly void EnsureInitialized()
{Util.GenerateAnyConversionBodies(tds, item)}
{Util.GenerateDebuggerProxyForStructs(tds, item)}
{Util.GenerateDebuggerProxyForStructs(item)}
}}
{GenerateEfCoreExtensions.GenerateIfNeeded(item)}
Expand Down
2 changes: 1 addition & 1 deletion src/Vogen/ManageAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static VogenConfigurationBuildResult GetDefaultConfigFromGlobalAttribute(
AttributeData? matchingAttribute = assemblyAttributes.SingleOrDefault(aa =>
allThatMatchByName.Equals(aa.AttributeClass, SymbolEqualityComparer.Default));

if (matchingAttribute == null)
if (matchingAttribute is null)
{
return VogenConfigurationBuildResult.Null;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Vogen/SemanticHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static class SemanticHelper
{
public static string? FullName(this INamedTypeSymbol? symbol)
{
if (symbol == null)
if (symbol is null)
return null;

var prefix = FullNamespace(symbol);
Expand All @@ -29,7 +29,7 @@ public static string FullNamespace(this ISymbol symbol)
{
var parts = new Stack<string>();
INamespaceSymbol? iterator = (symbol as INamespaceSymbol) ?? symbol.ContainingNamespace;
while (iterator != null)
while (iterator is not null)
{
if (!string.IsNullOrEmpty(iterator.Name))
{
Expand Down Expand Up @@ -63,15 +63,15 @@ public static IEnumerable<IPropertySymbol> WritableScalarProperties(this INamedT
return symbol.GetMembers().OfType<IPropertySymbol>().Where(p => p.CanWrite() && !p.HasParameters());
}

public static bool CanRead(this IPropertySymbol symbol) => symbol.GetMethod != null;
public static bool CanRead(this IPropertySymbol symbol) => symbol.GetMethod is not null;

public static bool CanWrite(this IPropertySymbol symbol) => symbol.SetMethod != null;
public static bool CanWrite(this IPropertySymbol symbol) => symbol.SetMethod is not null;

public static bool HasParameters(this IPropertySymbol symbol) => symbol.Parameters.Any();

public static bool ImplementsInterfaceOrBaseClass(this INamedTypeSymbol? typeSymbol, Type typeToCheck)
{
if (typeSymbol == null)
if (typeSymbol is null)
{
return false;
}
Expand All @@ -94,7 +94,7 @@ public static bool ImplementsInterfaceOrBaseClass(this INamedTypeSymbol? typeSym
}
}

if (typeSymbol.BaseType != null)
if (typeSymbol.BaseType is not null)
{
return ImplementsInterfaceOrBaseClass(typeSymbol.BaseType, typeToCheck);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Vogen/Templates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static class TypeResolver
{
public static string? ResolveTemplateNameFromTypeName(Type? nts)
{
if (nts == null) return null;
if (nts is null) return null;

var name = nts.Name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value,
public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
{
var result = serializer.Deserialize<global::System.String>(reader);
return result != null ? VOTYPE.Deserialize(result) : null;
return result is not null ? VOTYPE.Deserialize(result) : null;
}
}
14 changes: 7 additions & 7 deletions src/Vogen/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public static class Util

public static string GenerateValidation(VoWorkItem workItem)
{
if (workItem.ValidateMethod != null)
if (workItem.ValidateMethod is not null)
{
return @$"var validation = {workItem.TypeToAugment.Identifier}.{workItem.ValidateMethod.Identifier.Value}(value);
if (validation != Vogen.Validation.Ok)
{{
var ex = new {workItem.ValidationExceptionFullName}(validation.ErrorMessage);
if (validation.Data != null)
if (validation.Data is not null)
{{
foreach (var kvp in validation.Data)
{{
Expand Down Expand Up @@ -59,7 +59,7 @@ public static string GenerateCallToValidateForDeserializing(VoWorkItem workItem)
}
}

if (workItem.ValidateMethod == null)
if (workItem.ValidateMethod is null)
{
return sb.ToString();
}
Expand All @@ -78,7 +78,7 @@ public static string GenerateCallToValidateForDeserializing(VoWorkItem workItem)

public static string GenerateNormalizeInputMethodIfNeeded(VoWorkItem workItem)
{
if (workItem.NormalizeInputMethod != null)
if (workItem.NormalizeInputMethod is not null)
{
return @$"value = {workItem.TypeToAugment.Identifier}.{workItem.NormalizeInputMethod.Identifier.Value}(value);
";
Expand Down Expand Up @@ -143,7 +143,7 @@ public static string GenerateAnyConversionAttributes(TypeDeclarationSyntax tds,
return sb.ToString();
}

public static string GenerateAnyConversionAttributesForDebuggerProxy(TypeDeclarationSyntax tds, VoWorkItem item) => item.Conversions.ToString();
private static string GenerateAnyConversionAttributesForDebuggerProxy(VoWorkItem item) => item.Conversions.ToString();

public static string GenerateAnyConversionBodies(TypeDeclarationSyntax tds, VoWorkItem item)
{
Expand All @@ -156,7 +156,7 @@ public static string GenerateAnyConversionBodies(TypeDeclarationSyntax tds, VoWo
return sb.ToString();
}

public static string GenerateDebuggerProxyForStructs(TypeDeclarationSyntax tds, VoWorkItem item)
public static string GenerateDebuggerProxyForStructs(VoWorkItem item)
{
var createdWithMethod = item.DisableStackTraceRecordingInDebug
? @"public global::System.String CreatedWith => ""the From method"""
Expand All @@ -182,7 +182,7 @@ internal sealed class {{item.VoTypeName}}DebugView
{{createdWithMethod}};
#endif
public global::System.String Conversions => @"{{Util.GenerateAnyConversionAttributesForDebuggerProxy(tds, item)}}";
public global::System.String Conversions => @"{{Util.GenerateAnyConversionAttributesForDebuggerProxy(item)}}";
}
""";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace Whatever

public int CompareTo(_casting_public_partial_recordCastOperator_ImplicitCastOperator_ImplicitSystem_Guid other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_partial_recordCastOperator_ImplicitCastOperator_ImplicitSystem_Guid x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_partial_recordCastOperator_ImplicitCastOperator_ImplicitSystem_Guid", nameof(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace Whatever

public int CompareTo(_casting_public_partial_record_structCastOperator_ImplicitCastOperator_Explicitbyte other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_partial_record_structCastOperator_ImplicitCastOperator_Explicitbyte x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_partial_record_structCastOperator_ImplicitCastOperator_Explicitbyte", nameof(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace Whatever

public int CompareTo(_casting_public_partial_record_classCastOperator_ImplicitCastOperator_Explicitlong other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_partial_record_classCastOperator_ImplicitCastOperator_Explicitlong x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_partial_record_classCastOperator_ImplicitCastOperator_Explicitlong", nameof(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace Whatever

public int CompareTo(_casting_public_partial_recordCastOperator_ExplicitCastOperator_Implicitdecimal other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_partial_recordCastOperator_ExplicitCastOperator_Implicitdecimal x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_partial_recordCastOperator_ExplicitCastOperator_Implicitdecimal", nameof(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ namespace Whatever

public int CompareTo(_casting_public_partial_structCastOperator_ExplicitCastOperator_ExplicitSystem_DateTime other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_partial_structCastOperator_ExplicitCastOperator_ExplicitSystem_DateTime x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_partial_structCastOperator_ExplicitCastOperator_ExplicitSystem_DateTime", nameof(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ namespace Whatever

public int CompareTo(_casting_public_partial_structCastOperator_NoneCastOperator_NoneSystem_Guid other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_partial_structCastOperator_NoneCastOperator_NoneSystem_Guid x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_partial_structCastOperator_NoneCastOperator_NoneSystem_Guid", nameof(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ namespace Whatever

public int CompareTo(_casting_public_partial_recordCastOperator_NoneCastOperator_Nonebool other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_partial_recordCastOperator_NoneCastOperator_Nonebool x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_partial_recordCastOperator_NoneCastOperator_Nonebool", nameof(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace Whatever

public int CompareTo(_casting_public_partial_structCastOperator_ImplicitCastOperator_Nonechar other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_partial_structCastOperator_ImplicitCastOperator_Nonechar x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_partial_structCastOperator_ImplicitCastOperator_Nonechar", nameof(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace Whatever

public int CompareTo(_casting_public_partial_record_structCastOperator_ExplicitCastOperator_NoneSystem_Guid other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_partial_record_structCastOperator_ExplicitCastOperator_NoneSystem_Guid x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_partial_record_structCastOperator_ExplicitCastOperator_NoneSystem_Guid", nameof(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ namespace Whatever

public int CompareTo(_casting_public_partial_record_classCastOperator_NoneCastOperator_Explicitshort other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_partial_record_classCastOperator_NoneCastOperator_Explicitshort x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_partial_record_classCastOperator_NoneCastOperator_Explicitshort", nameof(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace Whatever

public int CompareTo(_casting_public_partial_recordCastOperator_ExplicitCastOperator_Explicitchar other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_partial_recordCastOperator_ExplicitCastOperator_Explicitchar x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_partial_recordCastOperator_ExplicitCastOperator_Explicitchar", nameof(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace Whatever

public int CompareTo(_casting_public_readonly_partial_record_structCastOperator_NoneCastOperator_Implicitbyte other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_readonly_partial_record_structCastOperator_NoneCastOperator_Implicitbyte x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_readonly_partial_record_structCastOperator_NoneCastOperator_Implicitbyte", nameof(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public System.Int64 Value

public int CompareTo(_casting_public_sealed_partial_classCastOperator_ImplicitCastOperator_Implicitlong other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_sealed_partial_classCastOperator_ImplicitCastOperator_Implicitlong x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_sealed_partial_classCastOperator_ImplicitCastOperator_Implicitlong", nameof(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ namespace Whatever

public int CompareTo(_casting_public_partial_recordCastOperator_NoneCastOperator_Explicitbyte other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_partial_recordCastOperator_NoneCastOperator_Explicitbyte x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_partial_recordCastOperator_NoneCastOperator_Explicitbyte", nameof(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ namespace Whatever

public int CompareTo(_casting_public_partial_structCastOperator_ExplicitCastOperator_ExplicitSystem_Guid other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_partial_structCastOperator_ExplicitCastOperator_ExplicitSystem_Guid x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_partial_structCastOperator_ExplicitCastOperator_ExplicitSystem_Guid", nameof(other));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public System.String Value

public int CompareTo(_casting_public_sealed_partial_classCastOperator_NoneCastOperator_Explicitstring other) => Value.CompareTo(other.Value);
public int CompareTo(object other) {
if(other == null) return 1;
if(other is null) return 1;
if(other is _casting_public_sealed_partial_classCastOperator_NoneCastOperator_Explicitstring x) return CompareTo(x);
throw new global::System.ArgumentException("Cannot compare to object as it is not of type _casting_public_sealed_partial_classCastOperator_NoneCastOperator_Explicitstring", nameof(other));
}
Expand Down
Loading

0 comments on commit 84a6d98

Please sign in to comment.