Browse Source

Focus on CS8600 (not even close to done thee is a ton of these)

pull/3287/head
apmoskevitz 10 months ago
parent
commit
dc2af218e4
  1. 1
      .editorconfig
  2. 8
      ICSharpCode.Decompiler/CSharp/Annotations.cs
  3. 10
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  4. 2
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs
  5. 11
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  6. 8
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs
  7. 2
      ICSharpCode.Decompiler/CSharp/OutputVisitor/GenericGrammarAmbiguityVisitor.cs
  8. 6
      ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertSpecialsDecorator.cs
  9. 2
      ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs
  10. 2
      ICSharpCode.Decompiler/CSharp/ProjectDecompiler/TargetFramework.cs
  11. 4
      ICSharpCode.Decompiler/CSharp/ProjectDecompiler/TargetServices.cs
  12. 4
      ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs
  13. 2
      ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs
  14. 10
      ICSharpCode.Decompiler/CSharp/Resolver/CSharpConversions.cs
  15. 42
      ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs
  16. 8
      ICSharpCode.Decompiler/CSharp/Resolver/MemberLookup.cs
  17. 2
      ICSharpCode.Decompiler/CSharp/Resolver/OverloadResolution.cs
  18. 2
      ICSharpCode.Decompiler/CSharp/Resolver/TypeInference.cs
  19. 2
      ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs
  20. 15
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  21. 2
      ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs
  22. 12
      ICSharpCode.Decompiler/CSharp/Syntax/AstNodeCollection.cs
  23. 272
      ICSharpCode.Decompiler/CSharp/Syntax/DepthFirstAstVisitor.cs
  24. 22
      ICSharpCode.Decompiler/CSharp/Syntax/IAnnotatable.cs
  25. 568
      ICSharpCode.Decompiler/CSharp/Syntax/IAstVisitor.cs
  26. 2
      ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/INode.cs
  27. 10
      ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/Pattern.cs
  28. 2
      ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/Repeat.cs
  29. 6
      ICSharpCode.Decompiler/CSharp/Syntax/Statements/Statement.cs
  30. 2
      ICSharpCode.Decompiler/CSharp/Syntax/SyntaxExtensions.cs
  31. 2
      ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/Accessor.cs
  32. 2
      ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EntityDeclaration.cs
  33. 2
      ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/MethodDeclaration.cs
  34. 16
      ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs
  35. 6
      ICSharpCode.Decompiler/CSharp/Transforms/AddCheckedBlocks.cs
  36. 4
      ICSharpCode.Decompiler/CSharp/Transforms/AddXmlDocumentationTransform.cs
  37. 4
      ICSharpCode.Decompiler/CSharp/Transforms/CombineQueryExpressions.cs
  38. 6
      ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs
  39. 4
      ICSharpCode.Decompiler/CSharp/Transforms/FixNameCollisions.cs
  40. 24
      ICSharpCode.Decompiler/CSharp/Transforms/IntroduceQueryExpressions.cs
  41. 8
      ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs
  42. 4
      ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs
  43. 2
      ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs
  44. 2
      ICSharpCode.Decompiler/CSharp/TypeSystem/ResolvedUsingScope.cs
  45. 10
      ICSharpCode.Decompiler/DecompilerException.cs
  46. 8
      ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs
  47. 2
      ICSharpCode.Decompiler/Documentation/GetPotentiallyNestedClassTypeReference.cs
  48. 2
      ICSharpCode.Decompiler/Documentation/IdStringProvider.cs
  49. 2
      ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs
  50. 4
      ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs
  51. 12
      ICSharpCode.Decompiler/IL/ControlFlow/AwaitInCatchTransform.cs
  52. 4
      ICSharpCode.Decompiler/IL/ControlFlow/AwaitInFinallyTransform.cs
  53. 8
      ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs
  54. 8
      ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs
  55. 2
      ICSharpCode.Decompiler/IL/ControlFlow/DetectPinnedRegions.cs
  56. 16
      ICSharpCode.Decompiler/IL/Transforms/CachedDelegateInitialization.cs
  57. 2
      ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs
  58. 3
      ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs
  59. 4
      ICSharpCode.Decompiler/IL/Transforms/IndexRangeTransform.cs
  60. 67
      ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs
  61. 6
      ICSharpCode.Decompiler/Semantics/ConstantResolveResult.cs
  62. 2
      ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs
  63. 4
      ICSharpCode.Decompiler/TypeSystem/TaskType.cs
  64. 2
      ILSpy.BamlDecompiler/BamlResourceNodeFactory.cs
  65. 4
      ILSpy/Languages/ILAstLanguage.cs
  66. 14
      ILSpy/MainWindow.xaml.cs
  67. 2
      ILSpy/TextView/DocumentationUIBuilder.cs
  68. 4
      ILSpy/TreeNodes/ResourceNodes/CursorResourceEntryNode.cs
  69. 2
      ILSpy/TreeNodes/ResourceNodes/IResourceNodeFactory.cs
  70. 4
      ILSpy/TreeNodes/ResourceNodes/IconResourceEntryNode.cs
  71. 4
      ILSpy/TreeNodes/ResourceNodes/ImageListResourceEntryNode.cs
  72. 4
      ILSpy/TreeNodes/ResourceNodes/ImageResourceEntryNode.cs
  73. 11
      ILSpy/TreeNodes/ResourceNodes/ResourceEntryNode.cs
  74. 4
      ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs
  75. 6
      ILSpy/TreeNodes/ResourceNodes/XamlResourceNode.cs
  76. 8
      ILSpy/TreeNodes/ResourceNodes/XmlResourceNode.cs
  77. 4
      ILSpy/Views/DebugSteps.xaml.cs

1
.editorconfig

@ -154,6 +154,7 @@ dotnet_diagnostic.IDE2003.severity = silent
#cleared null error types #cleared null error types
dotnet_diagnostic.CS8612.severity = error dotnet_diagnostic.CS8612.severity = error
dotnet_diagnostic.CS8714.severity = error dotnet_diagnostic.CS8714.severity = error
dotnet_diagnostic.CS8762.severity = error
dotnet_diagnostic.CS8765.severity = error dotnet_diagnostic.CS8765.severity = error
dotnet_diagnostic.CS8766.severity = error dotnet_diagnostic.CS8766.severity = error
dotnet_diagnostic.CS8767.severity = error dotnet_diagnostic.CS8767.severity = error

8
ICSharpCode.Decompiler/CSharp/Annotations.cs

