Browse Source

Merge b63837e466 into 64cbcd4002

pull/3287/merge
Andrew Moskevitz 9 months ago committed by GitHub
parent
commit
b1507fcede
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 60
      .editorconfig
  2. 6
      ICSharpCode.BamlDecompiler/Baml/BamlContext.cs
  3. 2
      ICSharpCode.BamlDecompiler/Baml/BamlNode.cs
  4. 2
      ICSharpCode.BamlDecompiler/Baml/BamlReader.cs
  5. 4
      ICSharpCode.BamlDecompiler/BamlDecompilerSettings.cs
  6. 10
      ICSharpCode.BamlDecompiler/BamlElement.cs
  7. 2
      ICSharpCode.BamlDecompiler/Handlers/Blocks/ConstructorParametersHandler.cs
  8. 2
      ICSharpCode.BamlDecompiler/Handlers/Blocks/DocumentHandler.cs
  9. 2
      ICSharpCode.BamlDecompiler/Handlers/Blocks/ElementHandler.cs
  10. 2
      ICSharpCode.BamlDecompiler/Handlers/Blocks/KeyElementStartHandler.cs
  11. 2
      ICSharpCode.BamlDecompiler/Handlers/Blocks/PropertyArrayHandler.cs
  12. 2
      ICSharpCode.BamlDecompiler/Handlers/Blocks/PropertyComplexHandler.cs
  13. 2
      ICSharpCode.BamlDecompiler/Handlers/Blocks/PropertyDictionaryHandler.cs
  14. 2
      ICSharpCode.BamlDecompiler/Handlers/Blocks/PropertyListHandler.cs
  15. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/AssemblyInfoHandler.cs
  16. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/AttributeInfoHandler.cs
  17. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/ConnectionIdHandler.cs
  18. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/ConstructorParameterTypeHandler.cs
  19. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/ContentPropertyHandler.cs
  20. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/DefAttributeHandler.cs
  21. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/DefAttributeKeyStringHandler.cs
  22. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/DefAttributeKeyTypeHandler.cs
  23. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/DeferableContentStartHandler.cs
  24. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/LineNumberAndPositionHandler.cs
  25. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/LinePositionHandler.cs
  26. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/LiteralContentHandler.cs
  27. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/OptimizedStaticResourceHandler.cs
  28. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/PIMappingHandler.cs
  29. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/PresentationOptionsAttributeHandler.cs
  30. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/PropertyCustomHandler.cs
  31. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/PropertyHandler.cs
  32. 5
      ICSharpCode.BamlDecompiler/Handlers/Records/PropertyTypeReferenceHandler.cs
  33. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/PropertyWithExtensionHandler.cs
  34. 6
      ICSharpCode.BamlDecompiler/Handlers/Records/PropertyWithStaticResourceIdHandler.cs
  35. 6
      ICSharpCode.BamlDecompiler/Handlers/Records/StaticResourceIdHandler.cs
  36. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/StaticResourceStartHandler.cs
  37. 4
      ICSharpCode.BamlDecompiler/Handlers/Records/TextHandler.cs
  38. 4
      ICSharpCode.BamlDecompiler/Handlers/Records/TypeInfoHandler.cs
  39. 2
      ICSharpCode.BamlDecompiler/Handlers/Records/XmlnsPropertyHandler.cs
  40. 1
      ICSharpCode.BamlDecompiler/ICSharpCode.BamlDecompiler.csproj
  41. 2
      ICSharpCode.BamlDecompiler/IHandlers.cs
  42. 13
      ICSharpCode.BamlDecompiler/Rewrite/ConnectionIdRewritePass.cs
  43. 6
      ICSharpCode.BamlDecompiler/Xaml/NamespaceMap.cs
  44. 2
      ICSharpCode.BamlDecompiler/Xaml/XamlProperty.cs
  45. 6
      ICSharpCode.BamlDecompiler/Xaml/XamlResourceKey.cs
  46. 6
      ICSharpCode.BamlDecompiler/Xaml/XamlType.cs
  47. 11
      ICSharpCode.BamlDecompiler/XamlContext.cs
  48. 5
      ICSharpCode.BamlDecompiler/XmlnsDictionary.cs
  49. 2
      ICSharpCode.Decompiler.PowerShell/GetDecompiledProjectCmdlet.cs
  50. 1
      ICSharpCode.Decompiler.PowerShell/ICSharpCode.Decompiler.PowerShell.csproj
  51. 2
      ICSharpCode.Decompiler.Tests/Semantics/OverloadResolutionTests.cs
  52. 8
      ICSharpCode.Decompiler/CSharp/Annotations.cs
  53. 34
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  54. 74
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs
  55. 50
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  56. 2
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpAmbience.cs
  57. 24
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs
  58. 2
      ICSharpCode.Decompiler/CSharp/OutputVisitor/GenericGrammarAmbiguityVisitor.cs
  59. 4
      ICSharpCode.Decompiler/CSharp/OutputVisitor/ITokenWriter.cs
  60. 12
      ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs
  61. 10
      ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs
  62. 2
      ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertRequiredSpacesDecorator.cs
  63. 10
      ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertSpecialsDecorator.cs
  64. 6
      ICSharpCode.Decompiler/CSharp/OutputVisitor/TextWriterTokenWriter.cs
  65. 2
      ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs
  66. 4
      ICSharpCode.Decompiler/CSharp/ProjectDecompiler/TargetFramework.cs
  67. 10
      ICSharpCode.Decompiler/CSharp/ProjectDecompiler/TargetServices.cs
  68. 26
      ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs
  69. 56
      ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs
  70. 6
      ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs
  71. 8
      ICSharpCode.Decompiler/CSharp/Resolver/AwaitResolveResult.cs
  72. 56
      ICSharpCode.Decompiler/CSharp/Resolver/CSharpConversions.cs
  73. 8
      ICSharpCode.Decompiler/CSharp/Resolver/CSharpInvocationResolveResult.cs
  74. 119
      ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs
  75. 2
      ICSharpCode.Decompiler/CSharp/Resolver/DynamicInvocationResolveResult.cs
  76. 4
      ICSharpCode.Decompiler/CSharp/Resolver/LambdaResolveResult.cs
  77. 48
      ICSharpCode.Decompiler/CSharp/Resolver/MemberLookup.cs
  78. 16
      ICSharpCode.Decompiler/CSharp/Resolver/MethodGroupResolveResult.cs
  79. 50
      ICSharpCode.Decompiler/CSharp/Resolver/OverloadResolution.cs
  80. 62
      ICSharpCode.Decompiler/CSharp/Resolver/TypeInference.cs
  81. 4
      ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs
  82. 38
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  83. 14
      ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs
  84. 20
      ICSharpCode.Decompiler/CSharp/Syntax/AstNodeCollection.cs
  85. 14
      ICSharpCode.Decompiler/CSharp/Syntax/AstType.cs
  86. 6
      ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs
  87. 10
      ICSharpCode.Decompiler/CSharp/Syntax/CSharpTokenNode.cs
  88. 14
      ICSharpCode.Decompiler/CSharp/Syntax/ComposedType.cs
  89. 276
      ICSharpCode.Decompiler/CSharp/Syntax/DepthFirstAstVisitor.cs
  90. 4
      ICSharpCode.Decompiler/CSharp/Syntax/DocumentationReference.cs
  91. 6
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousMethodExpression.cs
  92. 2
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousTypeCreateExpression.cs
  93. 4
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayCreateExpression.cs
  94. 8
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayInitializerExpression.cs
  95. 4
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AsExpression.cs
  96. 4
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AssignmentExpression.cs
  97. 4
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/BaseReferenceExpression.cs
  98. 4
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/BinaryOperatorExpression.cs
  99. 4
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/CastExpression.cs
  100. 4
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/CheckedExpression.cs
  101. Some files were not shown because too many files have changed in this diff Show More

60
.editorconfig

@ -147,3 +147,63 @@ dotnet_naming_rule.private_fields_rule.symbols = private_fields_symbols @@ -147,3 +147,63 @@ dotnet_naming_rule.private_fields_rule.symbols = private_fields_symbols
# MEF006: No importing constructor
dotnet_diagnostic.MEF006.severity = silent
dotnet_diagnostic.IDE2003.severity = silent
#nullability diagnostics
dotnet_diagnostic.CS8597.severity = error
dotnet_diagnostic.CS8600.severity = warning
dotnet_diagnostic.CS8601.severity = warning
dotnet_diagnostic.CS8602.severity = warning
dotnet_diagnostic.CS8603.severity = warning
dotnet_diagnostic.CS8604.severity = warning
dotnet_diagnostic.CS8605.severity = warning
dotnet_diagnostic.CS8606.severity = error
dotnet_diagnostic.CS8607.severity = error
dotnet_diagnostic.CS8608.severity = error
dotnet_diagnostic.CS8609.severity = error
dotnet_diagnostic.CS8610.severity = error
dotnet_diagnostic.CS8611.severity = error
dotnet_diagnostic.CS8612.severity = error
dotnet_diagnostic.CS8613.severity = error
dotnet_diagnostic.CS8614.severity = error
dotnet_diagnostic.CS8615.severity = error
dotnet_diagnostic.CS8617.severity = warning
dotnet_diagnostic.CS8618.severity = warning
dotnet_diagnostic.CS8619.severity = warning
dotnet_diagnostic.CS8620.severity = warning
dotnet_diagnostic.CS8621.severity = error
dotnet_diagnostic.CS8622.severity = error
dotnet_diagnostic.CS8624.severity = error
dotnet_diagnostic.CS8625.severity = error
dotnet_diagnostic.CS8629.severity = warning
dotnet_diagnostic.CS8631.severity = warning
dotnet_diagnostic.CS8633.severity = error
dotnet_diagnostic.CS8634.severity = error
dotnet_diagnostic.CS8643.severity = error
dotnet_diagnostic.CS8644.severity = error
dotnet_diagnostic.CS8645.severity = error
dotnet_diagnostic.CS8655.severity = error
dotnet_diagnostic.CS8667.severity = error
dotnet_diagnostic.CS8670.severity = error
dotnet_diagnostic.CS8714.severity = error
dotnet_diagnostic.CS8762.severity = error
dotnet_diagnostic.CS8763.severity = error
dotnet_diagnostic.CS8764.severity = error
dotnet_diagnostic.CS8765.severity = error
dotnet_diagnostic.CS8766.severity = error
dotnet_diagnostic.CS8767.severity = error
dotnet_diagnostic.CS8768.severity = error
dotnet_diagnostic.CS8769.severity = error
dotnet_diagnostic.CS8770.severity = error
dotnet_diagnostic.CS8773.severity = error
dotnet_diagnostic.CS8774.severity = error
dotnet_diagnostic.CS8775.severity = error
dotnet_diagnostic.CS8776.severity = error
dotnet_diagnostic.CS8775.severity = error
dotnet_diagnostic.CS8777.severity = error
#nullable error types still not cleaned up

6
ICSharpCode.BamlDecompiler/Baml/BamlContext.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.BamlDecompiler.Baml @@ -37,7 +37,7 @@ namespace ICSharpCode.BamlDecompiler.Baml
public IDecompilerTypeSystem TypeSystem { get; }
public KnownThings KnownThings { get; }
Dictionary<ushort, (string FullAssemblyName, IModule Assembly)> assemblyMap = new Dictionary<ushort, (string FullAssemblyName, IModule Assembly)>();
Dictionary<ushort, (string? FullAssemblyName, IModule? Assembly)> assemblyMap = new Dictionary<ushort, (string? FullAssemblyName, IModule? Assembly)>();
public Dictionary<ushort, AssemblyInfoRecord> AssemblyIdMap { get; }
public Dictionary<ushort, AttributeInfoRecord> AttributeIdMap { get; }
@ -88,7 +88,7 @@ namespace ICSharpCode.BamlDecompiler.Baml @@ -88,7 +88,7 @@ namespace ICSharpCode.BamlDecompiler.Baml
return ctx;
}
public (string FullAssemblyName, IModule Assembly) ResolveAssembly(ushort id)
public (string? FullAssemblyName, IModule? Assembly) ResolveAssembly(ushort id)
{
id &= 0xfff;
if (!assemblyMap.TryGetValue(id, out var assembly))
@ -116,7 +116,7 @@ namespace ICSharpCode.BamlDecompiler.Baml @@ -116,7 +116,7 @@ namespace ICSharpCode.BamlDecompiler.Baml
private IModule FindMatchingReference(AssemblyNameReference name)
{
IModule bestMatch = null;
IModule? bestMatch = null;
foreach (var module in TypeSystem.ReferencedModules)
{
if (module.AssemblyName == name.Name)

2
ICSharpCode.BamlDecompiler/Baml/BamlNode.cs

@ -111,7 +111,7 @@ namespace ICSharpCode.BamlDecompiler.Baml @@ -111,7 +111,7 @@ namespace ICSharpCode.BamlDecompiler.Baml
{
Debug.Assert(document.Count > 0 && document[0].Type == BamlRecordType.DocumentStart);
BamlBlockNode current = null;
BamlBlockNode? current = null;
var stack = new Stack<BamlBlockNode>();
for (int i = 0; i < document.Count; i++)

2
ICSharpCode.BamlDecompiler/Baml/BamlReader.cs

@ -91,7 +91,7 @@ namespace ICSharpCode.BamlDecompiler.Baml @@ -91,7 +91,7 @@ namespace ICSharpCode.BamlDecompiler.Baml
long pos = str.Position;
var type = (BamlRecordType)reader.ReadByte();
BamlRecord rec = null;
BamlRecord? rec = null;
switch (type)
{
case BamlRecordType.AssemblyInfo:

4
ICSharpCode.BamlDecompiler/BamlDecompilerSettings.cs

@ -37,9 +37,9 @@ namespace ICSharpCode.BamlDecompiler @@ -37,9 +37,9 @@ namespace ICSharpCode.BamlDecompiler
}
}
public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
if (PropertyChanged != null)
{

10
ICSharpCode.BamlDecompiler/BamlElement.cs

@ -41,13 +41,13 @@ namespace ICSharpCode.BamlDecompiler @@ -41,13 +41,13 @@ namespace ICSharpCode.BamlDecompiler
String = value;
}
public readonly XElement Element;
public readonly string String;
public readonly XElement? Element;
public readonly string? String;
public static implicit operator XamlNode(XElement value) => new XamlNode(value);
public static implicit operator XamlNode(string value) => new XamlNode(value);
public static implicit operator XElement(XamlNode node) => node.Element;
public static implicit operator string(XamlNode node) => node.String;
public static implicit operator XElement?(XamlNode node) => node.Element;
public static implicit operator string?(XamlNode node) => node.String;
}
internal class BamlElement
@ -55,7 +55,7 @@ namespace ICSharpCode.BamlDecompiler @@ -55,7 +55,7 @@ namespace ICSharpCode.BamlDecompiler
public BamlNode Node { get; }
public XamlNode Xaml { get; set; }
public BamlElement Parent { get; set; }
public BamlElement? Parent { get; set; }
public IList<BamlElement> Children { get; }
public BamlElement(BamlNode node)

2
ICSharpCode.BamlDecompiler/Handlers/Blocks/ConstructorParametersHandler.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.ConstructorParametersStart;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var doc = new BamlElement(node);
doc.Xaml = new XElement(ctx.GetPseudoName("Ctor"));

2
ICSharpCode.BamlDecompiler/Handlers/Blocks/DocumentHandler.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.DocumentStart;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var doc = new BamlElement(node);
doc.Xaml = new XElement(ctx.GetPseudoName("Document"));

2
ICSharpCode.BamlDecompiler/Handlers/Blocks/ElementHandler.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.ElementStart;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (ElementStartRecord)((BamlBlockNode)node).Header;
var doc = new BamlElement(node);

2
ICSharpCode.BamlDecompiler/Handlers/Blocks/KeyElementStartHandler.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
BamlRecordType IHandler.Type => BamlRecordType.KeyElementStart;
BamlElement IHandler.Translate(XamlContext ctx, BamlNode node, BamlElement parent)
BamlElement? IHandler.Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
XamlResourceKey.Create(node);
return null;

2
ICSharpCode.BamlDecompiler/Handlers/Blocks/PropertyArrayHandler.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.PropertyArrayStart;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyArrayStartRecord)((BamlBlockNode)node).Header;
var doc = new BamlElement(node);

2
ICSharpCode.BamlDecompiler/Handlers/Blocks/PropertyComplexHandler.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.PropertyComplexStart;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyComplexStartRecord)((BamlBlockNode)node).Header;
var doc = new BamlElement(node);

2
ICSharpCode.BamlDecompiler/Handlers/Blocks/PropertyDictionaryHandler.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.PropertyDictionaryStart;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyDictionaryStartRecord)((BamlBlockNode)node).Header;
var doc = new BamlElement(node);

2
ICSharpCode.BamlDecompiler/Handlers/Blocks/PropertyListHandler.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.PropertyListStart;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyListStartRecord)((BamlBlockNode)node).Header;
var doc = new BamlElement(node);

2
ICSharpCode.BamlDecompiler/Handlers/Records/AssemblyInfoHandler.cs

@ -28,6 +28,6 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -28,6 +28,6 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.AssemblyInfo;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) => null;
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent) => null;
}
}

2
ICSharpCode.BamlDecompiler/Handlers/Records/AttributeInfoHandler.cs

@ -28,6 +28,6 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -28,6 +28,6 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.AttributeInfo;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) => null;
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent) => null;
}
}

2
ICSharpCode.BamlDecompiler/Handlers/Records/ConnectionIdHandler.cs

@ -28,7 +28,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -28,7 +28,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.ConnectionId;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (ConnectionIdRecord)((BamlRecordNode)node).Record;

2
ICSharpCode.BamlDecompiler/Handlers/Records/ConstructorParameterTypeHandler.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.ConstructorParameterType;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (ConstructorParameterTypeRecord)((BamlRecordNode)node).Record;

2
ICSharpCode.BamlDecompiler/Handlers/Records/ContentPropertyHandler.cs

@ -28,7 +28,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -28,7 +28,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.ContentProperty;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (ContentPropertyRecord)((BamlRecordNode)node).Record;
// TODO: What to do here?

2
ICSharpCode.BamlDecompiler/Handlers/Records/DefAttributeHandler.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.DefAttribute;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (DefAttributeRecord)((BamlRecordNode)node).Record;

2
ICSharpCode.BamlDecompiler/Handlers/Records/DefAttributeKeyStringHandler.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.DefAttributeKeyString;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
XamlResourceKey.Create(node);
return null;

2
ICSharpCode.BamlDecompiler/Handlers/Records/DefAttributeKeyTypeHandler.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.DefAttributeKeyType;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
XamlResourceKey.Create(node);
return null;

2
ICSharpCode.BamlDecompiler/Handlers/Records/DeferableContentStartHandler.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.DeferableContentStart;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (DeferableContentStartRecord)((BamlRecordNode)node).Record;

2
ICSharpCode.BamlDecompiler/Handlers/Records/LineNumberAndPositionHandler.cs

@ -28,6 +28,6 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -28,6 +28,6 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.LineNumberAndPosition;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) => null;
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent) => null;
}
}

2
ICSharpCode.BamlDecompiler/Handlers/Records/LinePositionHandler.cs

@ -28,6 +28,6 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -28,6 +28,6 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.LinePosition;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) => null;
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent) => null;
}
}

2
ICSharpCode.BamlDecompiler/Handlers/Records/LiteralContentHandler.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.LiteralContent;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (LiteralContentRecord)((BamlRecordNode)node).Record;

2
ICSharpCode.BamlDecompiler/Handlers/Records/OptimizedStaticResourceHandler.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.OptimizedStaticResource;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (OptimizedStaticResourceRecord)((BamlRecordNode)node).Record;
var key = XamlResourceKey.FindKeyInSiblings(node);

2
ICSharpCode.BamlDecompiler/Handlers/Records/PIMappingHandler.cs

@ -28,6 +28,6 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -28,6 +28,6 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.PIMapping;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) => null;
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent) => null;
}
}

2
ICSharpCode.BamlDecompiler/Handlers/Records/PresentationOptionsAttributeHandler.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -30,7 +30,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.PresentationOptionsAttribute;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PresentationOptionsAttributeRecord)((BamlRecordNode)node).Record;

2
ICSharpCode.BamlDecompiler/Handlers/Records/PropertyCustomHandler.cs

@ -179,7 +179,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -179,7 +179,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
return property.IsAttachedTo(type);
}
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyCustomRecord)((BamlRecordNode)node).Record;
var serTypeId = ((short)record.SerializerTypeId & 0xfff);

2
ICSharpCode.BamlDecompiler/Handlers/Records/PropertyHandler.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public virtual BamlRecordType Type => BamlRecordType.Property;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyRecord)((BamlRecordNode)node).Record;

5
ICSharpCode.BamlDecompiler/Handlers/Records/PropertyTypeReferenceHandler.cs

@ -22,10 +22,9 @@ @@ -22,10 +22,9 @@
using System.Xml.Linq;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.BamlDecompiler.Baml;
using ICSharpCode.BamlDecompiler.Xaml;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.BamlDecompiler.Handlers
{
@ -33,7 +32,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -33,7 +32,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.PropertyTypeReference;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyTypeReferenceRecord)((BamlRecordNode)node).Record;
var attr = ctx.ResolveProperty(record.AttributeId);

2
ICSharpCode.BamlDecompiler/Handlers/Records/PropertyWithExtensionHandler.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.PropertyWithExtension;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyWithExtensionRecord)((BamlRecordNode)node).Record;
var extTypeId = ((short)record.Flags & 0xfff);

