Skip to content

Commit

Permalink
Use 'is null'
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsck committed Jul 14, 2019
1 parent 5a53964 commit c993df8
Show file tree
Hide file tree
Showing 178 changed files with 2,148 additions and 2,148 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 != null)
if (!(type.BaseType is 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 @@ -274,7 +274,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 != null && ca.ConstructorArguments.Count == 1) {
if (!(ca is 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 != null)
if (!(types is null))
stack.Push(types.GetEnumerator());
while (stack.Count > 0) {
var enumerator = stack.Pop();
Expand Down
82 changes: 41 additions & 41 deletions src/DotNet/AssemblyDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public UTF8String Culture {
/// <inheritdoc/>
public IList<DeclSecurity> DeclSecurities {
get {
if (declSecurities == null)
if (declSecurities is null)
InitializeDeclSecurities();
return declSecurities;
}
Expand All @@ -133,7 +133,7 @@ protected virtual void InitializeDeclSecurities() =>
/// </summary>
public IList<ModuleDef> Modules {
get {
if (modules == null)
if (modules is null)
InitializeModules();
return modules;
}
Expand All @@ -149,7 +149,7 @@ protected virtual void InitializeModules() =>
/// </summary>
public CustomAttributeCollection CustomAttributes {
get {
if (customAttributes == null)
if (customAttributes is null)
InitializeCustomAttributes();
return customAttributes;
}
Expand All @@ -175,7 +175,7 @@ protected virtual void InitializeCustomAttributes() =>
/// </summary>
public IList<PdbCustomDebugInfo> CustomDebugInfos {
get {
if (customDebugInfos == null)
if (customDebugInfos is null)
InitializeCustomDebugInfos();
return customDebugInfos;
}
Expand Down Expand Up @@ -340,7 +340,7 @@ public ModuleDef FindModule(UTF8String name) {
int count = modules.Count;
for (int i = 0; i < count; i++) {
var module = modules[i];
if (module == null)
if (module is null)
continue;
if (UTF8String.CaseInsensitiveEquals(module.Name, name))
return module;
Expand Down Expand Up @@ -368,18 +368,18 @@ public static AssemblyDef Load(string fileName, ModuleContext context) =>
/// <exception cref="ArgumentNullException">If <paramref name="fileName"/> is <c>null</c></exception>
/// <exception cref="BadImageFormatException">If it's not a .NET assembly (eg. not a .NET file or only a .NET module)</exception>
public static AssemblyDef Load(string fileName, ModuleCreationOptions options = null) {
if (fileName == null)
if (fileName is null)
throw new ArgumentNullException(nameof(fileName));
ModuleDef module = null;
try {
module = ModuleDefMD.Load(fileName, options);
var asm = module.Assembly;
if (asm == null)
if (asm is null)
throw new BadImageFormatException($"{fileName} is only a .NET module, not a .NET assembly. Use ModuleDef.Load().");
return asm;
}
catch {
if (module != null)
if (!(module is null))
module.Dispose();
throw;
}
Expand All @@ -405,18 +405,18 @@ public static AssemblyDef Load(byte[] data, ModuleContext context) =>
/// <exception cref="ArgumentNullException">If <paramref name="data"/> is <c>null</c></exception>
/// <exception cref="BadImageFormatException">If it's not a .NET assembly (eg. not a .NET file or only a .NET module)</exception>
public static AssemblyDef Load(byte[] data, ModuleCreationOptions options = null) {
if (data == null)
if (data is null)
throw new ArgumentNullException(nameof(data));
ModuleDef module = null;
try {
module = ModuleDefMD.Load(data, options);
var asm = module.Assembly;
if (asm == null)
if (asm is null)
throw new BadImageFormatException($"{module.ToString()} is only a .NET module, not a .NET assembly. Use ModuleDef.Load().");
return asm;
}
catch {
if (module != null)
if (!(module is null))
module.Dispose();
throw;
}
Expand Down Expand Up @@ -448,12 +448,12 @@ public static AssemblyDef Load(IntPtr addr, ModuleCreationOptions options = null
try {
module = ModuleDefMD.Load(addr, options);
var asm = module.Assembly;
if (asm == null)
if (asm is null)
throw new BadImageFormatException($"{module.ToString()} (addr: {addr.ToInt64():X8}) is only a .NET module, not a .NET assembly. Use ModuleDef.Load().");
return asm;
}
catch {
if (module != null)
if (!(module is null))
module.Dispose();
throw;
}
Expand Down Expand Up @@ -483,18 +483,18 @@ public static AssemblyDef Load(Stream stream, ModuleContext context) =>
/// <exception cref="ArgumentNullException">If <paramref name="stream"/> is <c>null</c></exception>
/// <exception cref="BadImageFormatException">If it's not a .NET assembly (eg. not a .NET file or only a .NET module)</exception>
public static AssemblyDef Load(Stream stream, ModuleCreationOptions options = null) {
if (stream == null)
if (stream is null)
throw new ArgumentNullException(nameof(stream));
ModuleDef module = null;
try {
module = ModuleDefMD.Load(stream, options);
var asm = module.Assembly;
if (asm == null)
if (asm is null)
throw new BadImageFormatException($"{module.ToString()} is only a .NET module, not a .NET assembly. Use ModuleDef.Load().");
return asm;
}
catch {
if (module != null)
if (!(module is null))
module.Dispose();
throw;
}
Expand Down Expand Up @@ -526,10 +526,10 @@ public TypeDef Find(string fullName, bool isReflectionName) {
int count = modules.Count;
for (int i = 0; i < count; i++) {
var module = modules[i];
if (module == null)
if (module is null)
continue;
var type = module.Find(fullName, isReflectionName);
if (type != null)
if (!(type is null))
return type;
}
return null;
Expand All @@ -547,10 +547,10 @@ public TypeDef Find(TypeRef typeRef) {
int count = modules.Count;
for (int i = 0; i < count; i++) {
var module = modules[i];
if (module == null)
if (module is null)
continue;
var type = module.Find(typeRef);
if (type != null)
if (!(type is null))
return type;
}
return null;
Expand All @@ -577,7 +577,7 @@ public void Write(Stream dest, ModuleWriterOptions options = null) =>
/// </summary>
/// <param name="targetAsm">Target assembly</param>
public bool IsFriendAssemblyOf(AssemblyDef targetAsm) {
if (targetAsm == null)
if (targetAsm is null)
return false;
if (this == targetAsm)
return true;
Expand Down Expand Up @@ -623,7 +623,7 @@ public bool IsFriendAssemblyOf(AssemblyDef targetAsm) {
/// <param name="signaturePubKey">Signature public key</param>
public void UpdateOrCreateAssemblySignatureKeyAttribute(StrongNamePublicKey identityPubKey, StrongNameKey identityKey, StrongNamePublicKey signaturePubKey) {
var manifestModule = ManifestModule;
if (manifestModule == null)
if (manifestModule is null)
return;

// Remove all existing attributes
Expand All @@ -634,7 +634,7 @@ public void UpdateOrCreateAssemblySignatureKeyAttribute(StrongNamePublicKey iden
continue;
CustomAttributes.RemoveAt(i);
i--;
if (ca == null)
if (ca is null)
ca = caTmp;
}

Expand All @@ -652,13 +652,13 @@ public void UpdateOrCreateAssemblySignatureKeyAttribute(StrongNamePublicKey iden
bool IsValidAssemblySignatureKeyAttribute(CustomAttribute ca) {
if (dnlib.Settings.IsThreadSafe)
return false;
if (ca == null)
if (ca is null)
return false;
var ctor = ca.Constructor;
if (ctor == null)
if (ctor is null)
return false;
var sig = ctor.MethodSig;
if (sig == null || sig.Params.Count != 2)
if (sig is null || sig.Params.Count != 2)
return false;
if (sig.Params[0].GetElementType() != ElementType.String)
return false;
Expand Down Expand Up @@ -698,26 +698,26 @@ public virtual bool TryGetOriginalTargetFrameworkAttribute(out string framework,

/// <inheritdoc/>
void IListListener<ModuleDef>.OnLazyAdd(int index, ref ModuleDef module) {
if (module == null)
if (module is null)
return;
#if DEBUG
if (module.Assembly == null)
throw new InvalidOperationException("Module.Assembly == null");
if (module.Assembly is null)
throw new InvalidOperationException("Module.Assembly is null");
#endif
}

/// <inheritdoc/>
void IListListener<ModuleDef>.OnAdd(int index, ModuleDef module) {
if (module == null)
if (module is null)
return;
if (module.Assembly != null)
if (!(module.Assembly is 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 != null)
if (!(module is 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 != null)
if (!(module is null))
module.Assembly = null;
}
}
Expand Down Expand Up @@ -787,9 +787,9 @@ public AssemblyDefUser(UTF8String name, Version version, PublicKey publicKey)
/// <param name="locale">Locale</param>
/// <exception cref="ArgumentNullException">If any of the args is invalid</exception>
public AssemblyDefUser(UTF8String name, Version version, PublicKey publicKey, UTF8String locale) {
if ((object)name == null)
if (name is null)
throw new ArgumentNullException(nameof(name));
if ((object)locale == null)
if (locale is null)
throw new ArgumentNullException(nameof(locale));
modules = new LazyList<ModuleDef>(this);
this.name = name;
Expand All @@ -816,7 +816,7 @@ public AssemblyDefUser(AssemblyName asmName)
/// <param name="asmName">Assembly name info</param>
/// <exception cref="ArgumentNullException">If <paramref name="asmName"/> is <c>null</c></exception>
public AssemblyDefUser(IAssembly asmName) {
if (asmName == null)
if (asmName is null)
throw new ArgumentNullException(nameof(asmName));
modules = new LazyList<ModuleDef>(this);
name = asmName.Name;
Expand Down Expand Up @@ -856,7 +856,7 @@ protected override void InitializeModules() {
module = readerModule;
else
module = readerModule.ReadModule(list2[index - 1], this);
if (module == null)
if (module is null)
module = new ModuleDefUser("INVALID", Guid.NewGuid());
module.Assembly = this;
return module;
Expand Down Expand Up @@ -909,10 +909,10 @@ void InitializeTargetFrameworkAttribute() {
if (ns != nameSystemRuntimeVersioning || name != nameTargetFrameworkAttribute)
continue;
var ca = CustomAttributeReader.Read(readerModule, caType, caRow.Value, gpContext);
if (ca == null || ca.ConstructorArguments.Count != 1)
if (ca is null || ca.ConstructorArguments.Count != 1)
continue;
var s = ca.ConstructorArguments[0].Value as UTF8String;
if ((object)s == null)
if (s is null)
continue;
if (TryCreateTargetFrameworkInfo(s, out var tmpFramework, out var tmpVersion, out var tmpProfile)) {
tfaFramework = tmpFramework;
Expand Down Expand Up @@ -984,7 +984,7 @@ static bool TryCreateTargetFrameworkInfo(string attrString, out string framework
profileRes = value;
}
}
if (versionRes == null)
if (versionRes is null)
return false;

framework = frameworkRes;
Expand Down Expand Up @@ -1029,7 +1029,7 @@ static bool TryParse(string s, out Version version) {
/// <exception cref="ArgumentException">If <paramref name="rid"/> is invalid</exception>
public AssemblyDefMD(ModuleDefMD readerModule, uint rid) {
#if DEBUG
if (readerModule == null)
if (readerModule is null)
throw new ArgumentNullException("readerModule");
if (readerModule.TablesStream.AssemblyTable.IsInvalidRID(rid))
throw new BadImageFormatException($"Assembly rid {rid} does not exist");
Expand Down
6 changes: 3 additions & 3 deletions src/DotNet/AssemblyHash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public AssemblyHash(AssemblyHashAlgorithm hashAlgo) {

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

Expand All @@ -65,7 +65,7 @@ public void Dispose() {
/// <param name="hashAlgo">The algorithm to use</param>
/// <returns>Hashed data or null if <paramref name="data"/> was <c>null</c></returns>
public static byte[] Hash(byte[] data, AssemblyHashAlgorithm hashAlgo) {
if (data == null)
if (data is null)
return null;

using (var asmHash = new AssemblyHash(hashAlgo)) {
Expand Down Expand Up @@ -123,7 +123,7 @@ public byte[] ComputeHash() {
/// <param name="publicKeyData">The data</param>
/// <returns>A new <see cref="PublicKeyToken"/> instance</returns>
public static PublicKeyToken CreatePublicKeyToken(byte[] publicKeyData) {
if (publicKeyData == null)
if (publicKeyData is null)
return new PublicKeyToken();
var hash = Hash(publicKeyData, AssemblyHashAlgorithm.SHA1);
var pkt = new byte[8];
Expand Down
10 changes: 5 additions & 5 deletions src/DotNet/AssemblyNameComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public enum AssemblyNameComparerFlags {
public int CompareTo(IAssembly a, IAssembly b) {
if (a == b)
return 0;
if (a == null)
if (a is null)
return -1;
if (b == null)
if (b is null)
return 1;

int v;
Expand Down Expand Up @@ -141,9 +141,9 @@ public int CompareTo(IAssembly a, IAssembly b) {
public int CompareClosest(IAssembly requested, IAssembly a, IAssembly b) {
if (a == b)
return 0;
if (a == null)
if (a is null)
return !CompareName ? 1 : UTF8String.CaseInsensitiveEquals(requested.Name, b.Name) ? 1 : 0;
if (b == null)
if (b is null)
return !CompareName ? 0 : UTF8String.CaseInsensitiveEquals(requested.Name, a.Name) ? 0 : 1;

// Compare the most important parts first:
Expand Down Expand Up @@ -237,7 +237,7 @@ public int CompareClosest(IAssembly requested, IAssembly a, IAssembly b) {
/// <param name="a">Assembly name</param>
/// <returns>The hash code</returns>
public int GetHashCode(IAssembly a) {
if (a == null)
if (a is null)
return 0;

int hash = 0;
Expand Down
Loading

0 comments on commit c993df8

Please sign in to comment.