Skip to content

Commit

Permalink
Use is not null
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsck committed Nov 11, 2020
1 parent 756680e commit 4e0837c
Show file tree
Hide file tree
Showing 123 changed files with 791 additions and 791 deletions.
2 changes: 1 addition & 1 deletion Examples/Example1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void Run() {
totalNumTypes++;
Console.WriteLine();
Console.WriteLine("Type: {0}", type.FullName);
if (!(type.BaseType is null))
if (type.BaseType is not null)
Console.WriteLine(" Base type: {0}", type.BaseType.FullName);

Console.WriteLine(" Methods: {0}", type.Methods.Count);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ NOTE: VS' debugger crashes if there's a `DebuggableAttribute` attribute and if t

```C#
var ca = module.Assembly.CustomAttributes.Find("System.Diagnostics.DebuggableAttribute");
if (!(ca is null) && ca.ConstructorArguments.Count == 1) {
if (ca is not null && ca.ConstructorArguments.Count == 1) {
var arg = ca.ConstructorArguments[0];
// VS' debugger crashes if value == 0x107, so clear EnC bit
if (arg.Type.FullName == "System.Diagnostics.DebuggableAttribute/DebuggingModes" && arg.Value is int value && value == 0x107) {
Expand Down
2 changes: 1 addition & 1 deletion src/DotNet/AllTypesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readonly struct AllTypesHelper {
public static IEnumerable<TypeDef> Types(IEnumerable<TypeDef> types) {
var visited = new Dictionary<TypeDef, bool>();
var stack = new Stack<IEnumerator<TypeDef>>();
if (!(types is null))
if (types is not null)
stack.Push(types.GetEnumerator());
while (stack.Count > 0) {
var enumerator = stack.Pop();
Expand Down
18 changes: 9 additions & 9 deletions src/DotNet/AssemblyDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public static AssemblyDef Load(string fileName, ModuleCreationOptions options =
return asm;
}
catch {
if (!(module is null))
if (module is not null)
module.Dispose();
throw;
}
Expand Down Expand Up @@ -416,7 +416,7 @@ public static AssemblyDef Load(byte[] data, ModuleCreationOptions options = null
return asm;
}
catch {
if (!(module is null))
if (module is not null)
module.Dispose();
throw;
}
Expand Down Expand Up @@ -453,7 +453,7 @@ public static AssemblyDef Load(IntPtr addr, ModuleCreationOptions options = null
return asm;
}
catch {
if (!(module is null))
if (module is not null)
module.Dispose();
throw;
}
Expand Down Expand Up @@ -494,7 +494,7 @@ public static AssemblyDef Load(Stream stream, ModuleCreationOptions options = nu
return asm;
}
catch {
if (!(module is null))
if (module is not null)
module.Dispose();
throw;
}
Expand Down Expand Up @@ -529,7 +529,7 @@ public TypeDef Find(string fullName, bool isReflectionName) {
if (module is null)
continue;
var type = module.Find(fullName, isReflectionName);
if (!(type is null))
if (type is not null)
return type;
}
return null;
Expand All @@ -550,7 +550,7 @@ public TypeDef Find(TypeRef typeRef) {
if (module is null)
continue;
var type = module.Find(typeRef);
if (!(type is null))
if (type is not null)
return type;
}
return null;
Expand Down Expand Up @@ -710,14 +710,14 @@ void IListListener<ModuleDef>.OnLazyAdd(int index, ref ModuleDef module) {
void IListListener<ModuleDef>.OnAdd(int index, ModuleDef module) {
if (module is null)
return;
if (!(module.Assembly is null))
if (module.Assembly is not null)
throw new InvalidOperationException("Module already has an assembly. Remove it from that assembly before adding it to this assembly.");
module.Assembly = this;
}

/// <inheritdoc/>
void IListListener<ModuleDef>.OnRemove(int index, ModuleDef module) {
if (!(module is null))
if (module is not null)
module.Assembly = null;
}

Expand All @@ -728,7 +728,7 @@ void IListListener<ModuleDef>.OnResize(int index) {
/// <inheritdoc/>
void IListListener<ModuleDef>.OnClear() {
foreach (var module in modules.GetEnumerable_NoLock()) {
if (!(module is null))
if (module is not null)
module.Assembly = null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DotNet/AssemblyHash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public AssemblyHash(AssemblyHashAlgorithm hashAlgo) =>

/// <inheritdoc/>
public void Dispose() {
if (!(hasher is null))
if (hasher is not null)
((IDisposable)hasher).Dispose();
}

Expand Down
2 changes: 1 addition & 1 deletion src/DotNet/AssemblyNameInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public AssemblyNameInfo(AssemblyName asmName) {
publicKeyOrToken = (PublicKeyBase)PublicKeyBase.CreatePublicKey(asmName.GetPublicKey()) ??
PublicKeyBase.CreatePublicKeyToken(asmName.GetPublicKeyToken());
name = asmName.Name ?? string.Empty;
culture = !(asmName.CultureInfo is null) && !(asmName.CultureInfo.Name is null) ? asmName.CultureInfo.Name : string.Empty;
culture = asmName.CultureInfo is not null && asmName.CultureInfo.Name is not null ? asmName.CultureInfo.Name : string.Empty;
}

/// <inhertidoc/>
Expand Down
44 changes: 22 additions & 22 deletions src/DotNet/AssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public GacInfo(int version, string prefix, string path, string[] subDirs) {
static AssemblyResolver() {
gacInfos = new List<GacInfo>();

if (!(Type.GetType("Mono.Runtime") is null)) {
if (Type.GetType("Mono.Runtime") is not null) {
var dirs = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
var extraMonoPathsList = new List<string>();
foreach (var prefix in FindMonoPrefixes()) {
Expand All @@ -83,7 +83,7 @@ static AssemblyResolver() {
}

var paths = Environment.GetEnvironmentVariable("MONO_PATH");
if (!(paths is null)) {
if (paths is not null) {
foreach (var tmp in paths.Split(Path.PathSeparator)) {
var path = tmp.Trim();
if (path != string.Empty && Directory.Exists(path))
Expand Down Expand Up @@ -254,7 +254,7 @@ public AssemblyDef Resolve(IAssembly assembly, ModuleDef sourceModule) {
int count = modules.Count;
for (int i = 0; i < count; i++) {
var module = modules[i];
if (!(module is null))
if (module is not null)
module.EnableTypeDefFindCache = true;
}
}
Expand All @@ -274,7 +274,7 @@ public AssemblyDef Resolve(IAssembly assembly, ModuleDef sourceModule) {

// Dupe assembly. Don't insert it.
var dupeModule = resolvedAssembly.ManifestModule;
if (!(dupeModule is null))
if (dupeModule is not null)
dupeModule.Dispose();
return asm1 ?? asm2;
#if THREAD_SAFE
Expand All @@ -289,7 +289,7 @@ public AssemblyDef Resolve(IAssembly assembly, ModuleDef sourceModule) {
/// <returns><c>true</c> if <paramref name="module"/>'s assembly is cached, <c>false</c>
/// if it's not cached because some other assembly with the exact same full name has
/// already been cached or if <paramref name="module"/> or its assembly is <c>null</c>.</returns>
public bool AddToCache(ModuleDef module) => !(module is null) && AddToCache(module.Assembly);
public bool AddToCache(ModuleDef module) => module is not null && AddToCache(module.Assembly);

/// <summary>
/// Add an assembly to the assembly cache
Expand All @@ -305,7 +305,7 @@ public bool AddToCache(AssemblyDef asm) {
#if THREAD_SAFE
theLock.EnterWriteLock(); try {
#endif
if (cachedAssemblies.TryGetValue(asmKey, out var cachedAsm) && !(cachedAsm is null))
if (cachedAssemblies.TryGetValue(asmKey, out var cachedAsm) && cachedAsm is not null)
return asm == cachedAsm;
cachedAssemblies[asmKey] = asm;
return true;
Expand All @@ -321,7 +321,7 @@ public bool AddToCache(AssemblyDef asm) {
/// <returns><c>true</c> if its assembly was removed, <c>false</c> if it wasn't removed
/// since it wasn't in the cache, it has no assembly, or <paramref name="module"/> was
/// <c>null</c></returns>
public bool Remove(ModuleDef module) => !(module is null) && Remove(module.Assembly);
public bool Remove(ModuleDef module) => module is not null && Remove(module.Assembly);

/// <summary>
/// Removes the assembly from the cache
Expand Down Expand Up @@ -392,13 +392,13 @@ AssemblyDef Resolve2(IAssembly assembly, ModuleDef sourceModule) {
return resolvedAssembly;

var moduleContext = defaultModuleContext;
if (moduleContext is null && !(sourceModule is null))
if (moduleContext is null && sourceModule is not null)
moduleContext = sourceModule.Context;

resolvedAssembly = FindExactAssembly(assembly, PreFindAssemblies(assembly, sourceModule, true), moduleContext) ??
FindExactAssembly(assembly, FindAssemblies(assembly, sourceModule, true), moduleContext) ??
FindExactAssembly(assembly, PostFindAssemblies(assembly, sourceModule, true), moduleContext);
if (!(resolvedAssembly is null))
if (resolvedAssembly is not null)
return resolvedAssembly;

if (!findExactMatch) {
Expand Down Expand Up @@ -428,15 +428,15 @@ AssemblyDef FindExactAssembly(IAssembly assembly, IEnumerable<string> paths, Mod
try {
mod = ModuleDefMD.Load(path, moduleContext);
var asm = mod.Assembly;
if (!(asm is null) && asmComparer.Equals(assembly, asm)) {
if (asm is not null && asmComparer.Equals(assembly, asm)) {
mod = null;
return asm;
}
}
catch {
}
finally {
if (!(mod is null))
if (mod is not null)
mod.Dispose();
}
}
Expand Down Expand Up @@ -470,10 +470,10 @@ AssemblyDef FindClosestAssembly(IAssembly assembly, AssemblyDef closest, IEnumer
try {
mod = ModuleDefMD.Load(path, moduleContext);
var asm = mod.Assembly;
if (!(asm is null) && asmComparer.CompareClosest(assembly, closest, asm) == 1) {
if (!IsCached(closest) && !(closest is null)) {
if (asm is not null && asmComparer.CompareClosest(assembly, closest, asm) == 1) {
if (!IsCached(closest) && closest is not null) {
var closeMod = closest.ManifestModule;
if (!(closeMod is null))
if (closeMod is not null)
closeMod.Dispose();
}
closest = asm;
Expand All @@ -483,7 +483,7 @@ AssemblyDef FindClosestAssembly(IAssembly assembly, AssemblyDef closest, IEnumer
catch {
}
finally {
if (!(mod is null))
if (mod is not null)
mod.Dispose();
}
}
Expand All @@ -503,7 +503,7 @@ bool IsCached(AssemblyDef asm) {
}

IEnumerable<string> FindAssemblies2(IAssembly assembly, IEnumerable<string> paths) {
if (!(paths is null)) {
if (paths is not null) {
var asmSimpleName = UTF8String.ToSystemStringOrEmpty(assembly.Name);
var exts = assembly.IsContentTypeWindowsRuntime ? winMDAssemblyExtensions : assemblyExtensions;
foreach (var ext in exts) {
Expand Down Expand Up @@ -601,14 +601,14 @@ IEnumerable<string> FindAssembliesGacExactly(IAssembly assembly, ModuleDef sourc
foreach (var path in FindAssembliesGacExactly(gacInfo, assembly, sourceModule))
yield return path;
}
if (!(extraMonoPaths is null)) {
if (extraMonoPaths is not null) {
foreach (var path in GetExtraMonoPaths(assembly, sourceModule))
yield return path;
}
}

static IEnumerable<string> GetExtraMonoPaths(IAssembly assembly, ModuleDef sourceModule) {
if (!(extraMonoPaths is null)) {
if (extraMonoPaths is not null) {
foreach (var dir in extraMonoPaths) {
string file;
try {
Expand All @@ -626,7 +626,7 @@ static IEnumerable<string> GetExtraMonoPaths(IAssembly assembly, ModuleDef sourc

IEnumerable<string> FindAssembliesGacExactly(GacInfo gacInfo, IAssembly assembly, ModuleDef sourceModule) {
var pkt = PublicKeyBase.ToPublicKeyToken(assembly.PublicKeyOrToken);
if (!(gacInfo is null) && !(pkt is null)) {
if (gacInfo is not null && pkt is not null) {
string pktString = pkt.ToString();
string verString = Utils.CreateVersionWithNoUndefinedValues(assembly.Version).ToString();
var cultureString = UTF8String.ToSystemStringOrEmpty(assembly.Culture);
Expand Down Expand Up @@ -655,14 +655,14 @@ IEnumerable<string> FindAssembliesGacAny(IAssembly assembly, ModuleDef sourceMod
foreach (var path in FindAssembliesGacAny(gacInfo, assembly, sourceModule))
yield return path;
}
if (!(extraMonoPaths is null)) {
if (extraMonoPaths is not null) {
foreach (var path in GetExtraMonoPaths(assembly, sourceModule))
yield return path;
}
}

IEnumerable<string> FindAssembliesGacAny(GacInfo gacInfo, IAssembly assembly, ModuleDef sourceModule) {
if (!(gacInfo is null)) {
if (gacInfo is not null) {
var asmSimpleName = UTF8String.ToSystemStringOrEmpty(assembly.Name);
foreach (var subDir in gacInfo.SubDirs) {
var baseDir = Path.Combine(gacInfo.Path, subDir);
Expand Down Expand Up @@ -771,7 +771,7 @@ protected IEnumerable<string> GetModulePrivateSearchPaths(ModuleDef module) {
}
catch {
}
if (!(baseDir is null))
if (baseDir is not null)
return new List<string> { baseDir };
return Array2.Empty<string>();
}
Expand Down
2 changes: 1 addition & 1 deletion src/DotNet/CorLibTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ ITypeDefOrRef CreateCorLibTypeRef(bool isCorLib, string name) {
var tr = new TypeRefUser(module, "System", name, corLibAssemblyRef);
if (isCorLib) {
var td = module.Find(tr);
if (!(td is null))
if (td is not null)
return td;
}
return module.UpdateRowId(tr);
Expand Down
4 changes: 2 additions & 2 deletions src/DotNet/CustomAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public string TypeFullName {

if (ctor is MethodDef mdCtor) {
var declType = mdCtor.DeclaringType;
if (!(declType is null))
if (declType is not null)
return declType.FullName;
}

Expand All @@ -48,7 +48,7 @@ public string TypeFullName {
/// <summary>
/// <c>true</c> if the raw custom attribute blob hasn't been parsed
/// </summary>
public bool IsRawBlob => !(rawData is null);
public bool IsRawBlob => rawData is not null;

/// <summary>
/// Gets the raw custom attribute blob or <c>null</c> if the CA was successfully parsed.
Expand Down
6 changes: 3 additions & 3 deletions src/DotNet/CustomAttributeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public CustomAttributeCollection(int length, object context, Func<object, int, C
/// </summary>
/// <param name="fullName">Full name of custom attribute type</param>
/// <returns><c>true</c> if the custom attribute type is present, <c>false</c> otherwise</returns>
public bool IsDefined(string fullName) => !(Find(fullName) is null);
public bool IsDefined(string fullName) => Find(fullName) is not null;

/// <summary>
/// Removes all custom attributes of a certain type
Expand All @@ -50,7 +50,7 @@ public void RemoveAll(string fullName) {
/// <returns>A <see cref="CustomAttribute"/> or <c>null</c> if it wasn't found</returns>
public CustomAttribute Find(string fullName) {
foreach (var ca in this) {
if (!(ca is null) && ca.TypeFullName == fullName)
if (ca is not null && ca.TypeFullName == fullName)
return ca;
}

Expand All @@ -64,7 +64,7 @@ public CustomAttribute Find(string fullName) {
/// <returns>All <see cref="CustomAttribute"/>s of the requested type</returns>
public IEnumerable<CustomAttribute> FindAll(string fullName) {
foreach (var ca in this) {
if (!(ca is null) && ca.TypeFullName == fullName)
if (ca is not null && ca.TypeFullName == fullName)
yield return ca;
}
}
Expand Down
Loading

0 comments on commit 4e0837c

Please sign in to comment.