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 45716af commit 9b0621d
Show file tree
Hide file tree
Showing 1,087 changed files with 4,598 additions and 4,598 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool ShouldPatchAssembly(string simpleName) {
}

static bool IsPublic(TypeDef type) {
while (!(type is null)) {
while (type is not null) {
if (!type.IsPublic && !type.IsNestedPublic)
return false;
type = type.DeclaringType;
Expand All @@ -59,7 +59,7 @@ static bool IsPublic(TypeDef type) {
}

static bool IsPublic(ExportedType type) {
while (!(type is null)) {
while (type is not null) {
if (!type.IsPublic && !type.IsNestedPublic)
return false;
type = type.DeclaringType;
Expand Down
2 changes: 1 addition & 1 deletion DnSpyCommon.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<IsDotNet Condition=" !$(TargetFramework.StartsWith(net4)) ">false</IsDotNet>
<IsSelfContainedDotNet Condition=" '$(IsDotNet)' == 'true' ">true</IsSelfContainedDotNet>
<Features>strict;nullablePublicOnly</Features>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<LangVersion Condition=" $(MSBuildProjectFile.EndsWith('.vbproj')) " >latest</LangVersion>
<NeutralLanguage>en</NeutralLanguage>
<AppDesignerFolderContentsVisibleOnlyInShowAllFiles>false</AppDesignerFolderContentsVisibleOnlyInShowAllFiles>
Expand Down
8 changes: 4 additions & 4 deletions Extensions/Examples/Example1.Extension/CodeCtxMenus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ sealed class TextEditorCommand2 : MenuItemBase {
sealed class TextEditorCommand3 : MenuItemBase {
public override void Execute(IMenuItemContext context) {
var md = GetTokenObj(context);
if (!(md is null)) {
if (md is not null) {
try {
Clipboard.SetText($"{md.MDToken.Raw:X8}");
}
Expand Down Expand Up @@ -101,14 +101,14 @@ public override void Execute(IMenuItemContext context) {

// Only show this in the document viewer
public override bool IsVisible(IMenuItemContext context) => context.CreatorObject.Guid == new Guid(MenuConstants.GUIDOBJ_DOCUMENTVIEWERCONTROL_GUID);
public override bool IsEnabled(IMenuItemContext context) => !(GetTokenObj(context) is null);
public override bool IsEnabled(IMenuItemContext context) => GetTokenObj(context) is not null;
}

[ExportMenuItem(Group = Constants.GROUP_TEXTEDITOR, Order = 30)]
sealed class TextEditorCommand4 : MenuItemBase {
public override void Execute(IMenuItemContext context) {
var documentViewer = GetDocumentViewer(context);
if (!(documentViewer is null)) {
if (documentViewer is not null) {
try {
var lineColumn = GetLineColumn(documentViewer.Caret.Position.VirtualBufferPosition);
Clipboard.SetText($"Line,col: {lineColumn.Line + 1},{lineColumn.Column + 1}");
Expand Down Expand Up @@ -150,6 +150,6 @@ public LineColumn(int line, int column) {

// Only show this in the document viewer
public override bool IsVisible(IMenuItemContext context) => context.CreatorObject.Guid == new Guid(MenuConstants.GUIDOBJ_DOCUMENTVIEWERCONTROL_GUID);
public override bool IsEnabled(IMenuItemContext context) => !(GetDocumentViewer(context) is null);
public override bool IsEnabled(IMenuItemContext context) => GetDocumentViewer(context) is not null;
}
}
8 changes: 4 additions & 4 deletions Extensions/Examples/Example1.Extension/TreeViewCtxMenus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ sealed class TVCommand4 : TVCtxMenuCommand {
sealed class TVCommand5 : TVCtxMenuCommand {
public override void Execute(TVContext context) {
var node = GetTokenNode(context);
if (!(node is null)) {
if (node is not null) {
try {
Clipboard.SetText($"{node.Reference!.MDToken.Raw:X8}");
}
Expand All @@ -105,14 +105,14 @@ public override void Execute(TVContext context) {
return $"Copy token {node.Reference!.MDToken.Raw:X8}";
}

public override bool IsVisible(TVContext context) => !(GetTokenNode(context) is null);
public override bool IsVisible(TVContext context) => GetTokenNode(context) is not null;
}

[ExportMenuItem(Header = "Copy Second Instruction", Group = Constants.GROUP_TREEVIEW, Order = 50)]
sealed class TVCommand6 : TVCtxMenuCommand {
public override void Execute(TVContext context) {
var instr = GetSecondInstruction(context);
if (!(instr is null)) {
if (instr is not null) {
try {
Clipboard.SetText($"Second instruction: {instr}");
}
Expand All @@ -132,6 +132,6 @@ public override void Execute(TVContext context) {
return body.Instructions[1];
}

public override bool IsEnabled(TVContext context) => !(GetSecondInstruction(context) is null);
public override bool IsEnabled(TVContext context) => GetSecondInstruction(context) is not null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sealed class AssemblyChildNodeTabContentFactory : IDocumentTabContentFactory {
// Serialize() doesn't add anything extra to 'section', but if it did, you'd have to
// get that info here and return null if the serialized data wasn't found.
var node = context.Nodes.Length == 1 ? context.Nodes[0] as AssemblyChildNode : null;
if (!(node is null))
if (node is not null)
return new AssemblyChildNodeTabContent(node);
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Examples/Example2.Extension/NewDsDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sealed class MyDsDocument : DsDocument {
// Used by MyDsDocumentNode.Decompile() to show the file in the text editor
public string Text {
get {
if (!(text is null))
if (text is not null)
return text;
try {
return text = File.ReadAllText(Filename);
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Examples/Example2.Extension/OutputTextPane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static IOutputTextPane Instance {
return _instance;
}
set {
if (!(_instance is null))
if (_instance is not null)
throw new InvalidOperationException("Can't initialize the logger twice");
_instance = value ?? throw new ArgumentNullException(nameof(value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sealed class AssemblyInfoTransform : IAstTransform {
public void Run(AstNode compilationUnit) {
foreach (var attrSect in compilationUnit.Descendants.OfType<AttributeSection>()) {
var attr = attrSect.Descendants.OfType<Attribute>().FirstOrDefault();
Debug2.Assert(!(attr is null));
Debug2.Assert(attr is not null);
if (attr is null)
continue;
bool remove = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public DecompilerProvider()
}

public DecompilerProvider(DecompilerSettingsService decompilerSettingsService) {
Debug2.Assert(!(decompilerSettingsService is null));
Debug2.Assert(decompilerSettingsService is not null);
this.decompilerSettingsService = decompilerSettingsService ?? throw new ArgumentNullException(nameof(decompilerSettingsService));
}

Expand Down Expand Up @@ -243,7 +243,7 @@ public override void Decompile(TypeDef type, IDecompilerOutput output, Decompila
void RunTransformsAndGenerateCode(ref BuilderState state, IDecompilerOutput output, DecompilationContext ctx, IAstTransform? additionalTransform = null) {
var astBuilder = state.AstBuilder;
astBuilder.RunTransformations(transformAbortCondition);
if (!(additionalTransform is null)) {
if (additionalTransform is not null) {
additionalTransform.Run(astBuilder.SyntaxTree);
}
AddXmlDocumentation(ref state, langSettings.Settings, astBuilder);
Expand All @@ -256,7 +256,7 @@ internal static void AddXmlDocumentation(ref BuilderState state, DecompilerSetti
var hasXmlDocFileTmp = state.State.HasXmlDocFile(module);
bool hasXmlDocFile;
if (hasXmlDocFileTmp is null) {
hasXmlDocFile = !(XmlDocLoader.LoadDocumentation(module) is null);
hasXmlDocFile = XmlDocLoader.LoadDocumentation(module) is not null;
state.State.SetHasXmlDocFile(module, hasXmlDocFile);
}
else
Expand Down Expand Up @@ -335,11 +335,11 @@ protected override void TypeToString(IDecompilerOutput output, ITypeDefOrRef? ty
static readonly UTF8String isReadOnlyAttributeString = new UTF8String("IsReadOnlyAttribute");
bool WriteRefIfByRef(IDecompilerOutput output, TypeSig typeSig, ParamDef? pd) {
if (typeSig.RemovePinnedAndModifiers() is ByRefSig) {
if (!(pd is null) && (!pd.IsIn && pd.IsOut)) {
if (pd is not null && (!pd.IsIn && pd.IsOut)) {
output.Write("out", BoxedTextColor.Keyword);
output.Write(" ", BoxedTextColor.Text);
}
else if (!(pd is null) && pd.IsDefined(systemRuntimeCompilerServicesString, isReadOnlyAttributeString)) {
else if (pd is not null && pd.IsDefined(systemRuntimeCompilerServicesString, isReadOnlyAttributeString)) {
output.Write("in", BoxedTextColor.Keyword);
output.Write(" ", BoxedTextColor.Text);
}
Expand Down Expand Up @@ -375,7 +375,7 @@ protected override void FormatPropertyName(IDecompilerOutput output, PropertyDef
}
if (isIndexer.Value) {
var accessor = property.GetMethod ?? property.SetMethod;
if (!(accessor is null) && accessor.HasOverrides) {
if (accessor is not null && accessor.HasOverrides) {
var methDecl = accessor.Overrides.First().MethodDeclaration;
var declaringType = methDecl is null ? null : methDecl.DeclaringType;
TypeToString(output, declaringType, includeNamespace: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public DecompilePartialTransform(TypeDef type, HashSet<IMemberDef> definitions,
public void Run(AstNode compilationUnit) {
foreach (var en in compilationUnit.Descendants.OfType<EntityDeclaration>()) {
var def = en.Annotation<IMemberDef>();
Debug2.Assert(!(def is null));
Debug2.Assert(def is not null);
if (def is null)
continue;
if (def == type) {
var tdecl = en as TypeDeclaration;
Debug2.Assert(!(tdecl is null));
if (!(tdecl is null)) {
Debug2.Assert(tdecl is not null);
if (tdecl is not null) {
if (addPartialKeyword) {
if (tdecl.ClassType != ClassType.Enum)
tdecl.Modifiers |= Modifiers.Partial;
Expand All @@ -63,7 +63,7 @@ public void Run(AstNode compilationUnit) {
}
foreach (var iface in tdecl.BaseTypes) {
var tdr = iface.Annotation<ITypeDefOrRef>();
if (!(tdr is null) && ifacesToRemove.Contains(tdr))
if (tdr is not null && ifacesToRemove.Contains(tdr))
iface.Remove();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public DecompileTypeMethodsTransform(HashSet<TypeDef> types, HashSet<MethodDef>
foreach (var method in methods) {
// If it's part of a property or event, include the property or event since there are no partial props/events
var prop = method.DeclaringType.Properties.FirstOrDefault(a => a.GetMethods.Contains(method) || a.SetMethods.Contains(method));
if (!(prop is null)) {
if (prop is not null) {
defsToShow.Add(prop);
foreach (var m in prop.GetMethods)
defsToShow.Add(m);
Expand All @@ -51,13 +51,13 @@ public DecompileTypeMethodsTransform(HashSet<TypeDef> types, HashSet<MethodDef>
}
else {
var evt = method.DeclaringType.Events.FirstOrDefault(a => a.AddMethod == method || a.RemoveMethod == method);
if (!(evt is null)) {
if (evt is not null) {
defsToShow.Add(evt);
if (!(evt.AddMethod is null))
if (evt.AddMethod is not null)
defsToShow.Add(evt.AddMethod);
if (!(evt.RemoveMethod is null))
if (evt.RemoveMethod is not null)
defsToShow.Add(evt.RemoveMethod);
if (!(evt.InvokeMethod is null))
if (evt.InvokeMethod is not null)
defsToShow.Add(evt.InvokeMethod);
foreach (var m in evt.OtherMethods)
defsToShow.Add(m);
Expand All @@ -73,7 +73,7 @@ public DecompileTypeMethodsTransform(HashSet<TypeDef> types, HashSet<MethodDef>
}
}
foreach (var def in defsToShow) {
for (var declType = def.DeclaringType; !(declType is null); declType = declType.DeclaringType)
for (var declType = def.DeclaringType; declType is not null; declType = declType.DeclaringType)
partialTypes.Add(declType);
}
foreach (var type in types) {
Expand All @@ -88,14 +88,14 @@ public DecompileTypeMethodsTransform(HashSet<TypeDef> types, HashSet<MethodDef>
public void Run(AstNode compilationUnit) {
foreach (var en in compilationUnit.Descendants.OfType<EntityDeclaration>()) {
var def = en.Annotation<IMemberDef>();
Debug2.Assert(!(def is null));
Debug2.Assert(def is not null);
if (def is null)
continue;

if (partialTypes.Contains(def)) {
var tdecl = en as TypeDeclaration;
Debug2.Assert(!(tdecl is null));
if (!(tdecl is null)) {
Debug2.Assert(tdecl is not null);
if (tdecl is not null) {
if (tdecl.ClassType != ClassType.Enum)
tdecl.Modifiers |= Modifiers.Partial;
if (!showDefinitions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public DecompilerProvider()
}

public DecompilerProvider(DecompilerSettingsService decompilerSettingsService) {
Debug2.Assert(!(decompilerSettingsService is null));
Debug2.Assert(decompilerSettingsService is not null);
this.decompilerSettingsService = decompilerSettingsService ?? throw new ArgumentNullException(nameof(decompilerSettingsService));
}

Expand Down Expand Up @@ -89,7 +89,7 @@ ReflectionDisassembler CreateReflectionDisassembler(IDecompilerOutput output, De
var sb = new StringBuilder();
if (langSettings.Settings.ShowXmlDocumentation)
disOpts.GetXmlDocComments = a => GetXmlDocComments(a, sb);
disOpts.CreateInstructionBytesReader = m => InstructionBytesReader.Create(m, !(ctx.IsBodyModified is null) && ctx.IsBodyModified(m));
disOpts.CreateInstructionBytesReader = m => InstructionBytesReader.Create(m, ctx.IsBodyModified is not null && ctx.IsBodyModified(m));
disOpts.ShowTokenAndRvaComments = langSettings.Settings.ShowTokenAndRvaComments;
disOpts.ShowILBytes = langSettings.Settings.ShowILBytes;
disOpts.SortMembers = langSettings.Settings.SortMembers;
Expand All @@ -111,7 +111,7 @@ static IEnumerable<string> GetXmlDocComments(IMemberRef mr, StringBuilder sb) {

foreach (var info in new XmlDocLine(doc)) {
sb.Clear();
if (!(info is null)) {
if (info is not null) {
sb.Append(' ');
info.Value.WriteTo(sb);
}
Expand All @@ -132,11 +132,11 @@ public override void Decompile(FieldDef field, IDecompilerOutput output, Decompi
public override void Decompile(PropertyDef property, IDecompilerOutput output, DecompilationContext ctx) {
ReflectionDisassembler rd = CreateReflectionDisassembler(output, ctx, property);
rd.DisassembleProperty(property, addLineSep: true);
if (!(property.GetMethod is null)) {
if (property.GetMethod is not null) {
output.WriteLine();
rd.DisassembleMethod(property.GetMethod, true);
}
if (!(property.SetMethod is null)) {
if (property.SetMethod is not null) {
output.WriteLine();
rd.DisassembleMethod(property.SetMethod, true);
}
Expand All @@ -149,11 +149,11 @@ public override void Decompile(PropertyDef property, IDecompilerOutput output, D
public override void Decompile(EventDef ev, IDecompilerOutput output, DecompilationContext ctx) {
ReflectionDisassembler rd = CreateReflectionDisassembler(output, ctx, ev);
rd.DisassembleEvent(ev, addLineSep: true);
if (!(ev.AddMethod is null)) {
if (ev.AddMethod is not null) {
output.WriteLine();
rd.DisassembleMethod(ev.AddMethod, true);
}
if (!(ev.RemoveMethod is null)) {
if (ev.RemoveMethod is not null) {
output.WriteLine();
rd.DisassembleMethod(ev.RemoveMethod, true);
}
Expand Down
Loading

0 comments on commit 9b0621d

Please sign in to comment.