@ -134,7 +134,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// Retrieves the <see cref="ISymbol"/> associated with this AstNode, or null if no symbol /// Retrieves the <see cref="ISymbol"/> associated with this AstNode, or null if no symbol
/// is associated with the node. /// is associated with the node.
/// </summary> /// </summary>
public static ISymbol GetSymbol(this AstNode node) public static ISymbol? GetSymbol(this AstNode node)
{ {
var rr = node.Annotation<ResolveResult>(); var rr = node.Annotation<ResolveResult>();
if (rr is MethodGroupResolveResult) if (rr is MethodGroupResolveResult)
@ -175,7 +175,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// Retrieves the <see cref="ILVariable"/> associated with this <see cref="IdentifierExpression"/>, /// Retrieves the <see cref="ILVariable"/> associated with this <see cref="IdentifierExpression"/>,
/// or <c>null</c> if no variable is associated with this identifier. /// or <c>null</c> if no variable is associated with this identifier.
/// </summary> /// </summary>
public static ILVariable GetILVariable(this IdentifierExpression expr) public static ILVariable? GetILVariable(this IdentifierExpression expr)
{ {
if (expr.Annotation<ResolveResult>() is ILVariableResolveResult rr) if (expr.Annotation<ResolveResult>() is ILVariableResolveResult rr)
return rr.Variable; return rr.Variable;
@ -187,7 +187,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// Retrieves the <see cref="ILVariable"/> associated with this <see cref="VariableInitializer"/>, /// Retrieves the <see cref="ILVariable"/> associated with this <see cref="VariableInitializer"/>,
/// or <c>null</c> if no variable is associated with this initializer. /// or <c>null</c> if no variable is associated with this initializer.
/// </summary> /// </summary>
public static ILVariable GetILVariable(this VariableInitializer vi) public static ILVariable? GetILVariable(this VariableInitializer vi)
{ {
if (vi.Annotation<ResolveResult>() is ILVariableResolveResult rr) if (vi.Annotation<ResolveResult>() is ILVariableResolveResult rr)
return rr.Variable; return rr.Variable;
@ -199,7 +199,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// Retrieves the <see cref="ILVariable"/> associated with this <see cref="ForeachStatement"/>, /// Retrieves the <see cref="ILVariable"/> associated with this <see cref="ForeachStatement"/>,
/// or <c>null</c> if no variable is associated with this foreach statement. /// or <c>null</c> if no variable is associated with this foreach statement.
/// </summary> /// </summary>
public static ILVariable GetILVariable(this ForeachStatement loop) public static ILVariable? GetILVariable(this ForeachStatement loop)
{ {
if (loop.Annotation<ResolveResult>() is ILVariableResolveResult rr) if (loop.Annotation<ResolveResult>() is ILVariableResolveResult rr)
return rr.Variable; return rr.Variable;

10
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -1213,7 +1213,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// <param name="member">The node of the member which new modifier state should be determined.</param> /// <param name="member">The node of the member which new modifier state should be determined.</param>
void SetNewModifier(EntityDeclaration member) void SetNewModifier(EntityDeclaration member)
{ {
var entity = (IEntity)member.GetSymbol(); var entity = member.GetSymbol() as IEntity;
var lookup = new MemberLookup(entity.DeclaringTypeDefinition, entity.ParentModule); var lookup = new MemberLookup(entity.DeclaringTypeDefinition, entity.ParentModule);
var baseTypes = entity.DeclaringType.GetNonInterfaceBaseTypes().Where(t => entity.DeclaringType != t).ToList(); var baseTypes = entity.DeclaringType.GetNonInterfaceBaseTypes().Where(t => entity.DeclaringType != t).ToList();
@ -1325,7 +1325,7 @@ namespace ICSharpCode.Decompiler.CSharp
foreach (var p in recordDecompiler.PrimaryConstructor.Parameters) foreach (var p in recordDecompiler.PrimaryConstructor.Parameters)
{ {
ParameterDeclaration pd = typeSystemAstBuilder.ConvertParameter(p); ParameterDeclaration pd = typeSystemAstBuilder.ConvertParameter(p);
(IProperty prop, IField field) = recordDecompiler.GetPropertyInfoByPrimaryConstructorParameter(p); (IProperty? prop, IField field) = recordDecompiler.GetPropertyInfoByPrimaryConstructorParameter(p);
if (prop != null) if (prop != null)
{ {
@ -1567,7 +1567,7 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
if (MemberIsHidden(module, field.MetadataToken, settings)) if (MemberIsHidden(module, field.MetadataToken, settings))
continue; continue;
object constantValue = field.GetConstantValue(); object? constantValue = field.GetConstantValue();
if (constantValue == null) if (constantValue == null)
continue; continue;
long currentValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, constantValue, false); long currentValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, constantValue, false);
@ -1958,7 +1958,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (decompilationContext.CurrentTypeDefinition.Kind == TypeKind.Enum && field.IsConst) if (decompilationContext.CurrentTypeDefinition.Kind == TypeKind.Enum && field.IsConst)
{ {
var enumDec = new EnumMemberDeclaration { Name = field.Name }; var enumDec = new EnumMemberDeclaration { Name = field.Name };
object constantValue = field.GetConstantValue(); object? constantValue = field.GetConstantValue();
if (constantValue != null) if (constantValue != null)
{ {
enumDec.Initializer = typeSystemAstBuilder.ConvertConstantValue(decompilationContext.CurrentTypeDefinition.EnumUnderlyingType, constantValue); enumDec.Initializer = typeSystemAstBuilder.ConvertConstantValue(decompilationContext.CurrentTypeDefinition.EnumUnderlyingType, constantValue);
@ -2022,7 +2022,7 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
type = null; type = null;
elementCount = 0; elementCount = 0;
IAttribute attr = field.GetAttribute(KnownAttribute.FixedBuffer); IAttribute? attr = field.GetAttribute(KnownAttribute.FixedBuffer);
if (attr != null && attr.FixedArguments.Length == 2) if (attr != null && attr.FixedArguments.Length == 2)
{ {
if (attr.FixedArguments[0].Value is IType trr && attr.FixedArguments[1].Value is int length) if (attr.FixedArguments[0].Value is IType trr && attr.FixedArguments[1].Value is int length)

2
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -1574,7 +1574,7 @@ namespace ICSharpCode.Decompiler.CSharp
arguments.Remove(value); arguments.Remove(value);
} }
IMember foundMember; IMember? foundMember;
while (!IsUnambiguousAccess(expectedTargetDetails, targetResolveResult, method, arguments, argumentNames, out foundMember)) while (!IsUnambiguousAccess(expectedTargetDetails, targetResolveResult, method, arguments, argumentNames, out foundMember))
{ {
if (!argumentsCasted) if (!argumentsCasted)

11
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -2535,7 +2535,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (resultType.Kind == TypeKind.Void) if (resultType.Kind == TypeKind.Void)
return compilation.FindType(KnownTypeCode.Task); return compilation.FindType(KnownTypeCode.Task);
ITypeDefinition def = compilation.FindType(KnownTypeCode.TaskOfT).GetDefinition(); ITypeDefinition? def = compilation.FindType(KnownTypeCode.TaskOfT).GetDefinition();
if (def != null) if (def != null)
return new ParameterizedType(def, new[] { resultType }); return new ParameterizedType(def, new[] { resultType });
else else
@ -2988,7 +2988,7 @@ namespace ICSharpCode.Decompiler.CSharp
memberName = "LongLength"; memberName = "LongLength";
code = KnownTypeCode.Int64; code = KnownTypeCode.Int64;
} }
IProperty member = arrayType.GetProperties(p => p.Name == memberName).FirstOrDefault(); IProperty? member = arrayType.GetProperties(p => p.Name == memberName).FirstOrDefault();
ResolveResult rr = member == null ResolveResult rr = member == null
? new ResolveResult(compilation.FindType(code)) ? new ResolveResult(compilation.FindType(code))
: new MemberResolveResult(arrayExpr.ResolveResult, member); : new MemberResolveResult(arrayExpr.ResolveResult, member);
@ -3917,7 +3917,8 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
TranslatedExpression value; TranslatedExpression value;
IType type; IType type;
if (inst.Value is StringToInt strToInt) var strToInt = inst.Value as StringToInt;
if (strToInt != null)
{ {
value = Translate(strToInt.Argument) value = Translate(strToInt.Argument)
.ConvertTo( .ConvertTo(
@ -4534,7 +4535,7 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
if (subPattern.HasDesignator) if (subPattern.HasDesignator)
{ {
if (!conversionMapping.TryGetValue(subPattern.Variable, out ILVariable value)) if (!conversionMapping.TryGetValue(subPattern.Variable, out ILVariable? value))
{ {
value = subPattern.Variable; value = subPattern.Variable;
} }
@ -4639,7 +4640,7 @@ namespace ICSharpCode.Decompiler.CSharp
Debug.Fail("Invalid sub pattern"); Debug.Fail("Invalid sub pattern");
continue; continue;
} }
IMember member; IMember? member;
if (testedOperand is CallInstruction call) if (testedOperand is CallInstruction call)
{ {
member = call.Method.AccessorOwner; member = call.Method.AccessorOwner;

8
ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -92,7 +92,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
/// </summary> /// </summary>
/// <param name="nextNode">The next node after the comma.</param> /// <param name="nextNode">The next node after the comma.</param>
/// <param name="noSpaceAfterComma">When set prevents printing a space after comma.</param> /// <param name="noSpaceAfterComma">When set prevents printing a space after comma.</param>
protected virtual void Comma(AstNode nextNode, bool noSpaceAfterComma = false) protected virtual void Comma(AstNode? nextNode, bool noSpaceAfterComma = false)
{ {
Space(policy.SpaceBeforeBracketComma); Space(policy.SpaceBeforeBracketComma);
// TODO: Comma policy has changed. // TODO: Comma policy has changed.
@ -105,7 +105,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
/// <summary> /// <summary>
/// Writes an optional comma, e.g. at the end of an enum declaration or in an array initializer /// Writes an optional comma, e.g. at the end of an enum declaration or in an array initializer
/// </summary> /// </summary>
protected virtual void OptionalComma(AstNode pos) protected virtual void OptionalComma(AstNode? pos)
{ {
// Look if there's a comma after the current node, and insert it if it exists. // Look if there's a comma after the current node, and insert it if it exists.
while (pos != null && pos.NodeType == NodeType.Whitespace) while (pos != null && pos.NodeType == NodeType.Whitespace)
@ -121,7 +121,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
/// <summary> /// <summary>
/// Writes an optional semicolon, e.g. at the end of a type or namespace declaration. /// Writes an optional semicolon, e.g. at the end of a type or namespace declaration.
/// </summary> /// </summary>
protected virtual void OptionalSemicolon(AstNode pos) protected virtual void OptionalSemicolon(AstNode? pos)
{ {
// Look if there's a semicolon after the current node, and insert it if it exists. // Look if there's a semicolon after the current node, and insert it if it exists.
while (pos != null && pos.NodeType == NodeType.Whitespace) while (pos != null && pos.NodeType == NodeType.Whitespace)
@ -1947,7 +1947,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
WriteIdentifier(labelStatement.GetChildByRole(Roles.Identifier)); WriteIdentifier(labelStatement.GetChildByRole(Roles.Identifier));
WriteToken(Roles.Colon); WriteToken(Roles.Colon);
bool foundLabelledStatement = false; bool foundLabelledStatement = false;
for (AstNode tmp = labelStatement.NextSibling; tmp != null; tmp = tmp.NextSibling) for (AstNode? tmp = labelStatement.NextSibling; tmp != null; tmp = tmp.NextSibling)
{ {
if (tmp.Role == labelStatement.Role) if (tmp.Role == labelStatement.Role)
{ {

2
ICSharpCode.Decompiler/CSharp/OutputVisitor/GenericGrammarAmbiguityVisitor.cs

@ -53,7 +53,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
var v = new GenericGrammarAmbiguityVisitor(); var v = new GenericGrammarAmbiguityVisitor();
v.genericNestingLevel = 1; v.genericNestingLevel = 1;
for (AstNode node = binaryOperatorExpression.Right; node != null; node = node.GetNextNode()) for (AstNode? node = binaryOperatorExpression.Right; node != null; node = node.GetNextNode())
{ {
if (node.AcceptVisitor(v)) if (node.AcceptVisitor(v))
return v.ambiguityFound; return v.ambiguityFound;

6
ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertSpecialsDecorator.cs

@ -84,7 +84,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
/// </summary> /// </summary>
void WriteSpecials(AstNode start, AstNode end) void WriteSpecials(AstNode start, AstNode end)
{ {
for (AstNode pos = start; pos != end; pos = pos.NextSibling) for (AstNode? pos = start; pos != end; pos = pos.NextSibling)
{ {
if (pos.Role == Roles.Comment) if (pos.Role == Roles.Comment)
{ {
@ -125,7 +125,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
return; return;
} }
// Look for the role between the current position and the nextNode. // Look for the role between the current position and the nextNode.
for (AstNode pos = positionStack.Peek(); pos != null && pos != nextNode; pos = pos.NextSibling) for (AstNode? pos = positionStack.Peek(); pos != null && pos != nextNode; pos = pos.NextSibling)
{ {
if (pos.Role == role) if (pos.Role == role)
{ {
@ -149,7 +149,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
{ {
return; return;
} }
for (AstNode pos = positionStack.Peek(); pos != null; pos = pos.NextSibling) for (AstNode? pos = positionStack.Peek(); pos != null; pos = pos.NextSibling)
{ {
if (pos == node) if (pos == node)
{ {

2
ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs

@ -272,7 +272,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
foreach (var reference in module.AssemblyReferences.Where(r => !ImplicitReferences.Contains(r.Name))) foreach (var reference in module.AssemblyReferences.Where(r => !ImplicitReferences.Contains(r.Name)))
{ {
if (isNetCoreApp && project.AssemblyReferenceClassifier.IsSharedAssembly(reference, out string runtimePack) && targetPacks.Contains(runtimePack)) if (isNetCoreApp && project.AssemblyReferenceClassifier.IsSharedAssembly(reference, out string? runtimePack) && targetPacks.Contains(runtimePack))
{ {
continue; continue;
} }

2
ICSharpCode.Decompiler/CSharp/ProjectDecompiler/TargetFramework.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
/// <summary> /// <summary>
/// Gets the target framework identifier. Can be null if not defined. /// Gets the target framework identifier. Can be null if not defined.
/// </summary> /// </summary>
public string Identifier { get; } public string? Identifier { get; }
/// <summary> /// <summary>
/// Gets the target framework moniker. Can be null if not supported. /// Gets the target framework moniker. Can be null if not supported.

4
ICSharpCode.Decompiler/CSharp/ProjectDecompiler/TargetServices.cs

@ -74,7 +74,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
{ {
string[] frameworkParts = targetFramework.Split(','); string[] frameworkParts = targetFramework.Split(',');
targetFrameworkIdentifier = frameworkParts.FirstOrDefault(a => !a.StartsWith(VersionToken, StringComparison.OrdinalIgnoreCase) && !a.StartsWith(ProfileToken, StringComparison.OrdinalIgnoreCase)); targetFrameworkIdentifier = frameworkParts.FirstOrDefault(a => !a.StartsWith(VersionToken, StringComparison.OrdinalIgnoreCase) && !a.StartsWith(ProfileToken, StringComparison.OrdinalIgnoreCase));
string frameworkVersion = frameworkParts.FirstOrDefault(a => a.StartsWith(VersionToken, StringComparison.OrdinalIgnoreCase)); string? frameworkVersion = frameworkParts.FirstOrDefault(a => a.StartsWith(VersionToken, StringComparison.OrdinalIgnoreCase));
if (frameworkVersion != null) if (frameworkVersion != null)
{ {
@ -83,7 +83,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
versionNumber *= 10; versionNumber *= 10;
} }
string frameworkProfile = frameworkParts.FirstOrDefault(a => a.StartsWith(ProfileToken, StringComparison.OrdinalIgnoreCase)); string? frameworkProfile = frameworkParts.FirstOrDefault(a => a.StartsWith(ProfileToken, StringComparison.OrdinalIgnoreCase));
if (frameworkProfile != null) if (frameworkProfile != null)
targetFrameworkProfile = frameworkProfile.Substring(ProfileToken.Length); targetFrameworkProfile = frameworkProfile.Substring(ProfileToken.Length);
} }

4
ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs

@ -325,7 +325,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
{ {
foreach (var r in module.Resources.Where(r => r.ResourceType == ResourceType.Embedded)) foreach (var r in module.Resources.Where(r => r.ResourceType == ResourceType.Embedded))
{ {
Stream stream = r.TryOpenStream(); Stream? stream = r.TryOpenStream();
stream.Position = 0; stream.Position = 0;
if (r.Name.EndsWith(".resources", StringComparison.OrdinalIgnoreCase)) if (r.Name.EndsWith(".resources", StringComparison.OrdinalIgnoreCase))
@ -341,7 +341,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
{ {
string fileName = SanitizeFileName(name) string fileName = SanitizeFileName(name)
.Replace('/', Path.DirectorySeparatorChar); .Replace('/', Path.DirectorySeparatorChar);
string dirName = Path.GetDirectoryName(fileName); string? dirName = Path.GetDirectoryName(fileName);
if (!string.IsNullOrEmpty(dirName) && directories.Add(dirName)) if (!string.IsNullOrEmpty(dirName) && directories.Add(dirName))
{ {
Directory.CreateDirectory(Path.Combine(TargetDirectory, dirName)); Directory.CreateDirectory(Path.Combine(TargetDirectory, dirName));

2
ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.Decompiler.CSharp
var collector = new RequiredNamespaceCollector(namespaces); var collector = new RequiredNamespaceCollector(namespaces);
foreach (var type in module.TypeDefinitions) foreach (var type in module.TypeDefinitions)
{ {
collector.CollectNamespaces(type, module, (CodeMappingInfo)null); collector.CollectNamespaces(type, module, (CodeMappingInfo?)null);
} }
collector.HandleAttributes(module.GetAssemblyAttributes()); collector.HandleAttributes(module.GetAssemblyAttributes());
collector.HandleAttributes(module.GetModuleAttributes()); collector.HandleAttributes(module.GetModuleAttributes());

10
ICSharpCode.Decompiler/CSharp/Resolver/CSharpConversions.cs

@ -56,7 +56,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
if (compilation == null) if (compilation == null)
throw new ArgumentNullException(nameof(compilation)); throw new ArgumentNullException(nameof(compilation));
CacheManager cache = compilation.CacheManager; CacheManager cache = compilation.CacheManager;
CSharpConversions operators = (CSharpConversions)cache.GetShared(typeof(CSharpConversions)); CSharpConversions? operators = (CSharpConversions)cache.GetShared(typeof(CSharpConversions));
if (operators == null) if (operators == null)
{ {
operators = (CSharpConversions)cache.GetOrAddShared(typeof(CSharpConversions), new CSharpConversions(compilation)); operators = (CSharpConversions)cache.GetOrAddShared(typeof(CSharpConversions), new CSharpConversions(compilation));
@ -182,7 +182,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
throw new ArgumentNullException(nameof(toType)); throw new ArgumentNullException(nameof(toType));
TypePair pair = new TypePair(fromType, toType); TypePair pair = new TypePair(fromType, toType);
if (implicitConversionCache.TryGetValue(pair, out Conversion c)) if (implicitConversionCache.TryGetValue(pair, out Conversion? c))
return c; return c;
c = ImplicitConversion(fromType, toType, allowUserDefined: true, allowTuple: true); c = ImplicitConversion(fromType, toType, allowUserDefined: true, allowTuple: true);
@ -600,7 +600,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
bool IdentityOrVarianceConversion(IType s, IType t, int subtypeCheckNestingDepth) bool IdentityOrVarianceConversion(IType s, IType t, int subtypeCheckNestingDepth)
{ {
ITypeDefinition def = s.GetDefinition(); ITypeDefinition? def = s.GetDefinition();
if (def != null) if (def != null)
{ {
if (!def.Equals(t.GetDefinition())) if (!def.Equals(t.GetDefinition()))
@ -697,7 +697,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
} }
else if (fromType.Kind == TypeKind.Delegate && toType.Kind == TypeKind.Delegate) else if (fromType.Kind == TypeKind.Delegate && toType.Kind == TypeKind.Delegate)
{ {
ITypeDefinition def = fromType.GetDefinition(); ITypeDefinition? def = fromType.GetDefinition();
if (def == null || !def.Equals(toType.GetDefinition())) if (def == null || !def.Equals(toType.GetDefinition()))
return false; return false;
ParameterizedType? ps = fromType as ParameterizedType; ParameterizedType? ps = fromType as ParameterizedType;
@ -811,7 +811,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
} }
else if (fromTypeCode == TypeCode.Int32) else if (fromTypeCode == TypeCode.Int32)
{ {
object cv = rr.ConstantValue; object? cv = rr.ConstantValue;
if (cv == null) if (cv == null)
return false; return false;
int val = (int)cv; int val = (int)cv;

42
ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs

@ -506,7 +506,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
} }
else if (expression.IsCompileTimeConstant && m.CanEvaluateAtCompileTime) else if (expression.IsCompileTimeConstant && m.CanEvaluateAtCompileTime)
{ {
object val; object? val;
try try
{ {
val = m.Invoke(this, expression.ConstantValue); val = m.Invoke(this, expression.ConstantValue);
@ -923,7 +923,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
} }
else if (lhs.IsCompileTimeConstant && rhs.IsCompileTimeConstant && m.CanEvaluateAtCompileTime) else if (lhs.IsCompileTimeConstant && rhs.IsCompileTimeConstant && m.CanEvaluateAtCompileTime)
{ {
object val; object? val;
try try
{ {
val = m.Invoke(this, lhs.ConstantValue, rhs.ConstantValue); val = m.Invoke(this, lhs.ConstantValue, rhs.ConstantValue);
@ -982,7 +982,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
#region Enum helper methods #region Enum helper methods
IType GetEnumUnderlyingType(IType enumType) IType GetEnumUnderlyingType(IType enumType)
{ {
ITypeDefinition def = enumType.GetDefinition(); ITypeDefinition? def = enumType.GetDefinition();
return def != null ? def.EnumUnderlyingType : SpecialType.UnknownType; return def != null ? def.EnumUnderlyingType : SpecialType.UnknownType;
} }
@ -1609,12 +1609,12 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return trr != null && trr.Type.Equals(rr.Type); return trr != null && trr.Type.Equals(rr.Type);
} }
ResolveResult LookInCurrentType(string identifier, IReadOnlyList<IType> typeArguments, NameLookupMode lookupMode, bool parameterizeResultType) ResolveResult? LookInCurrentType(string identifier, IReadOnlyList<IType> typeArguments, NameLookupMode lookupMode, bool parameterizeResultType)
{ {
int k = typeArguments.Count; int k = typeArguments.Count;
MemberLookup lookup = CreateMemberLookup(lookupMode); MemberLookup lookup = CreateMemberLookup(lookupMode);
// look in current type definitions // look in current type definitions
for (ITypeDefinition t = this.CurrentTypeDefinition; t != null; t = t.DeclaringTypeDefinition) for (ITypeDefinition? t = this.CurrentTypeDefinition; t != null; t = t.DeclaringTypeDefinition)
{ {
if (k == 0) if (k == 0)
{ {
@ -1651,7 +1651,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return null; return null;
} }
ResolveResult LookInCurrentUsingScope(string identifier, IReadOnlyList<IType> typeArguments, bool isInUsingDeclaration, bool parameterizeResultType) ResolveResult? LookInCurrentUsingScope(string identifier, IReadOnlyList<IType> typeArguments, bool isInUsingDeclaration, bool parameterizeResultType)
{ {
// look in current namespace definitions // look in current namespace definitions
ResolvedUsingScope currentUsingScope = this.CurrentUsingScope; ResolvedUsingScope currentUsingScope = this.CurrentUsingScope;
@ -1684,7 +1684,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
IType? firstResult = null; IType? firstResult = null;
foreach (var importedNamespace in u.Usings) foreach (var importedNamespace in u.Usings)
{ {
ITypeDefinition def = importedNamespace.GetTypeDefinition(identifier, typeArguments.Count); ITypeDefinition? def = importedNamespace.GetTypeDefinition(identifier, typeArguments.Count);
if (def != null) if (def != null)
{ {
IType resultType; IType resultType;
@ -1712,7 +1712,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return null; return null;
} }
ResolveResult LookInUsingScopeNamespace(ResolvedUsingScope usingScope, INamespace n, string identifier, IReadOnlyList<IType> typeArguments, bool parameterizeResultType) ResolveResult? LookInUsingScopeNamespace(ResolvedUsingScope usingScope, INamespace n, string identifier, IReadOnlyList<IType> typeArguments, bool parameterizeResultType)
{ {
if (n == null) if (n == null)
return null; return null;
@ -1720,7 +1720,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
int k = typeArguments.Count; int k = typeArguments.Count;
if (k == 0) if (k == 0)
{ {
INamespace childNamespace = n.GetChildNamespace(identifier); INamespace? childNamespace = n.GetChildNamespace(identifier);
if (childNamespace != null) if (childNamespace != null)
{ {
if (usingScope != null && usingScope.HasAlias(identifier)) if (usingScope != null && usingScope.HasAlias(identifier))
@ -1729,7 +1729,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
} }
} }
// then look for a type // then look for a type
ITypeDefinition def = n.GetTypeDefinition(identifier, k); ITypeDefinition? def = n.GetTypeDefinition(identifier, k);
if (def != null && TopLevelTypeDefinitionIsAccessible(def)) if (def != null && TopLevelTypeDefinitionIsAccessible(def))
{ {
IType result = def; IType result = def;
@ -1781,7 +1781,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
ResolveResult ResolveExternAlias(string alias) ResolveResult ResolveExternAlias(string alias)
{ {
INamespace ns = compilation.GetNamespaceForExternAlias(alias); INamespace? ns = compilation.GetNamespaceForExternAlias(alias);
if (ns != null) if (ns != null)
return new NamespaceResolveResult(ns); return new NamespaceResolveResult(ns);
else else
@ -1854,11 +1854,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
{ {
if (typeArguments.Count == 0) if (typeArguments.Count == 0)
{ {
INamespace childNamespace = nrr.Namespace.GetChildNamespace(identifier); INamespace? childNamespace = nrr.Namespace.GetChildNamespace(identifier);
if (childNamespace != null) if (childNamespace != null)
return new NamespaceResolveResult(childNamespace); return new NamespaceResolveResult(childNamespace);
} }
ITypeDefinition def = nrr.Namespace.GetTypeDefinition(identifier, typeArguments.Count); ITypeDefinition? def = nrr.Namespace.GetTypeDefinition(identifier, typeArguments.Count);
if (def != null) if (def != null)
{ {
if (parameterizeResultType && typeArguments.Count > 0) if (parameterizeResultType && typeArguments.Count > 0)
@ -1985,13 +1985,13 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
elementType = expression.Type.GetElementTypeFromIEnumerable(compilation, false, out bool? isGeneric); elementType = expression.Type.GetElementTypeFromIEnumerable(compilation, false, out bool? isGeneric);
if (isGeneric == true) if (isGeneric == true)
{ {
ITypeDefinition enumerableOfT = compilation.FindType(KnownTypeCode.IEnumerableOfT).GetDefinition(); ITypeDefinition? enumerableOfT = compilation.FindType(KnownTypeCode.IEnumerableOfT).GetDefinition();
if (enumerableOfT != null) if (enumerableOfT != null)
collectionType = new ParameterizedType(enumerableOfT, new[] { elementType }); collectionType = new ParameterizedType(enumerableOfT, new[] { elementType });
else else
collectionType = SpecialType.UnknownType; collectionType = SpecialType.UnknownType;
ITypeDefinition enumeratorOfT = compilation.FindType(KnownTypeCode.IEnumeratorOfT).GetDefinition(); ITypeDefinition? enumeratorOfT = compilation.FindType(KnownTypeCode.IEnumeratorOfT).GetDefinition();
if (enumeratorOfT != null) if (enumeratorOfT != null)
enumeratorType = new ParameterizedType(enumeratorOfT, new[] { elementType }); enumeratorType = new ParameterizedType(enumeratorOfT, new[] { elementType });
else else
@ -2060,7 +2060,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// new List { all extensions from SomeExtensions } /// new List { all extensions from SomeExtensions }
/// } /// }
/// </remarks> /// </remarks>
public List<List<IMethod>> GetExtensionMethods(IType targetType, string? name = null, IReadOnlyList<IType>? typeArguments = null, bool substituteInferredTypes = false) public List<List<IMethod>> GetExtensionMethods(IType? targetType, string? name = null, IReadOnlyList<IType>? typeArguments = null, bool substituteInferredTypes = false)
{ {
var lookup = CreateMemberLookup(); var lookup = CreateMemberLookup();
List<List<IMethod>> extensionMethodGroups = new List<List<IMethod>>(); List<List<IMethod>> extensionMethodGroups = new List<List<IMethod>>();
@ -2073,7 +2073,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
continue; continue;
if (!lookup.IsAccessible(method, false)) if (!lookup.IsAccessible(method, false))
continue; continue;
IType[] inferredTypes; IType[]? inferredTypes;
if (typeArguments != null && typeArguments.Count > 0) if (typeArguments != null && typeArguments.Count > 0)
{ {
if (method.TypeParameters.Count != typeArguments.Count) if (method.TypeParameters.Count != typeArguments.Count)
@ -2118,7 +2118,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// If an array is returned, any slot with an uninferred type argument will be set to the method's /// If an array is returned, any slot with an uninferred type argument will be set to the method's
/// corresponding type parameter. /// corresponding type parameter.
/// </param> /// </param>
public static bool IsEligibleExtensionMethod(IType targetType, IMethod method, bool useTypeInference, out IType[] outInferredTypes) public static bool IsEligibleExtensionMethod(IType targetType, IMethod method, bool useTypeInference, out IType[]? outInferredTypes)
{ {
if (targetType == null) if (targetType == null)
throw new ArgumentNullException(nameof(targetType)); throw new ArgumentNullException(nameof(targetType));
@ -2128,7 +2128,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return IsEligibleExtensionMethod(compilation, CSharpConversions.Get(compilation), targetType, method, useTypeInference, out outInferredTypes); return IsEligibleExtensionMethod(compilation, CSharpConversions.Get(compilation), targetType, method, useTypeInference, out outInferredTypes);
} }
static bool IsEligibleExtensionMethod(ICompilation compilation, CSharpConversions conversions, IType targetType, IMethod method, bool useTypeInference, out IType[]? outInferredTypes) static bool IsEligibleExtensionMethod(ICompilation compilation, CSharpConversions conversions, IType? targetType, IMethod method, bool useTypeInference, out IType[]? outInferredTypes)
{ {
outInferredTypes = null; outInferredTypes = null;
if (targetType == null) if (targetType == null)
@ -2814,9 +2814,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return new ConstantResolveResult(type, GetDefaultValue(type)); return new ConstantResolveResult(type, GetDefaultValue(type));
} }
public static object GetDefaultValue(IType type) public static object? GetDefaultValue(IType type)
{ {
ITypeDefinition typeDef = type.GetDefinition(); ITypeDefinition? typeDef = type.GetDefinition();
if (typeDef == null) if (typeDef == null)
return null; return null;
if (typeDef.Kind == TypeKind.Enum) if (typeDef.Kind == TypeKind.Enum)

8
ICSharpCode.Decompiler/CSharp/Resolver/MemberLookup.cs

@ -79,7 +79,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
{ {
if (targetType.Kind == TypeKind.TypeParameter) if (targetType.Kind == TypeKind.TypeParameter)
targetType = ((ITypeParameter)targetType).EffectiveBaseClass; targetType = ((ITypeParameter)targetType).EffectiveBaseClass;
ITypeDefinition typeDef = targetType.GetDefinition(); ITypeDefinition? typeDef = targetType.GetDefinition();
if (typeDef == null) if (typeDef == null)
return false; return false;
for (ITypeDefinition c = currentTypeDefinition; c != null; c = c.DeclaringTypeDefinition) for (ITypeDefinition c = currentTypeDefinition; c != null; c = c.DeclaringTypeDefinition)
@ -195,7 +195,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
foreach (var entityGroup in entities.GroupBy(e => e.Name)) foreach (var entityGroup in entities.GroupBy(e => e.Name))
{ {
List<LookupGroup> lookupGroups = new List<LookupGroup>(); List<LookupGroup>? lookupGroups = new List<LookupGroup>();
if (!lookupGroupDict.TryGetValue(entityGroup.Key, out lookupGroups)) if (!lookupGroupDict.TryGetValue(entityGroup.Key, out lookupGroups))
lookupGroupDict.Add(entityGroup.Key, lookupGroups = new List<LookupGroup>()); lookupGroupDict.Add(entityGroup.Key, lookupGroups = new List<LookupGroup>());
@ -243,7 +243,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
{ {
foreach (IType type in lookupGroup.NestedTypes) foreach (IType type in lookupGroup.NestedTypes)
{ {
ITypeDefinition typeDef = type.GetDefinition(); ITypeDefinition? typeDef = type.GetDefinition();
if (typeDef != null) if (typeDef != null)
yield return typeDef; yield return typeDef;
} }
@ -691,7 +691,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
// return true if type is an interface or System.Object // return true if type is an interface or System.Object
if (type.Kind == TypeKind.Interface) if (type.Kind == TypeKind.Interface)
return true; return true;
ITypeDefinition d = type.GetDefinition(); ITypeDefinition? d = type.GetDefinition();
return d != null && d.KnownTypeCode == KnownTypeCode.Object; return d != null && d.KnownTypeCode == KnownTypeCode.Object;
} }
#endregion #endregion

2
ICSharpCode.Decompiler/CSharp/Resolver/OverloadResolution.cs

@ -582,7 +582,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
} }
if (typeParameter.HasDefaultConstructorConstraint) if (typeParameter.HasDefaultConstructorConstraint)
{ {
ITypeDefinition def = typeArgument.GetDefinition(); ITypeDefinition? def = typeArgument.GetDefinition();
if (def != null && def.IsAbstract) if (def != null && def.IsAbstract)
return false; return false;
var ctors = typeArgument.GetConstructors( var ctors = typeArgument.GetConstructors(

2
ICSharpCode.Decompiler/CSharp/Resolver/TypeInference.cs

@ -1109,7 +1109,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
// Now filter out candidates that violate the upper bounds: // Now filter out candidates that violate the upper bounds:
foreach (IType ub in upperBounds) foreach (IType ub in upperBounds)
{ {
ITypeDefinition ubDef = ub.GetDefinition(); ITypeDefinition? ubDef = ub.GetDefinition();
if (ubDef != null) if (ubDef != null)
{ {
candidateTypeDefinitions.RemoveAll(c => !c.IsDerivedFrom(ubDef)); candidateTypeDefinitions.RemoveAll(c => !c.IsDerivedFrom(ubDef));

2
ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs

@ -547,7 +547,7 @@ namespace ICSharpCode.Decompiler.CSharp
} }
List<int> sequencePointCandidates = function.SequencePointCandidates; List<int>? sequencePointCandidates = function.SequencePointCandidates;
int currSPCandidateIndex = 0; int currSPCandidateIndex = 0;
for (int i = 0; i < newList.Count - 1; i++) for (int i = 0; i < newList.Count - 1; i++)

15
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -213,7 +213,8 @@ namespace ICSharpCode.Decompiler.CSharp
TranslatedExpression value; TranslatedExpression value;
IType type; IType type;
if (inst.Value is StringToInt strToInt) var strToInt = inst.Value as StringToInt;
if (strToInt != null)
{ {
value = exprBuilder.Translate(strToInt.Argument) value = exprBuilder.Translate(strToInt.Argument)
.ConvertTo( .ConvertTo(
@ -328,7 +329,7 @@ namespace ICSharpCode.Decompiler.CSharp
} }
Debug.Assert(block.FinalInstruction.OpCode == OpCode.Nop); Debug.Assert(block.FinalInstruction.OpCode == OpCode.Nop);
} }
if (endContainerLabels.TryGetValue(switchContainer, out string label)) if (endContainerLabels.TryGetValue(switchContainer, out string? label))
{ {
lastSectionStatements.Add(new LabelStatement { Label = label }); lastSectionStatements.Add(new LabelStatement { Label = label });
lastSectionStatements.Add(new BreakStatement()); lastSectionStatements.Add(new BreakStatement());
@ -411,7 +412,7 @@ namespace ICSharpCode.Decompiler.CSharp
else else
return new ReturnStatement().WithILInstruction(inst); return new ReturnStatement().WithILInstruction(inst);
} }
if (!endContainerLabels.TryGetValue(inst.TargetContainer, out string label)) if (!endContainerLabels.TryGetValue(inst.TargetContainer, out string? label))
{ {
label = "end_" + inst.TargetLabel; label = "end_" + inst.TargetLabel;
if (!duplicateLabels.TryGetValue(label, out int count)) if (!duplicateLabels.TryGetValue(label, out int count))
@ -1261,8 +1262,8 @@ namespace ICSharpCode.Decompiler.CSharp
Statement ConvertLoop(BlockContainer container) Statement ConvertLoop(BlockContainer container)
{ {
ILInstruction condition; ILInstruction? condition;
Block loopBody; Block? loopBody;
BlockStatement blockStatement; BlockStatement blockStatement;
continueCount = 0; continueCount = 0;
breakTarget = container; breakTarget = container;
@ -1480,7 +1481,7 @@ namespace ICSharpCode.Decompiler.CSharp
blockStatement.Add(Convert(block.FinalInstruction)); blockStatement.Add(Convert(block.FinalInstruction));
} }
} }
if (endContainerLabels.TryGetValue(container, out string label)) if (endContainerLabels.TryGetValue(container, out string? label))
{ {
if (isLoop && !(blockStatement.LastOrDefault() is ContinueStatement)) if (isLoop && !(blockStatement.LastOrDefault() is ContinueStatement))
{ {
@ -1500,7 +1501,7 @@ namespace ICSharpCode.Decompiler.CSharp
string EnsureUniqueLabel(Block block) string EnsureUniqueLabel(Block block)
{ {
if (labels.TryGetValue(block, out string label)) if (labels.TryGetValue(block, out string? label))
return label; return label;
if (!duplicateLabels.TryGetValue(block.Label, out int count)) if (!duplicateLabels.TryGetValue(block.Label, out int count))
{ {

2
ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs

@ -202,7 +202,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
get { return parent; } get { return parent; }
} }
public Role Role { public Role? Role {
get { get {
return Role.GetByIndex(flags & roleIndexMask); return Role.GetByIndex(flags & roleIndexMask);
} }

12
ICSharpCode.Decompiler/CSharp/Syntax/AstNodeCollection.cs

@ -49,7 +49,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
get { get {
int count = 0; int count = 0;
uint roleIndex = role.Index; uint roleIndex = role.Index;
for (AstNode cur = node.FirstChild; cur != null; cur = cur.NextSibling) for (AstNode? cur = node.FirstChild; cur != null; cur = cur.NextSibling)
{ {
if (cur.RoleIndex == roleIndex) if (cur.RoleIndex == roleIndex)
count++; count++;
@ -177,8 +177,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
uint roleIndex = role.Index; uint roleIndex = role.Index;
AstNode next; AstNode? next;
for (AstNode cur = node.FirstChild; cur != null; cur = next) for (AstNode? cur = node.FirstChild; cur != null; cur = next)
{ {
Debug.Assert(cur.Parent == node); Debug.Assert(cur.Parent == node);
// Remember next before yielding cur. // Remember next before yielding cur.
@ -214,7 +214,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return Pattern.DoMatchCollection(role, node.FirstChild, other.node.FirstChild, match); return Pattern.DoMatchCollection(role, node.FirstChild, other.node.FirstChild, match);
} }
public void InsertAfter(T existingItem, T newItem) public void InsertAfter(T? existingItem, T newItem)
{ {
node.InsertChildAfter(existingItem, newItem, role); node.InsertChildAfter(existingItem, newItem, role);
} }
@ -230,8 +230,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public void AcceptVisitor(IAstVisitor visitor) public void AcceptVisitor(IAstVisitor visitor)
{ {
uint roleIndex = role.Index; uint roleIndex = role.Index;
AstNode next; AstNode? next;
for (AstNode cur = node.FirstChild; cur != null; cur = next) for (AstNode? cur = node.FirstChild; cur != null; cur = next)
{ {
Debug.Assert(cur.Parent == node); Debug.Assert(cur.Parent == node);
// Remember next before yielding cur. // Remember next before yielding cur.

272
ICSharpCode.Decompiler/CSharp/Syntax/DepthFirstAstVisitor.cs

@ -34,7 +34,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
{ {
protected virtual void VisitChildren(AstNode node) protected virtual void VisitChildren(AstNode node)
{ {
AstNode next; AstNode? next;
for (var child = node.FirstChild; child != null; child = next) for (var child = node.FirstChild; child != null; child = next)
{ {
// Store next to allow the loop to continue // Store next to allow the loop to continue
@ -715,7 +715,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
{ {
protected virtual T VisitChildren(AstNode node) protected virtual T VisitChildren(AstNode node)
{ {
AstNode next; AstNode? next;
for (var child = node.FirstChild; child != null; child = next) for (var child = node.FirstChild; child != null; child = next)
{ {
// Store next to allow the loop to continue // Store next to allow the loop to continue
@ -1396,9 +1396,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary> /// </summary>
public abstract class DepthFirstAstVisitor<T, S> : IAstVisitor<T, S> public abstract class DepthFirstAstVisitor<T, S> : IAstVisitor<T, S>
{ {
protected virtual S VisitChildren(AstNode node, T data) protected virtual S? VisitChildren(AstNode node, T data)
{ {
AstNode next; AstNode? next;
for (var child = node.FirstChild; child != null; child = next) for (var child = node.FirstChild; child != null; child = next)
{ {
// Store next to allow the loop to continue // Store next to allow the loop to continue
@ -1409,7 +1409,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return default(S); return default(S);
} }
public virtual S VisitNullNode(AstNode nullNode, T data) public virtual S? VisitNullNode(AstNode nullNode, T data)
{ {
// Should we call VisitChildren here? // Should we call VisitChildren here?
// We usually want to ignore null nodes. // We usually want to ignore null nodes.
@ -1418,657 +1418,657 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return default(S); return default(S);
} }
public virtual S VisitSyntaxTree(SyntaxTree unit, T data) public virtual S? VisitSyntaxTree(SyntaxTree unit, T data)
{ {
return VisitChildren(unit, data); return VisitChildren(unit, data);
} }
public virtual S VisitComment(Comment comment, T data) public virtual S? VisitComment(Comment comment, T data)
{ {
return VisitChildren(comment, data); return VisitChildren(comment, data);
} }
public virtual S VisitDocumentationReference(DocumentationReference documentationReference, T data) public virtual S? VisitDocumentationReference(DocumentationReference documentationReference, T data)
{ {
return VisitChildren(documentationReference, data); return VisitChildren(documentationReference, data);
} }
public virtual S VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective, T data) public virtual S? VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective, T data)
{ {
return VisitChildren(preProcessorDirective, data); return VisitChildren(preProcessorDirective, data);
} }
public virtual S VisitIdentifier(Identifier identifier, T data) public virtual S? VisitIdentifier(Identifier identifier, T data)
{ {
return VisitChildren(identifier, data); return VisitChildren(identifier, data);
} }
public virtual S VisitCSharpTokenNode(CSharpTokenNode token, T data) public virtual S? VisitCSharpTokenNode(CSharpTokenNode token, T data)
{ {
return VisitChildren(token, data); return VisitChildren(token, data);
} }
public virtual S VisitPrimitiveType(PrimitiveType primitiveType, T data) public virtual S? VisitPrimitiveType(PrimitiveType primitiveType, T data)
{ {
return VisitChildren(primitiveType, data); return VisitChildren(primitiveType, data);
} }
public virtual S VisitComposedType(ComposedType composedType, T data) public virtual S? VisitComposedType(ComposedType composedType, T data)
{ {
return VisitChildren(composedType, data); return VisitChildren(composedType, data);
} }
public virtual S VisitSimpleType(SimpleType simpleType, T data) public virtual S? VisitSimpleType(SimpleType simpleType, T data)
{ {
return VisitChildren(simpleType, data); return VisitChildren(simpleType, data);
} }
public virtual S VisitMemberType(MemberType memberType, T data) public virtual S? VisitMemberType(MemberType memberType, T data)
{ {
return VisitChildren(memberType, data); return VisitChildren(memberType, data);
} }
public virtual S VisitTupleType(TupleAstType tupleType, T data) public virtual S? VisitTupleType(TupleAstType tupleType, T data)
{ {
return VisitChildren(tupleType, data); return VisitChildren(tupleType, data);
} }
public virtual S VisitTupleTypeElement(TupleTypeElement tupleTypeElement, T data) public virtual S? VisitTupleTypeElement(TupleTypeElement tupleTypeElement, T data)
{ {
return VisitChildren(tupleTypeElement, data); return VisitChildren(tupleTypeElement, data);
} }
public virtual S VisitFunctionPointerType(FunctionPointerAstType functionPointerType, T data) public virtual S? VisitFunctionPointerType(FunctionPointerAstType functionPointerType, T data)
{ {
return VisitChildren(functionPointerType, data); return VisitChildren(functionPointerType, data);
} }
public virtual S VisitInvocationType(InvocationAstType invocationType, T data) public virtual S? VisitInvocationType(InvocationAstType invocationType, T data)
{ {
return VisitChildren(invocationType, data); return VisitChildren(invocationType, data);
} }
public virtual S VisitAttribute(Attribute attribute, T data) public virtual S? VisitAttribute(Attribute attribute, T data)
{ {
return VisitChildren(attribute, data); return VisitChildren(attribute, data);
} }
public virtual S VisitAttributeSection(AttributeSection attributeSection, T data) public virtual S? VisitAttributeSection(AttributeSection attributeSection, T data)
{ {
return VisitChildren(attributeSection, data); return VisitChildren(attributeSection, data);
} }
public virtual S VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, T data) public virtual S? VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, T data)
{ {
return VisitChildren(delegateDeclaration, data); return VisitChildren(delegateDeclaration, data);
} }
public virtual S VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, T data) public virtual S? VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, T data)
{ {
return VisitChildren(namespaceDeclaration, data); return VisitChildren(namespaceDeclaration, data);
} }
public virtual S VisitTypeDeclaration(TypeDeclaration typeDeclaration, T data) public virtual S? VisitTypeDeclaration(TypeDeclaration typeDeclaration, T data)
{ {
return VisitChildren(typeDeclaration, data); return VisitChildren(typeDeclaration, data);
} }
public virtual S VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration, T data) public virtual S? VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration, T data)
{ {
return VisitChildren(typeParameterDeclaration, data); return VisitChildren(typeParameterDeclaration, data);
} }
public virtual S VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration, T data) public virtual S? VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration, T data)
{ {
return VisitChildren(enumMemberDeclaration, data); return VisitChildren(enumMemberDeclaration, data);
} }
public virtual S VisitUsingDeclaration(UsingDeclaration usingDeclaration, T data) public virtual S? VisitUsingDeclaration(UsingDeclaration usingDeclaration, T data)
{ {
return VisitChildren(usingDeclaration, data); return VisitChildren(usingDeclaration, data);
} }
public virtual S VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration, T data) public virtual S? VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration, T data)
{ {
return VisitChildren(usingDeclaration, data); return VisitChildren(usingDeclaration, data);
} }
public virtual S VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration, T data) public virtual S? VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration, T data)
{ {
return VisitChildren(externAliasDeclaration, data); return VisitChildren(externAliasDeclaration, data);
} }
public virtual S VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, T data) public virtual S? VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, T data)
{ {
return VisitChildren(constructorDeclaration, data); return VisitChildren(constructorDeclaration, data);
} }
public virtual S VisitConstructorInitializer(ConstructorInitializer constructorInitializer, T data) public virtual S? VisitConstructorInitializer(ConstructorInitializer constructorInitializer, T data)
{ {
return VisitChildren(constructorInitializer, data); return VisitChildren(constructorInitializer, data);
} }
public virtual S VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, T data) public virtual S? VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, T data)
{ {
return VisitChildren(destructorDeclaration, data); return VisitChildren(destructorDeclaration, data);
} }
public virtual S VisitEventDeclaration(EventDeclaration eventDeclaration, T data) public virtual S? VisitEventDeclaration(EventDeclaration eventDeclaration, T data)
{ {
return VisitChildren(eventDeclaration, data); return VisitChildren(eventDeclaration, data);
} }
public virtual S VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration, T data) public virtual S? VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration, T data)
{ {
return VisitChildren(eventDeclaration, data); return VisitChildren(eventDeclaration, data);
} }
public virtual S VisitFieldDeclaration(FieldDeclaration fieldDeclaration, T data) public virtual S? VisitFieldDeclaration(FieldDeclaration fieldDeclaration, T data)
{ {
return VisitChildren(fieldDeclaration, data); return VisitChildren(fieldDeclaration, data);
} }
public virtual S VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration, T data) public virtual S? VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration, T data)
{ {
return VisitChildren(fixedFieldDeclaration, data); return VisitChildren(fixedFieldDeclaration, data);
} }
public virtual S VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer, T data) public virtual S? VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer, T data)
{ {
return VisitChildren(fixedVariableInitializer, data); return VisitChildren(fixedVariableInitializer, data);
} }
public virtual S VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, T data) public virtual S? VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, T data)
{ {
return VisitChildren(indexerDeclaration, data); return VisitChildren(indexerDeclaration, data);
} }
public virtual S VisitMethodDeclaration(MethodDeclaration methodDeclaration, T data) public virtual S? VisitMethodDeclaration(MethodDeclaration methodDeclaration, T data)
{ {
return VisitChildren(methodDeclaration, data); return VisitChildren(methodDeclaration, data);
} }
public virtual S VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, T data) public virtual S? VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, T data)
{ {
return VisitChildren(operatorDeclaration, data); return VisitChildren(operatorDeclaration, data);
} }
public virtual S VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, T data) public virtual S? VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, T data)
{ {
return VisitChildren(propertyDeclaration, data); return VisitChildren(propertyDeclaration, data);
} }
public virtual S VisitAccessor(Accessor accessor, T data) public virtual S? VisitAccessor(Accessor accessor, T data)
{ {
return VisitChildren(accessor, data); return VisitChildren(accessor, data);
} }
public virtual S VisitVariableInitializer(VariableInitializer variableInitializer, T data) public virtual S? VisitVariableInitializer(VariableInitializer variableInitializer, T data)
{ {
return VisitChildren(variableInitializer, data); return VisitChildren(variableInitializer, data);
} }
public virtual S VisitParameterDeclaration(ParameterDeclaration parameterDeclaration, T data) public virtual S? VisitParameterDeclaration(ParameterDeclaration parameterDeclaration, T data)
{ {
return VisitChildren(parameterDeclaration, data); return VisitChildren(parameterDeclaration, data);
} }
public virtual S VisitConstraint(Constraint constraint, T data) public virtual S? VisitConstraint(Constraint constraint, T data)
{ {
return VisitChildren(constraint, data); return VisitChildren(constraint, data);
} }
public virtual S VisitBlockStatement(BlockStatement blockStatement, T data) public virtual S? VisitBlockStatement(BlockStatement blockStatement, T data)
{ {
return VisitChildren(blockStatement, data); return VisitChildren(blockStatement, data);
} }
public virtual S VisitExpressionStatement(ExpressionStatement expressionStatement, T data) public virtual S? VisitExpressionStatement(ExpressionStatement expressionStatement, T data)
{ {
return VisitChildren(expressionStatement, data); return VisitChildren(expressionStatement, data);
} }
public virtual S VisitBreakStatement(BreakStatement breakStatement, T data) public virtual S? VisitBreakStatement(BreakStatement breakStatement, T data)
{ {
return VisitChildren(breakStatement, data); return VisitChildren(breakStatement, data);
} }
public virtual S VisitCheckedStatement(CheckedStatement checkedStatement, T data) public virtual S? VisitCheckedStatement(CheckedStatement checkedStatement, T data)
{ {
return VisitChildren(checkedStatement, data); return VisitChildren(checkedStatement, data);
} }
public virtual S VisitContinueStatement(ContinueStatement continueStatement, T data) public virtual S? VisitContinueStatement(ContinueStatement continueStatement, T data)
{ {
return VisitChildren(continueStatement, data); return VisitChildren(continueStatement, data);
} }
public virtual S VisitDoWhileStatement(DoWhileStatement doWhileStatement, T data) public virtual S? VisitDoWhileStatement(DoWhileStatement doWhileStatement, T data)
{ {
return VisitChildren(doWhileStatement, data); return VisitChildren(doWhileStatement, data);
} }
public virtual S VisitEmptyStatement(EmptyStatement emptyStatement, T data) public virtual S? VisitEmptyStatement(EmptyStatement emptyStatement, T data)
{ {
return VisitChildren(emptyStatement, data); return VisitChildren(emptyStatement, data);
} }
public virtual S VisitFixedStatement(FixedStatement fixedStatement, T data) public virtual S? VisitFixedStatement(FixedStatement fixedStatement, T data)
{ {
return VisitChildren(fixedStatement, data); return VisitChildren(fixedStatement, data);
} }
public virtual S VisitForeachStatement(ForeachStatement foreachStatement, T data) public virtual S? VisitForeachStatement(ForeachStatement foreachStatement, T data)
{ {
return VisitChildren(foreachStatement, data); return VisitChildren(foreachStatement, data);
} }
public virtual S VisitForStatement(ForStatement forStatement, T data) public virtual S? VisitForStatement(ForStatement forStatement, T data)
{ {
return VisitChildren(forStatement, data); return VisitChildren(forStatement, data);
} }
public virtual S VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, T data) public virtual S? VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, T data)
{ {
return VisitChildren(gotoCaseStatement, data); return VisitChildren(gotoCaseStatement, data);
} }
public virtual S VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement, T data) public virtual S? VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement, T data)
{ {
return VisitChildren(gotoDefaultStatement, data); return VisitChildren(gotoDefaultStatement, data);
} }
public virtual S VisitGotoStatement(GotoStatement gotoStatement, T data) public virtual S? VisitGotoStatement(GotoStatement gotoStatement, T data)
{ {
return VisitChildren(gotoStatement, data); return VisitChildren(gotoStatement, data);
} }
public virtual S VisitIfElseStatement(IfElseStatement ifElseStatement, T data) public virtual S? VisitIfElseStatement(IfElseStatement ifElseStatement, T data)
{ {
return VisitChildren(ifElseStatement, data); return VisitChildren(ifElseStatement, data);
} }
public virtual S VisitLabelStatement(LabelStatement labelStatement, T data) public virtual S? VisitLabelStatement(LabelStatement labelStatement, T data)
{ {
return VisitChildren(labelStatement, data); return VisitChildren(labelStatement, data);
} }
public virtual S VisitLockStatement(LockStatement lockStatement, T data) public virtual S? VisitLockStatement(LockStatement lockStatement, T data)
{ {
return VisitChildren(lockStatement, data); return VisitChildren(lockStatement, data);
} }
public virtual S VisitReturnStatement(ReturnStatement returnStatement, T data) public virtual S? VisitReturnStatement(ReturnStatement returnStatement, T data)
{ {
return VisitChildren(returnStatement, data); return VisitChildren(returnStatement, data);
} }
public virtual S VisitSwitchStatement(SwitchStatement switchStatement, T data) public virtual S? VisitSwitchStatement(SwitchStatement switchStatement, T data)
{ {
return VisitChildren(switchStatement, data); return VisitChildren(switchStatement, data);
} }
public virtual S VisitSwitchSection(SwitchSection switchSection, T data) public virtual S? VisitSwitchSection(SwitchSection switchSection, T data)
{ {
return VisitChildren(switchSection, data); return VisitChildren(switchSection, data);
} }
public virtual S VisitCaseLabel(CaseLabel caseLabel, T data) public virtual S? VisitCaseLabel(CaseLabel caseLabel, T data)
{ {
return VisitChildren(caseLabel, data); return VisitChildren(caseLabel, data);
} }
public virtual S VisitSwitchExpression(SwitchExpression switchExpression, T data) public virtual S? VisitSwitchExpression(SwitchExpression switchExpression, T data)
{ {
return VisitChildren(switchExpression, data); return VisitChildren(switchExpression, data);
} }
public virtual S VisitSwitchExpressionSection(SwitchExpressionSection switchExpressionSection, T data) public virtual S? VisitSwitchExpressionSection(SwitchExpressionSection switchExpressionSection, T data)
{ {
return VisitChildren(switchExpressionSection, data); return VisitChildren(switchExpressionSection, data);
} }
public virtual S VisitThrowStatement(ThrowStatement throwStatement, T data) public virtual S? VisitThrowStatement(ThrowStatement throwStatement, T data)
{ {
return VisitChildren(throwStatement, data); return VisitChildren(throwStatement, data);
} }
public virtual S VisitTryCatchStatement(TryCatchStatement tryCatchStatement, T data) public virtual S? VisitTryCatchStatement(TryCatchStatement tryCatchStatement, T data)
{ {
return VisitChildren(tryCatchStatement, data); return VisitChildren(tryCatchStatement, data);
} }
public virtual S VisitCatchClause(CatchClause catchClause, T data) public virtual S? VisitCatchClause(CatchClause catchClause, T data)
{ {
return VisitChildren(catchClause, data); return VisitChildren(catchClause, data);
} }
public virtual S VisitUncheckedStatement(UncheckedStatement uncheckedStatement, T data) public virtual S? VisitUncheckedStatement(UncheckedStatement uncheckedStatement, T data)
{ {
return VisitChildren(uncheckedStatement, data); return VisitChildren(uncheckedStatement, data);
} }
public virtual S VisitUnsafeStatement(UnsafeStatement unsafeStatement, T data) public virtual S? VisitUnsafeStatement(UnsafeStatement unsafeStatement, T data)
{ {
return VisitChildren(unsafeStatement, data); return VisitChildren(unsafeStatement, data);
} }
public virtual S VisitUsingStatement(UsingStatement usingStatement, T data) public virtual S? VisitUsingStatement(UsingStatement usingStatement, T data)
{ {
return VisitChildren(usingStatement, data); return VisitChildren(usingStatement, data);
} }
public virtual S VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement, T data) public virtual S? VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement, T data)
{ {
return VisitChildren(variableDeclarationStatement, data); return VisitChildren(variableDeclarationStatement, data);
} }
public virtual S VisitLocalFunctionDeclarationStatement(LocalFunctionDeclarationStatement localFunctionDeclarationStatement, T data) public virtual S? VisitLocalFunctionDeclarationStatement(LocalFunctionDeclarationStatement localFunctionDeclarationStatement, T data)
{ {
return VisitChildren(localFunctionDeclarationStatement, data); return VisitChildren(localFunctionDeclarationStatement, data);
} }
public virtual S VisitWhileStatement(WhileStatement whileStatement, T data) public virtual S? VisitWhileStatement(WhileStatement whileStatement, T data)
{ {
return VisitChildren(whileStatement, data); return VisitChildren(whileStatement, data);
} }
public virtual S VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement, T data) public virtual S? VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement, T data)
{ {
return VisitChildren(yieldBreakStatement, data); return VisitChildren(yieldBreakStatement, data);
} }
public virtual S VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement, T data) public virtual S? VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement, T data)
{ {
return VisitChildren(yieldReturnStatement, data); return VisitChildren(yieldReturnStatement, data);
} }
public virtual S VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, T data) public virtual S? VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, T data)
{ {
return VisitChildren(anonymousMethodExpression, data); return VisitChildren(anonymousMethodExpression, data);
} }
public virtual S VisitLambdaExpression(LambdaExpression lambdaExpression, T data) public virtual S? VisitLambdaExpression(LambdaExpression lambdaExpression, T data)
{ {
return VisitChildren(lambdaExpression, data); return VisitChildren(lambdaExpression, data);
} }
public virtual S VisitAssignmentExpression(AssignmentExpression assignmentExpression, T data) public virtual S? VisitAssignmentExpression(AssignmentExpression assignmentExpression, T data)
{ {
return VisitChildren(assignmentExpression, data); return VisitChildren(assignmentExpression, data);
} }
public virtual S VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, T data) public virtual S? VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, T data)
{ {
return VisitChildren(baseReferenceExpression, data); return VisitChildren(baseReferenceExpression, data);
} }
public virtual S VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, T data) public virtual S? VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, T data)
{ {
return VisitChildren(binaryOperatorExpression, data); return VisitChildren(binaryOperatorExpression, data);
} }
public virtual S VisitCastExpression(CastExpression castExpression, T data) public virtual S? VisitCastExpression(CastExpression castExpression, T data)
{ {
return VisitChildren(castExpression, data); return VisitChildren(castExpression, data);
} }
public virtual S VisitCheckedExpression(CheckedExpression checkedExpression, T data) public virtual S? VisitCheckedExpression(CheckedExpression checkedExpression, T data)
{ {
return VisitChildren(checkedExpression, data); return VisitChildren(checkedExpression, data);
} }
public virtual S VisitConditionalExpression(ConditionalExpression conditionalExpression, T data) public virtual S? VisitConditionalExpression(ConditionalExpression conditionalExpression, T data)
{ {
return VisitChildren(conditionalExpression, data); return VisitChildren(conditionalExpression, data);
} }
public virtual S VisitIdentifierExpression(IdentifierExpression identifierExpression, T data) public virtual S? VisitIdentifierExpression(IdentifierExpression identifierExpression, T data)
{ {
return VisitChildren(identifierExpression, data); return VisitChildren(identifierExpression, data);
} }
public virtual S VisitIndexerExpression(IndexerExpression indexerExpression, T data) public virtual S? VisitIndexerExpression(IndexerExpression indexerExpression, T data)
{ {
return VisitChildren(indexerExpression, data); return VisitChildren(indexerExpression, data);
} }
public virtual S VisitInterpolatedStringExpression(InterpolatedStringExpression interpolatedStringExpression, T data) public virtual S? VisitInterpolatedStringExpression(InterpolatedStringExpression interpolatedStringExpression, T data)
{ {
return VisitChildren(interpolatedStringExpression, data); return VisitChildren(interpolatedStringExpression, data);
} }
public virtual S VisitInterpolation(Interpolation interpolation, T data) public virtual S? VisitInterpolation(Interpolation interpolation, T data)
{ {
return VisitChildren(interpolation, data); return VisitChildren(interpolation, data);
} }
public virtual S VisitInterpolatedStringText(InterpolatedStringText interpolatedStringText, T data) public virtual S? VisitInterpolatedStringText(InterpolatedStringText interpolatedStringText, T data)
{ {
return VisitChildren(interpolatedStringText, data); return VisitChildren(interpolatedStringText, data);
} }
public virtual S VisitInvocationExpression(InvocationExpression invocationExpression, T data) public virtual S? VisitInvocationExpression(InvocationExpression invocationExpression, T data)
{ {
return VisitChildren(invocationExpression, data); return VisitChildren(invocationExpression, data);
} }
public virtual S VisitDirectionExpression(DirectionExpression directionExpression, T data) public virtual S? VisitDirectionExpression(DirectionExpression directionExpression, T data)
{ {
return VisitChildren(directionExpression, data); return VisitChildren(directionExpression, data);
} }
public virtual S VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, T data) public virtual S? VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, T data)
{ {
return VisitChildren(memberReferenceExpression, data); return VisitChildren(memberReferenceExpression, data);
} }
public virtual S VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, T data) public virtual S? VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, T data)
{ {
return VisitChildren(nullReferenceExpression, data); return VisitChildren(nullReferenceExpression, data);
} }
public virtual S VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, T data) public virtual S? VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, T data)
{ {
return VisitChildren(objectCreateExpression, data); return VisitChildren(objectCreateExpression, data);
} }
public virtual S VisitDeclarationExpression(DeclarationExpression declarationExpression, T data) public virtual S? VisitDeclarationExpression(DeclarationExpression declarationExpression, T data)
{ {
return VisitChildren(declarationExpression, data); return VisitChildren(declarationExpression, data);
} }
public virtual S VisitRecursivePatternExpression(RecursivePatternExpression recursivePatternExpression, T data) public virtual S? VisitRecursivePatternExpression(RecursivePatternExpression recursivePatternExpression, T data)
{ {
return VisitChildren(recursivePatternExpression, data); return VisitChildren(recursivePatternExpression, data);
} }
public virtual S VisitOutVarDeclarationExpression(OutVarDeclarationExpression outVarDeclarationExpression, T data) public virtual S? VisitOutVarDeclarationExpression(OutVarDeclarationExpression outVarDeclarationExpression, T data)
{ {
return VisitChildren(outVarDeclarationExpression, data); return VisitChildren(outVarDeclarationExpression, data);
} }
public virtual S VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression, T data) public virtual S? VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression, T data)
{ {
return VisitChildren(anonymousTypeCreateExpression, data); return VisitChildren(anonymousTypeCreateExpression, data);
} }
public virtual S VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, T data) public virtual S? VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, T data)
{ {
return VisitChildren(arrayCreateExpression, data); return VisitChildren(arrayCreateExpression, data);
} }
public virtual S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data) public virtual S? VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data)
{ {
return VisitChildren(parenthesizedExpression, data); return VisitChildren(parenthesizedExpression, data);
} }
public virtual S VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, T data) public virtual S? VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, T data)
{ {
return VisitChildren(pointerReferenceExpression, data); return VisitChildren(pointerReferenceExpression, data);
} }
public virtual S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T data) public virtual S? VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T data)
{ {
return VisitChildren(primitiveExpression, data); return VisitChildren(primitiveExpression, data);
} }
public virtual S VisitSizeOfExpression(SizeOfExpression sizeOfExpression, T data) public virtual S? VisitSizeOfExpression(SizeOfExpression sizeOfExpression, T data)
{ {
return VisitChildren(sizeOfExpression, data); return VisitChildren(sizeOfExpression, data);
} }
public virtual S VisitStackAllocExpression(StackAllocExpression stackAllocExpression, T data) public virtual S? VisitStackAllocExpression(StackAllocExpression stackAllocExpression, T data)
{ {
return VisitChildren(stackAllocExpression, data); return VisitChildren(stackAllocExpression, data);
} }
public virtual S VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, T data) public virtual S? VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, T data)
{ {
return VisitChildren(thisReferenceExpression, data); return VisitChildren(thisReferenceExpression, data);
} }
public virtual S VisitThrowExpression(ThrowExpression throwExpression, T data) public virtual S? VisitThrowExpression(ThrowExpression throwExpression, T data)
{ {
return VisitChildren(throwExpression, data); return VisitChildren(throwExpression, data);
} }
public virtual S VisitTupleExpression(TupleExpression tupleExpression, T data) public virtual S? VisitTupleExpression(TupleExpression tupleExpression, T data)
{ {
return VisitChildren(tupleExpression, data); return VisitChildren(tupleExpression, data);
} }
public virtual S VisitTypeOfExpression(TypeOfExpression typeOfExpression, T data) public virtual S? VisitTypeOfExpression(TypeOfExpression typeOfExpression, T data)
{ {
return VisitChildren(typeOfExpression, data); return VisitChildren(typeOfExpression, data);
} }
public virtual S VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, T data) public virtual S? VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, T data)
{ {
return VisitChildren(typeReferenceExpression, data); return VisitChildren(typeReferenceExpression, data);
} }
public virtual S VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, T data) public virtual S? VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, T data)
{ {
return VisitChildren(unaryOperatorExpression, data); return VisitChildren(unaryOperatorExpression, data);
} }
public virtual S VisitUncheckedExpression(UncheckedExpression uncheckedExpression, T data) public virtual S? VisitUncheckedExpression(UncheckedExpression uncheckedExpression, T data)
{ {
return VisitChildren(uncheckedExpression, data); return VisitChildren(uncheckedExpression, data);
} }
public virtual S VisitQueryExpression(QueryExpression queryExpression, T data) public virtual S? VisitQueryExpression(QueryExpression queryExpression, T data)
{ {
return VisitChildren(queryExpression, data); return VisitChildren(queryExpression, data);
} }
public virtual S VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause, T data) public virtual S? VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause, T data)
{ {
return VisitChildren(queryContinuationClause, data); return VisitChildren(queryContinuationClause, data);
} }
public virtual S VisitQueryFromClause(QueryFromClause queryFromClause, T data) public virtual S? VisitQueryFromClause(QueryFromClause queryFromClause, T data)
{ {
return VisitChildren(queryFromClause, data); return VisitChildren(queryFromClause, data);
} }
public virtual S VisitQueryLetClause(QueryLetClause queryLetClause, T data) public virtual S? VisitQueryLetClause(QueryLetClause queryLetClause, T data)
{ {
return VisitChildren(queryLetClause, data); return VisitChildren(queryLetClause, data);
} }
public virtual S VisitQueryWhereClause(QueryWhereClause queryWhereClause, T data) public virtual S? VisitQueryWhereClause(QueryWhereClause queryWhereClause, T data)
{ {
return VisitChildren(queryWhereClause, data); return VisitChildren(queryWhereClause, data);
} }
public virtual S VisitQueryJoinClause(QueryJoinClause queryJoinClause, T data) public virtual S? VisitQueryJoinClause(QueryJoinClause queryJoinClause, T data)
{ {
return VisitChildren(queryJoinClause, data); return VisitChildren(queryJoinClause, data);
} }
public virtual S VisitQueryOrderClause(QueryOrderClause queryOrderClause, T data) public virtual S? VisitQueryOrderClause(QueryOrderClause queryOrderClause, T data)
{ {
return VisitChildren(queryOrderClause, data); return VisitChildren(queryOrderClause, data);
} }
public virtual S VisitQueryOrdering(QueryOrdering queryOrdering, T data) public virtual S? VisitQueryOrdering(QueryOrdering queryOrdering, T data)
{ {
return VisitChildren(queryOrdering, data); return VisitChildren(queryOrdering, data);
} }
public virtual S VisitQuerySelectClause(QuerySelectClause querySelectClause, T data) public virtual S? VisitQuerySelectClause(QuerySelectClause querySelectClause, T data)
{ {
return VisitChildren(querySelectClause, data); return VisitChildren(querySelectClause, data);
} }
public virtual S VisitQueryGroupClause(QueryGroupClause queryGroupClause, T data) public virtual S? VisitQueryGroupClause(QueryGroupClause queryGroupClause, T data)
{ {
return VisitChildren(queryGroupClause, data); return VisitChildren(queryGroupClause, data);
} }
public virtual S VisitAsExpression(AsExpression asExpression, T data) public virtual S? VisitAsExpression(AsExpression asExpression, T data)
{ {
return VisitChildren(asExpression, data); return VisitChildren(asExpression, data);
} }
public virtual S VisitIsExpression(IsExpression isExpression, T data) public virtual S? VisitIsExpression(IsExpression isExpression, T data)
{ {
return VisitChildren(isExpression, data); return VisitChildren(isExpression, data);
} }
public virtual S VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, T data) public virtual S? VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, T data)
{ {
return VisitChildren(defaultValueExpression, data); return VisitChildren(defaultValueExpression, data);
} }
public virtual S VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression, T data) public virtual S? VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression, T data)
{ {
return VisitChildren(undocumentedExpression, data); return VisitChildren(undocumentedExpression, data);
} }
public virtual S VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, T data) public virtual S? VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, T data)
{ {
return VisitChildren(arrayInitializerExpression, data); return VisitChildren(arrayInitializerExpression, data);
} }
public virtual S VisitArraySpecifier(ArraySpecifier arraySpecifier, T data) public virtual S? VisitArraySpecifier(ArraySpecifier arraySpecifier, T data)
{ {
return VisitChildren(arraySpecifier, data); return VisitChildren(arraySpecifier, data);
} }
public virtual S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T data) public virtual S? VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T data)
{ {
return VisitChildren(namedArgumentExpression, data); return VisitChildren(namedArgumentExpression, data);
} }
public virtual S VisitNamedExpression(NamedExpression namedExpression, T data) public virtual S? VisitNamedExpression(NamedExpression namedExpression, T data)
{ {
return VisitChildren(namedExpression, data); return VisitChildren(namedExpression, data);
} }
public virtual S VisitSingleVariableDesignation(SingleVariableDesignation singleVariableDesignation, T data) public virtual S? VisitSingleVariableDesignation(SingleVariableDesignation singleVariableDesignation, T data)
{ {
return VisitChildren(singleVariableDesignation, data); return VisitChildren(singleVariableDesignation, data);
} }
public virtual S VisitParenthesizedVariableDesignation(ParenthesizedVariableDesignation parenthesizedVariableDesignation, T data) public virtual S? VisitParenthesizedVariableDesignation(ParenthesizedVariableDesignation parenthesizedVariableDesignation, T data)
{ {
return VisitChildren(parenthesizedVariableDesignation, data); return VisitChildren(parenthesizedVariableDesignation, data);
} }
public virtual S VisitErrorNode(AstNode errorNode, T data) public virtual S? VisitErrorNode(AstNode errorNode, T data)
{ {
return VisitChildren(errorNode, data); return VisitChildren(errorNode, data);
} }
public virtual S VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern, T data) public virtual S? VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern, T data)
{ {
return VisitChildren(placeholder, data); return VisitChildren(placeholder, data);
} }
public virtual S VisitWithInitializerExpression(WithInitializerExpression withInitializerExpression, T data) public virtual S? VisitWithInitializerExpression(WithInitializerExpression withInitializerExpression, T data)
{ {
return VisitChildren(withInitializerExpression, data); return VisitChildren(withInitializerExpression, data);
} }

22
ICSharpCode.Decompiler/CSharp/Syntax/IAnnotatable.cs

@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <typeparam name='T'> /// <typeparam name='T'>
/// The type of the annotation. /// The type of the annotation.
/// </typeparam> /// </typeparam>
T Annotation<T>() where T : class; T? Annotation<T>() where T : class;
/// <summary> /// <summary>
/// Gets the first annotation of the specified type. /// Gets the first annotation of the specified type.
@ -51,7 +51,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <param name='type'> /// <param name='type'>
/// The type of the annotation. /// The type of the annotation.
/// </param> /// </param>
object Annotation(Type type); object? Annotation(Type type);
/// <summary> /// <summary>
/// Adds an annotation to this instance. /// Adds an annotation to this instance.
@ -89,7 +89,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
// or to an AnnotationList. // or to an AnnotationList.
// Once it is pointed at an AnnotationList, it will never change (this allows thread-safety support by locking the list) // Once it is pointed at an AnnotationList, it will never change (this allows thread-safety support by locking the list)
object annotations; object? annotations;
/// <summary> /// <summary>
/// Clones all annotations. /// Clones all annotations.
@ -136,7 +136,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
if (annotation == null) if (annotation == null)
throw new ArgumentNullException(nameof(annotation)); throw new ArgumentNullException(nameof(annotation));
retry: // Retry until successful retry: // Retry until successful
object oldAnnotation = Interlocked.CompareExchange(ref this.annotations, annotation, null); object? oldAnnotation = Interlocked.CompareExchange(ref this.annotations, annotation, null);
if (oldAnnotation == null) if (oldAnnotation == null)
{ {
return; // we successfully added a single annotation return; // we successfully added a single annotation
@ -167,7 +167,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public virtual void RemoveAnnotations<T>() where T : class public virtual void RemoveAnnotations<T>() where T : class
{ {
retry: // Retry until successful retry: // Retry until successful
object oldAnnotations = this.annotations; object? oldAnnotations = this.annotations;
AnnotationList? list = oldAnnotations as AnnotationList; AnnotationList? list = oldAnnotations as AnnotationList;
if (list != null) if (list != null)
{ {
@ -189,7 +189,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
if (type == null) if (type == null)
throw new ArgumentNullException(nameof(type)); throw new ArgumentNullException(nameof(type));
retry: // Retry until successful retry: // Retry until successful
object oldAnnotations = this.annotations; object? oldAnnotations = this.annotations;
AnnotationList? list = oldAnnotations as AnnotationList; AnnotationList? list = oldAnnotations as AnnotationList;
if (list != null) if (list != null)
{ {
@ -206,9 +206,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
} }
} }
public T Annotation<T>() where T : class public T? Annotation<T>() where T : class
{ {
object annotations = this.annotations; object? annotations = this.annotations;
AnnotationList? list = annotations as AnnotationList; AnnotationList? list = annotations as AnnotationList;
if (list != null) if (list != null)
{ {
@ -229,11 +229,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
} }
} }
public object Annotation(Type type) public object? Annotation(Type type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException(nameof(type)); throw new ArgumentNullException(nameof(type));
object annotations = this.annotations; object? annotations = this.annotations;
AnnotationList? list = annotations as AnnotationList; AnnotationList? list = annotations as AnnotationList;
if (list != null) if (list != null)
{ {
@ -259,7 +259,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary> /// </summary>
public IEnumerable<object> Annotations { public IEnumerable<object> Annotations {
get { get {
object annotations = this.annotations; object? annotations = this.annotations;
AnnotationList? list = annotations as AnnotationList; AnnotationList? list = annotations as AnnotationList;
if (list != null) if (list != null)
{ {

568
ICSharpCode.Decompiler/CSharp/Syntax/IAstVisitor.cs

@ -173,148 +173,148 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary> /// </summary>
public interface IAstVisitor<out S> public interface IAstVisitor<out S>
{ {
S VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression); S? VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression);
S VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression); S? VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression);
S VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression); S? VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression);
S VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression); S? VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression);
S VisitAsExpression(AsExpression asExpression); S? VisitAsExpression(AsExpression asExpression);
S VisitAssignmentExpression(AssignmentExpression assignmentExpression); S? VisitAssignmentExpression(AssignmentExpression assignmentExpression);
S VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression); S? VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression);
S VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression); S? VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression);
S VisitCastExpression(CastExpression castExpression); S? VisitCastExpression(CastExpression castExpression);
S VisitCheckedExpression(CheckedExpression checkedExpression); S? VisitCheckedExpression(CheckedExpression checkedExpression);
S VisitConditionalExpression(ConditionalExpression conditionalExpression); S? VisitConditionalExpression(ConditionalExpression conditionalExpression);
S VisitDeclarationExpression(DeclarationExpression declarationExpression); S? VisitDeclarationExpression(DeclarationExpression declarationExpression);
S VisitRecursivePatternExpression(RecursivePatternExpression recursivePatternExpression); S? VisitRecursivePatternExpression(RecursivePatternExpression recursivePatternExpression);
S VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression); S? VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression);
S VisitDirectionExpression(DirectionExpression directionExpression); S? VisitDirectionExpression(DirectionExpression directionExpression);
S VisitIdentifierExpression(IdentifierExpression identifierExpression); S? VisitIdentifierExpression(IdentifierExpression identifierExpression);
S VisitIndexerExpression(IndexerExpression indexerExpression); S? VisitIndexerExpression(IndexerExpression indexerExpression);
S VisitInterpolatedStringExpression(InterpolatedStringExpression interpolatedStringExpression); S? VisitInterpolatedStringExpression(InterpolatedStringExpression interpolatedStringExpression);
S VisitInvocationExpression(InvocationExpression invocationExpression); S? VisitInvocationExpression(InvocationExpression invocationExpression);
S VisitIsExpression(IsExpression isExpression); S? VisitIsExpression(IsExpression isExpression);
S VisitLambdaExpression(LambdaExpression lambdaExpression); S? VisitLambdaExpression(LambdaExpression lambdaExpression);
S VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression); S? VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression);
S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression); S? VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression);
S VisitNamedExpression(NamedExpression namedExpression); S? VisitNamedExpression(NamedExpression namedExpression);
S VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression); S? VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression);
S VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression); S? VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression);
S VisitOutVarDeclarationExpression(OutVarDeclarationExpression outVarDeclarationExpression); S? VisitOutVarDeclarationExpression(OutVarDeclarationExpression outVarDeclarationExpression);
S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression); S? VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression);
S VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression); S? VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression);
S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression); S? VisitPrimitiveExpression(PrimitiveExpression primitiveExpression);
S VisitSizeOfExpression(SizeOfExpression sizeOfExpression); S? VisitSizeOfExpression(SizeOfExpression sizeOfExpression);
S VisitStackAllocExpression(StackAllocExpression stackAllocExpression); S? VisitStackAllocExpression(StackAllocExpression stackAllocExpression);
S VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression); S? VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression);
S VisitThrowExpression(ThrowExpression throwExpression); S? VisitThrowExpression(ThrowExpression throwExpression);
S VisitTupleExpression(TupleExpression tupleExpression); S? VisitTupleExpression(TupleExpression tupleExpression);
S VisitTypeOfExpression(TypeOfExpression typeOfExpression); S? VisitTypeOfExpression(TypeOfExpression typeOfExpression);
S VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression); S? VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression);
S VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression); S? VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression);
S VisitUncheckedExpression(UncheckedExpression uncheckedExpression); S? VisitUncheckedExpression(UncheckedExpression uncheckedExpression);
S VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression); S? VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression);
S VisitWithInitializerExpression(WithInitializerExpression withInitializerExpression); S? VisitWithInitializerExpression(WithInitializerExpression withInitializerExpression);
S VisitQueryExpression(QueryExpression queryExpression); S? VisitQueryExpression(QueryExpression queryExpression);
S VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause); S? VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause);
S VisitQueryFromClause(QueryFromClause queryFromClause); S? VisitQueryFromClause(QueryFromClause queryFromClause);
S VisitQueryLetClause(QueryLetClause queryLetClause); S? VisitQueryLetClause(QueryLetClause queryLetClause);
S VisitQueryWhereClause(QueryWhereClause queryWhereClause); S? VisitQueryWhereClause(QueryWhereClause queryWhereClause);
S VisitQueryJoinClause(QueryJoinClause queryJoinClause); S? VisitQueryJoinClause(QueryJoinClause queryJoinClause);
S VisitQueryOrderClause(QueryOrderClause queryOrderClause); S? VisitQueryOrderClause(QueryOrderClause queryOrderClause);
S VisitQueryOrdering(QueryOrdering queryOrdering); S? VisitQueryOrdering(QueryOrdering queryOrdering);
S VisitQuerySelectClause(QuerySelectClause querySelectClause); S? VisitQuerySelectClause(QuerySelectClause querySelectClause);
S VisitQueryGroupClause(QueryGroupClause queryGroupClause); S? VisitQueryGroupClause(QueryGroupClause queryGroupClause);
S VisitAttribute(Attribute attribute); S? VisitAttribute(Attribute attribute);
S VisitAttributeSection(AttributeSection attributeSection); S? VisitAttributeSection(AttributeSection attributeSection);
S VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration); S? VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration);
S VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration); S? VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration);
S VisitTypeDeclaration(TypeDeclaration typeDeclaration); S? VisitTypeDeclaration(TypeDeclaration typeDeclaration);
S VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration); S? VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration);
S VisitUsingDeclaration(UsingDeclaration usingDeclaration); S? VisitUsingDeclaration(UsingDeclaration usingDeclaration);
S VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration); S? VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration);
S VisitBlockStatement(BlockStatement blockStatement); S? VisitBlockStatement(BlockStatement blockStatement);
S VisitBreakStatement(BreakStatement breakStatement); S? VisitBreakStatement(BreakStatement breakStatement);
S VisitCheckedStatement(CheckedStatement checkedStatement); S? VisitCheckedStatement(CheckedStatement checkedStatement);
S VisitContinueStatement(ContinueStatement continueStatement); S? VisitContinueStatement(ContinueStatement continueStatement);
S VisitDoWhileStatement(DoWhileStatement doWhileStatement); S? VisitDoWhileStatement(DoWhileStatement doWhileStatement);
S VisitEmptyStatement(EmptyStatement emptyStatement); S? VisitEmptyStatement(EmptyStatement emptyStatement);
S VisitExpressionStatement(ExpressionStatement expressionStatement); S? VisitExpressionStatement(ExpressionStatement expressionStatement);
S VisitFixedStatement(FixedStatement fixedStatement); S? VisitFixedStatement(FixedStatement fixedStatement);
S VisitForeachStatement(ForeachStatement foreachStatement); S? VisitForeachStatement(ForeachStatement foreachStatement);
S VisitForStatement(ForStatement forStatement); S? VisitForStatement(ForStatement forStatement);
S VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement); S? VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement);
S VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement); S? VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement);
S VisitGotoStatement(GotoStatement gotoStatement); S? VisitGotoStatement(GotoStatement gotoStatement);
S VisitIfElseStatement(IfElseStatement ifElseStatement); S? VisitIfElseStatement(IfElseStatement ifElseStatement);
S VisitLabelStatement(LabelStatement labelStatement); S? VisitLabelStatement(LabelStatement labelStatement);
S VisitLockStatement(LockStatement lockStatement); S? VisitLockStatement(LockStatement lockStatement);
S VisitReturnStatement(ReturnStatement returnStatement); S? VisitReturnStatement(ReturnStatement returnStatement);
S VisitSwitchStatement(SwitchStatement switchStatement); S? VisitSwitchStatement(SwitchStatement switchStatement);
S VisitSwitchSection(SwitchSection switchSection); S? VisitSwitchSection(SwitchSection switchSection);
S VisitCaseLabel(CaseLabel caseLabel); S? VisitCaseLabel(CaseLabel caseLabel);
S VisitSwitchExpression(SwitchExpression switchExpression); S? VisitSwitchExpression(SwitchExpression switchExpression);
S VisitSwitchExpressionSection(SwitchExpressionSection switchExpressionSection); S? VisitSwitchExpressionSection(SwitchExpressionSection switchExpressionSection);
S VisitThrowStatement(ThrowStatement throwStatement); S? VisitThrowStatement(ThrowStatement throwStatement);
S VisitTryCatchStatement(TryCatchStatement tryCatchStatement); S? VisitTryCatchStatement(TryCatchStatement tryCatchStatement);
S VisitCatchClause(CatchClause catchClause); S? VisitCatchClause(CatchClause catchClause);
S VisitUncheckedStatement(UncheckedStatement uncheckedStatement); S? VisitUncheckedStatement(UncheckedStatement uncheckedStatement);
S VisitUnsafeStatement(UnsafeStatement unsafeStatement); S? VisitUnsafeStatement(UnsafeStatement unsafeStatement);
S VisitUsingStatement(UsingStatement usingStatement); S? VisitUsingStatement(UsingStatement usingStatement);
S VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement); S? VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement);
S VisitLocalFunctionDeclarationStatement(LocalFunctionDeclarationStatement localFunctionDeclarationStatement); S? VisitLocalFunctionDeclarationStatement(LocalFunctionDeclarationStatement localFunctionDeclarationStatement);
S VisitWhileStatement(WhileStatement whileStatement); S? VisitWhileStatement(WhileStatement whileStatement);
S VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement); S? VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement);
S VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement); S? VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement);
S VisitAccessor(Accessor accessor); S? VisitAccessor(Accessor accessor);
S VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration); S? VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration);
S VisitConstructorInitializer(ConstructorInitializer constructorInitializer); S? VisitConstructorInitializer(ConstructorInitializer constructorInitializer);
S VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration); S? VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration);
S VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration); S? VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration);
S VisitEventDeclaration(EventDeclaration eventDeclaration); S? VisitEventDeclaration(EventDeclaration eventDeclaration);
S VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration); S? VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration);
S VisitFieldDeclaration(FieldDeclaration fieldDeclaration); S? VisitFieldDeclaration(FieldDeclaration fieldDeclaration);
S VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration); S? VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration);
S VisitMethodDeclaration(MethodDeclaration methodDeclaration); S? VisitMethodDeclaration(MethodDeclaration methodDeclaration);
S VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration); S? VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration);
S VisitParameterDeclaration(ParameterDeclaration parameterDeclaration); S? VisitParameterDeclaration(ParameterDeclaration parameterDeclaration);
S VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration); S? VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration);
S VisitVariableInitializer(VariableInitializer variableInitializer); S? VisitVariableInitializer(VariableInitializer variableInitializer);
S VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration); S? VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration);
S VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer); S? VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer);
S VisitSyntaxTree(SyntaxTree syntaxTree); S? VisitSyntaxTree(SyntaxTree syntaxTree);
S VisitSimpleType(SimpleType simpleType); S? VisitSimpleType(SimpleType simpleType);
S VisitMemberType(MemberType memberType); S? VisitMemberType(MemberType memberType);
S VisitTupleType(TupleAstType tupleType); S? VisitTupleType(TupleAstType tupleType);
S VisitTupleTypeElement(TupleTypeElement tupleTypeElement); S? VisitTupleTypeElement(TupleTypeElement tupleTypeElement);
S VisitFunctionPointerType(FunctionPointerAstType functionPointerType); S? VisitFunctionPointerType(FunctionPointerAstType functionPointerType);
S VisitInvocationType(InvocationAstType invocationType); S? VisitInvocationType(InvocationAstType invocationType);
S VisitComposedType(ComposedType composedType); S? VisitComposedType(ComposedType composedType);
S VisitArraySpecifier(ArraySpecifier arraySpecifier); S? VisitArraySpecifier(ArraySpecifier arraySpecifier);
S VisitPrimitiveType(PrimitiveType primitiveType); S? VisitPrimitiveType(PrimitiveType primitiveType);
S VisitComment(Comment comment); S? VisitComment(Comment comment);
S VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective); S? VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective);
S VisitDocumentationReference(DocumentationReference documentationReference); S? VisitDocumentationReference(DocumentationReference documentationReference);
S VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration); S? VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration);
S VisitConstraint(Constraint constraint); S? VisitConstraint(Constraint constraint);
S VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode); S? VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode);
S VisitIdentifier(Identifier identifier); S? VisitIdentifier(Identifier identifier);
S VisitInterpolation(Interpolation interpolation); S? VisitInterpolation(Interpolation interpolation);
S VisitInterpolatedStringText(InterpolatedStringText interpolatedStringText); S? VisitInterpolatedStringText(InterpolatedStringText interpolatedStringText);
S VisitSingleVariableDesignation(SingleVariableDesignation singleVariableDesignation); S? VisitSingleVariableDesignation(SingleVariableDesignation singleVariableDesignation);
S VisitParenthesizedVariableDesignation(ParenthesizedVariableDesignation parenthesizedVariableDesignation); S? VisitParenthesizedVariableDesignation(ParenthesizedVariableDesignation parenthesizedVariableDesignation);
S VisitNullNode(AstNode nullNode); S? VisitNullNode(AstNode nullNode);
S VisitErrorNode(AstNode errorNode); S? VisitErrorNode(AstNode errorNode);
S VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern); S? VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern);
} }
/// <summary> /// <summary>
@ -322,147 +322,147 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary> /// </summary>
public interface IAstVisitor<in T, out S> public interface IAstVisitor<in T, out S>
{ {
S VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, T data); S? VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, T data);
S VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression, T data); S? VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression, T data);
S VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, T data); S? VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, T data);
S VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, T data); S? VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, T data);
S VisitAsExpression(AsExpression asExpression, T data); S? VisitAsExpression(AsExpression asExpression, T data);
S VisitAssignmentExpression(AssignmentExpression assignmentExpression, T data); S? VisitAssignmentExpression(AssignmentExpression assignmentExpression, T data);
S VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, T data); S? VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, T data);
S VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, T data); S? VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, T data);
S VisitCastExpression(CastExpression castExpression, T data); S? VisitCastExpression(CastExpression castExpression, T data);
S VisitCheckedExpression(CheckedExpression checkedExpression, T data); S? VisitCheckedExpression(CheckedExpression checkedExpression, T data);
S VisitConditionalExpression(ConditionalExpression conditionalExpression, T data); S? VisitConditionalExpression(ConditionalExpression conditionalExpression, T data);
S VisitDeclarationExpression(DeclarationExpression declarationExpression, T data); S? VisitDeclarationExpression(DeclarationExpression declarationExpression, T data);
S VisitRecursivePatternExpression(RecursivePatternExpression recursivePatternExpression, T data); S? VisitRecursivePatternExpression(RecursivePatternExpression recursivePatternExpression, T data);
S VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, T data); S? VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, T data);
S VisitDirectionExpression(DirectionExpression directionExpression, T data); S? VisitDirectionExpression(DirectionExpression directionExpression, T data);
S VisitIdentifierExpression(IdentifierExpression identifierExpression, T data); S? VisitIdentifierExpression(IdentifierExpression identifierExpression, T data);
S VisitIndexerExpression(IndexerExpression indexerExpression, T data); S? VisitIndexerExpression(IndexerExpression indexerExpression, T data);
S VisitInterpolatedStringExpression(InterpolatedStringExpression interpolatedStringExpression, T data); S? VisitInterpolatedStringExpression(InterpolatedStringExpression interpolatedStringExpression, T data);
S VisitInvocationExpression(InvocationExpression invocationExpression, T data); S? VisitInvocationExpression(InvocationExpression invocationExpression, T data);
S VisitIsExpression(IsExpression isExpression, T data); S? VisitIsExpression(IsExpression isExpression, T data);
S VisitLambdaExpression(LambdaExpression lambdaExpression, T data); S? VisitLambdaExpression(LambdaExpression lambdaExpression, T data);
S VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, T data); S? VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, T data);
S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T data); S? VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T data);
S VisitNamedExpression(NamedExpression namedExpression, T data); S? VisitNamedExpression(NamedExpression namedExpression, T data);
S VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, T data); S? VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, T data);
S VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, T data); S? VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, T data);
S VisitOutVarDeclarationExpression(OutVarDeclarationExpression outVarDeclarationExpression, T data); S? VisitOutVarDeclarationExpression(OutVarDeclarationExpression outVarDeclarationExpression, T data);
S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data); S? VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data);
S VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, T data); S? VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, T data);
S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T data); S? VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T data);
S VisitSizeOfExpression(SizeOfExpression sizeOfExpression, T data); S? VisitSizeOfExpression(SizeOfExpression sizeOfExpression, T data);
S VisitStackAllocExpression(StackAllocExpression stackAllocExpression, T data); S? VisitStackAllocExpression(StackAllocExpression stackAllocExpression, T data);
S VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, T data); S? VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, T data);
S VisitThrowExpression(ThrowExpression throwExpression, T data); S? VisitThrowExpression(ThrowExpression throwExpression, T data);
S VisitTupleExpression(TupleExpression tupleExpression, T data); S? VisitTupleExpression(TupleExpression tupleExpression, T data);
S VisitTypeOfExpression(TypeOfExpression typeOfExpression, T data); S? VisitTypeOfExpression(TypeOfExpression typeOfExpression, T data);
S VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, T data); S? VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, T data);
S VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, T data); S? VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, T data);
S VisitUncheckedExpression(UncheckedExpression uncheckedExpression, T data); S? VisitUncheckedExpression(UncheckedExpression uncheckedExpression, T data);
S VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression, T data); S? VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression, T data);
S VisitWithInitializerExpression(WithInitializerExpression withInitializerExpression, T data); S? VisitWithInitializerExpression(WithInitializerExpression withInitializerExpression, T data);
S VisitQueryExpression(QueryExpression queryExpression, T data); S? VisitQueryExpression(QueryExpression queryExpression, T data);
S VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause, T data); S? VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause, T data);
S VisitQueryFromClause(QueryFromClause queryFromClause, T data); S? VisitQueryFromClause(QueryFromClause queryFromClause, T data);
S VisitQueryLetClause(QueryLetClause queryLetClause, T data); S? VisitQueryLetClause(QueryLetClause queryLetClause, T data);
S VisitQueryWhereClause(QueryWhereClause queryWhereClause, T data); S? VisitQueryWhereClause(QueryWhereClause queryWhereClause, T data);
S VisitQueryJoinClause(QueryJoinClause queryJoinClause, T data); S? VisitQueryJoinClause(QueryJoinClause queryJoinClause, T data);
S VisitQueryOrderClause(QueryOrderClause queryOrderClause, T data); S? VisitQueryOrderClause(QueryOrderClause queryOrderClause, T data);
S VisitQueryOrdering(QueryOrdering queryOrdering, T data); S? VisitQueryOrdering(QueryOrdering queryOrdering, T data);
S VisitQuerySelectClause(QuerySelectClause querySelectClause, T data); S? VisitQuerySelectClause(QuerySelectClause querySelectClause, T data);
S VisitQueryGroupClause(QueryGroupClause queryGroupClause, T data); S? VisitQueryGroupClause(QueryGroupClause queryGroupClause, T data);
S VisitAttribute(Attribute attribute, T data); S? VisitAttribute(Attribute attribute, T data);
S VisitAttributeSection(AttributeSection attributeSection, T data); S? VisitAttributeSection(AttributeSection attributeSection, T data);
S VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, T data); S? VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, T data);
S VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, T data); S? VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, T data);
S VisitTypeDeclaration(TypeDeclaration typeDeclaration, T data); S? VisitTypeDeclaration(TypeDeclaration typeDeclaration, T data);
S VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration, T data); S? VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration, T data);
S VisitUsingDeclaration(UsingDeclaration usingDeclaration, T data); S? VisitUsingDeclaration(UsingDeclaration usingDeclaration, T data);
S VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration, T data); S? VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration, T data);
S VisitBlockStatement(BlockStatement blockStatement, T data); S? VisitBlockStatement(BlockStatement blockStatement, T data);
S VisitBreakStatement(BreakStatement breakStatement, T data); S? VisitBreakStatement(BreakStatement breakStatement, T data);
S VisitCheckedStatement(CheckedStatement checkedStatement, T data); S? VisitCheckedStatement(CheckedStatement checkedStatement, T data);
S VisitContinueStatement(ContinueStatement continueStatement, T data); S? VisitContinueStatement(ContinueStatement continueStatement, T data);
S VisitDoWhileStatement(DoWhileStatement doWhileStatement, T data); S? VisitDoWhileStatement(DoWhileStatement doWhileStatement, T data);
S VisitEmptyStatement(EmptyStatement emptyStatement, T data); S? VisitEmptyStatement(EmptyStatement emptyStatement, T data);
S VisitExpressionStatement(ExpressionStatement expressionStatement, T data); S? VisitExpressionStatement(ExpressionStatement expressionStatement, T data);
S VisitFixedStatement(FixedStatement fixedStatement, T data); S? VisitFixedStatement(FixedStatement fixedStatement, T data);
S VisitForeachStatement(ForeachStatement foreachStatement, T data); S? VisitForeachStatement(ForeachStatement foreachStatement, T data);
S VisitForStatement(ForStatement forStatement, T data); S? VisitForStatement(ForStatement forStatement, T data);
S VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, T data); S? VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, T data);
S VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement, T data); S? VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement, T data);
S VisitGotoStatement(GotoStatement gotoStatement, T data); S? VisitGotoStatement(GotoStatement gotoStatement, T data);
S VisitIfElseStatement(IfElseStatement ifElseStatement, T data); S? VisitIfElseStatement(IfElseStatement ifElseStatement, T data);
S VisitLabelStatement(LabelStatement labelStatement, T data); S? VisitLabelStatement(LabelStatement labelStatement, T data);
S VisitLockStatement(LockStatement lockStatement, T data); S? VisitLockStatement(LockStatement lockStatement, T data);
S VisitReturnStatement(ReturnStatement returnStatement, T data); S? VisitReturnStatement(ReturnStatement returnStatement, T data);
S VisitSwitchStatement(SwitchStatement switchStatement, T data); S? VisitSwitchStatement(SwitchStatement switchStatement, T data);
S VisitSwitchSection(SwitchSection switchSection, T data); S? VisitSwitchSection(SwitchSection switchSection, T data);
S VisitCaseLabel(CaseLabel caseLabel, T data); S? VisitCaseLabel(CaseLabel caseLabel, T data);
S VisitSwitchExpression(SwitchExpression switchExpression, T data); S? VisitSwitchExpression(SwitchExpression switchExpression, T data);
S VisitSwitchExpressionSection(SwitchExpressionSection switchExpressionSection, T data); S? VisitSwitchExpressionSection(SwitchExpressionSection switchExpressionSection, T data);
S VisitThrowStatement(ThrowStatement throwStatement, T data); S? VisitThrowStatement(ThrowStatement throwStatement, T data);
S VisitTryCatchStatement(TryCatchStatement tryCatchStatement, T data); S? VisitTryCatchStatement(TryCatchStatement tryCatchStatement, T data);
S VisitCatchClause(CatchClause catchClause, T data); S? VisitCatchClause(CatchClause catchClause, T data);
S VisitUncheckedStatement(UncheckedStatement uncheckedStatement, T data); S? VisitUncheckedStatement(UncheckedStatement uncheckedStatement, T data);
S VisitUnsafeStatement(UnsafeStatement unsafeStatement, T data); S? VisitUnsafeStatement(UnsafeStatement unsafeStatement, T data);
S VisitUsingStatement(UsingStatement usingStatement, T data); S? VisitUsingStatement(UsingStatement usingStatement, T data);
S VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement, T data); S? VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement, T data);
S VisitLocalFunctionDeclarationStatement(LocalFunctionDeclarationStatement localFunctionDeclarationStatement, T data); S? VisitLocalFunctionDeclarationStatement(LocalFunctionDeclarationStatement localFunctionDeclarationStatement, T data);
S VisitWhileStatement(WhileStatement whileStatement, T data); S? VisitWhileStatement(WhileStatement whileStatement, T data);
S VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement, T data); S? VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement, T data);
S VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement, T data); S? VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement, T data);
S VisitAccessor(Accessor accessor, T data); S? VisitAccessor(Accessor accessor, T data);
S VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, T data); S? VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, T data);
S VisitConstructorInitializer(ConstructorInitializer constructorInitializer, T data); S? VisitConstructorInitializer(ConstructorInitializer constructorInitializer, T data);
S VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, T data); S? VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, T data);
S VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration, T data); S? VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration, T data);
S VisitEventDeclaration(EventDeclaration eventDeclaration, T data); S? VisitEventDeclaration(EventDeclaration eventDeclaration, T data);
S VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration, T data); S? VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration, T data);
S VisitFieldDeclaration(FieldDeclaration fieldDeclaration, T data); S? VisitFieldDeclaration(FieldDeclaration fieldDeclaration, T data);
S VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, T data); S? VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, T data);
S VisitMethodDeclaration(MethodDeclaration methodDeclaration, T data); S? VisitMethodDeclaration(MethodDeclaration methodDeclaration, T data);
S VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, T data); S? VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, T data);
S VisitParameterDeclaration(ParameterDeclaration parameterDeclaration, T data); S? VisitParameterDeclaration(ParameterDeclaration parameterDeclaration, T data);
S VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, T data); S? VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, T data);
S VisitVariableInitializer(VariableInitializer variableInitializer, T data); S? VisitVariableInitializer(VariableInitializer variableInitializer, T data);
S VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration, T data); S? VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration, T data);
S VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer, T data); S? VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer, T data);
S VisitSyntaxTree(SyntaxTree syntaxTree, T data); S? VisitSyntaxTree(SyntaxTree syntaxTree, T data);
S VisitSimpleType(SimpleType simpleType, T data); S? VisitSimpleType(SimpleType simpleType, T data);
S VisitMemberType(MemberType memberType, T data); S? VisitMemberType(MemberType memberType, T data);
S VisitTupleType(TupleAstType tupleType, T data); S? VisitTupleType(TupleAstType tupleType, T data);
S VisitTupleTypeElement(TupleTypeElement tupleTypeElement, T data); S? VisitTupleTypeElement(TupleTypeElement tupleTypeElement, T data);
S VisitFunctionPointerType(FunctionPointerAstType functionPointerType, T data); S? VisitFunctionPointerType(FunctionPointerAstType functionPointerType, T data);
S VisitInvocationType(InvocationAstType invocationType, T data); S? VisitInvocationType(InvocationAstType invocationType, T data);
S VisitComposedType(ComposedType composedType, T data); S? VisitComposedType(ComposedType composedType, T data);
S VisitArraySpecifier(ArraySpecifier arraySpecifier, T data); S? VisitArraySpecifier(ArraySpecifier arraySpecifier, T data);
S VisitPrimitiveType(PrimitiveType primitiveType, T data); S? VisitPrimitiveType(PrimitiveType primitiveType, T data);
S VisitComment(Comment comment, T data); S? VisitComment(Comment comment, T data);
S VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective, T data); S? VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective, T data);
S VisitDocumentationReference(DocumentationReference documentationReference, T data); S? VisitDocumentationReference(DocumentationReference documentationReference, T data);
S VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration, T data); S? VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration, T data);
S VisitConstraint(Constraint constraint, T data); S? VisitConstraint(Constraint constraint, T data);
S VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode, T data); S? VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode, T data);
S VisitIdentifier(Identifier identifier, T data); S? VisitIdentifier(Identifier identifier, T data);
S VisitInterpolation(Interpolation interpolation, T data); S? VisitInterpolation(Interpolation interpolation, T data);
S VisitInterpolatedStringText(InterpolatedStringText interpolatedStringText, T data); S? VisitInterpolatedStringText(InterpolatedStringText interpolatedStringText, T data);
S VisitSingleVariableDesignation(SingleVariableDesignation singleVariableDesignation, T data); S? VisitSingleVariableDesignation(SingleVariableDesignation singleVariableDesignation, T data);
S VisitParenthesizedVariableDesignation(ParenthesizedVariableDesignation parenthesizedVariableDesignation, T data); S? VisitParenthesizedVariableDesignation(ParenthesizedVariableDesignation parenthesizedVariableDesignation, T data);
S VisitNullNode(AstNode nullNode, T data); S? VisitNullNode(AstNode nullNode, T data);
S VisitErrorNode(AstNode errorNode, T data); S? VisitErrorNode(AstNode errorNode, T data);
S VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern, T data); S? VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern, T data);
} }
} }