6
ICSharpCode.BamlDecompiler/Handlers/Records/PropertyWithStaticResourceIdHandler.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -32,7 +32,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.PropertyWithStaticResourceId;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyWithStaticResourceIdRecord)((BamlRecordNode)node).Record;
var doc = new BamlElement(node);
@ -43,8 +43,8 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -43,8 +43,8 @@ namespace ICSharpCode.BamlDecompiler.Handlers
doc.Xaml.Element.AddAnnotation(elemAttr);
parent.Xaml.Element.Add(doc.Xaml.Element);
BamlNode found = node;
XamlResourceKey key;
BamlNode? found = node;
XamlResourceKey? key;
do
{
key = XamlResourceKey.FindKeyInAncestors(found.Parent, out found);

6
ICSharpCode.BamlDecompiler/Handlers/Records/StaticResourceIdHandler.cs

@ -27,12 +27,12 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -27,12 +27,12 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.StaticResourceId;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (StaticResourceIdRecord)((BamlRecordNode)node).Record;
BamlNode found = node;
XamlResourceKey key;
BamlNode? found = node;
XamlResourceKey? key;
do
{
key = XamlResourceKey.FindKeyInAncestors(found.Parent, out found);

2
ICSharpCode.BamlDecompiler/Handlers/Records/StaticResourceStartHandler.cs

@ -29,7 +29,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -29,7 +29,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.StaticResourceStart;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (StaticResourceStartRecord)((BamlBlockNode)node).Record;
var key = XamlResourceKey.FindKeyInSiblings(node);

4
ICSharpCode.BamlDecompiler/Handlers/Records/TextHandler.cs

@ -28,7 +28,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -28,7 +28,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.Text;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (TextRecord)((BamlRecordNode)node).Record;
@ -42,7 +42,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -42,7 +42,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.TextWithId;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (TextWithIdRecord)((BamlRecordNode)node).Record;

4
ICSharpCode.BamlDecompiler/Handlers/Records/TypeInfoHandler.cs

@ -28,13 +28,13 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -28,13 +28,13 @@ namespace ICSharpCode.BamlDecompiler.Handlers
{
public BamlRecordType Type => BamlRecordType.TypeInfo;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) => null;
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent) => null;
}
internal class TypeSerializerInfoHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.TypeSerializerInfo;
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) => null;
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent) => null;
}
}

2
ICSharpCode.BamlDecompiler/Handlers/Records/XmlnsPropertyHandler.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers @@ -52,7 +52,7 @@ namespace ICSharpCode.BamlDecompiler.Handlers
}
}
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (XmlnsPropertyRecord)((BamlRecordNode)node).Record;
foreach (var asmId in record.AssemblyIds)

1
ICSharpCode.BamlDecompiler/ICSharpCode.BamlDecompiler.csproj

@ -35,6 +35,7 @@ @@ -35,6 +35,7 @@
<DebugSymbols>true</DebugSymbols>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>

2
ICSharpCode.BamlDecompiler/IHandlers.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler @@ -31,7 +31,7 @@ namespace ICSharpCode.BamlDecompiler
internal interface IHandler
{
BamlRecordType Type { get; }
BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent);
BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent);
}
internal interface IDeferHandler

13
ICSharpCode.BamlDecompiler/Rewrite/ConnectionIdRewritePass.cs