2
ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/INode.cs

@ -25,7 +25,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching
/// </summary> /// </summary>
public interface INode public interface INode
{ {
Role Role { get; } Role? Role { get; }
INode? FirstChild { get; } INode? FirstChild { get; }
INode? NextSibling { get; } INode? NextSibling { get; }
bool IsNull { get; } bool IsNull { get; }

10
ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/Pattern.cs

@ -52,15 +52,15 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching
get { return false; } get { return false; }
} }
Role INode.Role { Role? INode.Role {
get { return null; } get { return null; }
} }
INode INode.NextSibling { INode? INode.NextSibling {
get { return null; } get { return null; }
} }
INode INode.FirstChild { INode? INode.FirstChild {
get { return null; } get { return null; }
} }
@ -80,8 +80,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching
stack.Push(new PossibleMatch(firstOtherChild, match.CheckPoint())); stack.Push(new PossibleMatch(firstOtherChild, match.CheckPoint()));
while (stack.Count > 0) while (stack.Count > 0)
{ {
INode cur1 = patternStack.Pop(); INode? cur1 = patternStack.Pop();
INode cur2 = stack.Peek().NextOther; INode? cur2 = stack.Peek().NextOther;
match.RestoreCheckPoint(stack.Pop().Checkpoint); match.RestoreCheckPoint(stack.Pop().Checkpoint);
bool success = true; bool success = true;
while (cur1 != null && success) while (cur1 != null && success)

2
ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/Repeat.cs

@ -44,7 +44,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching
this.MaxCount = int.MaxValue; this.MaxCount = int.MaxValue;
} }
public override bool DoMatchCollection(Role role, INode pos, Match match, BacktrackingInfo backtrackingInfo) public override bool DoMatchCollection(Role role, INode? pos, Match match, BacktrackingInfo backtrackingInfo)
{ {
var backtrackingStack = backtrackingInfo.backtrackingStack; var backtrackingStack = backtrackingInfo.backtrackingStack;
Debug.Assert(pos == null || pos.Role == role); Debug.Assert(pos == null || pos.Role == role);

6
ICSharpCode.Decompiler/CSharp/Syntax/Statements/Statement.cs

@ -63,7 +63,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
#endregion #endregion
#region PatternPlaceholder #region PatternPlaceholder
public static implicit operator Statement(PatternMatching.Pattern pattern) public static implicit operator Statement?(PatternMatching.Pattern? pattern)
{ {
return pattern != null ? new PatternPlaceholder(pattern) : null; return pattern != null ? new PatternPlaceholder(pattern) : null;
} }
@ -86,12 +86,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
visitor.VisitPatternPlaceholder(this, child); visitor.VisitPatternPlaceholder(this, child);
} }
public override T AcceptVisitor<T>(IAstVisitor<T> visitor) public override T? AcceptVisitor<T>(IAstVisitor<T> visitor)
{ {
return visitor.VisitPatternPlaceholder(this, child); return visitor.VisitPatternPlaceholder(this, child);
} }
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) public override S? AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitPatternPlaceholder(this, child, data); return visitor.VisitPatternPlaceholder(this, child, data);
} }