@ -22,15 +22,16 @@ using System.Linq; @@ -22,15 +22,16 @@ using System.Linq;
using System.Reflection.Metadata;
using System.Xml.Linq;
using ICSharpCode.BamlDecompiler.Xaml;
using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.IL.Transforms;
using ICSharpCode.Decompiler.Util;
using ICSharpCode.BamlDecompiler.Xaml;
namespace ICSharpCode.BamlDecompiler.Rewrite
{
using System.Diagnostics.CodeAnalysis;
using ICSharpCode.Decompiler.TypeSystem;
internal class ConnectionIdRewritePass : IRewritePass
@ -126,7 +127,7 @@ namespace ICSharpCode.BamlDecompiler.Rewrite @@ -126,7 +127,7 @@ namespace ICSharpCode.BamlDecompiler.Rewrite
return;
var connect = connectorInterface.GetMethods(m => m.Name == "Connect").SingleOrDefault();
IMethod connectMethod = null;
IMethod? connectMethod = null;
MethodDefinition connectMetadataEntry = default;
var module = ctx.TypeSystem.MainModule.MetadataFile;
@ -249,7 +250,7 @@ namespace ICSharpCode.BamlDecompiler.Rewrite @@ -249,7 +250,7 @@ namespace ICSharpCode.BamlDecompiler.Rewrite
}
}
bool MatchFieldAssignment(ILInstruction inst, out FieldAssignment field)
bool MatchFieldAssignment(ILInstruction inst, [NotNullWhen(true)] out FieldAssignment? field)
{
field = null;
if (!inst.MatchStFld(out _, out var fld, out var value) || !value.MatchCastClass(out var arg, out _)
@ -293,7 +294,7 @@ namespace ICSharpCode.BamlDecompiler.Rewrite @@ -293,7 +294,7 @@ namespace ICSharpCode.BamlDecompiler.Rewrite
// callvirt set_Event(ldloc v, ldsfld eventName)
// callvirt set_Handler(ldloc v, newobj RoutedEventHandler..ctor(ldloc this, ldftn eventHandler))
// callvirt Add(callvirt get_Setters(castclass System.Windows.Style(ldloc target)), ldloc v)
bool MatchEventSetterCreation(Block b, ref int pos, out EventRegistration @event)
bool MatchEventSetterCreation(Block b, ref int pos, [NotNullWhen(true)] out EventRegistration? @event)
{
@event = null;
if (!b.FinalInstruction.MatchNop())
@ -362,7 +363,7 @@ namespace ICSharpCode.BamlDecompiler.Rewrite @@ -362,7 +363,7 @@ namespace ICSharpCode.BamlDecompiler.Rewrite
return true;
}
bool MatchSimpleEventRegistration(ILInstruction inst, out EventRegistration @event)
bool MatchSimpleEventRegistration(ILInstruction inst, [NotNullWhen(true)] out EventRegistration? @event)
{
@event = null;
if (!(inst is CallInstruction call) || call.OpCode == OpCode.NewObj)

6
ICSharpCode.BamlDecompiler/Xaml/NamespaceMap.cs

@ -29,17 +29,17 @@ namespace ICSharpCode.BamlDecompiler.Xaml @@ -29,17 +29,17 @@ namespace ICSharpCode.BamlDecompiler.Xaml
{
internal class NamespaceMap
{
public string XmlnsPrefix { get; set; }
public string? XmlnsPrefix { get; set; }
public string FullAssemblyName { get; set; }
public string XMLNamespace { get; set; }
public string CLRNamespace { get; set; }
public string? CLRNamespace { get; set; }
public NamespaceMap(string prefix, string fullAssemblyName, string xmlNs)
: this(prefix, fullAssemblyName, xmlNs, null)
{
}
public NamespaceMap(string prefix, string fullAssemblyName, string xmlNs, string clrNs)
public NamespaceMap(string? prefix, string fullAssemblyName, string xmlNs, string? clrNs)
{
XmlnsPrefix = prefix;
FullAssemblyName = fullAssemblyName;

2
ICSharpCode.BamlDecompiler/Xaml/XamlProperty.cs

@ -82,7 +82,7 @@ namespace ICSharpCode.BamlDecompiler.Xaml @@ -82,7 +82,7 @@ namespace ICSharpCode.BamlDecompiler.Xaml
return true;
}
public XName ToXName(XamlContext ctx, XElement parent, bool isFullName = true)
public XName ToXName(XamlContext ctx, XElement? parent, bool isFullName = true)
{
var typeName = DeclaringType.ToXName(ctx);
XName name;

6
ICSharpCode.BamlDecompiler/Xaml/XamlResourceKey.cs

@ -78,7 +78,7 @@ namespace ICSharpCode.BamlDecompiler.Xaml @@ -78,7 +78,7 @@ namespace ICSharpCode.BamlDecompiler.Xaml
public BamlElement KeyElement { get; set; }
public IList<BamlNode> StaticResources { get; }
public static XamlResourceKey FindKeyInSiblings(BamlNode node)
public static XamlResourceKey? FindKeyInSiblings(BamlNode node)
{
var children = node.Parent.Children;
var index = children.IndexOf(node);
@ -90,9 +90,9 @@ namespace ICSharpCode.BamlDecompiler.Xaml @@ -90,9 +90,9 @@ namespace ICSharpCode.BamlDecompiler.Xaml
return null;
}
public static XamlResourceKey FindKeyInAncestors(BamlNode node) => FindKeyInAncestors(node, out var found);
public static XamlResourceKey? FindKeyInAncestors(BamlNode node) => FindKeyInAncestors(node, out var found);
public static XamlResourceKey FindKeyInAncestors(BamlNode node, out BamlNode found)
public static XamlResourceKey? FindKeyInAncestors(BamlNode node, out BamlNode? found)
{
BamlNode n = node;
do

6
ICSharpCode.BamlDecompiler/Xaml/XamlType.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.BamlDecompiler.Xaml @@ -37,7 +37,7 @@ namespace ICSharpCode.BamlDecompiler.Xaml
public string TypeNamespace { get; }
public string TypeName { get; }
public XNamespace Namespace { get; private set; }
public XNamespace? Namespace { get; private set; }
public IType ResolvedType { get; set; }
public XamlType(IModule assembly, string fullAssemblyName, string ns, string name)
@ -45,7 +45,7 @@ namespace ICSharpCode.BamlDecompiler.Xaml @@ -45,7 +45,7 @@ namespace ICSharpCode.BamlDecompiler.Xaml
{
}
public XamlType(IModule assembly, string fullAssemblyName, string ns, string name, XNamespace xmlns)
public XamlType(IModule assembly, string fullAssemblyName, string ns, string name, XNamespace? xmlns)
{
Assembly = assembly;
FullAssemblyName = fullAssemblyName;
@ -62,7 +62,7 @@ namespace ICSharpCode.BamlDecompiler.Xaml @@ -62,7 +62,7 @@ namespace ICSharpCode.BamlDecompiler.Xaml
// Since XmlnsProperty records are inside the element,
// the namespace is resolved after processing the element body.
string xmlNs = null;
string? xmlNs = null;
if (elem.Annotation<XmlnsScope>() != null)
xmlNs = elem.Annotation<XmlnsScope>().LookupXmlns(FullAssemblyName, TypeNamespace);
if (xmlNs == null)

11
ICSharpCode.BamlDecompiler/XamlContext.cs

@ -27,10 +27,9 @@ using System.Reflection.Metadata; @@ -27,10 +27,9 @@ using System.Reflection.Metadata;
using System.Threading;
using System.Xml.Linq;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.BamlDecompiler.Baml;
using ICSharpCode.BamlDecompiler.Xaml;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.BamlDecompiler
{
@ -143,7 +142,7 @@ namespace ICSharpCode.BamlDecompiler @@ -143,7 +142,7 @@ namespace ICSharpCode.BamlDecompiler
XamlType type;
string name;
IMember member;
IMember? member;
if (id > 0x7fff)
{
@ -207,8 +206,8 @@ namespace ICSharpCode.BamlDecompiler @@ -207,8 +206,8 @@ namespace ICSharpCode.BamlDecompiler
continue;
var xmlNs = attr.FixedArguments[0].Value as string;
var typeNs = attr.FixedArguments[1].Value as string;
Debug.Assert((object)xmlNs != null && (object)typeNs != null);
if ((object)xmlNs == null || (object)typeNs == null)
Debug.Assert((object?)xmlNs != null && (object?)typeNs != null);
if ((object?)xmlNs == null || (object?)typeNs == null)
continue;
if (typeNamespace == typeNs)
@ -221,7 +220,7 @@ namespace ICSharpCode.BamlDecompiler @@ -221,7 +220,7 @@ namespace ICSharpCode.BamlDecompiler
return possibleXmlNs.FirstOrDefault();
}
public XName GetKnownNamespace(string name, string xmlNamespace, XElement context = null)
public XName GetKnownNamespace(string name, string xmlNamespace, XElement? context = null)
{
var xNs = GetXmlNamespace(xmlNamespace);
XName xName;

5
ICSharpCode.BamlDecompiler/XmlnsDictionary.cs

@ -22,11 +22,10 @@ @@ -22,11 +22,10 @@
using System.Collections.Generic;
using ICSharpCode.BamlDecompiler.Xaml;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.BamlDecompiler.Xaml;
namespace ICSharpCode.BamlDecompiler
{
internal class XmlnsScope : List<NamespaceMap>
@ -58,7 +57,7 @@ namespace ICSharpCode.BamlDecompiler @@ -58,7 +57,7 @@ namespace ICSharpCode.BamlDecompiler
public XmlnsDictionary() => CurrentScope = null;
public XmlnsScope CurrentScope { get; set; }
public XmlnsScope? CurrentScope { get; set; }
public void PushScope(BamlElement element) => CurrentScope = new XmlnsScope(CurrentScope, element);

2
ICSharpCode.Decompiler.PowerShell/GetDecompiledProjectCmdlet.cs

@ -25,7 +25,7 @@ namespace ICSharpCode.Decompiler.PowerShell @@ -25,7 +25,7 @@ namespace ICSharpCode.Decompiler.PowerShell
readonly object syncObject = new object();
int completed;
string fileName;
ProgressRecord progress;
ProgressRecord? progress;
public void Report(DecompilationProgress value)
{

1
ICSharpCode.Decompiler.PowerShell/ICSharpCode.Decompiler.PowerShell.csproj

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<RootNamespace>ICSharpCode.Decompiler.PowerShell</RootNamespace>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>

2
ICSharpCode.Decompiler.Tests/Semantics/OverloadResolutionTests.cs

@ -258,7 +258,7 @@ namespace ICSharpCode.Decompiler.Tests.Semantics @@ -258,7 +258,7 @@ namespace ICSharpCode.Decompiler.Tests.Semantics
get { throw new NotImplementedException(); }
}
public override IType GetInferredReturnType(IType[] parameterTypes)
public override IType GetInferredReturnType(IType[]? parameterTypes)
{
return inferredReturnType;
}

8
ICSharpCode.Decompiler/CSharp/Annotations.cs

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

34
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection.Metadata;
@ -406,7 +407,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -406,7 +407,7 @@ namespace ICSharpCode.Decompiler.CSharp
static readonly Regex automaticPropertyBackingFieldRegex = new Regex(@"^<(.*)>k__BackingField$",
RegexOptions.Compiled | RegexOptions.CultureInvariant);
static bool IsAutomaticPropertyBackingField(FieldDefinition field, MetadataReader metadata, out string propertyName)
static bool IsAutomaticPropertyBackingField(FieldDefinition field, MetadataReader metadata, [NotNullWhen(true)] out string? propertyName)
{
propertyName = null;
var name = metadata.GetString(field.Name);
@ -540,7 +541,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -540,7 +541,7 @@ namespace ICSharpCode.Decompiler.CSharp
return typeSystemAstBuilder;
}
IDocumentationProvider CreateDefaultDocumentationProvider()
IDocumentationProvider? CreateDefaultDocumentationProvider()
{
try
{
@ -631,8 +632,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -631,8 +632,8 @@ namespace ICSharpCode.Decompiler.CSharp
void DoDecompileTypes(IEnumerable<TypeDefinitionHandle> types, DecompileRun decompileRun, ITypeResolveContext decompilationContext, SyntaxTree syntaxTree)
{
string currentNamespace = null;
AstNode groupNode = null;
string? currentNamespace = null;
AstNode? groupNode = null;
foreach (var typeDefHandle in types)
{
var typeDef = module.GetDefinition(typeDefHandle);
@ -1027,7 +1028,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1027,7 +1028,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
bool first = true;
ITypeDefinition parentTypeDef = null;
ITypeDefinition? parentTypeDef = null;
foreach (var entity in definitions)
{
@ -1095,7 +1096,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1095,7 +1096,7 @@ namespace ICSharpCode.Decompiler.CSharp
return syntaxTree;
}
ITypeDefinition FindCommonDeclaringTypeDefinition(ITypeDefinition a, ITypeDefinition b)
ITypeDefinition? FindCommonDeclaringTypeDefinition(ITypeDefinition a, ITypeDefinition b)
{
if (a == null || b == null)
return null;
@ -1212,7 +1213,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1212,7 +1213,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// <param name="member">The node of the member which new modifier state should be determined.</param>
void SetNewModifier(EntityDeclaration member)
{
var entity = (IEntity)member.GetSymbol();
var entity = member.GetSymbol() as IEntity;
var lookup = new MemberLookup(entity.DeclaringTypeDefinition, entity.ParentModule);
var baseTypes = entity.DeclaringType.GetNonInterfaceBaseTypes().Where(t => entity.DeclaringType != t).ToList();
@ -1315,7 +1316,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1315,7 +1316,7 @@ namespace ICSharpCode.Decompiler.CSharp
TypeKind.Struct => (settings.RecordStructs && typeDef.IsRecord) || settings.UsePrimaryConstructorSyntaxForNonRecordTypes,
_ => false,
};
RecordDecompiler recordDecompiler = isRecordLike ? new RecordDecompiler(typeSystem, typeDef, settings, CancellationToken) : null;
RecordDecompiler? recordDecompiler = isRecordLike ? new RecordDecompiler(typeSystem, typeDef, settings, CancellationToken) : null;
if (recordDecompiler != null)
decompileRun.RecordDecompilers.Add(typeDef, recordDecompiler);
@ -1324,7 +1325,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1324,7 +1325,7 @@ namespace ICSharpCode.Decompiler.CSharp
foreach (var p in recordDecompiler.PrimaryConstructor.Parameters)
{
ParameterDeclaration pd = typeSystemAstBuilder.ConvertParameter(p);
(IProperty prop, IField field) = recordDecompiler.GetPropertyInfoByPrimaryConstructorParameter(p);
(IProperty? prop, IField field) = recordDecompiler.GetPropertyInfoByPrimaryConstructorParameter(p);
if (prop != null)
{
@ -1566,7 +1567,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1566,7 +1567,7 @@ namespace ICSharpCode.Decompiler.CSharp
{
if (MemberIsHidden(module, field.MetadataToken, settings))
continue;
object constantValue = field.GetConstantValue();
object? constantValue = field.GetConstantValue();
if (constantValue == null)
continue;
long currentValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, constantValue, false);
@ -1779,7 +1780,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1779,7 +1780,7 @@ namespace ICSharpCode.Decompiler.CSharp
);
body = statementBuilder.ConvertAsBlock(function.Body);
Comment prev = null;
Comment? prev = null;
foreach (string warning in function.Warnings)
{
body.InsertChildAfter(prev, prev = new Comment(warning), Roles.Comment);
@ -1799,7 +1800,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1799,7 +1800,8 @@ namespace ICSharpCode.Decompiler.CSharp
internal static void AddAnnotationsToDeclaration(IMethod method, EntityDeclaration entityDecl, ILFunction function)
{
int i = 0;
var parameters = function.Variables.Where(v => v.Kind == VariableKind.Parameter).ToDictionary(v => v.Index);
//if the variable is a parameter is a parameter then index "should not" be null, would indicate an deeper under lying problem if it is so we assert not null (!)
var parameters = function.Variables.Where(v => v.Kind == VariableKind.Parameter).ToDictionary(v => v.Index!.Value);
foreach (var parameter in entityDecl.GetChildrenByRole(Roles.Parameter))
{
if (parameters.TryGetValue(i, out var v))
@ -1916,7 +1918,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1916,7 +1918,7 @@ namespace ICSharpCode.Decompiler.CSharp
return found;
}
bool FindAttribute(EntityDeclaration entityDecl, KnownAttribute attributeType, out Syntax.Attribute attribute)
bool FindAttribute(EntityDeclaration entityDecl, KnownAttribute attributeType, [NotNullWhen(true)] out Syntax.Attribute? attribute)
{
attribute = null;
foreach (var section in entityDecl.Attributes)
@ -1956,7 +1958,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1956,7 +1958,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (decompilationContext.CurrentTypeDefinition.Kind == TypeKind.Enum && field.IsConst)
{
var enumDec = new EnumMemberDeclaration { Name = field.Name };
object constantValue = field.GetConstantValue();
object? constantValue = field.GetConstantValue();
if (constantValue != null)
{
enumDec.Initializer = typeSystemAstBuilder.ConvertConstantValue(decompilationContext.CurrentTypeDefinition.EnumUnderlyingType, constantValue);
@ -2016,11 +2018,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2016,11 +2018,11 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
internal static bool IsFixedField(IField field, out IType type, out int elementCount)
internal static bool IsFixedField(IField field, out IType? type, out int elementCount)
{
type = null;
elementCount = 0;
IAttribute attr = field.GetAttribute(KnownAttribute.FixedBuffer);
IAttribute? attr = field.GetAttribute(KnownAttribute.FixedBuffer);
if (attr != null && attr.FixedArguments.Length == 2)
{
if (attr.FixedArguments[0].Value is IType trr && attr.FixedArguments[1].Value is int length)

74
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
@ -47,7 +48,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -47,7 +48,7 @@ namespace ICSharpCode.Decompiler.CSharp
public TranslatedExpression[] Arguments;
public IParameter[] ExpectedParameters;
public string[] ParameterNames;
public string[] ArgumentNames;
public string[]? ArgumentNames;
public int FirstOptionalArgumentIndex;
public BitSet IsPrimitiveValue;
public IReadOnlyList<int> ArgumentToParameterMap;
@ -146,7 +147,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -146,7 +147,7 @@ namespace ICSharpCode.Decompiler.CSharp
{
for (int i = 0; i < Arguments.Length; i++)
{
string inferredName;
string? inferredName;
switch (Arguments[i].Expression)
{
case IdentifierExpression identifier:
@ -188,13 +189,13 @@ namespace ICSharpCode.Decompiler.CSharp @@ -188,13 +189,13 @@ namespace ICSharpCode.Decompiler.CSharp
this.typeSystem = typeSystem;
}
public TranslatedExpression Build(CallInstruction inst, IType typeHint = null)
public TranslatedExpression Build(CallInstruction inst, IType? typeHint = null)
{
if (inst is NewObj newobj && IL.Transforms.DelegateConstruction.MatchDelegateConstruction(newobj, out _, out _, out _))
{
return HandleDelegateConstruction(newobj);
}
if (settings.TupleTypes && TupleTransform.MatchTupleConstruction(inst as NewObj, out var tupleElements) && tupleElements.Length >= 2)
if (settings.TupleTypes && TupleTransform.MatchTupleConstruction(inst as NewObj, out var tupleElements) && tupleElements?.Length >= 2)
{
var elementTypes = TupleType.GetTupleElementTypes(inst.Method.DeclaringType);
var elementNames = typeHint is TupleType tt ? tt.ElementNames : default;
@ -247,7 +248,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -247,7 +248,8 @@ namespace ICSharpCode.Decompiler.CSharp
return result;
}
static bool IsSpanBasedStringConcat(CallInstruction call, out List<(ILInstruction, KnownTypeCode)> operands)
static bool IsSpanBasedStringConcat(CallInstruction call, [NotNullWhen(true)] out List<(ILInstruction, KnownTypeCode)>? operands)
{
operands = null;
@ -313,8 +315,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -313,8 +315,8 @@ namespace ICSharpCode.Decompiler.CSharp
public ExpressionWithResolveResult Build(OpCode callOpCode, IMethod method,
IReadOnlyList<ILInstruction> callArguments,
IReadOnlyList<int> argumentToParameterMap = null,
IType constrainedTo = null)
IReadOnlyList<int>? argumentToParameterMap = null,
IType? constrainedTo = null)
{
if (method.IsExplicitInterfaceImplementation && callOpCode == OpCode.Call)
{
@ -332,7 +334,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -332,7 +334,7 @@ namespace ICSharpCode.Decompiler.CSharp
var expectedTargetDetails = new ExpectedTargetDetails {
CallOpCode = callOpCode
};
ILFunction localFunction = null;
ILFunction? localFunction = null;
if (method.IsLocalFunction)
{
localFunction = expressionBuilder.ResolveLocalFunction(method);
@ -523,7 +525,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -523,7 +525,7 @@ namespace ICSharpCode.Decompiler.CSharp
private ExpressionWithResolveResult HandleStringInterpolation(IMethod method, ArgumentList argumentList)
{
if (!TryGetStringInterpolationTokens(argumentList, out string format, out var tokens))
if (!TryGetStringInterpolationTokens(argumentList, out string? format, out var tokens))
return default;
var arguments = argumentList.Arguments;
@ -543,7 +545,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -543,7 +545,7 @@ namespace ICSharpCode.Decompiler.CSharp
argument = new TranslatedExpression(element, arrayCreationRR.InitializerElements.First());
}
if (tokens.Count == 0)
if (tokens == null || tokens.Count == 0)
{
return default;
}
@ -655,7 +657,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -655,7 +657,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
public ExpressionWithResolveResult BuildDictionaryInitializerExpression(OpCode callOpCode, IMethod method,
InitializedObjectResolveResult target, IReadOnlyList<ILInstruction> indices, ILInstruction value = null)
InitializedObjectResolveResult target, IReadOnlyList<ILInstruction> indices, ILInstruction? value = null)
{
if (method is null)
throw new ArgumentNullException(nameof(method));
@ -696,7 +698,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -696,7 +698,7 @@ namespace ICSharpCode.Decompiler.CSharp
);
}
private bool TryGetStringInterpolationTokens(ArgumentList argumentList, out string format, out List<(TokenKind Kind, int Index, int Alignment, string Format)> tokens)
private bool TryGetStringInterpolationTokens(ArgumentList argumentList, [NotNullWhen(true)] out string? format, [NotNullWhen(true)] out List<(TokenKind Kind, int Index, int Alignment, string? Format)>? tokens)
{
tokens = null;
format = null;
@ -707,9 +709,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -707,9 +709,9 @@ namespace ICSharpCode.Decompiler.CSharp
return false;
if (!arguments.Skip(1).All(a => !a.Expression.DescendantsAndSelf.OfType<PrimitiveExpression>().Any(p => p.Value is string)))
return false;
tokens = new List<(TokenKind Kind, int Index, int Alignment, string Format)>();
tokens = new List<(TokenKind Kind, int Index, int Alignment, string? Format)>();
int i = 0;
format = (string)crr.ConstantValue;
format = (string?)crr.ConstantValue;
foreach (var (kind, data) in TokenizeFormatString(format))
{
int index;
@ -775,7 +777,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -775,7 +777,7 @@ namespace ICSharpCode.Decompiler.CSharp
ArgumentWithAlignmentAndFormat,
}
private IEnumerable<(TokenKind, string)> TokenizeFormatString(string value)
private IEnumerable<(TokenKind, string?)> TokenizeFormatString(string value)
{
int pos = -1;
@ -867,14 +869,14 @@ namespace ICSharpCode.Decompiler.CSharp @@ -867,14 +869,14 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
private ArgumentList BuildArgumentList(ExpectedTargetDetails expectedTargetDetails, ResolveResult target, IMethod method,
int firstParamIndex, IReadOnlyList<ILInstruction> callArguments, IReadOnlyList<int> argumentToParameterMap)
private ArgumentList BuildArgumentList(ExpectedTargetDetails expectedTargetDetails, ResolveResult? target, IMethod method,
int firstParamIndex, IReadOnlyList<ILInstruction> callArguments, IReadOnlyList<int>? argumentToParameterMap)
{
ArgumentList list = new ArgumentList();
// Translate arguments to the expected parameter types
var arguments = new List<TranslatedExpression>(method.Parameters.Count);
string[] argumentNames = null;
string[]? argumentNames = null;
Debug.Assert(callArguments.Count == firstParamIndex + method.Parameters.Count);
var expectedParameters = new List<IParameter>(method.Parameters.Count); // parameters, but in argument order
bool isExpandedForm = false;
@ -978,11 +980,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -978,11 +980,11 @@ namespace ICSharpCode.Decompiler.CSharp
return p.Type.IsKnownType(KnownTypeCode.Boolean);
}
private bool TransformParamsArgument(ExpectedTargetDetails expectedTargetDetails, ResolveResult targetResolveResult,
private bool TransformParamsArgument(ExpectedTargetDetails expectedTargetDetails, ResolveResult? targetResolveResult,
IMethod method, IParameter parameter, TranslatedExpression arg, ref List<IParameter> expectedParameters,
ref List<TranslatedExpression> arguments)
{
if (CheckArgument(out int length, out IType elementType))
if (CheckArgument(out int length, out IType? elementType))
{
var expandedParameters = new List<IParameter>(expectedParameters);
var expandedArguments = new List<TranslatedExpression>(arguments);
@ -1010,7 +1012,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1010,7 +1012,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
return false;
bool CheckArgument(out int len, out IType t)
bool CheckArgument(out int len, [NotNullWhen(true)] out IType? t)
{
len = 0;
t = null;
@ -1069,7 +1071,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1069,7 +1071,7 @@ namespace ICSharpCode.Decompiler.CSharp
// initialize requireTarget flag
bool requireTarget;
ResolveResult targetResolveResult;
ResolveResult? targetResolveResult;
if ((allowedTransforms & CallTransformation.RequireTarget) != 0)
{
if (settings.AlwaysQualifyMemberReferences || expressionBuilder.HidesVariableWithName(method.Name))
@ -1393,9 +1395,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1393,9 +1395,9 @@ namespace ICSharpCode.Decompiler.CSharp
}
OverloadResolutionErrors IsUnambiguousCall(ExpectedTargetDetails expectedTargetDetails, IMethod method,
ResolveResult target, IType[] typeArguments, ResolveResult[] arguments,
string[] argumentNames, int firstOptionalArgumentIndex,
out IParameterizedMember foundMember, out bool bestCandidateIsExpandedForm)
ResolveResult? target, IType[] typeArguments, ResolveResult[] arguments,
string[]? argumentNames, int firstOptionalArgumentIndex,
out IParameterizedMember? foundMember, out bool bestCandidateIsExpandedForm)
{
foundMember = null;
bestCandidateIsExpandedForm = false;
@ -1504,7 +1506,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1504,7 +1506,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
bool IsUnambiguousAccess(ExpectedTargetDetails expectedTargetDetails, ResolveResult target, IMethod method,
IList<TranslatedExpression> arguments, string[] argumentNames, out IMember foundMember)
IList<TranslatedExpression> arguments, string[] argumentNames, out IMember? foundMember)
{
Log.WriteLine("IsUnambiguousAccess: Performing overload resolution for " + method);
Log.WriteCollection(" Arguments: ", arguments.Select(a => a.ResolveResult));
@ -1551,7 +1553,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1551,7 +1553,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
ExpressionWithResolveResult HandleAccessorCall(ExpectedTargetDetails expectedTargetDetails, IMethod method,
TranslatedExpression target, List<TranslatedExpression> arguments, string[] argumentNames)
TranslatedExpression target, List<TranslatedExpression> arguments, string[]? argumentNames)
{
bool requireTarget;
if (settings.AlwaysQualifyMemberReferences || method.AccessorOwner.SymbolKind == SymbolKind.Indexer || expressionBuilder.HidesVariableWithName(method.AccessorOwner.Name))
@ -1572,7 +1574,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1572,7 +1574,7 @@ namespace ICSharpCode.Decompiler.CSharp
arguments.Remove(value);
}
IMember foundMember;
IMember? foundMember;
while (!IsUnambiguousAccess(expectedTargetDetails, targetResolveResult, method, arguments, argumentNames, out foundMember))
{
if (!argumentsCasted)
@ -1674,7 +1676,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1674,7 +1676,7 @@ namespace ICSharpCode.Decompiler.CSharp
return false;
}
ExpressionWithResolveResult HandleConstructorCall(ExpectedTargetDetails expectedTargetDetails, ResolveResult target, IMethod method, ArgumentList argumentList)
ExpressionWithResolveResult HandleConstructorCall(ExpectedTargetDetails expectedTargetDetails, ResolveResult? target, IMethod method, ArgumentList argumentList)
{
if (settings.AnonymousTypes && method.DeclaringType.IsAnonymousType())
{
@ -1715,7 +1717,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1715,7 +1717,7 @@ namespace ICSharpCode.Decompiler.CSharp
CastArguments(argumentList.Arguments, argumentList.ExpectedParameters);
break; // make sure that we don't not end up in an infinite loop
}
IType returnTypeOverride = null;
IType? returnTypeOverride = null;
if (typeSystem.MainModule.TypeSystemOptions.HasFlag(TypeSystemOptions.NativeIntegersWithoutAttribute))
{
// For DeclaringType, we don't use nint/nuint (so that DeclaringType.GetConstructors etc. works),
@ -1821,11 +1823,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1821,11 +1823,11 @@ namespace ICSharpCode.Decompiler.CSharp
return expr.Expression.WithRR(new MemberResolveResult(null, method));
}
ExpressionWithResolveResult BuildDelegateReference(IMethod method, IMethod invokeMethod, ExpectedTargetDetails expectedTargetDetails, ILInstruction thisArg)
ExpressionWithResolveResult BuildDelegateReference(IMethod method, IMethod? invokeMethod, ExpectedTargetDetails expectedTargetDetails, ILInstruction? thisArg)
{
ExpressionBuilder expressionBuilder = this.expressionBuilder;
ExpressionWithResolveResult targetExpression;
(TranslatedExpression target, bool addTypeArguments, string methodName, ResolveResult result) = DisambiguateDelegateReference(method, invokeMethod, expectedTargetDetails, thisArg);
(TranslatedExpression target, bool addTypeArguments, string? methodName, ResolveResult result) = DisambiguateDelegateReference(method, invokeMethod, expectedTargetDetails, thisArg);
if (target.Expression != null)
{
var mre = new MemberReferenceExpression(target, methodName);
@ -1848,11 +1850,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1848,11 +1850,11 @@ namespace ICSharpCode.Decompiler.CSharp
}
(TranslatedExpression target, bool addTypeArguments, string methodName, ResolveResult result) DisambiguateDelegateReference(IMethod method, IMethod invokeMethod, ExpectedTargetDetails expectedTargetDetails, ILInstruction thisArg)
(TranslatedExpression target, bool addTypeArguments, string? methodName, ResolveResult result) DisambiguateDelegateReference(IMethod method, IMethod invokeMethod, ExpectedTargetDetails expectedTargetDetails, ILInstruction? thisArg)
{
if (method.IsLocalFunction)
{
ILFunction localFunction = expressionBuilder.ResolveLocalFunction(method);
ILFunction? localFunction = expressionBuilder.ResolveLocalFunction(method);
Debug.Assert(localFunction != null);
return (default, addTypeArguments: true, localFunction.Name, ToMethodGroup(method, localFunction));
}
@ -1932,7 +1934,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1932,7 +1934,7 @@ namespace ICSharpCode.Decompiler.CSharp
bool targetCasted = false;
bool addTypeArguments = false;
// Initial inputs for IsUnambiguousMethodReference:
ResolveResult targetResolveResult = targetAdded ? target.ResolveResult : null;
ResolveResult? targetResolveResult = targetAdded ? target.ResolveResult : null;
IReadOnlyList<IType> typeArguments = EmptyList<IType>.Instance;
// Find somewhat minimal solution:
ResolveResult result;
@ -1981,7 +1983,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1981,7 +1983,7 @@ namespace ICSharpCode.Decompiler.CSharp
return oce;
}
bool IsUnambiguousMethodReference(ExpectedTargetDetails expectedTargetDetails, IMethod method, ResolveResult target, IReadOnlyList<IType> typeArguments, bool isExtensionMethodReference, out ResolveResult result)
bool IsUnambiguousMethodReference(ExpectedTargetDetails expectedTargetDetails, IMethod method, ResolveResult target, IReadOnlyList<IType> typeArguments, bool isExtensionMethodReference, [NotNullWhen(true)] out ResolveResult result)
{
Log.WriteLine("IsUnambiguousMethodReference: Performing overload resolution for " + method);

50
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -153,7 +153,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -153,7 +153,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
public TranslatedExpression Translate(ILInstruction inst, IType typeHint = null)
public TranslatedExpression Translate(ILInstruction inst, IType? typeHint = null)
{
Debug.Assert(inst != null);
cancellationToken.ThrowIfCancellationRequested();
@ -265,7 +265,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -265,7 +265,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
internal ILFunction ResolveLocalFunction(IMethod method)
internal ILFunction? ResolveLocalFunction(IMethod method)
{
Debug.Assert(method.IsLocalFunction);
method = (IMethod)((IMethod)method.MemberDefinition).ReducedFrom.MemberDefinition;
@ -289,7 +289,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -289,7 +289,7 @@ namespace ICSharpCode.Decompiler.CSharp
return !(target.Expression is ThisReferenceExpression || target.Expression is BaseReferenceExpression);
}
ExpressionWithResolveResult ConvertField(IField field, ILInstruction targetInstruction = null)
ExpressionWithResolveResult ConvertField(IField field, ILInstruction? targetInstruction = null)
{
var target = TranslateTarget(targetInstruction,
nonVirtualInvocation: true,
@ -328,7 +328,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -328,7 +328,7 @@ namespace ICSharpCode.Decompiler.CSharp
return result == null || result.IsError || !result.Member.Equals(field, NormalizeTypeVisitor.TypeErasure);
}
MemberResolveResult mrr;
MemberResolveResult? mrr;
while (IsAmbiguousAccess(out mrr))
{
if (!requireTarget)
@ -486,7 +486,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -486,7 +486,7 @@ namespace ICSharpCode.Decompiler.CSharp
StackAllocExpression TranslateLocAlloc(LocAlloc inst, IType typeHint, out IType elementType)
{
TranslatedExpression countExpression;
PointerType pointerType;
PointerType? pointerType;
if (inst.Argument.MatchBinaryNumericInstruction(BinaryNumericOperator.Mul, out var left, out var right)
&& right.UnwrapConv(ConversionKind.SignExtend).UnwrapConv(ConversionKind.ZeroExtend).MatchSizeOf(out elementType))
{
@ -638,7 +638,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -638,7 +638,7 @@ namespace ICSharpCode.Decompiler.CSharp
{
Expression expr;
IType constantType;
object constantValue;
object? constantValue;
if (type.IsReferenceType == true || type.IsKnownType(KnownTypeCode.NullableOfT))
{
expr = new NullReferenceExpression();
@ -960,7 +960,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -960,7 +960,7 @@ namespace ICSharpCode.Decompiler.CSharp
.WithILInstruction(inst);
}
OperatorResolveResult rr = resolver.ResolveBinaryOperator(inst.Kind.ToBinaryOperatorType(), left.ResolveResult, right.ResolveResult) as OperatorResolveResult;
OperatorResolveResult? rr = resolver.ResolveBinaryOperator(inst.Kind.ToBinaryOperatorType(), left.ResolveResult, right.ResolveResult) as OperatorResolveResult;
if (rr == null || rr.IsError || rr.UserDefinedOperatorMethod != null
|| NullableType.GetUnderlyingType(rr.Operands[0].Type).GetStackType() != inst.InputType
|| !rr.Type.IsKnownType(KnownTypeCode.Boolean))
@ -1387,7 +1387,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1387,7 +1387,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
internal TranslatedExpression CallUnsafeIntrinsic(string name, Expression[] arguments, IType returnType, ILInstruction inst = null, IEnumerable<IType> typeArguments = null)
internal TranslatedExpression CallUnsafeIntrinsic(string name, Expression[] arguments, IType returnType, ILInstruction? inst = null, IEnumerable<IType>? typeArguments = null)
{
var target = new MemberReferenceExpression {
Target = new TypeReferenceExpression(astBuilder.ConvertType(compilation.FindType(KnownTypeCode.Unsafe))),
@ -1458,7 +1458,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1458,7 +1458,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (sub.CheckForOverflow)
return null;
// First, attempt to parse the 'sizeof' on the RHS
IType elementType;
IType? elementType;
if (inst.Right.MatchLdcI(out long elementSize))
{
elementType = null;
@ -2397,7 +2397,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2397,7 +2397,7 @@ namespace ICSharpCode.Decompiler.CSharp
);
var body = builder.ConvertAsBlock(function.Body);
Comment prev = null;
Comment? prev = null;
foreach (string warning in function.Warnings)
{
body.InsertChildAfter(prev, prev = new Comment(warning), Roles.Comment);
@ -2535,7 +2535,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2535,7 +2535,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (resultType.Kind == TypeKind.Void)
return compilation.FindType(KnownTypeCode.Task);
ITypeDefinition def = compilation.FindType(KnownTypeCode.TaskOfT).GetDefinition();
ITypeDefinition? def = compilation.FindType(KnownTypeCode.TaskOfT).GetDefinition();
if (def != null)
return new ParameterizedType(def, new[] { resultType });
else
@ -2544,7 +2544,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2544,7 +2544,8 @@ namespace ICSharpCode.Decompiler.CSharp
IEnumerable<ParameterDeclaration> MakeParameters(IReadOnlyList<IParameter> parameters, ILFunction function)
{
var variables = function.Variables.Where(v => v.Kind == VariableKind.Parameter).ToDictionary(v => v.Index);
//if the variable is a parameter is a parameter then index "should not" be null, would indicate an deeper under lying problem if it is so we assert not null (!)
var variables = function.Variables.Where(v => v.Kind == VariableKind.Parameter).ToDictionary(v => v.Index!.Value);
int i = 0;
foreach (var parameter in parameters)
{
@ -2612,7 +2613,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2612,7 +2613,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
internal TranslatedExpression TranslateTarget(ILInstruction target, bool nonVirtualInvocation,
internal TranslatedExpression TranslateTarget(ILInstruction? target, bool nonVirtualInvocation,
bool memberStatic, IType memberDeclaringType)
{
// If references are missing member.IsStatic might not be set correctly.
@ -2987,7 +2988,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2987,7 +2988,7 @@ namespace ICSharpCode.Decompiler.CSharp
memberName = "LongLength";
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
? new ResolveResult(compilation.FindType(code))
: new MemberResolveResult(arrayExpr.ResolveResult, member);
@ -3393,7 +3394,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -3393,7 +3394,7 @@ namespace ICSharpCode.Decompiler.CSharp
var elementsStack = new Stack<List<TranslatedExpression>>();
var elements = new List<TranslatedExpression>(block.Instructions.Count);
elementsStack.Push(elements);
List<IL.Transforms.AccessPathElement> currentPath = null;
List<IL.Transforms.AccessPathElement>? currentPath = null;
var indexVariables = new Dictionary<ILVariable, ILInstruction>();
foreach (var inst in block.Instructions.Skip(1))
{
@ -3544,7 +3545,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -3544,7 +3545,7 @@ namespace ICSharpCode.Decompiler.CSharp
{
var stloc = block.Instructions.FirstOrDefault() as StLoc;
var final = block.FinalInstruction as LdLoc;
if (stloc == null || final == null || !stloc.Value.MatchNewArr(out IType type))
if (stloc == null || final == null || !stloc.Value.MatchNewArr(out IType? type))
throw new ArgumentException("given Block is invalid!");
if (stloc.Variable != final.Variable || stloc.Variable.Kind != VariableKind.InitializerTarget)
throw new ArgumentException("given Block is invalid!");
@ -3563,11 +3564,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -3563,11 +3564,11 @@ namespace ICSharpCode.Decompiler.CSharp
for (int i = 1; i < block.Instructions.Count; i++)
{
if (!block.Instructions[i].MatchStObj(out ILInstruction target, out ILInstruction value, out IType t) || !type.Equals(t))
if (!block.Instructions[i].MatchStObj(out ILInstruction? target, out ILInstruction? value, out IType? t) || !type.Equals(t))
throw new ArgumentException("given Block is invalid!");
if (!target.MatchLdElema(out t, out ILInstruction array) || !type.Equals(t))
if (!target.MatchLdElema(out t, out ILInstruction? array) || !type.Equals(t))
throw new ArgumentException("given Block is invalid!");
if (!array.MatchLdLoc(out ILVariable v) || v != final.Variable)
if (!array.MatchLdLoc(out ILVariable? v) || v != final.Variable)
throw new ArgumentException("given Block is invalid!");
while (container.Count < dimensions)
{
@ -3602,7 +3603,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -3602,7 +3603,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
ArraySpecifier[] additionalSpecifiers;
AstType typeExpression;
AstType? typeExpression;
if (settings.AnonymousTypes && type.ContainsAnonymousType())
{
typeExpression = null;
@ -3916,7 +3917,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -3916,7 +3917,8 @@ namespace ICSharpCode.Decompiler.CSharp
{
TranslatedExpression value;
IType type;
if (inst.Value is StringToInt strToInt)
var strToInt = inst.Value as StringToInt;
if (strToInt != null)
{
value = Translate(strToInt.Argument)
.ConvertTo(
@ -4023,7 +4025,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -4023,7 +4025,7 @@ namespace ICSharpCode.Decompiler.CSharp
protected internal override TranslatedExpression VisitAwait(Await inst, TranslationContext context)
{
IType expectedType = null;
IType? expectedType = null;
if (inst.GetAwaiterMethod != null)
{
if (inst.GetAwaiterMethod.IsStatic)
@ -4533,7 +4535,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -4533,7 +4535,7 @@ namespace ICSharpCode.Decompiler.CSharp
{
if (subPattern.HasDesignator)
{
if (!conversionMapping.TryGetValue(subPattern.Variable, out ILVariable value))
if (!conversionMapping.TryGetValue(subPattern.Variable, out ILVariable? value))
{
value = subPattern.Variable;
}
@ -4638,7 +4640,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -4638,7 +4640,7 @@ namespace ICSharpCode.Decompiler.CSharp
Debug.Fail("Invalid sub pattern");
continue;
}
IMember member;
IMember? member;
if (testedOperand is CallInstruction call)
{
member = call.Method.AccessorOwner;

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

@ -58,7 +58,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -58,7 +58,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
TypeSystemAstBuilder astBuilder = CreateAstBuilder();
AstNode node = astBuilder.ConvertSymbol(symbol);
writer.StartNode(node);
EntityDeclaration entityDecl = node as EntityDeclaration;
EntityDeclaration? entityDecl = node as EntityDeclaration;
if (entityDecl != null)
PrintModifiers(entityDecl.Modifiers, writer);

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

@ -92,7 +92,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -92,7 +92,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
/// </summary>
/// <param name="nextNode">The next node after the 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);
// TODO: Comma policy has changed.
@ -105,7 +105,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -105,7 +105,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
/// <summary>
/// Writes an optional comma, e.g. at the end of an enum declaration or in an array initializer
/// </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.
while (pos != null && pos.NodeType == NodeType.Whitespace)
@ -121,7 +121,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -121,7 +121,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
/// <summary>
/// Writes an optional semicolon, e.g. at the end of a type or namespace declaration.
/// </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.
while (pos != null && pos.NodeType == NodeType.Whitespace)
@ -200,7 +200,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -200,7 +200,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
WriteKeyword(tokenRole.Token, tokenRole);
}
protected virtual void WriteKeyword(string token, Role tokenRole = null)
protected virtual void WriteKeyword(string token, Role? tokenRole = null)
{
writer.WriteKeyword(tokenRole, token);
isAtStartOfLine = false;
@ -529,7 +529,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -529,7 +529,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
NewLine();
return;
}
BlockStatement block = embeddedStatement as BlockStatement;
BlockStatement? block = embeddedStatement as BlockStatement;
if (block != null)
{
WriteBlock(block, policy.StatementBraceStyle);
@ -672,7 +672,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -672,7 +672,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
{
// "int a; new List<int> { a = 1 };" is an object initalizers and invalid, but
// "int a; new List<int> { { a = 1 } };" is a valid collection initializer.
AssignmentExpression ae = expr as AssignmentExpression;
AssignmentExpression? ae = expr as AssignmentExpression;
return ae != null && ae.Operator == AssignmentOperatorType.Assign;
}
@ -703,7 +703,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -703,7 +703,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
OpenBrace(wrap ? policy.ArrayInitializerBraceStyle : BraceStyle.EndOfLine, newLine: wrap);
if (!wrap)
Space();
AstNode last = null;
AstNode? last = null;
foreach (var (idx, node) in elements.WithIndex())
{
if (idx > 0)
@ -1658,7 +1658,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -1658,7 +1658,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
if (typeDeclaration.ClassType == ClassType.Enum)
{
bool first = true;
AstNode last = null;
AstNode? last = null;
foreach (var member in typeDeclaration.Members)
{
if (first)
@ -1947,7 +1947,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -1947,7 +1947,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
WriteIdentifier(labelStatement.GetChildByRole(Roles.Identifier));
WriteToken(Roles.Colon);
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)
{
@ -2340,7 +2340,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -2340,7 +2340,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
StartNode(constructorDeclaration);
WriteAttributes(constructorDeclaration.Attributes);
WriteModifiers(constructorDeclaration.ModifierTokens);
TypeDeclaration type = constructorDeclaration.Parent as TypeDeclaration;
TypeDeclaration? type = constructorDeclaration.Parent as TypeDeclaration;
if (type != null && type.Name != constructorDeclaration.Name)
WriteIdentifier((Identifier)type.NameToken.Clone());
else
@ -2386,7 +2386,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -2386,7 +2386,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
Space();
}
WriteToken(DestructorDeclaration.TildeRole);
TypeDeclaration type = destructorDeclaration.Parent as TypeDeclaration;
TypeDeclaration? type = destructorDeclaration.Parent as TypeDeclaration;
if (type != null && type.Name != destructorDeclaration.Name)
WriteIdentifier((Identifier)type.NameToken.Clone());
else
@ -2949,7 +2949,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -2949,7 +2949,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
public virtual void VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode)
{
CSharpModifierToken mod = cSharpTokenNode as CSharpModifierToken;
CSharpModifierToken? mod = cSharpTokenNode as CSharpModifierToken;
if (mod != null)
{
// ITokenWriter assumes that each node processed between a

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

@ -53,7 +53,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -53,7 +53,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
var v = new GenericGrammarAmbiguityVisitor();
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))
return v.ambiguityFound;

4
ICSharpCode.Decompiler/CSharp/OutputVisitor/ITokenWriter.cs

@ -46,7 +46,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -46,7 +46,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
/// <summary>
/// Writes a primitive/literal value
/// </summary>
public abstract void WritePrimitiveValue(object value, LiteralFormat format = LiteralFormat.None);
public abstract void WritePrimitiveValue(object? value, LiteralFormat format = LiteralFormat.None);
public abstract void WritePrimitiveType(string type);
@ -129,7 +129,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -129,7 +129,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
decoratedWriter.WriteToken(role, token);
}
public override void WritePrimitiveValue(object value, LiteralFormat format = LiteralFormat.None)
public override void WritePrimitiveValue(object? value, LiteralFormat format = LiteralFormat.None)
{
decoratedWriter.WritePrimitiveValue(value, format);
}

12
ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs

@ -105,20 +105,20 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -105,20 +105,20 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
public override void WriteKeyword(Role role, string keyword)
{
TextLocation start = locationProvider.Location;
CSharpTokenNode t = null;
CSharpTokenNode? t = null;
if (role is TokenRole)
t = new CSharpTokenNode(start, (TokenRole)role);
else if (role == EntityDeclaration.ModifierRole)
t = new CSharpModifierToken(start, CSharpModifierToken.GetModifierValue(keyword));
else if (keyword == "this")
{
ThisReferenceExpression node = nodes.Peek().LastOrDefault() as ThisReferenceExpression;
ThisReferenceExpression? node = nodes.Peek().LastOrDefault() as ThisReferenceExpression;
if (node != null)
node.Location = start;
}
else if (keyword == "base")
{
BaseReferenceExpression node = nodes.Peek().LastOrDefault() as BaseReferenceExpression;
BaseReferenceExpression? node = nodes.Peek().LastOrDefault() as BaseReferenceExpression;
if (node != null)
node.Location = start;
}
@ -138,9 +138,9 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -138,9 +138,9 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
base.WriteIdentifier(identifier);
}
public override void WritePrimitiveValue(object value, LiteralFormat format = LiteralFormat.None)
public override void WritePrimitiveValue(object? value, LiteralFormat format = LiteralFormat.None)
{
Expression node = nodes.Peek().LastOrDefault() as Expression;
Expression? node = nodes.Peek().LastOrDefault() as Expression;
var startLocation = locationProvider.Location;
base.WritePrimitiveValue(value, format);
if (node is PrimitiveExpression)
@ -155,7 +155,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -155,7 +155,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
public override void WritePrimitiveType(string type)
{
PrimitiveType node = nodes.Peek().LastOrDefault() as PrimitiveType;
PrimitiveType? node = nodes.Peek().LastOrDefault() as PrimitiveType;
if (node != null)
node.SetStartLocation(locationProvider.Location);
base.WritePrimitiveType(type);

10
ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs

@ -218,7 +218,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -218,7 +218,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
public override void VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression)
{
ParenthesizeIfRequired(unaryOperatorExpression.Expression, GetPrecedence(unaryOperatorExpression));
UnaryOperatorExpression child = unaryOperatorExpression.Expression as UnaryOperatorExpression;
UnaryOperatorExpression? child = unaryOperatorExpression.Expression as UnaryOperatorExpression;
if (child != null && InsertParenthesesForReadability)
Parenthesize(child);
base.VisitUnaryOperatorExpression(unaryOperatorExpression);
@ -233,7 +233,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -233,7 +233,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
}
// There's a nasty issue in the C# grammar: cast expressions including certain operators are ambiguous in some cases
// "(int)-1" is fine, but "(A)-b" is not a cast.
UnaryOperatorExpression uoe = castExpression.Expression as UnaryOperatorExpression;
UnaryOperatorExpression? uoe = castExpression.Expression as UnaryOperatorExpression;
if (uoe != null && !(uoe.Operator == UnaryOperatorType.BitNot || uoe.Operator == UnaryOperatorType.Not))
{
if (TypeCanBeMisinterpretedAsExpression(castExpression.Type))
@ -242,7 +242,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -242,7 +242,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
}
}
// The above issue can also happen with PrimitiveExpressions representing negative values:
PrimitiveExpression pe = castExpression.Expression as PrimitiveExpression;
PrimitiveExpression? pe = castExpression.Expression as PrimitiveExpression;
if (pe != null && pe.Value != null && TypeCanBeMisinterpretedAsExpression(castExpression.Type))
{
TypeCode typeCode = Type.GetTypeCode(pe.Value.GetType());
@ -286,7 +286,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -286,7 +286,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
// SimpleTypes can always be misinterpreted as IdentifierExpressions
// MemberTypes can be misinterpreted as MemberReferenceExpressions if they don't use double colon
// PrimitiveTypes or ComposedTypes can never be misinterpreted as expressions.
MemberType mt = type as MemberType;
MemberType? mt = type as MemberType;
if (mt != null)
return !mt.IsDoubleColon;
else
@ -354,7 +354,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -354,7 +354,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
BinaryOperatorType? GetBinaryOperatorType(Expression expr)
{
BinaryOperatorExpression boe = expr as BinaryOperatorExpression;
BinaryOperatorExpression? boe = expr as BinaryOperatorExpression;
if (boe != null)
return boe.Operator;
else

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

@ -148,7 +148,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -148,7 +148,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
lastWritten = LastWritten.Whitespace;
}
public override void WritePrimitiveValue(object value, LiteralFormat format = LiteralFormat.None)
public override void WritePrimitiveValue(object? value, LiteralFormat format = LiteralFormat.None)
{
if (lastWritten == LastWritten.KeywordOrIdentifier)
{

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

@ -82,9 +82,9 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -82,9 +82,9 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
/// <summary>
/// Writes all specials from start to end (exclusive). Does not touch the positionStack.
/// </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)
{
@ -118,14 +118,14 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -118,14 +118,14 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
WriteSpecialsUpToRole(role, null);
}
void WriteSpecialsUpToRole(Role role, AstNode nextNode)
void WriteSpecialsUpToRole(Role role, AstNode? nextNode)
{
if (positionStack.Count == 0)
{
return;
}
// 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)
{
@ -149,7 +149,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -149,7 +149,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
{
return;
}
for (AstNode pos = positionStack.Peek(); pos != null; pos = pos.NextSibling)
for (AstNode? pos = positionStack.Peek(); pos != null; pos = pos.NextSibling)
{
if (pos == node)
{

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

@ -233,7 +233,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -233,7 +233,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
return writer.ToString();
}
public override void WritePrimitiveValue(object value, LiteralFormat format = LiteralFormat.None)
public override void WritePrimitiveValue(object? value, LiteralFormat format = LiteralFormat.None)
{
if (value == null)
{
@ -437,7 +437,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -437,7 +437,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
/// Gets the escape sequence for the specified character.
/// </summary>
/// <remarks>This method does not convert ' or ".</remarks>
static string ConvertChar(char ch)
static string? ConvertChar(char ch)
{
switch (ch)
{
@ -499,7 +499,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -499,7 +499,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
StringBuilder sb = new StringBuilder();
foreach (char ch in str)
{
string s = ch == '"' ? "\\\"" : ConvertChar(ch);
string? s = ch == '"' ? "\\\"" : ConvertChar(ch);
if (s != null)
sb.Append(s);
else

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

@ -272,7 +272,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -272,7 +272,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
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;
}

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

@ -52,7 +52,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -52,7 +52,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
/// <summary>
/// Gets the target framework identifier. Can be null if not defined.
/// </summary>
public string Identifier { get; }
public string? Identifier { get; }
/// <summary>
/// Gets the target framework moniker. Can be null if not supported.
@ -79,7 +79,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -79,7 +79,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
/// </summary>
public bool IsPortableClassLibrary { get; }
static string GetTargetFrameworkMoniker(string frameworkIdentifier, int version)
static string? GetTargetFrameworkMoniker(string frameworkIdentifier, int version)
{
// Reference: https://docs.microsoft.com/en-us/dotnet/standard/frameworks
switch (frameworkIdentifier)

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

@ -66,15 +66,15 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -66,15 +66,15 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
break;
}
string targetFrameworkIdentifier = null;
string targetFrameworkProfile = null;
string? targetFrameworkIdentifier = null;
string? targetFrameworkProfile = null;
string targetFramework = module.DetectTargetFrameworkId();
if (!string.IsNullOrEmpty(targetFramework))
{
string[] frameworkParts = targetFramework.Split(',');
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)
{
@ -83,7 +83,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -83,7 +83,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
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)
targetFrameworkProfile = frameworkProfile.Substring(ProfileToken.Length);
}
@ -245,7 +245,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -245,7 +245,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
break;
}
MetadataFile resolvedReference;
MetadataFile? resolvedReference;
try
{
resolvedReference = assemblyResolver.Resolve(reference);

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

@ -71,7 +71,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -71,7 +71,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
public AssemblyReferenceClassifier AssemblyReferenceClassifier { get; }
public IDebugInfoProvider DebugInfoProvider { get; }
public IDebugInfoProvider? DebugInfoProvider { get; }
/// <summary>
/// The MSBuild ProjectGuid to use for the new project.
@ -106,9 +106,9 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -106,9 +106,9 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
public WholeProjectDecompiler(
DecompilerSettings settings,
IAssemblyResolver assemblyResolver,
IProjectFileWriter projectWriter,
AssemblyReferenceClassifier assemblyReferenceClassifier,
IDebugInfoProvider debugInfoProvider)
IProjectFileWriter? projectWriter,
AssemblyReferenceClassifier? assemblyReferenceClassifier,
IDebugInfoProvider? debugInfoProvider)
: this(settings, Guid.NewGuid(), assemblyResolver, projectWriter, assemblyReferenceClassifier, debugInfoProvider)
{
}
@ -117,9 +117,9 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -117,9 +117,9 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
DecompilerSettings settings,
Guid projectGuid,
IAssemblyResolver assemblyResolver,
IProjectFileWriter projectWriter,
AssemblyReferenceClassifier assemblyReferenceClassifier,
IDebugInfoProvider debugInfoProvider)
IProjectFileWriter? projectWriter,
AssemblyReferenceClassifier? assemblyReferenceClassifier,
IDebugInfoProvider? debugInfoProvider)
{
Settings = settings ?? throw new ArgumentNullException(nameof(settings));
ProjectGuid = projectGuid;
@ -325,7 +325,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -325,7 +325,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
{
foreach (var r in module.Resources.Where(r => r.ResourceType == ResourceType.Embedded))
{
Stream stream = r.TryOpenStream();
Stream? stream = r.TryOpenStream();
stream.Position = 0;
if (r.Name.EndsWith(".resources", StringComparison.OrdinalIgnoreCase))
@ -341,7 +341,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -341,7 +341,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
{
string fileName = SanitizeFileName(name)
.Replace('/', Path.DirectorySeparatorChar);
string dirName = Path.GetDirectoryName(fileName);
string? dirName = Path.GetDirectoryName(fileName);
if (!string.IsNullOrEmpty(dirName) && directories.Add(dirName))
{
Directory.CreateDirectory(Path.Combine(TargetDirectory, dirName));
@ -488,7 +488,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -488,7 +488,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
const int RT_ICON = 3;
const int RT_GROUP_ICON = 14;
unsafe static byte[] CreateApplicationIcon(Win32ResourceDirectory resources)
unsafe static byte[]? CreateApplicationIcon(Win32ResourceDirectory resources)
{
var iconGroup = resources.Find(new Win32ResourceName(RT_GROUP_ICON))?.FirstDirectory()?.FirstData()?.Data;
if (iconGroup == null)
@ -636,7 +636,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -636,7 +636,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
if (pos > 0)
text = text.Substring(0, pos);
text = text.Trim();
string extension = null;
string? extension = null;
int currentSegmentLength = 0;
if (treatAsFileName)
{
@ -781,9 +781,9 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -781,9 +781,9 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
public record struct ProjectItemInfo(string ItemType, string FileName)
{
public List<PartialTypeInfo> PartialTypes { get; set; } = null;
public List<PartialTypeInfo>? PartialTypes { get; set; } = null;
public Dictionary<string, string> AdditionalProperties { get; set; } = null;
public Dictionary<string, string>? AdditionalProperties { get; set; } = null;
public ProjectItemInfo With(string name, string value)
{

56
ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection.Metadata;
using System.Threading;
@ -39,8 +40,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -39,8 +40,8 @@ namespace ICSharpCode.Decompiler.CSharp
readonly bool isInheritedRecord;
readonly bool isStruct;
readonly bool isSealed;
readonly IMethod primaryCtor;
readonly IType baseClass;
readonly IMethod? primaryCtor;
readonly IType? baseClass;
readonly Dictionary<IField, IProperty> backingFieldToAutoProperty = new Dictionary<IField, IProperty>();
readonly Dictionary<IProperty, IField> autoPropertyToBackingField = new Dictionary<IProperty, IField>();
readonly Dictionary<IParameter, IMember> primaryCtorParameterToAutoPropertyOrBackingField = new Dictionary<IParameter, IMember>();
@ -75,7 +76,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -75,7 +76,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
bool IsAutoProperty(IProperty p, out IField field)
bool IsAutoProperty(IProperty p, [NotNullWhen(true)] out IField? field)
{
field = null;
if (p.IsStatic)
@ -108,7 +109,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -108,7 +109,7 @@ namespace ICSharpCode.Decompiler.CSharp
return field.Name == $"<{p.Name}>k__BackingField";
}
bool IsAutoGetter(IMethod method, out IField field)
bool IsAutoGetter(IMethod method, [NotNullWhen(true)] out IField? field)
{
field = null;
var body = DecompileBody(method);
@ -129,7 +130,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -129,7 +130,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
bool IsAutoSetter(IMethod method, out IField field)
bool IsAutoSetter(IMethod method, [NotNullWhen(true)] out IField? field)
{
field = null;
Debug.Assert(!method.IsStatic);
@ -137,7 +138,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -137,7 +138,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (body == null)
return false;
// this.field = value;
ILInstruction valueInst;
ILInstruction? valueInst;
if (method.IsStatic)
{
if (!body.Instructions[0].MatchStsFld(out field, out valueInst))
@ -158,7 +159,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -158,7 +159,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
IMethod DetectPrimaryConstructor()
IMethod? DetectPrimaryConstructor()
{
if (recordTypeDef.IsRecord)
{
@ -266,7 +267,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -266,7 +267,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// <summary>
/// Gets the detected primary constructor. Returns null, if there was no primary constructor detected.
/// </summary>
public IMethod PrimaryConstructor => primaryCtor;
public IMethod? PrimaryConstructor => primaryCtor;
public bool IsInheritedRecord => isInheritedRecord;
@ -373,7 +374,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -373,7 +374,7 @@ namespace ICSharpCode.Decompiler.CSharp
&& autoPropertyOrBackingFieldToPrimaryCtorParameter.ContainsKey((IProperty)property.Specialize(subst));
}
internal (IProperty prop, IField field) GetPropertyInfoByPrimaryConstructorParameter(IParameter parameter)
internal (IProperty? prop, IField field) GetPropertyInfoByPrimaryConstructorParameter(IParameter parameter)
{
var member = primaryCtorParameterToAutoPropertyOrBackingField[parameter];
if (member is IField field)
@ -450,9 +451,15 @@ namespace ICSharpCode.Decompiler.CSharp @@ -450,9 +451,15 @@ namespace ICSharpCode.Decompiler.CSharp
{
if (!(member is IField field))
{
if (!autoPropertyToBackingField.TryGetValue((IProperty)member, out field))
if (!autoPropertyToBackingField.TryGetValue((IProperty)member, out var fieldHolder))
{
continue;
}
else
{
field = fieldHolder;
}
}
if (pos >= body.Instructions.Count)
return false;
if (!body.Instructions[pos].MatchStFld(out var lhsTarget, out var lhsField, out var valueInst))
@ -516,7 +523,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -516,7 +523,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (!(body.Instructions.Single() is Leave leave))
return false;
// leave IL_0000 (call GetTypeFromHandle(ldtypetoken R))
if (!TransformExpressionTrees.MatchGetTypeFromHandle(leave.Value, out IType ty))
if (!TransformExpressionTrees.MatchGetTypeFromHandle(leave.Value, out IType? ty))
return false;
return IsRecordType(ty);
}
@ -569,7 +576,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -569,7 +576,7 @@ namespace ICSharpCode.Decompiler.CSharp
trueInst = Block.Unwrap(trueInst);
if (!MatchStringBuilderAppend(trueInst, builder, out var val))
return false;
if (!(val.MatchLdStr(out string text) && text == ", "))
if (!(val.MatchLdStr(out string? text) && text == ", "))
return false;
pos++;
@ -601,7 +608,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -601,7 +608,7 @@ namespace ICSharpCode.Decompiler.CSharp
callvirt Append(ldloc builder, ldstr " = ")
callvirt Append(ldloc builder, constrained[System.Int32].callvirt ToString(ldflda B(ldloc this)))
leave IL_0000 (ldc.i4 1) */
if (!MatchStringBuilderAppendConstant(out string text))
if (!MatchStringBuilderAppendConstant(out string? text))
return false;
string expectedText = (needsComma ? ", " : "") + member.Name + " = ";
if (text != expectedText)
@ -672,10 +679,10 @@ namespace ICSharpCode.Decompiler.CSharp @@ -672,10 +679,10 @@ namespace ICSharpCode.Decompiler.CSharp
return true;
}
bool MatchStringBuilderAppendConstant(out string text)
bool MatchStringBuilderAppendConstant([NotNullWhen(true)] out string? text)
{
text = null;
while (MatchStringBuilderAppend(body.Instructions[pos], builder, out var val) && val.MatchLdStr(out string valText))
while (MatchStringBuilderAppend(body.Instructions[pos], builder, out var val) && val.MatchLdStr(out string? valText))
{
text += valText;
pos++;
@ -684,7 +691,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -684,7 +691,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
private bool MatchStringBuilderAppend(ILInstruction inst, ILVariable sb, out ILInstruction val)
private bool MatchStringBuilderAppend(ILInstruction inst, ILVariable sb, [NotNullWhen(true)] out ILInstruction? val)
{
val = null;
if (!(inst is CallVirt { Method: { Name: "Append", DeclaringType: { Namespace: "System.Text", Name: "StringBuilder" } } } call))
@ -760,7 +767,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -760,7 +767,7 @@ namespace ICSharpCode.Decompiler.CSharp
{
return val != null && val.Length == 1 && call.Arguments[1].MatchLdcI4(val[0]);
}
return call.Arguments[1].MatchLdStr(out string val1) && val1 == val;
return call.Arguments[1].MatchLdStr(out string? val1) && val1 == val;
}
}
@ -912,7 +919,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -912,7 +919,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
private bool MatchGetEqualityContract(ILInstruction inst, out ILInstruction target)
private bool MatchGetEqualityContract(ILInstruction inst, [NotNullWhen(true)] out ILInstruction? target)
{
target = null;
if (!(inst is CallInstruction { Method: { Name: "get_EqualityContract" } } call))
@ -1099,7 +1106,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1099,7 +1106,7 @@ namespace ICSharpCode.Decompiler.CSharp
return returnInst != null && returnInst.MatchReturn(out var retVal) && retVal.MatchNop();
}
bool MatchMemberAccess(ILInstruction inst, out ILInstruction target, out IMember member)
bool MatchMemberAccess(ILInstruction inst, [NotNullWhen(true)] out ILInstruction? target, [NotNullWhen(true)] out IMember? member)
{
target = null;
member = null;
@ -1116,12 +1123,17 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1116,12 +1123,17 @@ namespace ICSharpCode.Decompiler.CSharp
member = property;
return true;
}
else if (inst.MatchLdFld(out target, out IField field))
else if (inst.MatchLdFld(out target, out IField? field))
{
if (backingFieldToAutoProperty.TryGetValue(field, out property))
if (backingFieldToAutoProperty.TryGetValue(field, out var propertyHolder))
{
property = propertyHolder;
member = property;
}
else
{
member = field;
}
return true;
}
else
@ -1130,7 +1142,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1130,7 +1142,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
Block DecompileBody(IMethod method)
Block? DecompileBody(IMethod method)
{
if (method == null || method.MetadataToken.IsNil)
return null;

6
ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -37,7 +37,7 @@ namespace ICSharpCode.Decompiler.CSharp
var collector = new RequiredNamespaceCollector(namespaces);
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.GetModuleAttributes());
@ -56,7 +56,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -56,7 +56,7 @@ namespace ICSharpCode.Decompiler.CSharp
collector.CollectNamespaces(entity, module);
}
void CollectNamespaces(IEntity entity, MetadataModule module, CodeMappingInfo mappingInfo = null)
void CollectNamespaces(IEntity entity, MetadataModule module, CodeMappingInfo? mappingInfo = null)
{
if (entity == null || entity.MetadataToken.IsNil || module.MetadataFile is not MetadataFile corFile)
return;
@ -334,7 +334,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -334,7 +334,7 @@ namespace ICSharpCode.Decompiler.CSharp
case HandleKind.MethodDefinition:
case HandleKind.MethodSpecification:
case HandleKind.MemberReference:
IMember member;
IMember? member;
try
{
member = module.ResolveEntity(handle, genericContext) as IMember;

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

@ -42,20 +42,20 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -42,20 +42,20 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// <summary>
/// Property representing the IsCompleted property on the awaiter type. Can be null if the awaiter type or the property was not found, or when awaiting a dynamic expression.
/// </summary>
public readonly IProperty IsCompletedProperty;
public readonly IProperty? IsCompletedProperty;
/// <summary>
/// Method representing the OnCompleted method on the awaiter type. Can be null if the awaiter type or the method was not found, or when awaiting a dynamic expression.
/// This can also refer to an UnsafeOnCompleted method, if the awaiter type implements <c>System.Runtime.CompilerServices.ICriticalNotifyCompletion</c>.
/// </summary>
public readonly IMethod OnCompletedMethod;
public readonly IMethod? OnCompletedMethod;
/// <summary>
/// Method representing the GetResult method on the awaiter type. Can be null if the awaiter type or the method was not found, or when awaiting a dynamic expression.
/// </summary>
public readonly IMethod GetResultMethod;
public readonly IMethod? GetResultMethod;
public AwaitResolveResult(IType resultType, ResolveResult getAwaiterInvocation, IType awaiterType, IProperty isCompletedProperty, IMethod onCompletedMethod, IMethod getResultMethod)
public AwaitResolveResult(IType resultType, ResolveResult getAwaiterInvocation, IType awaiterType, IProperty? isCompletedProperty, IMethod? onCompletedMethod, IMethod? getResultMethod)
: base(resultType)
{
if (awaiterType == null)

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

@ -56,7 +56,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -56,7 +56,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
if (compilation == null)
throw new ArgumentNullException(nameof(compilation));
CacheManager cache = compilation.CacheManager;
CSharpConversions operators = (CSharpConversions)cache.GetShared(typeof(CSharpConversions));
CSharpConversions? operators = (CSharpConversions)cache.GetShared(typeof(CSharpConversions));
if (operators == null)
{
operators = (CSharpConversions)cache.GetOrAddShared(typeof(CSharpConversions), new CSharpConversions(compilation));
@ -77,7 +77,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -77,7 +77,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
this.ToType = toType;
}
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return (obj is TypePair) && Equals((TypePair)obj);
}
@ -182,7 +182,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -182,7 +182,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
throw new ArgumentNullException(nameof(toType));
TypePair pair = new TypePair(fromType, toType);
if (implicitConversionCache.TryGetValue(pair, out Conversion c))
if (implicitConversionCache.TryGetValue(pair, out Conversion? c))
return c;
c = ImplicitConversion(fromType, toType, allowUserDefined: true, allowTuple: true);
@ -523,10 +523,10 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -523,10 +523,10 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
if (!(fromType.IsReferenceType == true && toType.IsReferenceType != false))
return false;
ArrayType fromArray = fromType as ArrayType;
ArrayType? fromArray = fromType as ArrayType;
if (fromArray != null)
{
ArrayType toArray = toType as ArrayType;
ArrayType? toArray = toType as ArrayType;
if (toArray != null)
{
// array covariance (the broken kind)
@ -554,9 +554,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -554,9 +554,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// For IList{T}, ICollection{T}, IEnumerable{T} and IReadOnlyList{T}, returns T.
/// Otherwise, returns null.
/// </summary>
IType UnpackGenericArrayInterface(IType interfaceType)
IType? UnpackGenericArrayInterface(IType interfaceType)
{
ParameterizedType pt = interfaceType as ParameterizedType;
ParameterizedType? pt = interfaceType as ParameterizedType;
if (pt != null)
{
switch (pt.GetDefinition()?.KnownTypeCode)
@ -600,13 +600,13 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -600,13 +600,13 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
bool IdentityOrVarianceConversion(IType s, IType t, int subtypeCheckNestingDepth)
{
ITypeDefinition def = s.GetDefinition();
ITypeDefinition? def = s.GetDefinition();
if (def != null)
{
if (!def.Equals(t.GetDefinition()))
return false;
ParameterizedType ps = s as ParameterizedType;
ParameterizedType pt = t as ParameterizedType;
ParameterizedType? ps = s as ParameterizedType;
ParameterizedType? pt = t as ParameterizedType;
if (ps != null && pt != null)
{
// C# 4.0 spec: §13.1.3.2 Variance Conversion
@ -697,11 +697,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -697,11 +697,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
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()))
return false;
ParameterizedType ps = fromType as ParameterizedType;
ParameterizedType pt = toType as ParameterizedType;
ParameterizedType? ps = fromType as ParameterizedType;
ParameterizedType? pt = toType as ParameterizedType;
if (ps == null || pt == null)
{
// non-generic delegate - return true for the identity conversion
@ -792,7 +792,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -792,7 +792,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
#endregion
#region Implicit Constant-Expression Conversion
bool ImplicitConstantExpressionConversion(ResolveResult rr, IType toType)
bool ImplicitConstantExpressionConversion(ResolveResult? rr, IType toType)
{
if (rr == null || !rr.IsCompileTimeConstant)
return false;
@ -811,7 +811,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -811,7 +811,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
else if (fromTypeCode == TypeCode.Int32)
{
object cv = rr.ConstantValue;
object? cv = rr.ConstantValue;
if (cv == null)
return false;
int val = (int)cv;
@ -938,9 +938,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -938,9 +938,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
&& (StandardImplicitConversion(a, b).IsValid || StandardImplicitConversion(b, a).IsValid);
}
IType FindMostEncompassedType(IEnumerable<IType> candidates)
IType? FindMostEncompassedType(IEnumerable<IType> candidates)
{
IType best = null;
IType? best = null;
foreach (var current in candidates)
{
if (best == null || IsEncompassedBy(current, best))
@ -951,9 +951,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -951,9 +951,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return best;
}
IType FindMostEncompassingType(IEnumerable<IType> candidates)
IType? FindMostEncompassingType(IEnumerable<IType> candidates)
{
IType best = null;
IType? best = null;
foreach (var current in candidates)
{
if (best == null || IsEncompassedBy(best, current))
@ -983,7 +983,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -983,7 +983,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return Conversion.UserDefinedConversion(selected[0].Method, isLifted: selected[0].IsLifted, isImplicit: isImplicit, isAmbiguous: true, conversionBeforeUserDefinedOperator: ExplicitConversion(source, mostSpecificSource), conversionAfterUserDefinedOperator: ExplicitConversion(mostSpecificTarget, target));
}
Conversion UserDefinedImplicitConversion(ResolveResult fromResult, IType fromType, IType toType)
Conversion UserDefinedImplicitConversion(ResolveResult? fromResult, IType fromType, IType toType)
{
// C# 4.0 spec §6.4.4 User-defined implicit conversions
var operators = GetApplicableConversionOperators(fromResult, fromType, toType, false);
@ -1025,7 +1025,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1025,7 +1025,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
}
Conversion UserDefinedExplicitConversion(ResolveResult fromResult, IType fromType, IType toType)
Conversion UserDefinedExplicitConversion(ResolveResult? fromResult, IType fromType, IType toType)
{
// C# 4.0 spec §6.4.5 User-defined explicit conversions
var operators = GetApplicableConversionOperators(fromResult, fromType, toType, true);
@ -1112,7 +1112,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1112,7 +1112,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return NullableType.GetUnderlyingType(type);
}
List<OperatorInfo> GetApplicableConversionOperators(ResolveResult fromResult, IType fromType, IType toType, bool isExplicit)
List<OperatorInfo> GetApplicableConversionOperators(ResolveResult? fromResult, IType fromType, IType toType, bool isExplicit)
{
// Find the candidate operators:
Predicate<IMethod> opFilter;
@ -1179,7 +1179,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1179,7 +1179,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
Conversion AnonymousFunctionConversion(ResolveResult resolveResult, IType toType)
{
// C# 5.0 spec §6.5 Anonymous function conversions
LambdaResolveResult f = resolveResult as LambdaResolveResult;
LambdaResolveResult? f = resolveResult as LambdaResolveResult;
if (f == null)
return Conversion.None;
if (!f.IsAnonymousMethod)
@ -1245,7 +1245,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1245,7 +1245,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
static IType UnpackExpressionTreeType(IType type)
{
ParameterizedType pt = type as ParameterizedType;
ParameterizedType? pt = type as ParameterizedType;
if (pt != null && pt.TypeParameterCount == 1 && pt.Name == "Expression" && pt.Namespace == "System.Linq.Expressions")
{
return pt.GetTypeArgument(0);
@ -1261,7 +1261,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1261,7 +1261,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
Conversion MethodGroupConversion(ResolveResult resolveResult, IType toType)
{
// C# 4.0 spec §6.6 Method group conversions
MethodGroupResolveResult rr = resolveResult as MethodGroupResolveResult;
MethodGroupResolveResult? rr = resolveResult as MethodGroupResolveResult;
if (rr == null)
return Conversion.None;
IMethod invoke = toType.GetDelegateInvokeMethod();
@ -1430,7 +1430,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1430,7 +1430,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// <returns>0 = neither is better; 1 = t1 is better; 2 = t2 is better</returns>
public int BetterConversion(ResolveResult resolveResult, IType t1, IType t2)
{
LambdaResolveResult lambda = resolveResult as LambdaResolveResult;
LambdaResolveResult? lambda = resolveResult as LambdaResolveResult;
if (lambda != null)
{
if (!lambda.IsAnonymousMethod)
@ -1482,9 +1482,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1482,9 +1482,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// <summary>
/// Unpacks the generic Task[T]. Returns null if the input is not Task[T].
/// </summary>
static IType UnpackTask(IType type)
static IType? UnpackTask(IType type)
{
ParameterizedType pt = type as ParameterizedType;
ParameterizedType? pt = type as ParameterizedType;
if (pt != null && pt.TypeParameterCount == 1 && pt.Name == "Task" && pt.Namespace == "System.Threading.Tasks")
{
return pt.GetTypeArgument(0);

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

@ -57,9 +57,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -57,9 +57,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
bool isExtensionMethodInvocation = false,
bool isExpandedForm = false,
bool isDelegateInvocation = false,
IReadOnlyList<int> argumentToParameterMap = null,
IList<ResolveResult> initializerStatements = null,
IType returnTypeOverride = null
IReadOnlyList<int>? argumentToParameterMap = null,
IList<ResolveResult>? initializerStatements = null,
IType? returnTypeOverride = null
)
: base(targetResult, member, arguments, initializerStatements, returnTypeOverride)
{
@ -88,7 +88,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -88,7 +88,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public override IList<ResolveResult> GetArgumentsForCall()
{
ResolveResult[] results = new ResolveResult[Member.Parameters.Count];
List<ResolveResult> paramsArguments = IsExpandedForm ? new List<ResolveResult>() : null;
List<ResolveResult>? paramsArguments = IsExpandedForm ? new List<ResolveResult>() : null;
// map arguments to parameters:
for (int i = 0; i < Arguments.Count; i++)
{

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

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using ICSharpCode.Decompiler.CSharp.Syntax;
@ -154,7 +155,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -154,7 +155,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return WithContext(context.WithCurrentMember(member));
}
ITypeResolveContext ITypeResolveContext.WithCurrentMember(IMember member)
ITypeResolveContext ITypeResolveContext.WithCurrentMember(IMember? member)
{
return WithCurrentMember(member);
}
@ -188,12 +189,12 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -188,12 +189,12 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// <summary>
/// Sets the current type definition.
/// </summary>
public CSharpResolver WithCurrentTypeDefinition(ITypeDefinition typeDefinition)
public CSharpResolver WithCurrentTypeDefinition(ITypeDefinition? typeDefinition)
{
if (this.CurrentTypeDefinition == typeDefinition)
return this;
TypeDefinitionCache newTypeDefinitionCache;
TypeDefinitionCache? newTypeDefinitionCache;
if (typeDefinition != null)
newTypeDefinitionCache = new TypeDefinitionCache(typeDefinition);
else
@ -203,7 +204,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -203,7 +204,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
checkForOverflow, isWithinLambdaExpression, newTypeDefinitionCache, localVariableStack, objectInitializerStack);
}
ITypeResolveContext ITypeResolveContext.WithCurrentTypeDefinition(ITypeDefinition typeDefinition)
ITypeResolveContext ITypeResolveContext.WithCurrentTypeDefinition(ITypeDefinition? typeDefinition)
{
return WithCurrentTypeDefinition(typeDefinition);
}
@ -344,7 +345,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -344,7 +345,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
switch (op)
{
case UnaryOperatorType.Dereference:
PointerType p = expression.Type as PointerType;
PointerType? p = expression.Type as PointerType;
if (p != null)
return UnaryOperatorResolveResult(p.ElementType, op, expression);
else
@ -357,7 +358,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -357,7 +358,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
ResolveResult getAwaiterInvocation = ResolveInvocation(getAwaiterMethodGroup, Empty<ResolveResult>.Array, argumentNames: null, allowOptionalParameters: false);
var lookup = CreateMemberLookup();
IMethod getResultMethod;
IMethod? getResultMethod;
IType awaitResultType;
var getResultMethodGroup = lookup.Lookup(getAwaiterInvocation, "GetResult", EmptyList<IType>.Instance, true) as MethodGroupResolveResult;
if (getResultMethodGroup != null)
@ -505,7 +506,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -505,7 +506,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
else if (expression.IsCompileTimeConstant && m.CanEvaluateAtCompileTime)
{
object val;
object? val;
try
{
val = m.Invoke(this, expression.ConstantValue);
@ -564,7 +565,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -564,7 +565,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
#endregion
#region GetOverloadableOperatorName
static string GetOverloadableOperatorName(UnaryOperatorType op)
static string? GetOverloadableOperatorName(UnaryOperatorType op)
{
switch (op)
{
@ -922,7 +923,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -922,7 +923,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
else if (lhs.IsCompileTimeConstant && rhs.IsCompileTimeConstant && m.CanEvaluateAtCompileTime)
{
object val;
object? val;
try
{
val = m.Invoke(this, lhs.ConstantValue, rhs.ConstantValue);
@ -979,9 +980,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -979,9 +980,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
#endregion
#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;
}
@ -1202,7 +1203,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1202,7 +1203,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
#endregion
#region GetOverloadableOperatorName
static string GetOverloadableOperatorName(BinaryOperatorType op)
static string? GetOverloadableOperatorName(BinaryOperatorType op)
{
switch (op)
{
@ -1490,7 +1491,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1490,7 +1491,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
}
// Look in parameters of current method
IParameterizedMember parameterizedMember = this.CurrentMember as IParameterizedMember;
IParameterizedMember? parameterizedMember = this.CurrentMember as IParameterizedMember;
if (parameterizedMember != null)
{
foreach (IParameter p in parameterizedMember.Parameters)
@ -1504,7 +1505,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1504,7 +1505,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
// look in type parameters of current method
IMethod m = this.CurrentMember as IMethod;
IMethod? m = this.CurrentMember as IMethod;
if (m != null)
{
foreach (ITypeParameter tp in m.TypeParameters)
@ -1517,10 +1518,10 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1517,10 +1518,10 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
bool parameterizeResultType = !(typeArguments.Count != 0 && typeArguments.All(t => t.Kind == TypeKind.UnboundTypeArgument));
ResolveResult r = null;
ResolveResult? r = null;
if (currentTypeDefinitionCache != null)
{
Dictionary<string, ResolveResult> cache = null;
Dictionary<string, ResolveResult>? cache = null;
bool foundInCache = false;
if (k == 0)
{
@ -1597,7 +1598,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1597,7 +1598,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
}
public bool IsVariableReferenceWithSameType(ResolveResult rr, string identifier, out TypeResolveResult trr)
public bool IsVariableReferenceWithSameType(ResolveResult rr, string identifier, [NotNullWhen(true)] out TypeResolveResult? trr)
{
if (!(rr is MemberResolveResult || rr is LocalResolveResult))
{
@ -1608,12 +1609,12 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1608,12 +1609,12 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
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;
MemberLookup lookup = CreateMemberLookup(lookupMode);
// 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)
{
@ -1650,7 +1651,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1650,7 +1651,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
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
ResolvedUsingScope currentUsingScope = this.CurrentUsingScope;
@ -1680,10 +1681,10 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1680,10 +1681,10 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
// finally, look in the imported namespaces:
if (!(isInUsingDeclaration && u == currentUsingScope))
{
IType firstResult = null;
IType? firstResult = null;
foreach (var importedNamespace in u.Usings)
{
ITypeDefinition def = importedNamespace.GetTypeDefinition(identifier, typeArguments.Count);
ITypeDefinition? def = importedNamespace.GetTypeDefinition(identifier, typeArguments.Count);
if (def != null)
{
IType resultType;
@ -1711,7 +1712,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1711,7 +1712,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
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)
return null;
@ -1719,7 +1720,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1719,7 +1720,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
int k = typeArguments.Count;
if (k == 0)
{
INamespace childNamespace = n.GetChildNamespace(identifier);
INamespace? childNamespace = n.GetChildNamespace(identifier);
if (childNamespace != null)
{
if (usingScope != null && usingScope.HasAlias(identifier))
@ -1728,7 +1729,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1728,7 +1729,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
}
// then look for a type
ITypeDefinition def = n.GetTypeDefinition(identifier, k);
ITypeDefinition? def = n.GetTypeDefinition(identifier, k);
if (def != null && TopLevelTypeDefinitionIsAccessible(def))
{
IType result = def;
@ -1780,7 +1781,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1780,7 +1781,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
ResolveResult ResolveExternAlias(string alias)
{
INamespace ns = compilation.GetNamespaceForExternAlias(alias);
INamespace? ns = compilation.GetNamespaceForExternAlias(alias);
if (ns != null)
return new NamespaceResolveResult(ns);
else
@ -1794,7 +1795,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1794,7 +1795,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
// C# 4.0 spec: §7.6.4
bool parameterizeResultType = !(typeArguments.Count != 0 && typeArguments.All(t => t.Kind == TypeKind.UnboundTypeArgument));
NamespaceResolveResult nrr = target as NamespaceResolveResult;
NamespaceResolveResult? nrr = target as NamespaceResolveResult;
if (nrr != null)
{
return ResolveMemberAccessOnNamespace(nrr, identifier, typeArguments, parameterizeResultType);
@ -1838,7 +1839,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1838,7 +1839,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
else
{
MethodGroupResolveResult mgrr = result as MethodGroupResolveResult;
MethodGroupResolveResult? mgrr = result as MethodGroupResolveResult;
if (mgrr != null)
{
Debug.Assert(mgrr.extensionMethods == null);
@ -1853,11 +1854,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1853,11 +1854,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
{
if (typeArguments.Count == 0)
{
INamespace childNamespace = nrr.Namespace.GetChildNamespace(identifier);
INamespace? childNamespace = nrr.Namespace.GetChildNamespace(identifier);
if (childNamespace != null)
return new NamespaceResolveResult(childNamespace);
}
ITypeDefinition def = nrr.Namespace.GetTypeDefinition(identifier, typeArguments.Count);
ITypeDefinition? def = nrr.Namespace.GetTypeDefinition(identifier, typeArguments.Count);
if (def != null)
{
if (parameterizeResultType && typeArguments.Count > 0)
@ -1914,7 +1915,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1914,7 +1915,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
IType collectionType, enumeratorType, elementType;
ResolveResult getEnumeratorInvocation;
ResolveResult currentRR = null;
ResolveResult? currentRR = null;
// C# 4.0 spec: §8.8.4 The foreach statement
if (expression.Type.Kind == TypeKind.Array || expression.Type.Kind == TypeKind.Dynamic)
{
@ -1958,7 +1959,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1958,7 +1959,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
CheckForEnumerableInterface(expression, out collectionType, out enumeratorType, out elementType, out getEnumeratorInvocation);
}
}
IMethod moveNextMethod = null;
IMethod? moveNextMethod = null;
var moveNextMethodGroup = memberLookup.Lookup(new ResolveResult(enumeratorType), "MoveNext", EmptyList<IType>.Instance, false) as MethodGroupResolveResult;
if (moveNextMethodGroup != null)
{
@ -1970,7 +1971,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1970,7 +1971,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
if (currentRR == null)
currentRR = memberLookup.Lookup(new ResolveResult(enumeratorType), "Current", EmptyList<IType>.Instance, false);
IProperty currentProperty = null;
IProperty? currentProperty = null;
if (currentRR is MemberResolveResult)
currentProperty = ((MemberResolveResult)currentRR).Member as IProperty;
@ -1984,13 +1985,13 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1984,13 +1985,13 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
elementType = expression.Type.GetElementTypeFromIEnumerable(compilation, false, out bool? isGeneric);
if (isGeneric == true)
{
ITypeDefinition enumerableOfT = compilation.FindType(KnownTypeCode.IEnumerableOfT).GetDefinition();
ITypeDefinition? enumerableOfT = compilation.FindType(KnownTypeCode.IEnumerableOfT).GetDefinition();
if (enumerableOfT != null)
collectionType = new ParameterizedType(enumerableOfT, new[] { elementType });
else
collectionType = SpecialType.UnknownType;
ITypeDefinition enumeratorOfT = compilation.FindType(KnownTypeCode.IEnumeratorOfT).GetDefinition();
ITypeDefinition? enumeratorOfT = compilation.FindType(KnownTypeCode.IEnumeratorOfT).GetDefinition();
if (enumeratorOfT != null)
enumeratorType = new ParameterizedType(enumeratorOfT, new[] { elementType });
else
@ -2030,7 +2031,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2030,7 +2031,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// new List { all extensions from SomeExtensions }
/// }
/// </remarks>
public List<List<IMethod>> GetExtensionMethods(string name = null, IReadOnlyList<IType> typeArguments = null)
public List<List<IMethod>> GetExtensionMethods(string? name = null, IReadOnlyList<IType>? typeArguments = null)
{
return GetExtensionMethods(null, name, typeArguments);
}
@ -2059,7 +2060,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2059,7 +2060,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// new List { all extensions from SomeExtensions }
/// }
/// </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();
List<List<IMethod>> extensionMethodGroups = new List<List<IMethod>>();
@ -2072,7 +2073,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2072,7 +2073,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
continue;
if (!lookup.IsAccessible(method, false))
continue;
IType[] inferredTypes;
IType[]? inferredTypes;
if (typeArguments != null && typeArguments.Count > 0)
{
if (method.TypeParameters.Count != typeArguments.Count)
@ -2117,7 +2118,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2117,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
/// corresponding type parameter.
/// </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)
throw new ArgumentNullException(nameof(targetType));
@ -2127,7 +2128,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2127,7 +2128,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
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;
if (targetType == null)
@ -2221,7 +2222,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2221,7 +2222,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
#region ResolveInvocation
IList<ResolveResult> AddArgumentNamesIfNecessary(ResolveResult[] arguments, string[] argumentNames)
IList<ResolveResult> AddArgumentNamesIfNecessary(ResolveResult[] arguments, string[]? argumentNames)
{
if (argumentNames == null)
{
@ -2238,7 +2239,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2238,7 +2239,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
}
private ResolveResult ResolveInvocation(ResolveResult target, ResolveResult[] arguments, string[] argumentNames, bool allowOptionalParameters)
private ResolveResult ResolveInvocation(ResolveResult target, ResolveResult[] arguments, string[]? argumentNames, bool allowOptionalParameters)
{
// C# 4.0 spec: §7.6.5
@ -2248,7 +2249,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2248,7 +2249,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
bool isDynamic = arguments.Any(a => a.Type.Kind == TypeKind.Dynamic);
MethodGroupResolveResult mgrr = target as MethodGroupResolveResult;
MethodGroupResolveResult? mgrr = target as MethodGroupResolveResult;
if (mgrr != null)
{
if (isDynamic)
@ -2292,12 +2293,12 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2292,12 +2293,12 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
mgrr.TargetType, mgrr.MethodName, mgrr.TypeArguments, CreateParameters(arguments, argumentNames));
}
}
UnknownMemberResolveResult umrr = target as UnknownMemberResolveResult;
UnknownMemberResolveResult? umrr = target as UnknownMemberResolveResult;
if (umrr != null)
{
return new UnknownMethodResolveResult(umrr.TargetType, umrr.MemberName, umrr.TypeArguments, CreateParameters(arguments, argumentNames));
}
UnknownIdentifierResolveResult uirr = target as UnknownIdentifierResolveResult;
UnknownIdentifierResolveResult? uirr = target as UnknownIdentifierResolveResult;
if (uirr != null && CurrentTypeDefinition != null)
{
return new UnknownMethodResolveResult(CurrentTypeDefinition, uirr.Identifier, EmptyList<IType>.Instance, CreateParameters(arguments, argumentNames));
@ -2330,7 +2331,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2330,7 +2331,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// The argument names. Pass the null string for positional arguments.
/// </param>
/// <returns>InvocationResolveResult or UnknownMethodResolveResult</returns>
public ResolveResult ResolveInvocation(ResolveResult target, ResolveResult[] arguments, string[] argumentNames = null)
public ResolveResult ResolveInvocation(ResolveResult target, ResolveResult[] arguments, string[]? argumentNames = null)
{
return ResolveInvocation(target, arguments, argumentNames, allowOptionalParameters: true);
}
@ -2370,7 +2371,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2370,7 +2371,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
// create the parameter:
ByReferenceResolveResult brrr = arguments[i] as ByReferenceResolveResult;
ByReferenceResolveResult? brrr = arguments[i] as ByReferenceResolveResult;
if (brrr != null)
{
list.Add(new DefaultParameter(arguments[i].Type, argumentNames[i], referenceKind: brrr.ReferenceKind));
@ -2394,19 +2395,19 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2394,19 +2395,19 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
static string GuessParameterName(ResolveResult rr)
{
MemberResolveResult mrr = rr as MemberResolveResult;
MemberResolveResult? mrr = rr as MemberResolveResult;
if (mrr != null)
return mrr.Member.Name;
UnknownMemberResolveResult umrr = rr as UnknownMemberResolveResult;
UnknownMemberResolveResult? umrr = rr as UnknownMemberResolveResult;
if (umrr != null)
return umrr.MemberName;
MethodGroupResolveResult mgrr = rr as MethodGroupResolveResult;
MethodGroupResolveResult? mgrr = rr as MethodGroupResolveResult;
if (mgrr != null)
return mgrr.MethodName;
LocalResolveResult vrr = rr as LocalResolveResult;
LocalResolveResult? vrr = rr as LocalResolveResult;
if (vrr != null)
return MakeParameterName(vrr.Variable.Name);
@ -2429,7 +2430,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2429,7 +2430,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return char.ToLower(variableName[0]) + variableName.Substring(1);
}
OverloadResolution CreateOverloadResolution(ResolveResult[] arguments, string[] argumentNames = null, IType[] typeArguments = null)
OverloadResolution CreateOverloadResolution(ResolveResult[] arguments, string[]? argumentNames = null, IType[]? typeArguments = null)
{
var or = new OverloadResolution(compilation, arguments, argumentNames, typeArguments, conversions);
or.CheckForOverflow = checkForOverflow;
@ -2450,7 +2451,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2450,7 +2451,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// The argument names. Pass the null string for positional arguments.
/// </param>
/// <returns>ArrayAccessResolveResult, InvocationResolveResult, or ErrorResolveResult</returns>
public ResolveResult ResolveIndexer(ResolveResult target, ResolveResult[] arguments, string[] argumentNames = null)
public ResolveResult ResolveIndexer(ResolveResult target, ResolveResult[] arguments, string[]? argumentNames = null)
{
switch (target.Type.Kind)
{
@ -2533,7 +2534,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2533,7 +2534,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// <see cref="InvocationResolveResult.InitializerStatements"/>
/// </param>
/// <returns>InvocationResolveResult or ErrorResolveResult</returns>
public ResolveResult ResolveObjectCreation(IType type, ResolveResult[] arguments, string[] argumentNames = null, bool allowProtectedAccess = false, IList<ResolveResult> initializerStatements = null)
public ResolveResult ResolveObjectCreation(IType type, ResolveResult[] arguments, string[]? argumentNames = null, bool allowProtectedAccess = false, IList<ResolveResult>? initializerStatements = null)
{
if (type.Kind == TypeKind.Delegate && arguments.Length == 1)
{
@ -2813,9 +2814,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2813,9 +2814,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
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)
return null;
if (typeDef.Kind == TypeKind.Enum)
@ -2875,7 +2876,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2875,7 +2876,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// The initializer elements. May be null if no array initializer was specified.
/// The resolver may mutate this array to wrap elements in <see cref="ConversionResolveResult"/>s!
/// </param>
public ArrayCreateResolveResult ResolveArrayCreation(IType elementType, int[] sizeArguments, ResolveResult[] initializerElements = null)
public ArrayCreateResolveResult ResolveArrayCreation(IType elementType, int[] sizeArguments, ResolveResult[]? initializerElements = null)
{
ResolveResult[] sizeArgResults = new ResolveResult[sizeArguments.Length];
for (int i = 0; i < sizeArguments.Length; i++)
@ -2904,7 +2905,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2904,7 +2905,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// The initializer elements. May be null if no array initializer was specified.
/// The resolver may mutate this array to wrap elements in <see cref="ConversionResolveResult"/>s!
/// </param>
public ArrayCreateResolveResult ResolveArrayCreation(IType elementType, ResolveResult[] sizeArguments, ResolveResult[] initializerElements = null)
public ArrayCreateResolveResult ResolveArrayCreation(IType elementType, ResolveResult[] sizeArguments, ResolveResult[]? initializerElements = null)
{
int dimensions = sizeArguments.Length;
if (dimensions == 0)
@ -2944,7 +2945,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -2944,7 +2945,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return new OperatorResolveResult(lhs.Type, linqOp, lhs, this.Convert(rhs, lhs.Type));
}
ResolveResult bopResult = ResolveBinaryOperator(bop.Value, lhs, rhs);
OperatorResolveResult opResult = bopResult as OperatorResolveResult;
OperatorResolveResult? opResult = bopResult as OperatorResolveResult;
if (opResult == null || opResult.Operands.Count != 2)
return bopResult;
return new OperatorResolveResult(lhs.Type, linqOp, opResult.UserDefinedOperatorMethod, opResult.IsLiftedOperator,

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

@ -72,7 +72,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -72,7 +72,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// </summary>
public readonly IList<ResolveResult> InitializerStatements;
public DynamicInvocationResolveResult(ResolveResult target, DynamicInvocationType invocationType, IList<ResolveResult> arguments, IList<ResolveResult> initializerStatements = null) : base(SpecialType.Dynamic)
public DynamicInvocationResolveResult(ResolveResult target, DynamicInvocationType invocationType, IList<ResolveResult> arguments, IList<ResolveResult>? initializerStatements = null) : base(SpecialType.Dynamic)
{
this.Target = target;
this.InvocationType = invocationType;

4
ICSharpCode.Decompiler/CSharp/Resolver/LambdaResolveResult.cs

@ -65,7 +65,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -65,7 +65,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// This method determines the return type inferred from the lambda body, which is used as part of C# type inference.
/// Use the <see cref="ReturnType"/> property to retrieve the actual return type as determined by the target delegate type.
/// </remarks>
public abstract IType GetInferredReturnType(IType[] parameterTypes);
public abstract IType GetInferredReturnType(IType[]? parameterTypes);
/// <summary>
/// Gets the list of parameters.
@ -138,7 +138,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -138,7 +138,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public override ResolveResult Body { get; }
public override IType GetInferredReturnType(IType[] parameterTypes)
public override IType GetInferredReturnType(IType[]? parameterTypes)
{
// We don't know how to compute which type would be inferred if
// given other parameter types.

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

@ -79,7 +79,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -79,7 +79,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
{
if (targetType.Kind == TypeKind.TypeParameter)
targetType = ((ITypeParameter)targetType).EffectiveBaseClass;
ITypeDefinition typeDef = targetType.GetDefinition();
ITypeDefinition? typeDef = targetType.GetDefinition();
if (typeDef == null)
return false;
for (ITypeDefinition c = currentTypeDefinition; c != null; c = c.DeclaringTypeDefinition)
@ -189,21 +189,21 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -189,21 +189,21 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
{
var nestedTypes = type.GetNestedTypes(options: GetMemberOptions.IgnoreInheritedMembers | GetMemberOptions.ReturnMemberDefinitions);
// GetDefinition() might return null if some IType has a strange implementation of GetNestedTypes.
entities.AddRange(nestedTypes.Select(t => t.GetDefinition()).Where(td => td != null));
entities.AddRange(nestedTypes.Select(t => t.GetDefinition()).OfType<ITypeDefinition>());
}
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))
lookupGroupDict.Add(entityGroup.Key, lookupGroups = new List<LookupGroup>());
List<IType> newNestedTypes = null;
List<IParameterizedMember> newMethods = null;
IMember newNonMethod = null;
List<IType>? newNestedTypes = null;
List<IParameterizedMember>? newMethods = null;
IMember? newNonMethod = null;
IEnumerable<IType> typeBaseTypes = null;
IEnumerable<IType>? typeBaseTypes = null;
if (!targetIsTypeParameter)
{
@ -243,7 +243,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -243,7 +243,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
{
foreach (IType type in lookupGroup.NestedTypes)
{
ITypeDefinition typeDef = type.GetDefinition();
ITypeDefinition? typeDef = type.GetDefinition();
if (typeDef != null)
yield return typeDef;
}
@ -259,18 +259,18 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -259,18 +259,18 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public readonly IType DeclaringType;
// When a nested type is hidden, it is simply removed from the list.
public List<IType> NestedTypes;
public List<IType>? NestedTypes;
// When members are hidden, they are merely marked as hidden.
// We still need to store the hidden methods so that the 'override' processing can
// find them, so that it won't introduce the override as a new method.
public readonly List<IParameterizedMember> Methods;
public readonly List<IParameterizedMember>? Methods;
public bool MethodsAreHidden;
public IMember NonMethod;
public IMember? NonMethod;
public bool NonMethodIsHidden;
public LookupGroup(IType declaringType, List<IType> nestedTypes, List<IParameterizedMember> methods, IMember nonMethod)
public LookupGroup(IType declaringType, List<IType>? nestedTypes, List<IParameterizedMember>? methods, IMember? nonMethod)
{
this.DeclaringType = declaringType;
this.NestedTypes = nestedTypes;
@ -310,8 +310,8 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -310,8 +310,8 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
{
foreach (IType type in declaringType.GetNonInterfaceBaseTypes())
{
List<IType> newNestedTypes = null;
IEnumerable<IType> typeBaseTypes = null;
List<IType>? newNestedTypes = null;
IEnumerable<IType>? typeBaseTypes = null;
IEnumerable<IType> nestedTypes;
if (parameterizeResultType)
@ -389,11 +389,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -389,11 +389,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
foreach (IType type in targetResolveResult.Type.GetNonInterfaceBaseTypes())
{
List<IType> newNestedTypes = null;
List<IParameterizedMember> newMethods = null;
IMember newNonMethod = null;
List<IType>? newNestedTypes = null;
List<IParameterizedMember>? newMethods = null;
IMember? newNonMethod = null;
IEnumerable<IType> typeBaseTypes = null;
IEnumerable<IType>? typeBaseTypes = null;
if (!isInvocation && !targetIsTypeParameter)
{
@ -452,10 +452,10 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -452,10 +452,10 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
List<LookupGroup> lookupGroups = new List<LookupGroup>();
foreach (IType type in targetType.GetNonInterfaceBaseTypes())
{
List<IParameterizedMember> newMethods = null;
IMember newNonMethod = null;
List<IParameterizedMember>? newMethods = null;
IMember? newNonMethod = null;
IEnumerable<IType> typeBaseTypes = null;
IEnumerable<IType>? typeBaseTypes = null;
var members = type.GetProperties(filter, GetMemberOptions.IgnoreInheritedMembers);
AddMembers(type, members, allowProtectedAccess, lookupGroups, true, ref typeBaseTypes, ref newMethods, ref newNonMethod);
@ -551,7 +551,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -551,7 +551,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
if (!IsAccessible(member, allowProtectedAccess))
continue;
IParameterizedMember method;
IParameterizedMember? method;
if (treatAllParameterizedMembersAsMethods)
method = member as IParameterizedMember;
else
@ -691,7 +691,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -691,7 +691,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
// return true if type is an interface or System.Object
if (type.Kind == TypeKind.Interface)
return true;
ITypeDefinition d = type.GetDefinition();
ITypeDefinition? d = type.GetDefinition();
return d != null && d.KnownTypeCode == KnownTypeCode.Object;
}
#endregion
@ -753,7 +753,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -753,7 +753,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
{
if (isInEnumMemberInitializer)
{
IField field = resultGroup.NonMethod as IField;
IField? field = resultGroup.NonMethod as IField;
if (field != null && field.DeclaringTypeDefinition != null && field.DeclaringTypeDefinition.Kind == TypeKind.Enum)
{
return new MemberResolveResult(

16
ICSharpCode.Decompiler/CSharp/Resolver/MethodGroupResolveResult.cs

@ -79,11 +79,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -79,11 +79,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
{
readonly IReadOnlyList<MethodListWithDeclaringType> methodLists;
readonly IReadOnlyList<IType> typeArguments;
readonly ResolveResult targetResult;
readonly ResolveResult? targetResult;
readonly string methodName;
public MethodGroupResolveResult(ResolveResult targetResult, string methodName,
IReadOnlyList<MethodListWithDeclaringType> methods, IReadOnlyList<IType> typeArguments)
public MethodGroupResolveResult(ResolveResult? targetResult, string methodName,
IReadOnlyList<MethodListWithDeclaringType> methods, IReadOnlyList<IType>? typeArguments)
: base(SpecialType.NoType)
{
if (methods == null)
@ -143,10 +143,10 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -143,10 +143,10 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// List of extension methods, used to avoid re-calculating it in ResolveInvocation() when it was already
/// calculated by ResolveMemberAccess().
/// </summary>
internal List<List<IMethod>> extensionMethods;
internal List<List<IMethod>>? extensionMethods;
// the resolver is used to fetch extension methods on demand
internal CSharpResolver resolver;
internal CSharpResolver? resolver;
/// <summary>
/// Gets all candidate extension methods.
@ -229,12 +229,12 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -229,12 +229,12 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return string.Format("[{0} with {1} method(s)]", GetType().Name, this.Methods.Count());
}
public OverloadResolution PerformOverloadResolution(ICompilation compilation, ResolveResult[] arguments, string[] argumentNames = null,
public OverloadResolution PerformOverloadResolution(ICompilation compilation, ResolveResult[] arguments, string[]? argumentNames = null,
bool allowExtensionMethods = true,
bool allowExpandingParams = true,
bool allowOptionalParameters = true,
bool allowImplicitIn = true,
bool checkForOverflow = false, CSharpConversions conversions = null)
bool checkForOverflow = false, CSharpConversions? conversions = null)
{
Log.WriteLine("Performing overload resolution for " + this);
Log.WriteCollection(" Arguments: ", arguments);
@ -260,7 +260,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -260,7 +260,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
ResolveResult[] extArguments = new ResolveResult[arguments.Length + 1];
extArguments[0] = new ResolveResult(this.TargetType);
arguments.CopyTo(extArguments, 1);
string[] extArgumentNames = null;
string[]? extArgumentNames = null;
if (argumentNames != null)
{
extArgumentNames = new string[argumentNames.Length + 1];

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

@ -78,7 +78,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -78,7 +78,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public bool IsGenericMethod {
get {
IMethod method = Member as IMethod;
IMethod? method = Member as IMethod;
return method != null && method.TypeParameters.Count > 0;
}
}
@ -108,7 +108,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -108,7 +108,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
// (without any type parameter substitution, not even class type parameters)
// We'll re-substitute them as part of RunTypeInference().
this.Parameters = memberDefinition.Parameters;
IMethod methodDefinition = memberDefinition as IMethod;
IMethod? methodDefinition = memberDefinition as IMethod;
if (methodDefinition != null && methodDefinition.TypeParameters.Count > 0)
{
this.TypeParameters = methodDefinition.TypeParameters;
@ -130,13 +130,13 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -130,13 +130,13 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
readonly CSharpConversions conversions;
//List<Candidate> candidates = new List<Candidate>();
Candidate bestCandidate;
Candidate bestCandidateAmbiguousWith;
Candidate? bestCandidateAmbiguousWith;
IType[] explicitlyGivenTypeArguments;
bool bestCandidateWasValidated;
OverloadResolutionErrors bestCandidateValidationResult;
#region Constructor
public OverloadResolution(ICompilation compilation, ResolveResult[] arguments, string[] argumentNames = null, IType[] typeArguments = null, CSharpConversions conversions = null)
public OverloadResolution(ICompilation compilation, ResolveResult[] arguments, string[]? argumentNames = null, IType[]? typeArguments = null, CSharpConversions? conversions = null)
{
if (compilation == null)
throw new ArgumentNullException(nameof(compilation));
@ -286,7 +286,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -286,7 +286,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
if (candidate.IsExpandedForm && i == candidate.Parameters.Count - 1)
{
ArrayType arrayType = type as ArrayType;
ArrayType? arrayType = type as ArrayType;
if (arrayType != null && arrayType.Dimensions == 1)
type = arrayType.ElementType;
else
@ -311,7 +311,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -311,7 +311,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
if (methodLists == null)
throw new ArgumentNullException(nameof(methodLists));
// Base types come first, so go through the list backwards (derived types first)
bool[] isHiddenByDerivedType;
bool[]? isHiddenByDerivedType;
if (methodLists.Count > 1)
isHiddenByDerivedType = new bool[methodLists.Count];
else
@ -436,8 +436,8 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -436,8 +436,8 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
ResolveParameterTypes(candidate, true);
return;
}
ParameterizedType parameterizedDeclaringType = candidate.Member.DeclaringType as ParameterizedType;
IReadOnlyList<IType> classTypeArguments;
ParameterizedType? parameterizedDeclaringType = candidate.Member.DeclaringType as ParameterizedType;
IReadOnlyList<IType>? classTypeArguments;
if (parameterizedDeclaringType != null)
{
classTypeArguments = parameterizedDeclaringType.TypeArguments;
@ -504,7 +504,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -504,7 +504,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
if (newType != type && ConstraintsValid)
{
// something was changed, so we need to validate the constraints
ParameterizedType newParameterizedType = newType as ParameterizedType;
ParameterizedType? newParameterizedType = newType as ParameterizedType;
if (newParameterizedType != null)
{
// C# 4.0 spec: §4.4.4 Satisfying constraints
@ -552,7 +552,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -552,7 +552,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// The substitution is used to check constraints that depend on other type parameters (or recursively on the same type parameter).
/// May be null if no substitution should be used.</param>
/// <returns>True if the constraints are satisfied; false otherwise.</returns>
public static bool ValidateConstraints(ITypeParameter typeParameter, IType typeArgument, TypeVisitor substitution = null)
public static bool ValidateConstraints(ITypeParameter typeParameter, IType typeArgument, TypeVisitor? substitution = null)
{
if (typeParameter == null)
throw new ArgumentNullException(nameof(typeParameter));
@ -582,7 +582,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -582,7 +582,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
if (typeParameter.HasDefaultConstructorConstraint)
{
ITypeDefinition def = typeArgument.GetDefinition();
ITypeDefinition? def = typeArgument.GetDefinition();
if (def != null && def.IsAbstract)
return false;
var ctors = typeArgument.GetConstructors(
@ -791,8 +791,8 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -791,8 +791,8 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return r;
// prefer non-lifted operators
ILiftedOperator lift1 = c1.Member as ILiftedOperator;
ILiftedOperator lift2 = c2.Member as ILiftedOperator;
ILiftedOperator? lift1 = c1.Member as ILiftedOperator;
ILiftedOperator? lift2 = c2.Member as ILiftedOperator;
if (lift1 == null && lift2 != null)
return 1;
if (lift1 != null && lift2 == null)
@ -843,16 +843,16 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -843,16 +843,16 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
if ((t2 is ITypeParameter) && !(t1 is ITypeParameter))
return 1;
ParameterizedType p1 = t1 as ParameterizedType;
ParameterizedType p2 = t2 as ParameterizedType;
ParameterizedType? p1 = t1 as ParameterizedType;
ParameterizedType? p2 = t2 as ParameterizedType;
if (p1 != null && p2 != null && p1.TypeParameterCount == p2.TypeParameterCount)
{
int r = MoreSpecificFormalParameters(p1.TypeArguments, p2.TypeArguments);
if (r > 0)
return r;
}
TypeWithElementType tew1 = t1 as TypeWithElementType;
TypeWithElementType tew2 = t2 as TypeWithElementType;
TypeWithElementType? tew1 = t1 as TypeWithElementType;
TypeWithElementType? tew2 = t2 as TypeWithElementType;
if (tew1 != null && tew2 != null)
{
return MoreSpecificFormalParameter(tew1.ElementType, tew2.ElementType);
@ -891,7 +891,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -891,7 +891,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
#endregion
#region Output Properties
public IParameterizedMember BestCandidate {
public IParameterizedMember? BestCandidate {
get { return bestCandidate != null ? bestCandidate.Member : null; }
}
@ -919,7 +919,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -919,7 +919,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
get { return bestCandidate != null && IsApplicable(bestCandidate.Errors); }
}
public IParameterizedMember BestCandidateAmbiguousWith {
public IParameterizedMember? BestCandidateAmbiguousWith {
get { return bestCandidateAmbiguousWith != null ? bestCandidateAmbiguousWith.Member : null; }
}
@ -958,7 +958,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -958,7 +958,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
///
/// parameterIndex = GetArgumentToParameterMap()[argumentIndex]
/// </summary>
public IReadOnlyList<int> GetArgumentToParameterMap()
public IReadOnlyList<int>? GetArgumentToParameterMap()
{
if (bestCandidate != null)
return bestCandidate.ArgumentToParameterMap;
@ -994,7 +994,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -994,7 +994,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return GetArgumentsWithConversions(null, GetBestCandidateWithSubstitutedTypeArguments());
}
IList<ResolveResult> GetArgumentsWithConversions(ResolveResult targetResolveResult, IParameterizedMember bestCandidateForNamedArguments)
IList<ResolveResult> GetArgumentsWithConversions(ResolveResult? targetResolveResult, IParameterizedMember? bestCandidateForNamedArguments)
{
var conversions = this.ArgumentConversions;
ResolveResult[] args = new ResolveResult[arguments.Length];
@ -1037,11 +1037,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1037,11 +1037,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return args;
}
public IParameterizedMember GetBestCandidateWithSubstitutedTypeArguments()
public IParameterizedMember? GetBestCandidateWithSubstitutedTypeArguments()
{
if (bestCandidate == null)
return null;
IMethod method = bestCandidate.Member as IMethod;
IMethod? method = bestCandidate.Member as IMethod;
if (method != null && method.TypeParameters.Count > 0)
{
return ((IMethod)method.MemberDefinition).Specialize(GetSubstitution(bestCandidate));
@ -1072,9 +1072,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1072,9 +1072,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// <param name="returnTypeOverride">
/// If not null, use this instead of the ReturnType of the member as the type of the created resolve result.
/// </param>
public CSharpInvocationResolveResult CreateResolveResult(ResolveResult targetResolveResult, IList<ResolveResult> initializerStatements = null, IType returnTypeOverride = null)
public CSharpInvocationResolveResult CreateResolveResult(ResolveResult? targetResolveResult, IList<ResolveResult>? initializerStatements = null, IType? returnTypeOverride = null)
{
IParameterizedMember member = GetBestCandidateWithSubstitutedTypeArguments();
IParameterizedMember? member = GetBestCandidateWithSubstitutedTypeArguments();
if (member == null)
throw new InvalidOperationException();

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

@ -94,11 +94,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -94,11 +94,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
#endregion
TP[] typeParameters;
IType[] parameterTypes;
ResolveResult[] arguments;
bool[,] dependencyMatrix;
IReadOnlyList<IType> classTypeArguments;
TP[]? typeParameters;
IType[]? parameterTypes;
ResolveResult[]? arguments;
bool[,]? dependencyMatrix;
IReadOnlyList<IType>? classTypeArguments;
#region InferTypeArguments (main function)
/// <summary>
@ -113,7 +113,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -113,7 +113,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
/// when inferring a method group or lambda.
/// </param>
/// <returns>The inferred type arguments.</returns>
public IType[] InferTypeArguments(IReadOnlyList<ITypeParameter> typeParameters, IReadOnlyList<ResolveResult> arguments, IReadOnlyList<IType> parameterTypes, out bool success, IReadOnlyList<IType> classTypeArguments = null)
public IType[] InferTypeArguments(IReadOnlyList<ITypeParameter> typeParameters, IReadOnlyList<ResolveResult> arguments, IReadOnlyList<IType> parameterTypes, out bool success, IReadOnlyList<IType>? classTypeArguments = null)
{
if (typeParameters == null)
throw new ArgumentNullException(nameof(typeParameters));
@ -283,7 +283,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -283,7 +283,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
ResolveResult Ei = arguments[i];
IType Ti = parameterTypes[i];
LambdaResolveResult lrr = Ei as LambdaResolveResult;
LambdaResolveResult? lrr = Ei as LambdaResolveResult;
if (lrr != null)
{
MakeExplicitParameterTypeInference(lrr, Ti);
@ -397,7 +397,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -397,7 +397,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
IType[] InputTypes(ResolveResult e, IType t)
{
// C# 4.0 spec: §7.5.2.3 Input types
LambdaResolveResult lrr = e as LambdaResolveResult;
LambdaResolveResult? lrr = e as LambdaResolveResult;
if (lrr != null && lrr.IsImplicitlyTyped || e is MethodGroupResolveResult)
{
IMethod m = GetDelegateOrExpressionTreeSignature(t);
@ -417,7 +417,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -417,7 +417,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
IType[] OutputTypes(ResolveResult e, IType t)
{
// C# 4.0 spec: §7.5.2.4 Output types
LambdaResolveResult lrr = e as LambdaResolveResult;
LambdaResolveResult? lrr = e as LambdaResolveResult;
if (lrr != null || e is MethodGroupResolveResult)
{
IMethod m = GetDelegateOrExpressionTreeSignature(t);
@ -524,7 +524,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -524,7 +524,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
Log.WriteLine(" MakeOutputTypeInference from " + e + " to " + t);
// If E is an anonymous function with inferred return type U (§7.5.2.12) and T is a delegate type or expression
// tree type with return type Tb, then a lower-bound inference (§7.5.2.9) is made from U to Tb.
LambdaResolveResult lrr = e as LambdaResolveResult;
LambdaResolveResult? lrr = e as LambdaResolveResult;
if (lrr != null)
{
IMethod m = GetDelegateOrExpressionTreeSignature(t);
@ -556,7 +556,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -556,7 +556,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
// with parameter types T1…Tk and return type Tb, and overload resolution
// of E with the types T1…Tk yields a single method with return type U, then a lower­-bound
// inference is made from U to Tb.
MethodGroupResolveResult mgrr = e as MethodGroupResolveResult;
MethodGroupResolveResult? mgrr = e as MethodGroupResolveResult;
if (mgrr != null)
{
IMethod m = GetDelegateOrExpressionTreeSignature(t);
@ -651,24 +651,24 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -651,24 +651,24 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return;
}
// Handle by reference types:
ByReferenceType brU = U as ByReferenceType;
ByReferenceType brV = V as ByReferenceType;
ByReferenceType? brU = U as ByReferenceType;
ByReferenceType? brV = V as ByReferenceType;
if (brU != null && brV != null)
{
MakeExactInference(brU.ElementType, brV.ElementType);
return;
}
// Handle array types:
ArrayType arrU = U as ArrayType;
ArrayType arrV = V as ArrayType;
ArrayType? arrU = U as ArrayType;
ArrayType? arrV = V as ArrayType;
if (arrU != null && arrV != null && arrU.Dimensions == arrV.Dimensions)
{
MakeExactInference(arrU.ElementType, arrV.ElementType);
return;
}
// Handle parameterized type:
ParameterizedType pU = U.TupleUnderlyingTypeOrSelf() as ParameterizedType;
ParameterizedType pV = V.TupleUnderlyingTypeOrSelf() as ParameterizedType;
ParameterizedType? pU = U.TupleUnderlyingTypeOrSelf() as ParameterizedType;
ParameterizedType? pV = V.TupleUnderlyingTypeOrSelf() as ParameterizedType;
if (pU != null && pV != null
&& object.Equals(pU.GenericType, pV.GenericType)
&& pU.TypeParameterCount == pV.TypeParameterCount)
@ -698,7 +698,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -698,7 +698,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
}
TP GetTPForType(IType v)
TP? GetTPForType(IType v)
{
if (v is NullabilityAnnotatedTypeParameter natp)
{
@ -743,17 +743,17 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -743,17 +743,17 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return;
}
// Handle by reference types:
ByReferenceType brU = U as ByReferenceType;
ByReferenceType brV = V as ByReferenceType;
ByReferenceType? brU = U as ByReferenceType;
ByReferenceType? brV = V as ByReferenceType;
if (brU != null && brV != null)
{
MakeExactInference(brU.ElementType, brV.ElementType);
return;
}
// Handle array types:
ArrayType arrU = U as ArrayType;
ArrayType arrV = V as ArrayType;
ParameterizedType pV = V.TupleUnderlyingTypeOrSelf() as ParameterizedType;
ArrayType? arrU = U as ArrayType;
ArrayType? arrV = V as ArrayType;
ParameterizedType? pV = V.TupleUnderlyingTypeOrSelf() as ParameterizedType;
if (arrU != null && arrV != null && arrU.Dimensions == arrV.Dimensions)
{
MakeLowerBoundInference(arrU.ElementType, arrV.ElementType);
@ -767,10 +767,10 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -767,10 +767,10 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
// Handle parameterized types:
if (pV != null)
{
ParameterizedType uniqueBaseType = null;
ParameterizedType? uniqueBaseType = null;
foreach (IType baseU in U.GetAllBaseTypes())
{
ParameterizedType pU = baseU.TupleUnderlyingTypeOrSelf() as ParameterizedType;
ParameterizedType? pU = baseU.TupleUnderlyingTypeOrSelf() as ParameterizedType;
if (pU != null && object.Equals(pU.GenericType, pV.GenericType) && pU.TypeParameterCount == pV.TypeParameterCount)
{
if (uniqueBaseType == null)
@ -872,9 +872,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -872,9 +872,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
}
// Handle array types:
ArrayType arrU = U as ArrayType;
ArrayType arrV = V as ArrayType;
ParameterizedType pU = U.TupleUnderlyingTypeOrSelf() as ParameterizedType;
ArrayType? arrU = U as ArrayType;
ArrayType? arrV = V as ArrayType;
ParameterizedType? pU = U.TupleUnderlyingTypeOrSelf() as ParameterizedType;
if (arrV != null && arrU != null && arrU.Dimensions == arrV.Dimensions)
{
MakeUpperBoundInference(arrU.ElementType, arrV.ElementType);
@ -888,10 +888,10 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -888,10 +888,10 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
// Handle parameterized types:
if (pU != null)
{
ParameterizedType uniqueBaseType = null;
ParameterizedType? uniqueBaseType = null;
foreach (IType baseV in V.GetAllBaseTypes())
{
ParameterizedType pV = baseV.TupleUnderlyingTypeOrSelf() as ParameterizedType;
ParameterizedType? pV = baseV.TupleUnderlyingTypeOrSelf() as ParameterizedType;
if (pV != null && object.Equals(pU.GenericType, pV.GenericType) && pU.TypeParameterCount == pV.TypeParameterCount)
{
if (uniqueBaseType == null)
@ -1109,7 +1109,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1109,7 +1109,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
// Now filter out candidates that violate the upper bounds:
foreach (IType ub in upperBounds)
{
ITypeDefinition ubDef = ub.GetDefinition();
ITypeDefinition? ubDef = ub.GetDefinition();
if (ubDef != null)
{
candidateTypeDefinitions.RemoveAll(c => !c.IsDerivedFrom(ubDef));

4
ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs

@ -76,7 +76,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -76,7 +76,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// <summary>
/// The function containing this sequence point.
/// </summary>
internal ILFunction Function;
internal ILFunction? Function;
public StatePerSequencePoint(AstNode primaryNode)
{
@ -547,7 +547,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -547,7 +547,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
List<int> sequencePointCandidates = function.SequencePointCandidates;
List<int>? sequencePointCandidates = function.SequencePointCandidates;
int currSPCandidateIndex = 0;
for (int i = 0; i < newList.Count - 1; i++)

38
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
@ -151,7 +152,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -151,7 +152,7 @@ namespace ICSharpCode.Decompiler.CSharp
return new IfElseStatement(condition, trueStatement, falseStatement).WithILInstruction(inst);
}
internal IEnumerable<ConstantResolveResult> CreateTypedCaseLabel(long i, IType type, List<(string Key, int Value)> map = null)
internal IEnumerable<ConstantResolveResult> CreateTypedCaseLabel(long i, IType type, List<(string? Key, int Value)>? map = null)
{
object value;
// unpack nullable type, if necessary:
@ -203,7 +204,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -203,7 +204,7 @@ namespace ICSharpCode.Decompiler.CSharp
return TranslateSwitch(null, inst).WithILInstruction(inst);
}
SwitchStatement TranslateSwitch(BlockContainer switchContainer, SwitchInstruction inst)
SwitchStatement TranslateSwitch(BlockContainer? switchContainer, SwitchInstruction inst)
{
var oldBreakTarget = breakTarget;
breakTarget = switchContainer; // 'break' within a switch would only leave the switch
@ -212,7 +213,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -212,7 +213,8 @@ namespace ICSharpCode.Decompiler.CSharp
TranslatedExpression value;
IType type;
if (inst.Value is StringToInt strToInt)
var strToInt = inst.Value as StringToInt;
if (strToInt != null)
{
value = exprBuilder.Translate(strToInt.Argument)
.ConvertTo(
@ -243,7 +245,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -243,7 +245,7 @@ namespace ICSharpCode.Decompiler.CSharp
foreach (var section in inst.Sections)
{
// This is used in the block-label mapping.
ConstantResolveResult firstValueResolveResult;
ConstantResolveResult? firstValueResolveResult;
var astSection = new Syntax.SwitchSection();
// Create case labels:
if (section == defaultSection)
@ -327,7 +329,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -327,7 +329,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
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 BreakStatement());
@ -346,7 +348,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -346,7 +348,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (!bodyInst.HasFlag(InstructionFlags.EndPointUnreachable))
{
// we need to insert 'break;'
BlockStatement block = body as BlockStatement;
BlockStatement? block = body as BlockStatement;
if (block != null)
{
block.Add(new BreakStatement());
@ -383,7 +385,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -383,7 +385,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
/// <summary>Target container that a 'break;' statement would break out of</summary>
BlockContainer breakTarget;
BlockContainer? breakTarget;
/// <summary>Dictionary from BlockContainer to label name for 'goto of_container';</summary>
readonly Dictionary<BlockContainer, string> endContainerLabels = new Dictionary<BlockContainer, string>();
@ -410,7 +412,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -410,7 +412,7 @@ namespace ICSharpCode.Decompiler.CSharp
else
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;
if (!duplicateLabels.TryGetValue(label, out int count))
@ -622,7 +624,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -622,7 +624,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
Statement TransformToForeach(UsingInstruction inst, Expression resource)
Statement? TransformToForeach(UsingInstruction inst, Expression resource)
{
if (!settings.ForEachStatement)
{
@ -731,7 +733,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -731,7 +733,7 @@ namespace ICSharpCode.Decompiler.CSharp
break;
}
VariableDesignation designation = null;
VariableDesignation? designation = null;
// Handle the required foreach-variable transformation:
switch (transformation)
@ -875,7 +877,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -875,7 +877,7 @@ namespace ICSharpCode.Decompiler.CSharp
return NormalizeTypeVisitor.TypeErasure.EquivalentTypes(a, b);
}
private bool IsDynamicCastToIEnumerable(Expression expr, out Expression dynamicExpr)
private bool IsDynamicCastToIEnumerable(Expression expr, [NotNullWhen(true)] out Expression? dynamicExpr)
{
if (!(expr is CastExpression cast))
{
@ -898,7 +900,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -898,7 +900,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// Otherwise returns the unmodified container.
/// </summary>
/// <param name="optionalLeaveInst">If the leave is a return/break and has no side-effects, we can move the return out of the using-block and put it after the loop, otherwise returns null.</param>
BlockContainer UnwrapNestedContainerIfPossible(BlockContainer container, out Leave optionalLeaveInst)
BlockContainer UnwrapNestedContainerIfPossible(BlockContainer container, out Leave? optionalLeaveInst)
{
optionalLeaveInst = null;
// Check block structure:
@ -978,7 +980,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -978,7 +980,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// <param name="singleGetter">Returns the call instruction invoking Current's getter.</param>
/// <param name="foreachVariable">Returns the the foreach variable, if a suitable was found. This variable is only assigned once and its assignment is the first statement in <paramref name="loopBody"/>.</param>
/// <returns><see cref="RequiredGetCurrentTransformation"/> for details.</returns>
RequiredGetCurrentTransformation DetectGetCurrentTransformation(BlockContainer usingContainer, Block loopBody, BlockContainer loopContainer, ILVariable enumerator, ILInstruction moveNextUsage, out CallInstruction singleGetter, out ILVariable foreachVariable)
RequiredGetCurrentTransformation DetectGetCurrentTransformation(BlockContainer usingContainer, Block loopBody, BlockContainer loopContainer, ILVariable enumerator, ILInstruction moveNextUsage, out CallInstruction? singleGetter, out ILVariable? foreachVariable)
{
singleGetter = null;
foreachVariable = null;
@ -1260,8 +1262,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1260,8 +1262,8 @@ namespace ICSharpCode.Decompiler.CSharp
Statement ConvertLoop(BlockContainer container)
{
ILInstruction condition;
Block loopBody;
ILInstruction? condition;
Block? loopBody;
BlockStatement blockStatement;
continueCount = 0;
breakTarget = container;
@ -1425,7 +1427,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1425,7 +1427,7 @@ namespace ICSharpCode.Decompiler.CSharp
method.Body = nestedBuilder.ConvertAsBlock(function.Body);
Comment prev = null;
Comment? prev = null;
foreach (string warning in function.Warnings)
{
method.Body.InsertChildAfter(prev, prev = new Comment(warning), Roles.Comment);
@ -1479,7 +1481,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1479,7 +1481,7 @@ namespace ICSharpCode.Decompiler.CSharp
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))
{
@ -1499,7 +1501,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1499,7 +1501,7 @@ namespace ICSharpCode.Decompiler.CSharp
string EnsureUniqueLabel(Block block)
{
if (labels.TryGetValue(block, out string label))
if (labels.TryGetValue(block, out string? label))
return label;
if (!duplicateLabels.TryGetValue(block.Label, out int count))
{

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

@ -202,7 +202,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -202,7 +202,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
get { return parent; }
}
public Role Role {
public Role? Role {
get {
return Role.GetByIndex(flags & roleIndexMask);
}
@ -340,7 +340,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -340,7 +340,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// Gets the first child with the specified role.
/// Returns the role's null object if the child is not found.
/// </summary>
public T GetChildByRole<T>(Role<T> role) where T : AstNode?
public T? GetChildByRole<T>(Role<T> role) where T : AstNode
{
if (role == null)
throw new ArgumentNullException(nameof(role));
@ -348,7 +348,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -348,7 +348,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
for (var cur = firstChild; cur != null; cur = cur.nextSibling)
{
if ((cur.flags & roleIndexMask) == roleIndex)
return (T)cur;
return (T?)cur;
}
return role.NullObject;
}
@ -368,16 +368,16 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -368,16 +368,16 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return new AstNodeCollection<T>(this, role);
}
protected void SetChildByRole<T>(Role<T> role, T newChild) where T : AstNode
protected void SetChildByRole<T>(Role<T> role, T? newChild) where T : AstNode
{
AstNode oldChild = GetChildByRole(role);
if (oldChild.IsNull)
AstNode? oldChild = GetChildByRole(role);
if (oldChild?.IsNull != false)
AddChild(newChild, role);
else
oldChild.ReplaceWith(newChild);
}
public void AddChild<T>(T child, Role<T> role) where T : AstNode
public void AddChild<T>(T? child, Role<T> role) where T : AstNode
{
if (role == null)
throw new ArgumentNullException(nameof(role));

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

@ -49,7 +49,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -49,7 +49,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
get {
int count = 0;
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)
count++;
@ -149,7 +149,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -149,7 +149,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// Returns the first element for which the predicate returns true,
/// or the null node (AstNode with IsNull=true) if no such object is found.
/// </summary>
public T FirstOrNullObject(Func<T, bool> predicate = null)
public T FirstOrNullObject(Func<T, bool>? predicate = null)
{
foreach (T item in this)
if (predicate == null || predicate(item))
@ -161,7 +161,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -161,7 +161,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// Returns the last element for which the predicate returns true,
/// or the null node (AstNode with IsNull=true) if no such object is found.
/// </summary>
public T LastOrNullObject(Func<T, bool> predicate = null)
public T LastOrNullObject(Func<T, bool>? predicate = null)
{
T result = role.NullObject;
foreach (T item in this)
@ -177,8 +177,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -177,8 +177,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public IEnumerator<T> GetEnumerator()
{
uint roleIndex = role.Index;
AstNode next;
for (AstNode cur = node.FirstChild; cur != null; cur = next)
AstNode? next;
for (AstNode? cur = node.FirstChild; cur != null; cur = next)
{
Debug.Assert(cur.Parent == node);
// Remember next before yielding cur.
@ -200,9 +200,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -200,9 +200,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return node.GetHashCode() ^ role.GetHashCode();
}
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
AstNodeCollection<T> other = obj as AstNodeCollection<T>;
AstNodeCollection<T>? other = obj as AstNodeCollection<T>;
if (other == null)
return false;
return this.node == other.node && this.role == other.role;
@ -214,7 +214,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -214,7 +214,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
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);
}
@ -230,8 +230,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -230,8 +230,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public void AcceptVisitor(IAstVisitor visitor)
{
uint roleIndex = role.Index;
AstNode next;
for (AstNode cur = node.FirstChild; cur != null; cur = next)
AstNode? next;
for (AstNode? cur = node.FirstChild; cur != null; cur = next)
{
Debug.Assert(cur.Parent == node);
// Remember next before yielding cur.

14
ICSharpCode.Decompiler/CSharp/Syntax/AstType.cs

@ -56,12 +56,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -56,12 +56,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitNullNode(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
return other == null || other.IsNull;
}
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider)
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider? interningProvider)
{
return SpecialType.UnknownType;
}
@ -102,12 +102,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -102,12 +102,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitPatternPlaceholder(this, child, data);
}
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider)
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider? interningProvider)
{
throw new NotSupportedException();
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}
@ -133,7 +133,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -133,7 +133,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary>
public bool IsVar()
{
SimpleType st = this as SimpleType;
SimpleType? st = this as SimpleType;
return st != null && st.Identifier == "var" && st.TypeArguments.Count == 0;
}
@ -148,7 +148,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -148,7 +148,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// For resolving simple names, the current namespace and usings from the CurrentUsingScope
/// (on CSharpTypeResolveContext only) is used.
/// </remarks>
public ITypeReference ToTypeReference(InterningProvider interningProvider = null)
public ITypeReference ToTypeReference(InterningProvider? interningProvider = null)
{
return ToTypeReference(GetNameLookupMode(), interningProvider);
}
@ -163,7 +163,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -163,7 +163,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// For resolving simple names, the current namespace and usings from the CurrentUsingScope
/// (on CSharpTypeResolveContext only) is used.
/// </remarks>
public abstract ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null);
public abstract ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider? interningProvider = null);
/// <summary>
/// Gets the name lookup mode from the context (looking at the ancestors of this <see cref="AstType"/>).

6
ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs

@ -49,14 +49,14 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -49,14 +49,14 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
}
}
public override string ToString(CSharpFormattingOptions formattingOptions)
public override string ToString(CSharpFormattingOptions? formattingOptions)
{
return GetModifierName(Modifier);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
CSharpModifierToken o = other as CSharpModifierToken;
CSharpModifierToken? o = other as CSharpModifierToken;
return o != null && this.modifier == o.modifier;
}

10
ICSharpCode.Decompiler/CSharp/Syntax/CSharpTokenNode.cs

@ -64,7 +64,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -64,7 +64,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitNullNode(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
return other == null || other.IsNull;
}
@ -100,14 +100,14 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -100,14 +100,14 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
}
}
public CSharpTokenNode(TextLocation location, TokenRole role)
public CSharpTokenNode(TextLocation location, TokenRole? role)
{
this.startLocation = location;
if (role != null)
this.flags |= role.Index << AstNodeFlagsUsedBits;
}
public override string ToString(CSharpFormattingOptions formattingOptions)
public override string ToString(CSharpFormattingOptions? formattingOptions)
{
uint tokenRoleIndex = (this.flags >> AstNodeFlagsUsedBits);
if (Role.GetByIndex(tokenRoleIndex) is TokenRole r)
@ -132,9 +132,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -132,9 +132,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitCSharpTokenNode(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
CSharpTokenNode o = other as CSharpTokenNode;
CSharpTokenNode? o = other as CSharpTokenNode;
return o != null && !o.IsNull && !(o is CSharpModifierToken);
}
}

14
ICSharpCode.Decompiler/CSharp/Syntax/ComposedType.cs

@ -144,9 +144,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -144,9 +144,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitComposedType(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
ComposedType o = other as ComposedType;
ComposedType? o = other as ComposedType;
return o != null
&& this.HasNullableSpecifier == o.HasNullableSpecifier
&& this.PointerRank == o.PointerRank
@ -156,7 +156,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -156,7 +156,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
&& this.ArraySpecifiers.DoMatch(o.ArraySpecifiers, match);
}
public override string ToString(CSharpFormattingOptions formattingOptions)
public override string ToString(CSharpFormattingOptions? formattingOptions)
{
StringBuilder b = new StringBuilder();
if (this.HasRefSpecifier)
@ -201,7 +201,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -201,7 +201,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return this;
}
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null)
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider? interningProvider = null)
{
if (interningProvider == null)
interningProvider = InterningProvider.Dummy;
@ -287,13 +287,13 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -287,13 +287,13 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitArraySpecifier(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
ArraySpecifier o = other as ArraySpecifier;
ArraySpecifier? o = other as ArraySpecifier;
return o != null && this.Dimensions == o.Dimensions;
}
public override string ToString(CSharpFormattingOptions formattingOptions)
public override string ToString(CSharpFormattingOptions? formattingOptions)
{
return "[" + new string(',', this.Dimensions - 1) + "]";
}

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

@ -34,7 +34,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -34,7 +34,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
{
protected virtual void VisitChildren(AstNode node)
{
AstNode next;
AstNode? next;
for (var child = node.FirstChild; child != null; child = next)
{
// Store next to allow the loop to continue
@ -713,9 +713,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -713,9 +713,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary>
public abstract class DepthFirstAstVisitor<T> : IAstVisitor<T>
{
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)
{
// Store next to allow the loop to continue
@ -726,7 +726,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -726,7 +726,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return default(T);
}
public virtual T VisitNullNode(AstNode nullNode)
public virtual T? VisitNullNode(AstNode nullNode)
{
// Should we call VisitChildren here?
// We usually want to ignore null nodes.
@ -1396,9 +1396,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -1396,9 +1396,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary>
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)
{
// Store next to allow the loop to continue
@ -1409,7 +1409,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -1409,7 +1409,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return default(S);
}
public virtual S VisitNullNode(AstNode nullNode, T data)
public virtual S? VisitNullNode(AstNode nullNode, T data)
{
// Should we call VisitChildren here?
// We usually want to ignore null nodes.
@ -1418,657 +1418,657 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -1418,657 +1418,657 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return default(S);
}
public virtual S VisitSyntaxTree(SyntaxTree unit, T data)
public virtual S? VisitSyntaxTree(SyntaxTree unit, T 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);
}
public virtual S VisitDocumentationReference(DocumentationReference documentationReference, T data)
public virtual S? VisitDocumentationReference(DocumentationReference documentationReference, T 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);
}
public virtual S VisitIdentifier(Identifier identifier, T data)
public virtual S? VisitIdentifier(Identifier identifier, T 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);
}
public virtual S VisitPrimitiveType(PrimitiveType primitiveType, T data)
public virtual S? VisitPrimitiveType(PrimitiveType primitiveType, T 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);
}
public virtual S VisitSimpleType(SimpleType simpleType, T data)
public virtual S? VisitSimpleType(SimpleType simpleType, T 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);
}
public virtual S VisitTupleType(TupleAstType tupleType, T data)
public virtual S? VisitTupleType(TupleAstType tupleType, T 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);
}
public virtual S VisitFunctionPointerType(FunctionPointerAstType functionPointerType, T data)
public virtual S? VisitFunctionPointerType(FunctionPointerAstType functionPointerType, T 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);
}
public virtual S VisitAttribute(Attribute attribute, T data)
public virtual S? VisitAttribute(Attribute attribute, T 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);
}
public virtual S VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, T data)
public virtual S? VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, T 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);
}
public virtual S VisitTypeDeclaration(TypeDeclaration typeDeclaration, T data)
public virtual S? VisitTypeDeclaration(TypeDeclaration typeDeclaration, T 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);
}
public virtual S VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration, T data)
public virtual S? VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration, T 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);
}
public virtual S VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration, T data)
public virtual S? VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration, T 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);
}
public virtual S VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, T data)
public virtual S? VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, T 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);
}
public virtual S VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, T data)
public virtual S? VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, T 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);
}
public virtual S VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration, T data)
public virtual S? VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration, T 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);
}
public virtual S VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration, T data)
public virtual S? VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration, T 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);
}
public virtual S VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, T data)
public virtual S? VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, T 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);
}
public virtual S VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, T data)
public virtual S? VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, T 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);
}
public virtual S VisitAccessor(Accessor accessor, T data)
public virtual S? VisitAccessor(Accessor accessor, T 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);
}
public virtual S VisitParameterDeclaration(ParameterDeclaration parameterDeclaration, T data)
public virtual S? VisitParameterDeclaration(ParameterDeclaration parameterDeclaration, T 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);
}
public virtual S VisitBlockStatement(BlockStatement blockStatement, T data)
public virtual S? VisitBlockStatement(BlockStatement blockStatement, T 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);
}
public virtual S VisitBreakStatement(BreakStatement breakStatement, T data)
public virtual S? VisitBreakStatement(BreakStatement breakStatement, T 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);
}
public virtual S VisitContinueStatement(ContinueStatement continueStatement, T data)
public virtual S? VisitContinueStatement(ContinueStatement continueStatement, T 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);
}
public virtual S VisitEmptyStatement(EmptyStatement emptyStatement, T data)
public virtual S? VisitEmptyStatement(EmptyStatement emptyStatement, T 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);
}
public virtual S VisitForeachStatement(ForeachStatement foreachStatement, T data)
public virtual S? VisitForeachStatement(ForeachStatement foreachStatement, T 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);
}
public virtual S VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, T data)
public virtual S? VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, T 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);
}
public virtual S VisitGotoStatement(GotoStatement gotoStatement, T data)
public virtual S? VisitGotoStatement(GotoStatement gotoStatement, T 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);
}
public virtual S VisitLabelStatement(LabelStatement labelStatement, T data)
public virtual S? VisitLabelStatement(LabelStatement labelStatement, T 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);
}
public virtual S VisitReturnStatement(ReturnStatement returnStatement, T data)
public virtual S? VisitReturnStatement(ReturnStatement returnStatement, T 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);
}
public virtual S VisitSwitchSection(SwitchSection switchSection, T data)
public virtual S? VisitSwitchSection(SwitchSection switchSection, T 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);
}
public virtual S VisitSwitchExpression(SwitchExpression switchExpression, T data)
public virtual S? VisitSwitchExpression(SwitchExpression switchExpression, T 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);
}
public virtual S VisitThrowStatement(ThrowStatement throwStatement, T data)
public virtual S? VisitThrowStatement(ThrowStatement throwStatement, T 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);
}
public virtual S VisitCatchClause(CatchClause catchClause, T data)
public virtual S? VisitCatchClause(CatchClause catchClause, T 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);
}
public virtual S VisitUnsafeStatement(UnsafeStatement unsafeStatement, T data)
public virtual S? VisitUnsafeStatement(UnsafeStatement unsafeStatement, T 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);
}
public virtual S VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement, T data)
public virtual S? VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement, T 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);
}
public virtual S VisitWhileStatement(WhileStatement whileStatement, T data)
public virtual S? VisitWhileStatement(WhileStatement whileStatement, T 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);
}
public virtual S VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement, T data)
public virtual S? VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement, T 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);
}
public virtual S VisitLambdaExpression(LambdaExpression lambdaExpression, T data)
public virtual S? VisitLambdaExpression(LambdaExpression lambdaExpression, T 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);
}
public virtual S VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, T data)
public virtual S? VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, T 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);
}
public virtual S VisitCastExpression(CastExpression castExpression, T data)
public virtual S? VisitCastExpression(CastExpression castExpression, T 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);
}
public virtual S VisitConditionalExpression(ConditionalExpression conditionalExpression, T data)
public virtual S? VisitConditionalExpression(ConditionalExpression conditionalExpression, T 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);
}
public virtual S VisitIndexerExpression(IndexerExpression indexerExpression, T data)
public virtual S? VisitIndexerExpression(IndexerExpression indexerExpression, T 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);
}
public virtual S VisitInterpolation(Interpolation interpolation, T data)
public virtual S? VisitInterpolation(Interpolation interpolation, T 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);
}
public virtual S VisitInvocationExpression(InvocationExpression invocationExpression, T data)
public virtual S? VisitInvocationExpression(InvocationExpression invocationExpression, T 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);
}
public virtual S VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, T data)
public virtual S? VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, T 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);
}
public virtual S VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, T data)
public virtual S? VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, T 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);
}
public virtual S VisitRecursivePatternExpression(RecursivePatternExpression recursivePatternExpression, T data)
public virtual S? VisitRecursivePatternExpression(RecursivePatternExpression recursivePatternExpression, T 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);
}
public virtual S VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression, T data)
public virtual S? VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression, T 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);
}
public virtual S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data)
public virtual S? VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T 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);
}
public virtual S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T data)
public virtual S? VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T 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);
}
public virtual S VisitStackAllocExpression(StackAllocExpression stackAllocExpression, T data)
public virtual S? VisitStackAllocExpression(StackAllocExpression stackAllocExpression, T 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);
}
public virtual S VisitThrowExpression(ThrowExpression throwExpression, T data)
public virtual S? VisitThrowExpression(ThrowExpression throwExpression, T 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);
}
public virtual S VisitTypeOfExpression(TypeOfExpression typeOfExpression, T data)
public virtual S? VisitTypeOfExpression(TypeOfExpression typeOfExpression, T 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);
}
public virtual S VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, T data)
public virtual S? VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, T 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);
}
public virtual S VisitQueryExpression(QueryExpression queryExpression, T data)
public virtual S? VisitQueryExpression(QueryExpression queryExpression, T 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);
}
public virtual S VisitQueryFromClause(QueryFromClause queryFromClause, T data)
public virtual S? VisitQueryFromClause(QueryFromClause queryFromClause, T 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);
}
public virtual S VisitQueryWhereClause(QueryWhereClause queryWhereClause, T data)
public virtual S? VisitQueryWhereClause(QueryWhereClause queryWhereClause, T 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);
}
public virtual S VisitQueryOrderClause(QueryOrderClause queryOrderClause, T data)
public virtual S? VisitQueryOrderClause(QueryOrderClause queryOrderClause, T 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);
}
public virtual S VisitQuerySelectClause(QuerySelectClause querySelectClause, T data)
public virtual S? VisitQuerySelectClause(QuerySelectClause querySelectClause, T 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);
}
public virtual S VisitAsExpression(AsExpression asExpression, T data)
public virtual S? VisitAsExpression(AsExpression asExpression, T 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);
}
public virtual S VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, T data)
public virtual S? VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, T 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);
}
public virtual S VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, T data)
public virtual S? VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, T 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);
}
public virtual S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T data)
public virtual S? VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T 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);
}
public virtual S VisitSingleVariableDesignation(SingleVariableDesignation singleVariableDesignation, T data)
public virtual S? VisitSingleVariableDesignation(SingleVariableDesignation singleVariableDesignation, T 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);
}
public virtual S VisitErrorNode(AstNode errorNode, T data)
public virtual S? VisitErrorNode(AstNode errorNode, T 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);
}
public virtual S VisitWithInitializerExpression(WithInitializerExpression withInitializerExpression, T data)
public virtual S? VisitWithInitializerExpression(WithInitializerExpression withInitializerExpression, T data)
{
return VisitChildren(withInitializerExpression, data);
}

4
ICSharpCode.Decompiler/CSharp/Syntax/DocumentationReference.cs

@ -109,9 +109,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -109,9 +109,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
get { return GetChildrenByRole(Roles.Parameter); }
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
DocumentationReference o = other as DocumentationReference;
DocumentationReference? o = other as DocumentationReference;
if (!(o != null && this.SymbolKind == o.SymbolKind && this.HasParameterList == o.HasParameterList))
return false;
if (this.SymbolKind == SymbolKind.Operator)

6
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousMethodExpression.cs

@ -77,7 +77,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -77,7 +77,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
{
}
public AnonymousMethodExpression(BlockStatement body, IEnumerable<ParameterDeclaration> parameters = null)
public AnonymousMethodExpression(BlockStatement body, IEnumerable<ParameterDeclaration>? parameters = null)
{
if (parameters != null)
{
@ -109,9 +109,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -109,9 +109,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitAnonymousMethodExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
AnonymousMethodExpression o = other as AnonymousMethodExpression;
AnonymousMethodExpression? o = other as AnonymousMethodExpression;
return o != null && this.IsAsync == o.IsAsync && this.HasParameterList == o.HasParameterList
&& this.Parameters.DoMatch(o.Parameters, match) && this.Body.DoMatch(o.Body, match);
}

2
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousTypeCreateExpression.cs

@ -81,7 +81,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -81,7 +81,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitAnonymousTypeCreateExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
var o = other as AnonymousTypeCreateExpression;
return o != null && this.Initializers.DoMatch(o.Initializers, match);

4
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayCreateExpression.cs

@ -69,9 +69,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -69,9 +69,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitArrayCreateExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
ArrayCreateExpression o = other as ArrayCreateExpression;
ArrayCreateExpression? o = other as ArrayCreateExpression;
return o != null && this.Type.DoMatch(o.Type, match)
&& this.Arguments.DoMatch(o.Arguments, match)
&& this.AdditionalArraySpecifiers.DoMatch(o.AdditionalArraySpecifiers, match)

8
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/ArrayInitializerExpression.cs

@ -85,7 +85,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -85,7 +85,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitNullNode(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
return other == null || other.IsNull;
}
@ -119,9 +119,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -119,9 +119,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitArrayInitializerExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
ArrayInitializerExpression o = other as ArrayInitializerExpression;
ArrayInitializerExpression? o = other as ArrayInitializerExpression;
return o != null && this.Elements.DoMatch(o.Elements, match);
}
@ -176,7 +176,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -176,7 +176,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitPatternPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
return child.DoMatch(other, match);
}

4
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AsExpression.cs

@ -73,9 +73,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -73,9 +73,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitAsExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
AsExpression o = other as AsExpression;
AsExpression? o = other as AsExpression;
return o != null && this.Expression.DoMatch(o.Expression, match) && this.Type.DoMatch(o.Type, match);
}
}

4
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AssignmentExpression.cs

@ -103,9 +103,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -103,9 +103,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitAssignmentExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
AssignmentExpression o = other as AssignmentExpression;
AssignmentExpression? o = other as AssignmentExpression;
return o != null && (this.Operator == AssignmentOperatorType.Any || this.Operator == o.Operator)
&& this.Left.DoMatch(o.Left, match) && this.Right.DoMatch(o.Right, match);
}

4
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/BaseReferenceExpression.cs

@ -63,9 +63,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -63,9 +63,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitBaseReferenceExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
BaseReferenceExpression o = other as BaseReferenceExpression;
BaseReferenceExpression? o = other as BaseReferenceExpression;
return o != null;
}
}

4
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/BinaryOperatorExpression.cs

@ -105,9 +105,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -105,9 +105,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitBinaryOperatorExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
BinaryOperatorExpression o = other as BinaryOperatorExpression;
BinaryOperatorExpression? o = other as BinaryOperatorExpression;
return o != null && (this.Operator == BinaryOperatorType.Any || this.Operator == o.Operator)
&& this.Left.DoMatch(o.Left, match) && this.Right.DoMatch(o.Right, match);
}

4
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/CastExpression.cs

@ -75,9 +75,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -75,9 +75,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitCastExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
CastExpression o = other as CastExpression;
CastExpression? o = other as CastExpression;
return o != null && this.Type.DoMatch(o.Type, match) && this.Expression.DoMatch(o.Expression, match);
}
}

4
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/CheckedExpression.cs

@ -75,9 +75,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -75,9 +75,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return visitor.VisitCheckedExpression(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
protected internal override bool DoMatch(AstNode? other, PatternMatching.Match match)
{
CheckedExpression o = other as CheckedExpression;
CheckedExpression? o = other as CheckedExpression;
return o != null && this.Expression.DoMatch(o.Expression, match);
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save