2
ICSharpCode.Decompiler/CSharp/Syntax/SyntaxExtensions.cs

@ -54,7 +54,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public static Statement GetNextStatement(this Statement statement) public static Statement GetNextStatement(this Statement statement)
{ {
AstNode next = statement.NextSibling; AstNode? next = statement.NextSibling;
while (next != null && !(next is Statement)) while (next != null && !(next is Statement))
next = next.NextSibling; next = next.NextSibling;
return (Statement)next; return (Statement)next;

2
ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/Accessor.cs

@ -76,7 +76,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary> /// </summary>
public CSharpTokenNode Keyword { public CSharpTokenNode Keyword {
get { get {
for (AstNode child = this.FirstChild; child != null; child = child.NextSibling) for (AstNode? child = this.FirstChild; child != null; child = child.NextSibling)
{ {
if (child.Role == PropertyDeclaration.GetKeywordRole || child.Role == PropertyDeclaration.SetKeywordRole if (child.Role == PropertyDeclaration.GetKeywordRole || child.Role == PropertyDeclaration.SetKeywordRole
|| child.Role == PropertyDeclaration.InitKeywordRole || child.Role == PropertyDeclaration.InitKeywordRole

2
ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/EntityDeclaration.cs

@ -89,7 +89,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
internal static void SetModifiers(AstNode node, Modifiers newValue) internal static void SetModifiers(AstNode node, Modifiers newValue)
{ {
Modifiers oldValue = GetModifiers(node); Modifiers oldValue = GetModifiers(node);
AstNode insertionPos = node.GetChildrenByRole(AttributeRole).LastOrDefault(); AstNode? insertionPos = node.GetChildrenByRole(AttributeRole).LastOrDefault();
foreach (Modifiers m in CSharpModifierToken.AllModifiers) foreach (Modifiers m in CSharpModifierToken.AllModifiers)
{ {
if ((m & newValue) != 0) if ((m & newValue) != 0)

2
ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/MethodDeclaration.cs

@ -70,7 +70,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public bool IsExtensionMethod { public bool IsExtensionMethod {
get { get {
ParameterDeclaration pd = (ParameterDeclaration)GetChildByRole(Roles.Parameter); ParameterDeclaration? pd = GetChildByRole(Roles.Parameter) as ParameterDeclaration;
return pd != null && pd.HasThisModifier; return pd != null && pd.HasThisModifier;
} }
} }

16
ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs

@ -462,13 +462,13 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
AstType ConvertTypeHelper(IType genericType, IReadOnlyList<IType> typeArguments) AstType ConvertTypeHelper(IType genericType, IReadOnlyList<IType> typeArguments)
{ {
ITypeDefinition typeDef = genericType.GetDefinition(); ITypeDefinition? typeDef = genericType.GetDefinition();
Debug.Assert(typeDef != null || genericType.Kind == TypeKind.Unknown); Debug.Assert(typeDef != null || genericType.Kind == TypeKind.Unknown);
Debug.Assert(typeArguments.Count >= genericType.TypeParameterCount); Debug.Assert(typeArguments.Count >= genericType.TypeParameterCount);
if (UseKeywordsForBuiltinTypes && typeDef != null) if (UseKeywordsForBuiltinTypes && typeDef != null)
{ {
string keyword = KnownTypeReference.GetCSharpNameByTypeCode(typeDef.KnownTypeCode); string? keyword = KnownTypeReference.GetCSharpNameByTypeCode(typeDef.KnownTypeCode);
if (keyword != null) if (keyword != null)
{ {
return new PrimitiveType(keyword); return new PrimitiveType(keyword);
@ -1053,7 +1053,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
} }
if (underlyingType.IsKnownType(KnownTypeCode.Double) || underlyingType.IsKnownType(KnownTypeCode.Single)) if (underlyingType.IsKnownType(KnownTypeCode.Double) || underlyingType.IsKnownType(KnownTypeCode.Single))
return ConvertFloatingPointLiteral(underlyingType, constantValue); return ConvertFloatingPointLiteral(underlyingType, constantValue);
IType literalType = underlyingType; IType? literalType = underlyingType;
bool integerTypeMismatch = underlyingType.IsCSharpSmallIntegerType() || underlyingType.IsCSharpNativeIntegerType(); bool integerTypeMismatch = underlyingType.IsCSharpSmallIntegerType() || underlyingType.IsCSharpNativeIntegerType();
if (integerTypeMismatch) if (integerTypeMismatch)
{ {
@ -1213,7 +1213,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
Expression ConvertEnumValue(IType type, long val) Expression ConvertEnumValue(IType type, long val)
{ {
ITypeDefinition enumDefinition = type.GetDefinition(); ITypeDefinition? enumDefinition = type.GetDefinition();
TypeCode enumBaseTypeCode = ReflectionHelper.GetTypeCode(enumDefinition.EnumUnderlyingType); TypeCode enumBaseTypeCode = ReflectionHelper.GetTypeCode(enumDefinition.EnumUnderlyingType);
var fields = enumDefinition.Fields var fields = enumDefinition.Fields
.Select(PrepareConstant) .Select(PrepareConstant)
@ -1295,7 +1295,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
{ {
if (!field.IsConst) if (!field.IsConst)
return (-1, null); return (-1, null);
object constantValue = field.GetConstantValue(); object? constantValue = field.GetConstantValue();
if (constantValue == null) if (constantValue == null)
return (-1, null); return (-1, null);
return ((long)CSharpPrimitiveCast.Cast(TypeCode.Int64, constantValue, checkForOverflow: false), field); return ((long)CSharpPrimitiveCast.Cast(TypeCode.Int64, constantValue, checkForOverflow: false), field);
@ -1890,7 +1890,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
DelegateDeclaration ConvertDelegate(IMethod invokeMethod, Modifiers modifiers) DelegateDeclaration ConvertDelegate(IMethod invokeMethod, Modifiers modifiers)
{ {
ITypeDefinition d = invokeMethod.DeclaringTypeDefinition; ITypeDefinition? d = invokeMethod.DeclaringTypeDefinition;
DelegateDeclaration decl = new DelegateDeclaration(); DelegateDeclaration decl = new DelegateDeclaration();
decl.Modifiers = modifiers & ~Modifiers.Sealed; decl.Modifiers = modifiers & ~Modifiers.Sealed;
@ -2019,7 +2019,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
decl.Modifiers = ModifierFromAccessibility(accessor.Accessibility); decl.Modifiers = ModifierFromAccessibility(accessor.Accessibility);
if (this.ShowModifiers && accessor.HasReadonlyModifier()) if (this.ShowModifiers && accessor.HasReadonlyModifier())
decl.Modifiers |= Modifiers.Readonly; decl.Modifiers |= Modifiers.Readonly;
TokenRole keywordRole = kind switch { TokenRole? keywordRole = kind switch {
MethodSemanticsAttributes.Getter => PropertyDeclaration.GetKeywordRole, MethodSemanticsAttributes.Getter => PropertyDeclaration.GetKeywordRole,
MethodSemanticsAttributes.Setter => PropertyDeclaration.SetKeywordRole, MethodSemanticsAttributes.Setter => PropertyDeclaration.SetKeywordRole,
MethodSemanticsAttributes.Adder => CustomEventDeclaration.AddKeywordRole, MethodSemanticsAttributes.Adder => CustomEventDeclaration.AddKeywordRole,
@ -2460,7 +2460,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
static bool IsObjectOrValueType(IType type) static bool IsObjectOrValueType(IType type)
{ {
ITypeDefinition d = type.GetDefinition(); ITypeDefinition? d = type.GetDefinition();
return d != null && (d.KnownTypeCode == KnownTypeCode.Object || d.KnownTypeCode == KnownTypeCode.ValueType); return d != null && (d.KnownTypeCode == KnownTypeCode.Object || d.KnownTypeCode == KnownTypeCode.ValueType);
} }
#endregion #endregion

6
ICSharpCode.Decompiler/CSharp/Transforms/AddCheckedBlocks.cs

@ -244,7 +244,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
BlockStatement? block = node as BlockStatement; BlockStatement? block = node as BlockStatement;
if (block == null) if (block == null)
{ {
for (AstNode child = node.FirstChild; child != null; child = child.NextSibling) for (AstNode? child = node.FirstChild; child != null; child = child.NextSibling)
{ {
Run(child, context); Run(child, context);
} }
@ -275,7 +275,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
InsertedNode? nodesUncheckedContextCheckedBlockOpen = null; InsertedNode? nodesUncheckedContextCheckedBlockOpen = null;
Statement? checkedBlockStart = null; Statement? checkedBlockStart = null;
Statement statement = block.Statements.FirstOrDefault(); Statement? statement = block.Statements.FirstOrDefault();
while (true) while (true)
{ {
// Blocks can be closed 'for free'. We use '<=' so that blocks are closed as late as possible (goal 4b) // Blocks can be closed 'for free'. We use '<=' so that blocks are closed as late as possible (goal 4b)
@ -340,7 +340,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
if (node is BlockStatement) if (node is BlockStatement)
return GetResultFromBlock((BlockStatement)node); return GetResultFromBlock((BlockStatement)node);
Result result = new Result(); Result result = new Result();
for (AstNode child = node.FirstChild; child != null; child = child.NextSibling) for (AstNode? child = node.FirstChild; child != null; child = child.NextSibling)
{ {
Result childResult = GetResult(child); Result childResult = GetResult(child);
result.CostInCheckedContext += childResult.CostInCheckedContext; result.CostInCheckedContext += childResult.CostInCheckedContext;

4
ICSharpCode.Decompiler/CSharp/Transforms/AddXmlDocumentationTransform.cs

@ -63,7 +63,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
static void InsertXmlDocumentation(AstNode node, StringReader r) static void InsertXmlDocumentation(AstNode node, StringReader r)
{ {
// Find the first non-empty line: // Find the first non-empty line:
string firstLine; string? firstLine;
do do
{ {
firstLine = r.ReadLine(); firstLine = r.ReadLine();
@ -71,7 +71,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
return; return;
} while (string.IsNullOrWhiteSpace(firstLine)); } while (string.IsNullOrWhiteSpace(firstLine));
string indentation = firstLine.Substring(0, firstLine.Length - firstLine.TrimStart().Length); string indentation = firstLine.Substring(0, firstLine.Length - firstLine.TrimStart().Length);
string line = firstLine; string? line = firstLine;
int skippedWhitespaceLines = 0; int skippedWhitespaceLines = 0;
// Copy all lines from input to output, except for empty lines at the end. // Copy all lines from input to output, except for empty lines at the end.
while (line != null) while (line != null)

4
ICSharpCode.Decompiler/CSharp/Transforms/CombineQueryExpressions.cs

@ -47,8 +47,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
void CombineQueries(AstNode node, Dictionary<string, object> fromOrLetIdentifiers) void CombineQueries(AstNode node, Dictionary<string, object> fromOrLetIdentifiers)
{ {
AstNode next; AstNode? next;
for (AstNode child = node.FirstChild; child != null; child = next) for (AstNode? child = node.FirstChild; child != null; child = next)
{ {
// store reference to next child before transformation // store reference to next child before transformation
next = child.NextSibling; next = child.NextSibling;

6
ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs

@ -297,7 +297,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
} }
try try
{ {
for (AstNode child = node.FirstChild; child != null; child = child.NextSibling) for (AstNode? child = node.FirstChild; child != null; child = child.NextSibling)
{ {
FindInsertionPoints(child, nodeLevel + 1); FindInsertionPoints(child, nodeLevel + 1);
} }
@ -321,7 +321,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
{ {
InsertionPoint newPoint; InsertionPoint newPoint;
int startIndex = scopeTracking.Count - 1; int startIndex = scopeTracking.Count - 1;
BlockContainer captureScope = variable.CaptureScope; BlockContainer? captureScope = variable.CaptureScope;
while (captureScope != null && !IsRelevantScope(captureScope)) while (captureScope != null && !IsRelevantScope(captureScope))
{ {
captureScope = BlockContainer.FindClosestContainer(captureScope.Parent); captureScope = BlockContainer.FindClosestContainer(captureScope.Parent);
@ -356,7 +356,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
} }
} }
} }
if (variableDict.TryGetValue(variable, out VariableToDeclare v)) if (variableDict.TryGetValue(variable, out VariableToDeclare? v))
{ {
v.InsertionPoint = FindCommonParent(v.InsertionPoint, newPoint); v.InsertionPoint = FindCommonParent(v.InsertionPoint, newPoint);
} }

4
ICSharpCode.Decompiler/CSharp/Transforms/FixNameCollisions.cs

@ -67,8 +67,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
{ {
if (node is IdentifierExpression || node is MemberReferenceExpression) if (node is IdentifierExpression || node is MemberReferenceExpression)
{ {
ISymbol symbol = node.GetSymbol(); ISymbol? symbol = node.GetSymbol();
if (symbol != null && renamedSymbols.TryGetValue(symbol, out string newName)) if (symbol != null && renamedSymbols.TryGetValue(symbol, out string? newName))
{ {
node.GetChildByRole(Roles.Identifier).Name = newName; node.GetChildByRole(Roles.Identifier).Name = newName;
} }

24
ICSharpCode.Decompiler/CSharp/Transforms/IntroduceQueryExpressions.cs

@ -88,8 +88,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
node.ReplaceWith(query); node.ReplaceWith(query);
} }
AstNode next; AstNode? next;
for (AstNode child = (query ?? node).FirstChild; child != null; child = next) for (AstNode? child = (query ?? node).FirstChild; child != null; child = next)
{ {
// store reference to next child before transformation // store reference to next child before transformation
next = child.NextSibling; next = child.NextSibling;
@ -103,7 +103,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
return context.Settings.Discards; return context.Settings.Discards;
} }
QueryExpression DecompileQuery(InvocationExpression invocation) QueryExpression? DecompileQuery(InvocationExpression? invocation)
{ {
if (invocation == null) if (invocation == null)
return null; return null;
@ -119,7 +119,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
if (!IsComplexQuery(mre)) if (!IsComplexQuery(mre))
return null; return null;
Expression expr = invocation.Arguments.Single(); Expression expr = invocation.Arguments.Single();
if (MatchSimpleLambda(expr, out ParameterDeclaration parameter, out Expression body)) if (MatchSimpleLambda(expr, out ParameterDeclaration? parameter, out Expression? body))
{ {
QueryExpression query = new QueryExpression(); QueryExpression query = new QueryExpression();
query.Clauses.Add(MakeFromClause(parameter, mre.Target.Detach())); query.Clauses.Add(MakeFromClause(parameter, mre.Target.Detach()));
@ -134,8 +134,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
{ {
Expression keyLambda = invocation.Arguments.ElementAt(0); Expression keyLambda = invocation.Arguments.ElementAt(0);
Expression projectionLambda = invocation.Arguments.ElementAt(1); Expression projectionLambda = invocation.Arguments.ElementAt(1);
if (MatchSimpleLambda(keyLambda, out ParameterDeclaration parameter1, out Expression keySelector) if (MatchSimpleLambda(keyLambda, out ParameterDeclaration? parameter1, out Expression? keySelector)
&& MatchSimpleLambda(projectionLambda, out ParameterDeclaration parameter2, out Expression elementSelector) && MatchSimpleLambda(projectionLambda, out ParameterDeclaration? parameter2, out Expression? elementSelector)
&& parameter1.Name == parameter2.Name) && parameter1.Name == parameter2.Name)
{ {
QueryExpression query = new QueryExpression(); QueryExpression query = new QueryExpression();
@ -152,7 +152,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
else if (invocation.Arguments.Count == 1) else if (invocation.Arguments.Count == 1)
{ {
Expression lambda = invocation.Arguments.Single(); Expression lambda = invocation.Arguments.Single();
if (MatchSimpleLambda(lambda, out ParameterDeclaration parameter, out Expression keySelector)) if (MatchSimpleLambda(lambda, out ParameterDeclaration? parameter, out Expression? keySelector))
{ {
QueryExpression query = new QueryExpression(); QueryExpression query = new QueryExpression();
query.Clauses.Add(MakeFromClause(parameter, mre.Target.Detach())); query.Clauses.Add(MakeFromClause(parameter, mre.Target.Detach()));
@ -167,7 +167,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
if (invocation.Arguments.Count != 2) if (invocation.Arguments.Count != 2)
return null; return null;
var fromExpressionLambda = invocation.Arguments.ElementAt(0); var fromExpressionLambda = invocation.Arguments.ElementAt(0);
if (!MatchSimpleLambda(fromExpressionLambda, out ParameterDeclaration parameter, out Expression collectionSelector)) if (!MatchSimpleLambda(fromExpressionLambda, out ParameterDeclaration? parameter, out Expression? collectionSelector))
return null; return null;
if (IsNullConditional(collectionSelector)) if (IsNullConditional(collectionSelector))
return null; return null;
@ -194,7 +194,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
if (!IsComplexQuery(mre)) if (!IsComplexQuery(mre))
return null; return null;
Expression expr = invocation.Arguments.Single(); Expression expr = invocation.Arguments.Single();
if (MatchSimpleLambda(expr, out ParameterDeclaration parameter, out Expression body)) if (MatchSimpleLambda(expr, out ParameterDeclaration? parameter, out Expression? body))
{ {
QueryExpression query = new QueryExpression(); QueryExpression query = new QueryExpression();
query.Clauses.Add(MakeFromClause(parameter, mre.Target.Detach())); query.Clauses.Add(MakeFromClause(parameter, mre.Target.Detach()));
@ -213,7 +213,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
if (!IsComplexQuery(mre)) if (!IsComplexQuery(mre))
return null; return null;
var lambda = invocation.Arguments.Single(); var lambda = invocation.Arguments.Single();
if (MatchSimpleLambda(lambda, out ParameterDeclaration parameter, out Expression orderExpression)) if (MatchSimpleLambda(lambda, out ParameterDeclaration? parameter, out Expression? orderExpression))
{ {
if (ValidateThenByChain(invocation, parameter.Name)) if (ValidateThenByChain(invocation, parameter.Name))
{ {
@ -257,10 +257,10 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
if (IsNullConditional(source2)) if (IsNullConditional(source2))
return null; return null;
Expression outerLambda = invocation.Arguments.ElementAt(1); Expression outerLambda = invocation.Arguments.ElementAt(1);
if (!MatchSimpleLambda(outerLambda, out ParameterDeclaration element1, out Expression key1)) if (!MatchSimpleLambda(outerLambda, out ParameterDeclaration? element1, out Expression? key1))
return null; return null;
Expression innerLambda = invocation.Arguments.ElementAt(2); Expression innerLambda = invocation.Arguments.ElementAt(2);
if (!MatchSimpleLambda(innerLambda, out ParameterDeclaration element2, out Expression key2)) if (!MatchSimpleLambda(innerLambda, out ParameterDeclaration? element2, out Expression? key2))
return null; return null;
LambdaExpression? lambda = invocation.Arguments.ElementAt(3) as LambdaExpression; LambdaExpression? lambda = invocation.Arguments.ElementAt(3) as LambdaExpression;
if (lambda != null && lambda.Parameters.Count == 2 && lambda.Body is Expression) if (lambda != null && lambda.Parameters.Count == 2 && lambda.Body is Expression)

8
ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs

@ -62,7 +62,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
// Go through the children, and keep visiting a node as long as it changes. // Go through the children, and keep visiting a node as long as it changes.
// Because some transforms delete/replace nodes before and after the node being transformed, we rely // Because some transforms delete/replace nodes before and after the node being transformed, we rely
// on the transform's return value to know where we need to keep iterating. // on the transform's return value to know where we need to keep iterating.
for (AstNode child = node.FirstChild; child != null; child = child.NextSibling) for (AstNode? child = node.FirstChild; child != null; child = child.NextSibling)
{ {
AstNode oldChild; AstNode oldChild;
do do
@ -88,7 +88,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
public override AstNode VisitForStatement(ForStatement forStatement) public override AstNode VisitForStatement(ForStatement forStatement)
{ {
AstNode result = TransformForeachOnArray(forStatement); AstNode? result = TransformForeachOnArray(forStatement);
if (result != null) if (result != null)
return result; return result;
return base.VisitForStatement(forStatement); return base.VisitForStatement(forStatement);
@ -174,7 +174,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
} }
}; };
public ForStatement TransformFor(ExpressionStatement node) public ForStatement? TransformFor(ExpressionStatement node)
{ {
if (!context.Settings.ForStatement) if (!context.Settings.ForStatement)
return null; return null;
@ -339,7 +339,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
return false; return false;
} }
Statement TransformForeachOnArray(ForStatement forStatement) Statement? TransformForeachOnArray(ForStatement forStatement)
{ {
if (!context.Settings.ForEachStatement) if (!context.Settings.ForEachStatement)
return null; return null;

4
ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs

@ -206,7 +206,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
Match m = fieldInitializerPattern.Match(instanceCtorsNotChainingWithThis[0].Body.FirstOrDefault()); Match m = fieldInitializerPattern.Match(instanceCtorsNotChainingWithThis[0].Body.FirstOrDefault());
if (!m.Success) if (!m.Success)
break; break;
IMember fieldOrPropertyOrEvent = (m.Get<AstNode>("fieldAccess").Single().GetSymbol() as IMember)?.MemberDefinition; IMember? fieldOrPropertyOrEvent = (m.Get<AstNode>("fieldAccess").Single().GetSymbol() as IMember)?.MemberDefinition;
if (!(fieldOrPropertyOrEvent is IField) && !(fieldOrPropertyOrEvent is IProperty) && !(fieldOrPropertyOrEvent is IEvent)) if (!(fieldOrPropertyOrEvent is IField) && !(fieldOrPropertyOrEvent is IProperty) && !(fieldOrPropertyOrEvent is IEvent))
break; break;
var fieldOrPropertyOrEventDecl = members.FirstOrDefault(f => f.GetSymbol() == fieldOrPropertyOrEvent) as EntityDeclaration; var fieldOrPropertyOrEventDecl = members.FirstOrDefault(f => f.GetSymbol() == fieldOrPropertyOrEvent) as EntityDeclaration;
@ -346,7 +346,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
AssignmentExpression? assignment = es.Expression as AssignmentExpression; AssignmentExpression? assignment = es.Expression as AssignmentExpression;
if (assignment == null || assignment.Operator != AssignmentOperatorType.Assign) if (assignment == null || assignment.Operator != AssignmentOperatorType.Assign)
break; break;
IMember fieldOrProperty = (assignment.Left.GetSymbol() as IMember)?.MemberDefinition; IMember? fieldOrProperty = (assignment.Left.GetSymbol() as IMember)?.MemberDefinition;
if (!(fieldOrProperty is IField || fieldOrProperty is IProperty) || !fieldOrProperty.IsStatic) if (!(fieldOrProperty is IField || fieldOrProperty is IProperty) || !fieldOrProperty.IsStatic)
break; break;
// Only move fields that are constants, if the declaring type is not marked beforefieldinit. // Only move fields that are constants, if the declaring type is not marked beforefieldinit.

2
ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

@ -156,7 +156,7 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
if (descendant == Expression) if (descendant == Expression)
return this; return this;
for (AstNode parent = descendant.Parent; parent != null; parent = parent.Parent) for (AstNode? parent = descendant.Parent; parent != null; parent = parent.Parent)
{ {
foreach (var inst in parent.Annotations.OfType<ILInstruction>()) foreach (var inst in parent.Annotations.OfType<ILInstruction>())
descendant.AddAnnotation(inst); descendant.AddAnnotation(inst);

2
ICSharpCode.Decompiler/CSharp/TypeSystem/ResolvedUsingScope.cs

@ -70,7 +70,7 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem
public INamespace Namespace { public INamespace Namespace {
get { get {
INamespace result = LazyInit.VolatileRead(ref this.@namespace); INamespace? result = LazyInit.VolatileRead(ref this.@namespace);
if (result != null) if (result != null)
{ {
return result; return result;

10
ICSharpCode.Decompiler/DecompilerException.cs

@ -98,7 +98,7 @@ namespace ICSharpCode.Decompiler
static string GetTypeName(Exception exception) static string GetTypeName(Exception exception)
{ {
string type = exception.GetType().FullName; string? type = exception.GetType().FullName;
if (exception is ExternalException || exception is IOException) if (exception is ExternalException || exception is IOException)
return type + " (" + Marshal.GetHRForException(exception).ToString("x8") + ")"; return type + " (" + Marshal.GetHRForException(exception).ToString("x8") + ")";
else else
@ -114,8 +114,8 @@ namespace ICSharpCode.Decompiler
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
for (int i = 0; i < stackTrace.FrameCount; i++) for (int i = 0; i < stackTrace.FrameCount; i++)
{ {
StackFrame frame = stackTrace.GetFrame(i); StackFrame? frame = stackTrace.GetFrame(i);
MethodBase method = frame.GetMethod(); MethodBase? method = frame.GetMethod();
if (method == null) if (method == null)
continue; continue;
@ -123,7 +123,7 @@ namespace ICSharpCode.Decompiler
b.AppendLine(); b.AppendLine();
b.Append(" at "); b.Append(" at ");
Type declaringType = method.DeclaringType; Type? declaringType = method.DeclaringType;
if (declaringType != null) if (declaringType != null)
{ {
b.Append(declaringType.FullName.Replace('+', '.')); b.Append(declaringType.FullName.Replace('+', '.'));
@ -173,7 +173,7 @@ namespace ICSharpCode.Decompiler
string? filename = null; string? filename = null;
try try
{ {
string fullpath = frame.GetFileName(); string? fullpath = frame.GetFileName();
if (fullpath != null) if (fullpath != null)
filename = Path.GetFileName(fullpath); filename = Path.GetFileName(fullpath);
} }

8
ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs

@ -1040,10 +1040,10 @@ namespace ICSharpCode.Decompiler.Disassembler
output.Write("lpstruct"); output.Write("lpstruct");
break; break;
case 0x2c: // CustomMarshaler case 0x2c: // CustomMarshaler
string guidValue = blob.ReadSerializedString(); string? guidValue = blob.ReadSerializedString();
string unmanagedType = blob.ReadSerializedString(); string? unmanagedType = blob.ReadSerializedString();
string managedType = blob.ReadSerializedString(); string? managedType = blob.ReadSerializedString();
string cookie = blob.ReadSerializedString(); string? cookie = blob.ReadSerializedString();
var guid = !string.IsNullOrEmpty(guidValue) ? new Guid(guidValue) : Guid.Empty; var guid = !string.IsNullOrEmpty(guidValue) ? new Guid(guidValue) : Guid.Empty;

2
ICSharpCode.Decompiler/Documentation/GetPotentiallyNestedClassTypeReference.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.Decompiler.Documentation
{ {
if (asm == null) if (asm == null)
continue; continue;
ITypeDefinition typeDef = asm.GetTypeDefinition(new TopLevelTypeName(ns, name, topLevelTPC)); ITypeDefinition? typeDef = asm.GetTypeDefinition(new TopLevelTypeName(ns, name, topLevelTPC));
for (int j = i + 1; j < parts.Length && typeDef != null; j++) for (int j = i + 1; j < parts.Length && typeDef != null; j++)
{ {
int tpc = (j == parts.Length - 1 ? typeParameterCount : 0); int tpc = (j == parts.Length - 1 ? typeParameterCount : 0);

2
ICSharpCode.Decompiler/Documentation/IdStringProvider.cs

@ -155,7 +155,7 @@ namespace ICSharpCode.Decompiler.Documentation
b.Append('@'); b.Append('@');
break; break;
default: default:
IType declType = type.DeclaringType; IType? declType = type.DeclaringType;
if (declType != null) if (declType != null)
{ {
AppendTypeName(b, declType, explicitInterfaceImpl); AppendTypeName(b, declType, explicitInterfaceImpl);

2
ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs

@ -54,7 +54,7 @@ namespace ICSharpCode.Decompiler.Documentation
throw new ArgumentNullException(nameof(module)); throw new ArgumentNullException(nameof(module));
lock (cache) lock (cache)
{ {
if (!cache.TryGetValue(module, out XmlDocumentationProvider xmlDoc)) if (!cache.TryGetValue(module, out XmlDocumentationProvider? xmlDoc))
{ {
string xmlDocFile = LookupLocalizedXmlDoc(module.FileName); string xmlDocFile = LookupLocalizedXmlDoc(module.FileName);
if (xmlDocFile == null) if (xmlDocFile == null)

4
ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs

@ -1084,8 +1084,8 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
bool IsBuilderFieldOnThis(ILInstruction inst) bool IsBuilderFieldOnThis(ILInstruction inst)
{ {
IField field; IField? field;
ILInstruction target; ILInstruction? target;
if (builderType.IsReferenceType == true) if (builderType.IsReferenceType == true)
{ {
// ldfld(StateMachine::<>t__builder, ldloc(this)) // ldfld(StateMachine::<>t__builder, ldloc(this))

12
ICSharpCode.Decompiler/IL/ControlFlow/AwaitInCatchTransform.cs

@ -102,7 +102,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
break; break;
case SwitchSection jumpTableEntry: case SwitchSection jumpTableEntry:
Debug.Assert(switchInstructionOpt == null || jumpTableEntry.Parent == switchInstructionOpt); Debug.Assert(switchInstructionOpt == null || jumpTableEntry.Parent == switchInstructionOpt);
switchInstructionOpt = (SwitchInstruction)jumpTableEntry.Parent; switchInstructionOpt = jumpTableEntry.Parent as SwitchInstruction;
break; break;
} }
@ -142,7 +142,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
if (result.NextBlockOrExitContainer is Block nextBlock && nextBlock.IncomingEdgeCount == 0) if (result.NextBlockOrExitContainer is Block nextBlock && nextBlock.IncomingEdgeCount == 0)
{ {
List<Block> dependentBlocks = new List<Block>(); List<Block> dependentBlocks = new List<Block>();
Block current = nextBlock; Block? current = nextBlock;
do do
{ {
@ -201,8 +201,8 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
{ {
ILVariable? v = null; ILVariable? v = null;
if (MatchExceptionCaptureBlock(context, block, if (MatchExceptionCaptureBlock(context, block,
ref v, out StLoc typedExceptionVariableStore, ref v, out StLoc? typedExceptionVariableStore,
out Block captureBlock, out Block throwBlock)) out Block? captureBlock, out Block? throwBlock))
{ {
context.Step($"ExceptionDispatchInfo.Capture({v.Name}).Throw() => throw;", typedExceptionVariableStore); context.Step($"ExceptionDispatchInfo.Capture({v.Name}).Throw() => throw;", typedExceptionVariableStore);
block.Instructions.RemoveRange(typedExceptionVariableStore.ChildIndex + 1, 2); block.Instructions.RemoveRange(typedExceptionVariableStore.ChildIndex + 1, 2);
@ -355,7 +355,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
return false; return false;
} }
bool ParseIfJumpTable(int id, Block jumpTableEntryBlock, ILVariable identifierVariable, out Block? realEntryPoint, out ILInstruction? nextBlockOrExitContainer, out ILInstruction? jumpTableEntry) bool ParseIfJumpTable(int id, Block jumpTableEntryBlock, ILVariable identifierVariable, [NotNullWhen(true)] out Block? realEntryPoint, out ILInstruction? nextBlockOrExitContainer, [NotNullWhen(true)] out ILInstruction? jumpTableEntry)
{ {
realEntryPoint = null; realEntryPoint = null;
nextBlockOrExitContainer = null; nextBlockOrExitContainer = null;
@ -420,7 +420,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
// => // =>
// throw(ldloc result.Handler.Variable) // throw(ldloc result.Handler.Variable)
internal static bool MatchExceptionCaptureBlock(ILTransformContext context, Block block, internal static bool MatchExceptionCaptureBlock(ILTransformContext context, Block block,
ref ILVariable objectVariable, out StLoc? typedExceptionVariableStore, out Block? captureBlock, out Block? throwBlock) ref ILVariable? objectVariable, out StLoc? typedExceptionVariableStore, out Block? captureBlock, out Block? throwBlock)
{ {
bool DerivesFromException(IType t) => t.GetAllBaseTypes().Any(ty => ty.IsKnownType(KnownTypeCode.Exception)); bool DerivesFromException(IType t) => t.GetAllBaseTypes().Any(ty => ty.IsKnownType(KnownTypeCode.Exception));

4
ICSharpCode.Decompiler/IL/ControlFlow/AwaitInFinallyTransform.cs

@ -81,7 +81,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
// stloc V_6(ldloc V_3) - store exception in 'global' object variable // stloc V_6(ldloc V_3) - store exception in 'global' object variable
// br IL_0075 - jump out of catch block to the head of the finallyBlock // br IL_0075 - jump out of catch block to the head of the finallyBlock
var catchBlockEntry = catchBlockContainer.EntryPoint; var catchBlockEntry = catchBlockContainer.EntryPoint;
ILVariable objectVariable; ILVariable? objectVariable;
switch (catchBlockEntry.Instructions.Count) switch (catchBlockEntry.Instructions.Count)
{ {
case 2: case 2:
@ -127,7 +127,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
StateRangeAnalysis sra = new StateRangeAnalysis(StateRangeAnalysisMode.AwaitInFinally, null, stateVariable); StateRangeAnalysis sra = new StateRangeAnalysis(StateRangeAnalysisMode.AwaitInFinally, null, stateVariable);
sra.AssignStateRanges(noThrowBlock, Util.LongSet.Universe); sra.AssignStateRanges(noThrowBlock, Util.LongSet.Universe);
var mapping = sra.GetBlockStateSetMapping((BlockContainer)noThrowBlock.Parent); var mapping = sra.GetBlockStateSetMapping(noThrowBlock.Parent as BlockContainer);
var mappingForLeave = sra.GetBlockStateSetMappingForLeave(); var mappingForLeave = sra.GetBlockStateSetMappingForLeave();
context.StepStartGroup("Inline finally block with await", tryCatch.Handlers[0]); context.StepStartGroup("Inline finally block with await", tryCatch.Handlers[0]);

8
ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs

@ -45,9 +45,9 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
Other Other
} }
private BlockTransformContext context; private BlockTransformContext? context;
private ControlFlowNode cfgNode; private ControlFlowNode? cfgNode;
private BlockContainer currentContainer; private BlockContainer? currentContainer;
/// <summary> /// <summary>
/// Builds structured control flow for the block associated with the control flow node. /// Builds structured control flow for the block associated with the control flow node.
@ -59,7 +59,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
public void Run(Block block, BlockTransformContext context) public void Run(Block block, BlockTransformContext context)
{ {
this.context = context; this.context = context;
currentContainer = (BlockContainer)block.Parent; currentContainer = block.Parent as BlockContainer;
// We only embed blocks into this block if they aren't referenced anywhere else, // We only embed blocks into this block if they aren't referenced anywhere else,
// so those blocks are dominated by this block. // so those blocks are dominated by this block.

8
ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs

@ -120,11 +120,11 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
// (where 'v' has no other uses) // (where 'v' has no other uses)
// Simplify these to a simple `ret(<inst>)` so that they match the release build version. // Simplify these to a simple `ret(<inst>)` so that they match the release build version.
// //
if (block.Instructions.Count == 2 && block.Instructions[1].MatchReturn(out ILInstruction value)) if (block.Instructions.Count == 2 && block.Instructions[1].MatchReturn(out ILInstruction? value))
{ {
var ret = (Leave)block.Instructions[1]; var ret = (Leave)block.Instructions[1];
if (value.MatchLdLoc(out ILVariable v) if (value.MatchLdLoc(out ILVariable? v)
&& v.IsSingleDefinition && v.LoadCount == 1 && block.Instructions[0].MatchStLoc(v, out ILInstruction inst)) && v.IsSingleDefinition && v.LoadCount == 1 && block.Instructions[0].MatchStLoc(v, out ILInstruction? inst))
{ {
context.Step("Inline variable in return block", block); context.Step("Inline variable in return block", block);
inst.AddILRange(ret.Value); inst.AddILRange(ret.Value);
@ -228,7 +228,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
if (!value.MatchLdLoc(out var returnVar)) if (!value.MatchLdLoc(out var returnVar))
return false; return false;
var container = branch.TargetContainer; var container = branch.TargetContainer;
for (ILInstruction inst = branch; inst != container; inst = inst.Parent) for (ILInstruction? inst = branch; inst != container; inst = inst.Parent)
{ {
if (inst.Parent is TryFinally tryFinally && inst.SlotInfo == TryFinally.TryBlockSlot) if (inst.Parent is TryFinally tryFinally && inst.SlotInfo == TryFinally.TryBlockSlot)
{ {

2
ICSharpCode.Decompiler/IL/ControlFlow/DetectPinnedRegions.cs

@ -106,7 +106,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
for (int j = 0; j < block.Instructions.Count - 1; j++) for (int j = 0; j < block.Instructions.Count - 1; j++)
{ {
var inst = block.Instructions[j]; var inst = block.Instructions[j];
if (inst.MatchStLoc(out ILVariable v, out var value) && v.Kind == VariableKind.PinnedLocal) if (inst.MatchStLoc(out ILVariable? v, out var value) && v.Kind == VariableKind.PinnedLocal)
{ {
if (block.Instructions[j + 1].OpCode != OpCode.Branch) if (block.Instructions[j + 1].OpCode != OpCode.Branch)
{ {

16
ICSharpCode.Decompiler/IL/Transforms/CachedDelegateInitialization.cs

@ -88,9 +88,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms
if (trueInst == null || trueInst.Instructions.Count != 1 || !inst.FalseInst.MatchNop()) if (trueInst == null || trueInst.Instructions.Count != 1 || !inst.FalseInst.MatchNop())
return false; return false;
var storeInst = trueInst.Instructions[0]; var storeInst = trueInst.Instructions[0];
if (!inst.Condition.MatchCompEquals(out ILInstruction left, out ILInstruction right) || !left.MatchLdsFld(out IField field) || !right.MatchLdNull()) if (!inst.Condition.MatchCompEquals(out ILInstruction? left, out ILInstruction? right) || !left.MatchLdsFld(out IField? field) || !right.MatchLdNull())
return false; return false;
if (!storeInst.MatchStsFld(out IField field2, out ILInstruction value) || !field.Equals(field2) || !field.IsCompilerGeneratedOrIsInCompilerGeneratedClass()) if (!storeInst.MatchStsFld(out IField? field2, out ILInstruction? value) || !field.Equals(field2) || !field.IsCompilerGeneratedOrIsInCompilerGeneratedClass())
return false; return false;
if (!DelegateConstruction.MatchDelegateConstruction(value.UnwrapConv(ConversionKind.Invalid) as NewObj, out _, out _, out _, true)) if (!DelegateConstruction.MatchDelegateConstruction(value.UnwrapConv(ConversionKind.Invalid) as NewObj, out _, out _, out _, true))
return false; return false;
@ -117,10 +117,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Block? trueInst = inst.TrueInst as Block; Block? trueInst = inst.TrueInst as Block;
if (trueInst == null || (trueInst.Instructions.Count != 1) || !inst.FalseInst.MatchNop()) if (trueInst == null || (trueInst.Instructions.Count != 1) || !inst.FalseInst.MatchNop())
return false; return false;
if (!inst.Condition.MatchCompEquals(out ILInstruction left, out ILInstruction right) || !left.MatchLdLoc(out ILVariable v) || !right.MatchLdNull()) if (!inst.Condition.MatchCompEquals(out ILInstruction? left, out ILInstruction? right) || !left.MatchLdLoc(out ILVariable? v) || !right.MatchLdNull())
return false; return false;
var storeInst = trueInst.Instructions.Last(); var storeInst = trueInst.Instructions.Last();
if (!storeInst.MatchStLoc(v, out ILInstruction value)) if (!storeInst.MatchStLoc(v, out ILInstruction? value))
return false; return false;
if (!DelegateConstruction.MatchDelegateConstruction(value as NewObj, out _, out _, out _, true)) if (!DelegateConstruction.MatchDelegateConstruction(value as NewObj, out _, out _, out _, true))
return false; return false;
@ -157,7 +157,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Block? trueInst = inst.TrueInst as Block; Block? trueInst = inst.TrueInst as Block;
if (trueInst == null || (trueInst.Instructions.Count != 1) || !inst.FalseInst.MatchNop()) if (trueInst == null || (trueInst.Instructions.Count != 1) || !inst.FalseInst.MatchNop())
return false; return false;
if (!inst.Condition.MatchCompEquals(out ILInstruction left, out ILInstruction right) || !left.MatchLdLoc(out ILVariable s) || !right.MatchLdNull()) if (!inst.Condition.MatchCompEquals(out ILInstruction? left, out ILInstruction? right) || !left.MatchLdLoc(out ILVariable? s) || !right.MatchLdNull())
return false; return false;
var storeInst = trueInst.Instructions.Last() as StLoc; var storeInst = trueInst.Instructions.Last() as StLoc;
var storeBeforeIf = inst.Parent.Children.ElementAtOrDefault(inst.ChildIndex - 1) as StLoc; var storeBeforeIf = inst.Parent.Children.ElementAtOrDefault(inst.ChildIndex - 1) as StLoc;
@ -189,7 +189,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Block? trueInst = inst.TrueInst as Block; Block? trueInst = inst.TrueInst as Block;
if (trueInst == null || (trueInst.Instructions.Count != 1) || !inst.FalseInst.MatchNop()) if (trueInst == null || (trueInst.Instructions.Count != 1) || !inst.FalseInst.MatchNop())
return false; return false;
if (!inst.Condition.MatchCompEquals(out ILInstruction left, out ILInstruction right) || !left.MatchLdLoc(out ILVariable s) || !right.MatchLdNull()) if (!inst.Condition.MatchCompEquals(out ILInstruction? left, out ILInstruction? right) || !left.MatchLdLoc(out ILVariable? s) || !right.MatchLdNull())
return false; return false;
var storeInst = trueInst.Instructions.Last() as StLoc; var storeInst = trueInst.Instructions.Last() as StLoc;
var storeBeforeIf = inst.Parent.Children.ElementAtOrDefault(inst.ChildIndex - 1) as StLoc; var storeBeforeIf = inst.Parent.Children.ElementAtOrDefault(inst.ChildIndex - 1) as StLoc;
@ -240,7 +240,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{ {
return false; return false;
} }
if (!inst.Condition.MatchCompEquals(out ILInstruction left, out ILInstruction right) || !right.MatchLdNull()) if (!inst.Condition.MatchCompEquals(out ILInstruction? left, out ILInstruction? right) || !right.MatchLdNull())
return false; return false;
if (!ldobj.Match(left).Success) if (!ldobj.Match(left).Success)
return false; return false;
@ -311,7 +311,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{ {
return false; return false;
} }
if (!inst.Condition.MatchCompNotEqualsNull(out ILInstruction left)) if (!inst.Condition.MatchCompNotEqualsNull(out ILInstruction? left))
return false; return false;
if (!ldobj.Match(left).Success) if (!ldobj.Match(left).Success)
return false; return false;

2
ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs

@ -65,7 +65,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{ {
for (int i = 0; i < block.Instructions.Count; i++) for (int i = 0; i < block.Instructions.Count; i++)
{ {
if (block.Instructions[i].MatchStLoc(out ILVariable v, out ILInstruction copiedExpr)) if (block.Instructions[i].MatchStLoc(out ILVariable? v, out ILInstruction? copiedExpr))
{ {
if (v.IsSingleDefinition && v.LoadCount == 0 && v.Kind == VariableKind.StackSlot) if (v.IsSingleDefinition && v.LoadCount == 0 && v.Kind == VariableKind.StackSlot)
{ {

3
ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs

@ -104,7 +104,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
// This transform is required because ILInlining only works with stloc/ldloc // This transform is required because ILInlining only works with stloc/ldloc
internal static bool StObjToStLoc(StObj inst, ILTransformContext context) internal static bool StObjToStLoc(StObj inst, ILTransformContext context)
{ {
if (inst.Target.MatchLdLoca(out ILVariable v) if (inst.Target.MatchLdLoca(out ILVariable? v)
&& TypeUtils.IsCompatibleTypeForMemoryAccess(v.Type, inst.Type) && TypeUtils.IsCompatibleTypeForMemoryAccess(v.Type, inst.Type)
&& inst.UnalignedPrefix == 0 && inst.UnalignedPrefix == 0
&& !inst.IsVolatile) && !inst.IsVolatile)
@ -222,6 +222,5 @@ namespace ICSharpCode.Decompiler.IL.Transforms
} }
return false; return false;
} }
} }
} }

4
ICSharpCode.Decompiler/IL/Transforms/IndexRangeTransform.cs

@ -38,7 +38,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{ {
if (!context.Settings.Ranges) if (!context.Settings.Ranges)
return false; return false;
if (!ldelema.Array.MatchLdLoc(out ILVariable array)) if (!ldelema.Array.MatchLdLoc(out ILVariable? array))
return false; return false;
if (ldelema.Indices.Count != 1) if (ldelema.Indices.Count != 1)
return false; // the index/range feature doesn't support multi-dimensional arrays return false; // the index/range feature doesn't support multi-dimensional arrays
@ -176,7 +176,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
} }
// stloc startOffsetVar(call GetOffset(startIndexLoad, ldloc length)) // stloc startOffsetVar(call GetOffset(startIndexLoad, ldloc length))
if (!(block.Instructions[pos].MatchStLoc(out ILVariable startOffsetVar, out ILInstruction startOffsetVarInit) if (!(block.Instructions[pos].MatchStLoc(out ILVariable? startOffsetVar, out ILInstruction? startOffsetVarInit)
&& startOffsetVar.IsSingleDefinition && startOffsetVar.StackType == StackType.I4)) && startOffsetVar.IsSingleDefinition && startOffsetVar.StackType == StackType.I4))
{ {
// Not our primary indexing/slicing pattern. // Not our primary indexing/slicing pattern.

67
ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs

@ -106,9 +106,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms
context.Step("Remove hashtable initializer", actual); context.Step("Remove hashtable initializer", actual);
if (jumpToNext != null) if (jumpToNext != null)
{ {
actual.Instructions.SecondToLastOrDefault().ReplaceWith(jumpToNext); actual.Instructions.SecondToLastOrDefault()?.ReplaceWith(jumpToNext);
} }
actual.Instructions.LastOrDefault().ReplaceWith(new Branch(next)); actual.Instructions.LastOrDefault()?.ReplaceWith(new Branch(next));
omittedBlocks.Add(containingBlock, previous); omittedBlocks.Add(containingBlock, previous);
changedContainers.Add(body); changedContainers.Add(body);
} }
@ -196,7 +196,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
ExtensionMethods.Swap(ref firstBlockOrDefaultJump, ref nextCaseJump); ExtensionMethods.Swap(ref firstBlockOrDefaultJump, ref nextCaseJump);
} }
// match call to operator ==(string, string) // match call to operator ==(string, string)
if (!MatchStringEqualityComparison(condition, out var switchValueVar, out string firstBlockValue, out bool isVBCompareString)) if (!MatchStringEqualityComparison(condition, out var switchValueVar, out string? firstBlockValue, out bool isVBCompareString))
return false; return false;
if (isVBCompareString) if (isVBCompareString)
{ {
@ -217,13 +217,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; return false;
} }
var values = new List<(string, ILInstruction)>(); var values = new List<(string?, ILInstruction)>();
var uniqueValues = new HashSet<string>(); var uniqueValues = new HashSet<string?>();
int numberOfUniqueMatchesWithCurrentVariable = 0; int numberOfUniqueMatchesWithCurrentVariable = 0;
HashSet<Block> caseBlocks = new HashSet<Block>(); HashSet<Block> caseBlocks = new HashSet<Block>();
caseBlocks.Add((Block)instructions[i].Parent); caseBlocks.Add((Block)instructions[i].Parent);
bool AddSwitchSection(string value, ILInstruction inst) bool AddSwitchSection(string? value, ILInstruction inst)
{ {
if (!uniqueValues.Add(value)) if (!uniqueValues.Add(value))
return false; return false;
@ -306,14 +306,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms
} }
} }
// if instruction must be followed by a branch to the next case // if instruction must be followed by a branch to the next case
if (!nextCaseJump.MatchBranch(out Block currentCaseBlock)) if (!nextCaseJump.MatchBranch(out Block? currentCaseBlock))
return false; return false;
// extract all cases and add them to the values list. // extract all cases and add them to the values list.
ILInstruction nextCaseBlock; ILInstruction nextCaseBlock;
do do
{ {
nextCaseBlock = MatchCaseBlock(currentCaseBlock, switchValueVar, out string value, out bool emptyStringEqualsNull, out ILInstruction block); (nextCaseBlock, var block) = MatchCaseBlock(currentCaseBlock, switchValueVar, out string? value, out bool emptyStringEqualsNull);
if (nextCaseBlock == null) if (nextCaseBlock == null || block == null)
break; break;
if (emptyStringEqualsNull && string.IsNullOrEmpty(value)) if (emptyStringEqualsNull && string.IsNullOrEmpty(value))
{ {
@ -474,7 +474,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return true; return true;
} }
bool IsIsInternedCall(Call call, [NotNullWhen(true)] out ILInstruction? argument) bool IsIsInternedCall(Call? call, [NotNullWhen(true)] out ILInstruction? argument)
{ {
if (call != null if (call != null
&& call.Method.DeclaringType.IsKnownType(KnownTypeCode.String) && call.Method.DeclaringType.IsKnownType(KnownTypeCode.String)
@ -504,19 +504,20 @@ namespace ICSharpCode.Decompiler.IL.Transforms
/// The <paramref name="switchVariable"/> is updated if the value gets copied to a different variable. /// The <paramref name="switchVariable"/> is updated if the value gets copied to a different variable.
/// See comments below for more info. /// See comments below for more info.
/// </summary> /// </summary>
ILInstruction? MatchCaseBlock(Block currentBlock, ILVariable switchVariable, out string? value, out bool emptyStringEqualsNull, out ILInstruction? caseBlockOrLeave)
(ILInstruction? NextBlock, ILInstruction? CaseBlockOrLeave) MatchCaseBlock(Block currentBlock, ILVariable switchVariable, out string? value, out bool emptyStringEqualsNull)
{ {
value = null; value = null;
caseBlockOrLeave = null; ILInstruction? caseBlockOrLeave = null;
emptyStringEqualsNull = false; emptyStringEqualsNull = false;
if (currentBlock.IncomingEdgeCount != 1 || currentBlock.Instructions.Count != 2) if (currentBlock.IncomingEdgeCount != 1 || currentBlock.Instructions.Count != 2)
return null; return (null, null);
if (!currentBlock.MatchIfAtEndOfBlock(out var condition, out var caseBlockBranch, out var nextBlockBranch)) if (!currentBlock.MatchIfAtEndOfBlock(out var condition, out var caseBlockBranch, out var nextBlockBranch))
return null; return (null, null);
if (!MatchStringEqualityComparison(condition, switchVariable, out value, out bool isVBCompareString)) if (!MatchStringEqualityComparison(condition, switchVariable, out value, out bool isVBCompareString))
{ {
return null; return (null, null);
} }
if (isVBCompareString) if (isVBCompareString)
{ {
@ -533,21 +534,21 @@ namespace ICSharpCode.Decompiler.IL.Transforms
} }
else else
{ {
return null; return (null, null);
} }
if (nextBlockBranch.MatchBranch(out Block? nextBlock)) if (nextBlockBranch.MatchBranch(out Block? nextBlock))
{ {
// success // success
return nextBlock; return (nextBlock, caseBlockOrLeave);
} }
else if (nextBlockBranch.MatchLeave(out BlockContainer? blockContainer)) else if (nextBlockBranch.MatchLeave(out BlockContainer? blockContainer))
{ {
// success // success
return blockContainer; return (blockContainer, caseBlockOrLeave);
} }
else else
{ {
return null; return (null, caseBlockOrLeave);
} }
} }
@ -1030,20 +1031,20 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; return false;
} }
var stringValues = new List<(string Value, ILInstruction TargetBlockOrLeave)>(); var stringValues = new List<(string? Value, ILInstruction TargetBlockOrLeave)>();
SwitchSection defaultSection = switchInst.GetDefaultSection(); SwitchSection defaultSection = switchInst.GetDefaultSection();
if (!(defaultSection.Body.MatchBranch(out Block exitOrDefaultBlock) || defaultSection.Body.MatchLeave(out _))) if (!(defaultSection.Body.MatchBranch(out Block? exitOrDefaultBlock) || defaultSection.Body.MatchLeave(out _)))
return false; return false;
foreach (var section in switchInst.Sections) foreach (var section in switchInst.Sections)
{ {
if (section == defaultSection) if (section == defaultSection)
continue; continue;
// extract target block // extract target block
if (!section.Body.MatchBranch(out Block target)) if (!section.Body.MatchBranch(out Block? target))
return false; return false;
string stringValue; string? stringValue;
bool emptyStringEqualsNull; bool emptyStringEqualsNull;
if (MatchRoslynEmptyStringCaseBlockHead(target, switchValueLoad.Variable, out ILInstruction targetOrLeave, out Block currentExitBlock)) if (MatchRoslynEmptyStringCaseBlockHead(target, switchValueLoad.Variable, out ILInstruction? targetOrLeave, out Block? currentExitBlock))
{ {
stringValue = ""; stringValue = "";
emptyStringEqualsNull = false; emptyStringEqualsNull = false;
@ -1168,7 +1169,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
// implements https://github.com/dotnet/roslyn/pull/66081 // implements https://github.com/dotnet/roslyn/pull/66081
// if (comp(ldloc switchValueVar == ldnull)) br nullCase // if (comp(ldloc switchValueVar == ldnull)) br nullCase
// br nextBlock // br nextBlock
Block switchOnLengthBlock; Block? switchOnLengthBlock;
int switchOnLengthBlockStartOffset; int switchOnLengthBlockStartOffset;
Block? nullCase = null; Block? nullCase = null;
if (instructions[i].MatchIfInstruction(out var condition, out var exitBlockJump) if (instructions[i].MatchIfInstruction(out var condition, out var exitBlockJump)
@ -1206,7 +1207,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Block? defaultCase = null; Block? defaultCase = null;
if (!MatchSwitchOnLengthBlock(ref switchValueVar, switchOnLengthBlock, switchOnLengthBlockStartOffset, out var blocksByLength)) if (!MatchSwitchOnLengthBlock(ref switchValueVar, switchOnLengthBlock, switchOnLengthBlockStartOffset, out var blocksByLength))
return false; return false;
List<(string, ILInstruction)> stringValues = new(); List<(string?, ILInstruction)> stringValues = new();
foreach (var b in blocksByLength) foreach (var b in blocksByLength)
{ {
if (b.Length.Count() != 1) if (b.Length.Count() != 1)
@ -1231,7 +1232,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
} }
} }
} }
else if (MatchRoslynCaseBlockHead(b.TargetBlock, switchValueVar, out var bodyOrLeave, out var exit, out string stringValue, out _)) else if (MatchRoslynCaseBlockHead(b.TargetBlock, switchValueVar, out var bodyOrLeave, out var exit, out string? stringValue, out _))
{ {
if (exit != defaultCase) if (exit != defaultCase)
return false; return false;
@ -1269,7 +1270,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
context.Step(nameof(MatchRoslynSwitchOnStringUsingLengthAndChar), instructions[i]); context.Step(nameof(MatchRoslynSwitchOnStringUsingLengthAndChar), instructions[i]);
var defaultLabel = new LongSet(new LongInterval(0, stringValues.Count)).Invert(); var defaultLabel = new LongSet(new LongInterval(0, stringValues.Count)).Invert();
var values = new string[stringValues.Count]; var values = new string?[stringValues.Count];
var sections = new SwitchSection[stringValues.Count]; var sections = new SwitchSection[stringValues.Count];
foreach (var (idx, (value, bodyInstruction)) in stringValues.WithIndex()) foreach (var (idx, (value, bodyInstruction)) in stringValues.WithIndex())
{ {
@ -1400,7 +1401,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return results?.Count > 0; return results?.Count > 0;
} }
bool MatchSwitchOnLengthBlock(ref ILVariable switchValueVar, Block switchOnLengthBlock, int startOffset, [NotNullWhen(true)] out List<(LongSet Length, Block TargetBlock)>? blocks) bool MatchSwitchOnLengthBlock(ref ILVariable? switchValueVar, Block switchOnLengthBlock, int startOffset, out List<(LongSet Length, Block TargetBlock)>? blocks)
{ {
blocks = null; blocks = null;
SwitchInstruction? @switch; SwitchInstruction? @switch;
@ -1476,6 +1477,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
default: default:
return false; return false;
} }
if (@switch == null) if (@switch == null)
return true; return true;
blocks = new(@switch.Sections.Count); blocks = new(@switch.Sections.Count);
@ -1507,7 +1509,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
/// br newDefaultBlock /// br newDefaultBlock
/// } /// }
/// </summary> /// </summary>
private bool IsNullCheckInDefaultBlock(ref Block exitOrDefaultBlock, ILVariable switchVar, [NotNullWhen(true)] out Block? nullValueCaseBlock) private bool IsNullCheckInDefaultBlock(ref Block? exitOrDefaultBlock, ILVariable switchVar, [NotNullWhen(true)] out Block? nullValueCaseBlock)
{ {
nullValueCaseBlock = null; nullValueCaseBlock = null;
if (exitOrDefaultBlock == null) if (exitOrDefaultBlock == null)
@ -1533,7 +1535,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
/// if (call op_Equality(ldloc switchValueVar, stringValue)) br body /// if (call op_Equality(ldloc switchValueVar, stringValue)) br body
/// br exit /// br exit
/// </summary> /// </summary>
bool MatchRoslynCaseBlockHead(Block target, ILVariable switchValueVar, [NotNullWhen(true)] out ILInstruction? bodyOrLeave, [NotNullWhen(true)] out Block? defaultOrExitBlock, [NotNullWhen(true)] out string? stringValue, out bool emptyStringEqualsNull) bool MatchRoslynCaseBlockHead(Block target, ILVariable switchValueVar, [NotNullWhen(true)] out ILInstruction? bodyOrLeave, out Block? defaultOrExitBlock, out string? stringValue, out bool emptyStringEqualsNull)
{ {
bodyOrLeave = null; bodyOrLeave = null;
defaultOrExitBlock = null; defaultOrExitBlock = null;
@ -1593,7 +1595,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
/// br exit /// br exit
/// } /// }
/// </summary> /// </summary>
bool MatchRoslynEmptyStringCaseBlockHead(Block target, ILVariable switchValueVar, [NotNullWhen(true)] out ILInstruction? bodyOrLeave, [NotNullWhen(true)] out Block? defaultOrExitBlock) bool MatchRoslynEmptyStringCaseBlockHead(Block target, ILVariable switchValueVar, [NotNullWhen(true)] out ILInstruction? bodyOrLeave, out Block? defaultOrExitBlock)
{ {
bodyOrLeave = null; bodyOrLeave = null;
defaultOrExitBlock = null; defaultOrExitBlock = null;
@ -1628,6 +1630,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; return false;
if (bodyBranch.MatchLeave(out _)) if (bodyBranch.MatchLeave(out _))
{ {
bodyOrLeave = bodyBranch; bodyOrLeave = bodyBranch;
return true; return true;
} }

6
ICSharpCode.Decompiler/Semantics/ConstantResolveResult.cs

@ -32,9 +32,9 @@ namespace ICSharpCode.Decompiler.Semantics
/// </summary> /// </summary>
public class ConstantResolveResult : ResolveResult public class ConstantResolveResult : ResolveResult
{ {
object constantValue; object? constantValue;
public ConstantResolveResult(IType type, object constantValue) : base(type) public ConstantResolveResult(IType type, object? constantValue) : base(type)
{ {
this.constantValue = constantValue; this.constantValue = constantValue;
} }
@ -43,7 +43,7 @@ namespace ICSharpCode.Decompiler.Semantics
get { return true; } get { return true; }
} }
public override object ConstantValue { public override object? ConstantValue {
get { return constantValue; } get { return constantValue; }
} }

2
ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs

@ -227,7 +227,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <summary> /// <summary>
/// Gets the type code for the specified type, or TypeCode.Empty if none of the other type codes match. /// Gets the type code for the specified type, or TypeCode.Empty if none of the other type codes match.
/// </summary> /// </summary>
public static TypeCode GetTypeCode(this IType type) public static TypeCode GetTypeCode(this IType? type)
{ {
ITypeDefinition? def = type as ITypeDefinition; ITypeDefinition? def = type as ITypeDefinition;
if (def != null) if (def != null)

4
ICSharpCode.Decompiler/TypeSystem/TaskType.cs

@ -74,8 +74,8 @@ namespace ICSharpCode.Decompiler.TypeSystem
var arg = attribute.FixedArguments[0]; var arg = attribute.FixedArguments[0];
if (!arg.Type.IsKnownType(KnownTypeCode.Type)) if (!arg.Type.IsKnownType(KnownTypeCode.Type))
return false; return false;
builderType = (IType)arg.Value; builderType = arg.Value as IType;
return true; return builderType != null;
} }
return false; return false;
} }

2
ILSpy.BamlDecompiler/BamlResourceNodeFactory.cs

@ -35,7 +35,7 @@ namespace ILSpy.BamlDecompiler
[PartCreationPolicy(CreationPolicy.Shared)] [PartCreationPolicy(CreationPolicy.Shared)]
public sealed class BamlResourceNodeFactory : IResourceNodeFactory public sealed class BamlResourceNodeFactory : IResourceNodeFactory
{ {
public ITreeNode CreateNode(Resource resource) public ITreeNode? CreateNode(Resource resource)
{ {
if (resource.Name.EndsWith(".baml", StringComparison.OrdinalIgnoreCase)) if (resource.Name.EndsWith(".baml", StringComparison.OrdinalIgnoreCase))
return new BamlResourceEntryNode(resource.Name, resource.TryOpenStream); return new BamlResourceEntryNode(resource.Name, resource.TryOpenStream);

4
ILSpy/Languages/ILAstLanguage.cs

@ -39,9 +39,9 @@ namespace ICSharpCode.ILSpy
/// </summary> /// </summary>
abstract class ILAstLanguage : Language abstract class ILAstLanguage : Language
{ {
public event EventHandler StepperUpdated; public event EventHandler? StepperUpdated;
protected virtual void OnStepperUpdated(EventArgs e = null) protected virtual void OnStepperUpdated(EventArgs? e = null)
{ {
StepperUpdated?.Invoke(this, e ?? new EventArgs()); StepperUpdated?.Invoke(this, e ?? new EventArgs());
} }

14
ILSpy/MainWindow.xaml.cs

@ -44,6 +44,7 @@ using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem.Implementation; using ICSharpCode.Decompiler.TypeSystem.Implementation;
using ICSharpCode.ILSpy.AppEnv; using ICSharpCode.ILSpy.AppEnv;
using ICSharpCode.ILSpy.Commands; using ICSharpCode.ILSpy.Commands;
using ICSharpCode.ILSpy.Controls.TreeView;
using ICSharpCode.ILSpy.Docking; using ICSharpCode.ILSpy.Docking;
using ICSharpCode.ILSpy.Options; using ICSharpCode.ILSpy.Options;
using ICSharpCode.ILSpy.Search; using ICSharpCode.ILSpy.Search;
@ -51,16 +52,15 @@ using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.Themes; using ICSharpCode.ILSpy.Themes;
using ICSharpCode.ILSpy.TreeNodes; using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpy.Updates; using ICSharpCode.ILSpy.Updates;
using ICSharpCode.ILSpy.Util;
using ICSharpCode.ILSpy.ViewModels; using ICSharpCode.ILSpy.ViewModels;
using ICSharpCode.ILSpyX; using ICSharpCode.ILSpyX;
using ICSharpCode.ILSpyX.Extensions;
using ICSharpCode.ILSpyX.FileLoaders; using ICSharpCode.ILSpyX.FileLoaders;
using ICSharpCode.ILSpyX.Settings; using ICSharpCode.ILSpyX.Settings;
using ICSharpCode.ILSpy.Controls.TreeView; using ICSharpCode.ILSpyX.TreeView;
using ICSharpCode.ILSpy.Util;
using ICSharpCode.ILSpyX.Extensions;
using Microsoft.Win32; using Microsoft.Win32;
using ICSharpCode.ILSpyX.TreeView;
using TomsToolbox.Composition; using TomsToolbox.Composition;
@ -749,10 +749,10 @@ namespace ICSharpCode.ILSpy
} }
} }
internal static IEntity FindEntityInRelevantAssemblies(string navigateTo, IEnumerable<LoadedAssembly> relevantAssemblies) internal static IEntity? FindEntityInRelevantAssemblies(string navigateTo, IEnumerable<LoadedAssembly> relevantAssemblies)
{ {
ITypeReference typeRef = null; ITypeReference? typeRef = null;
IMemberReference memberRef = null; IMemberReference? memberRef = null;
if (navigateTo.StartsWith("T:", StringComparison.Ordinal)) if (navigateTo.StartsWith("T:", StringComparison.Ordinal))
{ {
typeRef = IdStringProvider.ParseTypeName(navigateTo); typeRef = IdStringProvider.ParseTypeName(navigateTo);

2
ILSpy/TextView/DocumentationUIBuilder.cs

@ -128,7 +128,7 @@ namespace ICSharpCode.ILSpy.TextView
AddBlock(block); AddBlock(block);
} }
public void AddXmlDocumentation(string xmlDocumentation, IEntity declaringEntity, Func<string, IEntity> resolver) public void AddXmlDocumentation(string xmlDocumentation, IEntity declaringEntity, Func<string, IEntity?> resolver)
{ {
if (xmlDocumentation == null) if (xmlDocumentation == null)
return; return;

4
ILSpy/TreeNodes/ResourceNodes/CursorResourceEntryNode.cs

@ -36,7 +36,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
{ {
static readonly string[] imageFileExtensions = { ".cur" }; static readonly string[] imageFileExtensions = { ".cur" };
public ITreeNode CreateNode(Resource resource) public ITreeNode? CreateNode(Resource resource)
{ {
string key = resource.Name; string key = resource.Name;
foreach (string fileExt in imageFileExtensions) foreach (string fileExt in imageFileExtensions)
@ -70,7 +70,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
return false; return false;
//HACK: windows imaging does not understand that .cur files have the same layout as .ico //HACK: windows imaging does not understand that .cur files have the same layout as .ico
// so load to data, and modify the ResourceType in the header to make look like an icon... // so load to data, and modify the ResourceType in the header to make look like an icon...
MemoryStream s = data as MemoryStream; MemoryStream? s = data as MemoryStream;
if (s == null) if (s == null)
{ {
// data was stored in another stream type (e.g. PinnedBufferedMemoryStream) // data was stored in another stream type (e.g. PinnedBufferedMemoryStream)

2
ILSpy/TreeNodes/ResourceNodes/IResourceNodeFactory.cs

@ -26,6 +26,6 @@ namespace ICSharpCode.ILSpy.TreeNodes
/// </summary> /// </summary>
public interface IResourceNodeFactory public interface IResourceNodeFactory
{ {
ITreeNode CreateNode(Resource resource); ITreeNode? CreateNode(Resource resource);
} }
} }

4
ILSpy/TreeNodes/ResourceNodes/IconResourceEntryNode.cs

@ -34,7 +34,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
[PartCreationPolicy(CreationPolicy.Shared)] [PartCreationPolicy(CreationPolicy.Shared)]
sealed class IconResourceNodeFactory : IResourceNodeFactory sealed class IconResourceNodeFactory : IResourceNodeFactory
{ {
public ITreeNode CreateNode(Resource resource) public ITreeNode? CreateNode(Resource resource)
{ {
if (resource.Name.EndsWith(".ico", StringComparison.OrdinalIgnoreCase)) if (resource.Name.EndsWith(".ico", StringComparison.OrdinalIgnoreCase))
{ {
@ -46,7 +46,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
sealed class IconResourceEntryNode : ResourceEntryNode sealed class IconResourceEntryNode : ResourceEntryNode
{ {
public IconResourceEntryNode(string key, Func<Stream> data) public IconResourceEntryNode(string key, Func<Stream?> data)
: base(key, data) : base(key, data)
{ {
} }

4
ILSpy/TreeNodes/ResourceNodes/ImageListResourceEntryNode.cs

@ -31,12 +31,12 @@ namespace ICSharpCode.ILSpy.TreeNodes
[PartCreationPolicy(CreationPolicy.Shared)] [PartCreationPolicy(CreationPolicy.Shared)]
sealed class ImageListResourceEntryNodeFactory : IResourceNodeFactory sealed class ImageListResourceEntryNodeFactory : IResourceNodeFactory
{ {
public ITreeNode CreateNode(Resource resource) public ITreeNode? CreateNode(Resource resource)
{ {
return null; return null;
} }
public ILSpyTreeNode CreateNode(string key, object data) public ILSpyTreeNode? CreateNode(string key, object data)
{ {
if (data is ImageListStreamer) if (data is ImageListStreamer)
return new ImageListResourceEntryNode(key, (ImageListStreamer)data); return new ImageListResourceEntryNode(key, (ImageListStreamer)data);

4
ILSpy/TreeNodes/ResourceNodes/ImageResourceEntryNode.cs

@ -36,7 +36,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
{ {
static readonly string[] imageFileExtensions = { ".png", ".gif", ".bmp", ".jpg" }; static readonly string[] imageFileExtensions = { ".png", ".gif", ".bmp", ".jpg" };
public ITreeNode CreateNode(Resource resource) public ITreeNode? CreateNode(Resource resource)
{ {
string key = resource.Name; string key = resource.Name;
foreach (string fileExt in imageFileExtensions) foreach (string fileExt in imageFileExtensions)
@ -50,7 +50,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
sealed class ImageResourceEntryNode : ResourceEntryNode sealed class ImageResourceEntryNode : ResourceEntryNode
{ {
public ImageResourceEntryNode(string key, Func<Stream> openStream) public ImageResourceEntryNode(string key, Func<Stream?> openStream)
: base(key, openStream) : base(key, openStream)
{ {
} }

11
ILSpy/TreeNodes/ResourceNodes/ResourceEntryNode.cs

@ -34,18 +34,18 @@ namespace ICSharpCode.ILSpy.TreeNodes
public class ResourceEntryNode : ILSpyTreeNode public class ResourceEntryNode : ILSpyTreeNode
{ {
private readonly string key; private readonly string key;
private readonly Func<Stream> openStream; private readonly Func<Stream?> openStream;
public override object Text => Language.EscapeName(key); public override object Text => Language.EscapeName(key);
public override object Icon => Images.Resource; public override object Icon => Images.Resource;
protected Stream OpenStream() protected Stream? OpenStream()
{ {
return openStream(); return openStream();
} }
public ResourceEntryNode(string key, Func<Stream> openStream) public ResourceEntryNode(string key, Func<Stream?> openStream)
{ {
if (key == null) if (key == null)
throw new ArgumentNullException(nameof(key)); throw new ArgumentNullException(nameof(key));
@ -57,7 +57,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
public static ILSpyTreeNode Create(Resource resource) public static ILSpyTreeNode Create(Resource resource)
{ {
ILSpyTreeNode result = null; ILSpyTreeNode? result = null;
foreach (var factory in App.ExportProvider.GetExportedValues<IResourceNodeFactory>()) foreach (var factory in App.ExportProvider.GetExportedValues<IResourceNodeFactory>())
{ {
result = factory.CreateNode(resource) as ILSpyTreeNode; result = factory.CreateNode(resource) as ILSpyTreeNode;
@ -78,13 +78,14 @@ namespace ICSharpCode.ILSpy.TreeNodes
language.WriteCommentLine(output, string.Format("{0} = {1}", key, data)); language.WriteCommentLine(output, string.Format("{0} = {1}", key, data));
} }
public override bool Save(ViewModels.TabPageModel tabPage) public override bool Save(ViewModels.TabPageModel? tabPage)
{ {
SaveFileDialog dlg = new SaveFileDialog(); SaveFileDialog dlg = new SaveFileDialog();
dlg.FileName = Path.GetFileName(WholeProjectDecompiler.SanitizeFileName(key)); dlg.FileName = Path.GetFileName(WholeProjectDecompiler.SanitizeFileName(key));
if (dlg.ShowDialog() == true) if (dlg.ShowDialog() == true)
{ {
using var data = OpenStream(); using var data = OpenStream();
using var fs = dlg.OpenFile(); using var fs = dlg.OpenFile();
data.CopyTo(fs); data.CopyTo(fs);
} }

4
ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs

@ -41,7 +41,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
[PartCreationPolicy(CreationPolicy.Shared)] [PartCreationPolicy(CreationPolicy.Shared)]
sealed class ResourcesFileTreeNodeFactory : IResourceNodeFactory sealed class ResourcesFileTreeNodeFactory : IResourceNodeFactory
{ {
public ITreeNode CreateNode(Resource resource) public ITreeNode? CreateNode(Resource resource)
{ {
if (resource.Name.EndsWith(".resources", StringComparison.OrdinalIgnoreCase)) if (resource.Name.EndsWith(".resources", StringComparison.OrdinalIgnoreCase))
{ {
@ -50,7 +50,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
return null; return null;
} }
public ILSpyTreeNode CreateNode(string key, object data) public ILSpyTreeNode? CreateNode(string key, object data)
{ {
return null; return null;
} }

6
ILSpy/TreeNodes/ResourceNodes/XamlResourceNode.cs

@ -34,7 +34,7 @@ namespace ICSharpCode.ILSpy.Xaml
[PartCreationPolicy(CreationPolicy.Shared)] [PartCreationPolicy(CreationPolicy.Shared)]
sealed class XamlResourceNodeFactory : IResourceNodeFactory sealed class XamlResourceNodeFactory : IResourceNodeFactory
{ {
public ITreeNode CreateNode(Resource resource) public ITreeNode? CreateNode(Resource resource)
{ {
if (resource.Name.EndsWith(".xaml", StringComparison.OrdinalIgnoreCase)) if (resource.Name.EndsWith(".xaml", StringComparison.OrdinalIgnoreCase))
return new XamlResourceEntryNode(resource.Name, resource.TryOpenStream); return new XamlResourceEntryNode(resource.Name, resource.TryOpenStream);
@ -45,9 +45,9 @@ namespace ICSharpCode.ILSpy.Xaml
sealed class XamlResourceEntryNode : ResourceEntryNode sealed class XamlResourceEntryNode : ResourceEntryNode
{ {
string xaml; string? xaml;
public XamlResourceEntryNode(string key, Func<Stream> openStream) : base(key, openStream) public XamlResourceEntryNode(string key, Func<Stream?> openStream) : base(key, openStream)
{ {
} }

8
ILSpy/TreeNodes/ResourceNodes/XmlResourceNode.cs

@ -36,7 +36,7 @@ namespace ICSharpCode.ILSpy.Xaml
{ {
private readonly static string[] xmlFileExtensions = { ".xml", ".xsd", ".xslt" }; private readonly static string[] xmlFileExtensions = { ".xml", ".xsd", ".xslt" };
public ITreeNode CreateNode(Resource resource) public ITreeNode? CreateNode(Resource resource)
{ {
string key = resource.Name; string key = resource.Name;
foreach (string fileExt in xmlFileExtensions) foreach (string fileExt in xmlFileExtensions)
@ -50,9 +50,9 @@ namespace ICSharpCode.ILSpy.Xaml
sealed class XmlResourceEntryNode : ResourceEntryNode sealed class XmlResourceEntryNode : ResourceEntryNode
{ {
string xml; string? xml;
public XmlResourceEntryNode(string key, Func<Stream> data) public XmlResourceEntryNode(string key, Func<Stream?> data)
: base(key, data) : base(key, data)
{ {
} }
@ -74,7 +74,7 @@ namespace ICSharpCode.ILSpy.Xaml
public override bool View(TabPageModel tabPage) public override bool View(TabPageModel tabPage)
{ {
AvalonEditTextOutput output = new AvalonEditTextOutput(); AvalonEditTextOutput output = new AvalonEditTextOutput();
IHighlightingDefinition highlighting = null; IHighlightingDefinition? highlighting = null;
tabPage.ShowTextView(textView => textView.RunWithCancellation( tabPage.ShowTextView(textView => textView.RunWithCancellation(
token => Task.Factory.StartNew( token => Task.Factory.StartNew(

4
ILSpy/Views/DebugSteps.xaml.cs

@ -48,7 +48,7 @@ namespace ICSharpCode.ILSpy
#endif #endif
} }
private void WritingOptions_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) private void WritingOptions_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{ {
DecompileAsync(lastSelectedStep); DecompileAsync(lastSelectedStep);
} }
@ -80,7 +80,7 @@ namespace ICSharpCode.ILSpy
#endif #endif
} }
private void ILAstStepperUpdated(object sender, EventArgs e) private void ILAstStepperUpdated(object? sender, EventArgs? e)
{ {
#if DEBUG #if DEBUG
if (language == null) if (language == null)

Loading…
Cancel
Save