Browse Source

Fix CA1507:UseNameofInPlaceOfString, adjust formatting of some older source files copied from NRefactory.

pull/1790/head
Siegfried Pammer 6 years ago
parent
commit
e211b01595
  1. 4
      ICSharpCode.Decompiler/CSharp/Annotations.cs
  2. 16
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpAmbience.cs
  3. 38
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs
  4. 2
      ICSharpCode.Decompiler/CSharp/OutputVisitor/ITokenWriter.cs
  5. 2
      ICSharpCode.Decompiler/CSharp/OutputVisitor/TextWriterTokenWriter.cs
  6. 7
      ICSharpCode.Decompiler/CSharp/Resolver/AwaitResolveResult.cs
  7. 52
      ICSharpCode.Decompiler/CSharp/Resolver/CSharpConversions.cs
  8. 20
      ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs
  9. 20
      ICSharpCode.Decompiler/CSharp/Resolver/MemberLookup.cs
  10. 2
      ICSharpCode.Decompiler/CSharp/Resolver/MethodGroupResolveResult.cs
  11. 26
      ICSharpCode.Decompiler/CSharp/Resolver/OverloadResolution.cs
  12. 24
      ICSharpCode.Decompiler/CSharp/Resolver/TypeInference.cs
  13. 274
      ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs
  14. 6
      ICSharpCode.Decompiler/CSharp/Syntax/AstNodeCollection.cs
  15. 2
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/Expression.cs
  16. 2
      ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/NamespaceDeclaration.cs
  17. 66
      ICSharpCode.Decompiler/CSharp/Syntax/IAnnotatable.cs
  18. 4
      ICSharpCode.Decompiler/CSharp/Syntax/Identifier.cs
  19. 2
      ICSharpCode.Decompiler/CSharp/Syntax/IdentifierExpressionBackreference.cs
  20. 2
      ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/Backreference.cs
  21. 4
      ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/Choice.cs
  22. 4
      ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/INode.cs
  23. 2
      ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/NamedNode.cs
  24. 2
      ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/OptionalNode.cs
  25. 2
      ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/Repeat.cs
  26. 6
      ICSharpCode.Decompiler/CSharp/Syntax/Role.cs
  27. 2
      ICSharpCode.Decompiler/CSharp/Syntax/Statements/Statement.cs
  28. 16
      ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs
  29. 2
      ICSharpCode.Decompiler/CSharp/TypeSystem/AliasNamespaceReference.cs
  30. 4
      ICSharpCode.Decompiler/CSharp/TypeSystem/MemberTypeOrNamespaceReference.cs
  31. 4
      ICSharpCode.Decompiler/CSharp/TypeSystem/ResolvedUsingScope.cs
  32. 2
      ICSharpCode.Decompiler/CSharp/TypeSystem/SimpleTypeOrNamespaceReference.cs
  33. 4
      ICSharpCode.Decompiler/CSharp/TypeSystem/UsingScope.cs
  34. 2
      ICSharpCode.Decompiler/DebugInfo/DebugInfoGenerator.cs
  35. 2
      ICSharpCode.Decompiler/DecompilerException.cs
  36. 10
      ICSharpCode.Decompiler/Documentation/IdStringProvider.cs
  37. 4
      ICSharpCode.Decompiler/Documentation/XmlDocumentationElement.cs
  38. 6
      ICSharpCode.Decompiler/Documentation/XmlDocumentationProvider.cs
  39. 2
      ICSharpCode.Decompiler/IL/Instructions/CallIndirect.cs
  40. 2
      ICSharpCode.Decompiler/IL/Instructions/CompoundAssignmentInstruction.cs
  41. 4
      ICSharpCode.Decompiler/IL/Transforms/NullPropagationTransform.cs
  42. 2
      ICSharpCode.Decompiler/Metadata/AssemblyReferences.cs
  43. 4
      ICSharpCode.Decompiler/Semantics/ArrayAccessResolveResult.cs
  44. 2
      ICSharpCode.Decompiler/Semantics/ArrayCreateResolveResult.cs
  45. 6
      ICSharpCode.Decompiler/Semantics/Conversion.cs
  46. 4
      ICSharpCode.Decompiler/Semantics/ConversionResolveResult.cs
  47. 8
      ICSharpCode.Decompiler/Semantics/ForEachResolveResult.cs
  48. 2
      ICSharpCode.Decompiler/Semantics/LocalResolveResult.cs
  49. 8
      ICSharpCode.Decompiler/Semantics/NamedArgumentResolveResult.cs
  50. 4
      ICSharpCode.Decompiler/Semantics/OperatorResolveResult.cs
  51. 2
      ICSharpCode.Decompiler/Semantics/ResolveResult.cs
  52. 2
      ICSharpCode.Decompiler/Semantics/SizeOfResolveResult.cs
  53. 4
      ICSharpCode.Decompiler/Semantics/TypeIsResolveResult.cs
  54. 2
      ICSharpCode.Decompiler/Semantics/TypeOfResolveResult.cs
  55. 2
      ICSharpCode.Decompiler/Semantics/UnknownMemberResolveResult.cs
  56. 8
      ICSharpCode.Decompiler/TypeSystem/ArrayType.cs
  57. 2
      ICSharpCode.Decompiler/TypeSystem/ByReferenceType.cs
  58. 4
      ICSharpCode.Decompiler/TypeSystem/FullTypeName.cs
  59. 4
      ICSharpCode.Decompiler/TypeSystem/Implementation/AbstractTypeParameter.cs
  60. 4
      ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultAttribute.cs
  61. 8
      ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultParameter.cs
  62. 4
      ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultVariable.cs
  63. 2
      ICSharpCode.Decompiler/TypeSystem/Implementation/GetClassTypeReference.cs
  64. 8
      ICSharpCode.Decompiler/TypeSystem/Implementation/MergedNamespace.cs
  65. 4
      ICSharpCode.Decompiler/TypeSystem/Implementation/NestedTypeReference.cs
  66. 4
      ICSharpCode.Decompiler/TypeSystem/Implementation/SimpleCompilation.cs
  67. 2
      ICSharpCode.Decompiler/TypeSystem/Implementation/SpecializedMember.cs
  68. 2
      ICSharpCode.Decompiler/TypeSystem/Implementation/SpecializedMethod.cs
  69. 2
      ICSharpCode.Decompiler/TypeSystem/Implementation/TypeWithElementType.cs
  70. 4
      ICSharpCode.Decompiler/TypeSystem/Implementation/UnknownType.cs
  71. 6
      ICSharpCode.Decompiler/TypeSystem/InheritanceHelper.cs
  72. 10
      ICSharpCode.Decompiler/TypeSystem/NullableType.cs
  73. 2
      ICSharpCode.Decompiler/TypeSystem/ParameterListComparer.cs
  74. 8
      ICSharpCode.Decompiler/TypeSystem/ParameterizedType.cs
  75. 2
      ICSharpCode.Decompiler/TypeSystem/PointerType.cs
  76. 2
      ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs
  77. 4
      ICSharpCode.Decompiler/TypeSystem/SimpleTypeResolveContext.cs
  78. 2
      ICSharpCode.Decompiler/TypeSystem/SpecialType.cs
  79. 4
      ICSharpCode.Decompiler/TypeSystem/TaskType.cs
  80. 4
      ICSharpCode.Decompiler/TypeSystem/TopLevelTypeName.cs
  81. 22
      ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs
  82. 2
      ICSharpCode.Decompiler/Util/CallbackOnDispose.cs
  83. 4
      ICSharpCode.Decompiler/Util/EmptyList.cs
  84. 8
      ICSharpCode.Decompiler/Util/GraphVizGraph.cs
  85. 6
      ICSharpCode.Decompiler/Util/KeyComparer.cs
  86. 8
      ICSharpCode.Decompiler/Util/ProjectedList.cs
  87. 30
      ICSharpCode.Decompiler/Util/ResXResourceWriter.cs

4
ICSharpCode.Decompiler/CSharp/Annotations.cs

@ -41,7 +41,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// <summary> /// <summary>
/// Currently unused; we'll probably use the LdToken ILInstruction as annotation instead when LdToken support gets reimplemented. /// Currently unused; we'll probably use the LdToken ILInstruction as annotation instead when LdToken support gets reimplemented.
/// </summary> /// </summary>
public class LdTokenAnnotation {} public class LdTokenAnnotation { }
public static class AnnotationExtensions public static class AnnotationExtensions
{ {
@ -223,7 +223,7 @@ namespace ICSharpCode.Decompiler.CSharp
public ILVariableResolveResult(ILVariable v, IType type) : base(type) public ILVariableResolveResult(ILVariable v, IType type) : base(type)
{ {
this.Variable = v ?? throw new ArgumentNullException("v"); this.Variable = v ?? throw new ArgumentNullException(nameof(v));
} }
} }

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

@ -38,7 +38,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
public string ConvertSymbol(ISymbol symbol) public string ConvertSymbol(ISymbol symbol)
{ {
if (symbol == null) if (symbol == null)
throw new ArgumentNullException("symbol"); throw new ArgumentNullException(nameof(symbol));
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
ConvertSymbol(symbol, new TextWriterTokenWriter(writer), FormattingOptionsFactory.CreateEmpty()); ConvertSymbol(symbol, new TextWriterTokenWriter(writer), FormattingOptionsFactory.CreateEmpty());
@ -48,11 +48,11 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
public void ConvertSymbol(ISymbol symbol, TokenWriter writer, CSharpFormattingOptions formattingPolicy) public void ConvertSymbol(ISymbol symbol, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
{ {
if (symbol == null) if (symbol == null)
throw new ArgumentNullException("symbol"); throw new ArgumentNullException(nameof(symbol));
if (writer == null) if (writer == null)
throw new ArgumentNullException("writer"); throw new ArgumentNullException(nameof(writer));
if (formattingPolicy == null) if (formattingPolicy == null)
throw new ArgumentNullException("formattingPolicy"); throw new ArgumentNullException(nameof(formattingPolicy));
TypeSystemAstBuilder astBuilder = CreateAstBuilder(); TypeSystemAstBuilder astBuilder = CreateAstBuilder();
AstNode node = astBuilder.ConvertSymbol(symbol); AstNode node = astBuilder.ConvertSymbol(symbol);
@ -93,8 +93,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
} }
if ((ConversionFlags & ConversionFlags.PlaceReturnTypeAfterParameterList) != ConversionFlags.PlaceReturnTypeAfterParameterList if ((ConversionFlags & ConversionFlags.PlaceReturnTypeAfterParameterList) != ConversionFlags.PlaceReturnTypeAfterParameterList
&& (ConversionFlags & ConversionFlags.ShowReturnType) == ConversionFlags.ShowReturnType) && (ConversionFlags & ConversionFlags.ShowReturnType) == ConversionFlags.ShowReturnType) {
{
var rt = node.GetChildByRole(Roles.Type); var rt = node.GetChildByRole(Roles.Type);
if (!rt.IsNull) { if (!rt.IsNull) {
rt.AcceptVisitor(new CSharpOutputVisitor(writer, formattingPolicy)); rt.AcceptVisitor(new CSharpOutputVisitor(writer, formattingPolicy));
@ -131,8 +130,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
} }
if ((ConversionFlags & ConversionFlags.PlaceReturnTypeAfterParameterList) == ConversionFlags.PlaceReturnTypeAfterParameterList if ((ConversionFlags & ConversionFlags.PlaceReturnTypeAfterParameterList) == ConversionFlags.PlaceReturnTypeAfterParameterList
&& (ConversionFlags & ConversionFlags.ShowReturnType) == ConversionFlags.ShowReturnType) && (ConversionFlags & ConversionFlags.ShowReturnType) == ConversionFlags.ShowReturnType) {
{
var rt = node.GetChildByRole(Roles.Type); var rt = node.GetChildByRole(Roles.Type);
if (!rt.IsNull) { if (!rt.IsNull) {
writer.Space(); writer.Space();
@ -318,7 +316,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
public string ConvertType(IType type) public string ConvertType(IType type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
TypeSystemAstBuilder astBuilder = CreateAstBuilder(); TypeSystemAstBuilder astBuilder = CreateAstBuilder();
astBuilder.AlwaysUseShortTypeNames = (ConversionFlags & ConversionFlags.UseFullyQualifiedEntityNames) != ConversionFlags.UseFullyQualifiedEntityNames; astBuilder.AlwaysUseShortTypeNames = (ConversionFlags & ConversionFlags.UseFullyQualifiedEntityNames) != ConversionFlags.UseFullyQualifiedEntityNames;

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

@ -36,27 +36,27 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
{ {
readonly protected TokenWriter writer; readonly protected TokenWriter writer;
readonly protected CSharpFormattingOptions policy; readonly protected CSharpFormattingOptions policy;
readonly protected Stack<AstNode> containerStack = new Stack<AstNode> (); readonly protected Stack<AstNode> containerStack = new Stack<AstNode>();
public CSharpOutputVisitor (TextWriter textWriter, CSharpFormattingOptions formattingPolicy) public CSharpOutputVisitor(TextWriter textWriter, CSharpFormattingOptions formattingPolicy)
{ {
if (textWriter == null) { if (textWriter == null) {
throw new ArgumentNullException ("textWriter"); throw new ArgumentNullException(nameof(textWriter));
} }
if (formattingPolicy == null) { if (formattingPolicy == null) {
throw new ArgumentNullException ("formattingPolicy"); throw new ArgumentNullException(nameof(formattingPolicy));
} }
this.writer = TokenWriter.Create(textWriter, formattingPolicy.IndentationString); this.writer = TokenWriter.Create(textWriter, formattingPolicy.IndentationString);
this.policy = formattingPolicy; this.policy = formattingPolicy;
} }
public CSharpOutputVisitor (TokenWriter writer, CSharpFormattingOptions formattingPolicy) public CSharpOutputVisitor(TokenWriter writer, CSharpFormattingOptions formattingPolicy)
{ {
if (writer == null) { if (writer == null) {
throw new ArgumentNullException ("writer"); throw new ArgumentNullException(nameof(writer));
} }
if (formattingPolicy == null) { if (formattingPolicy == null) {
throw new ArgumentNullException ("formattingPolicy"); throw new ArgumentNullException(nameof(formattingPolicy));
} }
this.writer = new InsertSpecialsDecorator(new InsertRequiredSpacesDecorator(writer)); this.writer = new InsertSpecialsDecorator(new InsertRequiredSpacesDecorator(writer));
this.policy = formattingPolicy; this.policy = formattingPolicy;
@ -148,7 +148,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
RPar(); RPar();
} }
#if DOTNET35 #if DOTNET35
void WriteCommaSeparatedList(IEnumerable<VariableInitializer> list) void WriteCommaSeparatedList(IEnumerable<VariableInitializer> list)
{ {
WriteCommaSeparatedList(list.SafeCast<VariableInitializer, AstNode>()); WriteCommaSeparatedList(list.SafeCast<VariableInitializer, AstNode>());
@ -169,7 +169,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
WriteCommaSeparatedListInParenthesis(list.SafeCast<ParameterDeclaration, AstNode>(), spaceWithin); WriteCommaSeparatedListInParenthesis(list.SafeCast<ParameterDeclaration, AstNode>(), spaceWithin);
} }
#endif #endif
protected virtual void WriteCommaSeparatedListInBrackets(IEnumerable<ParameterDeclaration> list, bool spaceWithin) protected virtual void WriteCommaSeparatedListInBrackets(IEnumerable<ParameterDeclaration> list, bool spaceWithin)
{ {
@ -337,7 +337,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
writer.WriteToken(Roles.LBrace, "{"); writer.WriteToken(Roles.LBrace, "{");
break; break;
default: default:
throw new ArgumentOutOfRangeException (); throw new ArgumentOutOfRangeException();
} }
writer.Indent(); writer.Indent();
NewLine(); NewLine();
@ -720,7 +720,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
spacePolicy = true; spacePolicy = true;
break; break;
default: default:
throw new NotSupportedException ("Invalid value for BinaryOperatorType"); throw new NotSupportedException("Invalid value for BinaryOperatorType");
} }
Space(spacePolicy); Space(spacePolicy);
WriteToken(BinaryOperatorExpression.GetOperatorRole(binaryOperatorExpression.Operator)); WriteToken(BinaryOperatorExpression.GetOperatorRole(binaryOperatorExpression.Operator));
@ -803,7 +803,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
WriteKeyword(DirectionExpression.InKeywordRole); WriteKeyword(DirectionExpression.InKeywordRole);
break; break;
default: default:
throw new NotSupportedException ("Invalid value for FieldDirection"); throw new NotSupportedException("Invalid value for FieldDirection");
} }
Space(); Space();
directionExpression.Expression.AcceptVisitor(this); directionExpression.Expression.AcceptVisitor(this);
@ -1350,7 +1350,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
{ {
StartNode(namespaceDeclaration); StartNode(namespaceDeclaration);
WriteKeyword(Roles.NamespaceKeyword); WriteKeyword(Roles.NamespaceKeyword);
namespaceDeclaration.NamespaceName.AcceptVisitor (this); namespaceDeclaration.NamespaceName.AcceptVisitor(this);
OpenBrace(policy.NamespaceBraceStyle); OpenBrace(policy.NamespaceBraceStyle);
foreach (var member in namespaceDeclaration.Members) { foreach (var member in namespaceDeclaration.Members) {
member.AcceptVisitor(this); member.AcceptVisitor(this);
@ -2186,7 +2186,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
WriteKeyword(OperatorDeclaration.OperatorKeywordRole); WriteKeyword(OperatorDeclaration.OperatorKeywordRole);
Space(); Space();
if (operatorDeclaration.OperatorType == OperatorType.Explicit if (operatorDeclaration.OperatorType == OperatorType.Explicit
|| operatorDeclaration.OperatorType == OperatorType.Implicit) { || operatorDeclaration.OperatorType == OperatorType.Implicit) {
operatorDeclaration.ReturnType.AcceptVisitor(this); operatorDeclaration.ReturnType.AcceptVisitor(this);
} else { } else {
WriteToken(OperatorDeclaration.GetToken(operatorDeclaration.OperatorType), OperatorDeclaration.GetRole(operatorDeclaration.OperatorType)); WriteToken(OperatorDeclaration.GetToken(operatorDeclaration.OperatorType), OperatorDeclaration.GetRole(operatorDeclaration.OperatorType));
@ -2409,9 +2409,9 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
public virtual void VisitNewLine(NewLineNode newLineNode) public virtual void VisitNewLine(NewLineNode newLineNode)
{ {
// formatter.StartNode(newLineNode); // formatter.StartNode(newLineNode);
// formatter.NewLine(); // formatter.NewLine();
// formatter.EndNode(newLineNode); // formatter.EndNode(newLineNode);
} }
public virtual void VisitWhitespace(WhitespaceNode whitespaceNode) public virtual void VisitWhitespace(WhitespaceNode whitespaceNode)
@ -2445,7 +2445,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
WriteKeyword(TypeParameterDeclaration.InVarianceKeywordRole); WriteKeyword(TypeParameterDeclaration.InVarianceKeywordRole);
break; break;
default: default:
throw new NotSupportedException ("Invalid value for VarianceModifier"); throw new NotSupportedException("Invalid value for VarianceModifier");
} }
WriteIdentifier(typeParameterDeclaration.NameToken); WriteIdentifier(typeParameterDeclaration.NameToken);
EndNode(typeParameterDeclaration); EndNode(typeParameterDeclaration);
@ -2472,7 +2472,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
// StartNode(parentNode)-EndNode(parentNode)-pair is a child of parentNode. // StartNode(parentNode)-EndNode(parentNode)-pair is a child of parentNode.
WriteKeyword(CSharpModifierToken.GetModifierName(mod.Modifier), cSharpTokenNode.Role); WriteKeyword(CSharpModifierToken.GetModifierName(mod.Modifier), cSharpTokenNode.Role);
} else { } else {
throw new NotSupportedException ("Should never visit individual tokens"); throw new NotSupportedException("Should never visit individual tokens");
} }
} }

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

@ -94,7 +94,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
protected DecoratingTokenWriter(TokenWriter decoratedWriter) protected DecoratingTokenWriter(TokenWriter decoratedWriter)
{ {
if (decoratedWriter == null) if (decoratedWriter == null)
throw new ArgumentNullException("decoratedWriter"); throw new ArgumentNullException(nameof(decoratedWriter));
this.decoratedWriter = decoratedWriter; this.decoratedWriter = decoratedWriter;
} }

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

@ -47,7 +47,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
public TextWriterTokenWriter(TextWriter textWriter) public TextWriterTokenWriter(TextWriter textWriter)
{ {
if (textWriter == null) if (textWriter == null)
throw new ArgumentNullException("textWriter"); throw new ArgumentNullException(nameof(textWriter));
this.textWriter = textWriter; this.textWriter = textWriter;
this.IndentationString = "\t"; this.IndentationString = "\t";
this.line = 1; this.line = 1;

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

@ -58,9 +58,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
: base(resultType) : base(resultType)
{ {
if (awaiterType == null) if (awaiterType == null)
throw new ArgumentNullException("awaiterType"); throw new ArgumentNullException(nameof(awaiterType));
if (getAwaiterInvocation == null) if (getAwaiterInvocation == null)
throw new ArgumentNullException("getAwaiterInvocation"); throw new ArgumentNullException(nameof(getAwaiterInvocation));
this.GetAwaiterInvocation = getAwaiterInvocation; this.GetAwaiterInvocation = getAwaiterInvocation;
this.AwaiterType = awaiterType; this.AwaiterType = awaiterType;
this.IsCompletedProperty = isCompletedProperty; this.IsCompletedProperty = isCompletedProperty;
@ -72,7 +72,8 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
get { return this.GetAwaiterInvocation.IsError || (AwaiterType.Kind != TypeKind.Dynamic && (this.IsCompletedProperty == null || this.OnCompletedMethod == null || this.GetResultMethod == null)); } get { return this.GetAwaiterInvocation.IsError || (AwaiterType.Kind != TypeKind.Dynamic && (this.IsCompletedProperty == null || this.OnCompletedMethod == null || this.GetResultMethod == null)); }
} }
public override IEnumerable<ResolveResult> GetChildResults() { public override IEnumerable<ResolveResult> GetChildResults()
{
return new[] { GetAwaiterInvocation }; return new[] { GetAwaiterInvocation };
} }
} }

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

@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public CSharpConversions(ICompilation compilation) public CSharpConversions(ICompilation compilation)
{ {
if (compilation == null) if (compilation == null)
throw new ArgumentNullException("compilation"); throw new ArgumentNullException(nameof(compilation));
this.compilation = compilation; this.compilation = compilation;
} }
@ -53,7 +53,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public static CSharpConversions Get(ICompilation compilation) public static CSharpConversions Get(ICompilation compilation)
{ {
if (compilation == null) if (compilation == null)
throw new ArgumentNullException("compilation"); throw new ArgumentNullException(nameof(compilation));
CacheManager cache = compilation.CacheManager; CacheManager cache = compilation.CacheManager;
CSharpConversions operators = (CSharpConversions)cache.GetShared(typeof(CSharpConversions)); CSharpConversions operators = (CSharpConversions)cache.GetShared(typeof(CSharpConversions));
if (operators == null) { if (operators == null) {
@ -151,16 +151,16 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public Conversion ImplicitConversion(ResolveResult resolveResult, IType toType) public Conversion ImplicitConversion(ResolveResult resolveResult, IType toType)
{ {
if (resolveResult == null) if (resolveResult == null)
throw new ArgumentNullException("resolveResult"); throw new ArgumentNullException(nameof(resolveResult));
return ImplicitConversion(resolveResult, toType, allowUserDefined: true, allowTuple: true); return ImplicitConversion(resolveResult, toType, allowUserDefined: true, allowTuple: true);
} }
public Conversion ImplicitConversion(IType fromType, IType toType) public Conversion ImplicitConversion(IType fromType, IType toType)
{ {
if (fromType == null) if (fromType == null)
throw new ArgumentNullException("fromType"); throw new ArgumentNullException(nameof(fromType));
if (toType == null) if (toType == null)
throw new ArgumentNullException("toType"); throw new ArgumentNullException(nameof(toType));
TypePair pair = new TypePair(fromType, toType); TypePair pair = new TypePair(fromType, toType);
Conversion c; Conversion c;
@ -176,9 +176,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public Conversion StandardImplicitConversion(IType fromType, IType toType) public Conversion StandardImplicitConversion(IType fromType, IType toType)
{ {
if (fromType == null) if (fromType == null)
throw new ArgumentNullException("fromType"); throw new ArgumentNullException(nameof(fromType));
if (toType == null) if (toType == null)
throw new ArgumentNullException("toType"); throw new ArgumentNullException(nameof(toType));
return StandardImplicitConversion(fromType, toType, allowTupleConversion: true); return StandardImplicitConversion(fromType, toType, allowTupleConversion: true);
} }
@ -220,9 +220,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public bool IsConstraintConvertible(IType fromType, IType toType) public bool IsConstraintConvertible(IType fromType, IType toType)
{ {
if (fromType == null) if (fromType == null)
throw new ArgumentNullException("fromType"); throw new ArgumentNullException(nameof(fromType));
if (toType == null) if (toType == null)
throw new ArgumentNullException("toType"); throw new ArgumentNullException(nameof(toType));
if (IdentityConversion(fromType, toType)) if (IdentityConversion(fromType, toType))
return true; return true;
@ -247,9 +247,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public Conversion ExplicitConversion(ResolveResult resolveResult, IType toType) public Conversion ExplicitConversion(ResolveResult resolveResult, IType toType)
{ {
if (resolveResult == null) if (resolveResult == null)
throw new ArgumentNullException("resolveResult"); throw new ArgumentNullException(nameof(resolveResult));
if (toType == null) if (toType == null)
throw new ArgumentNullException("toType"); throw new ArgumentNullException(nameof(toType));
if (resolveResult.Type.Kind == TypeKind.Dynamic) if (resolveResult.Type.Kind == TypeKind.Dynamic)
return Conversion.ExplicitDynamicConversion; return Conversion.ExplicitDynamicConversion;
@ -270,9 +270,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public Conversion ExplicitConversion(IType fromType, IType toType) public Conversion ExplicitConversion(IType fromType, IType toType)
{ {
if (fromType == null) if (fromType == null)
throw new ArgumentNullException("fromType"); throw new ArgumentNullException(nameof(fromType));
if (toType == null) if (toType == null)
throw new ArgumentNullException("toType"); throw new ArgumentNullException(nameof(toType));
Conversion c = ImplicitConversion(fromType, toType, allowUserDefined: false, allowTuple: false); Conversion c = ImplicitConversion(fromType, toType, allowUserDefined: false, allowTuple: false);
if (c != Conversion.None) if (c != Conversion.None)
@ -800,7 +800,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
if (best == null || IsEncompassedBy(current, best)) if (best == null || IsEncompassedBy(current, best))
best = current; best = current;
else if (!IsEncompassedBy(best, current)) else if (!IsEncompassedBy(best, current))
return null; // Ambiguous return null; // Ambiguous
} }
return best; return best;
} }
@ -812,7 +812,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
if (best == null || IsEncompassedBy(best, current)) if (best == null || IsEncompassedBy(best, current))
best = current; best = current;
else if (!IsEncompassedBy(current, best)) else if (!IsEncompassedBy(current, best))
return null; // Ambiguous return null; // Ambiguous
} }
return best; return best;
} }
@ -861,13 +861,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return other; return other;
} }
return selected; return selected;
} } else if (NullableType.IsNullable(toType))
else if (NullableType.IsNullable(toType))
return UserDefinedImplicitConversion(fromResult, fromType, NullableType.GetUnderlyingType(toType)); return UserDefinedImplicitConversion(fromResult, fromType, NullableType.GetUnderlyingType(toType));
else else
return Conversion.None; return Conversion.None;
} } else {
else {
return Conversion.None; return Conversion.None;
} }
} }
@ -913,15 +911,13 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
return other; return other;
} }
return selected; return selected;
} } else if (NullableType.IsNullable(toType))
else if (NullableType.IsNullable(toType))
return UserDefinedExplicitConversion(fromResult, fromType, NullableType.GetUnderlyingType(toType)); return UserDefinedExplicitConversion(fromResult, fromType, NullableType.GetUnderlyingType(toType));
else if (NullableType.IsNullable(fromType)) else if (NullableType.IsNullable(fromType))
return UserDefinedExplicitConversion(null, NullableType.GetUnderlyingType(fromType), toType); // A? -> A -> B return UserDefinedExplicitConversion(null, NullableType.GetUnderlyingType(fromType), toType); // A? -> A -> B
else else
return Conversion.None; return Conversion.None;
} } else {
else {
return Conversion.None; return Conversion.None;
} }
} }
@ -1106,9 +1102,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public bool IsDelegateCompatible(IMethod method, IType delegateType) public bool IsDelegateCompatible(IMethod method, IType delegateType)
{ {
if (method == null) if (method == null)
throw new ArgumentNullException("method"); throw new ArgumentNullException(nameof(method));
if (delegateType == null) if (delegateType == null)
throw new ArgumentNullException("delegateType"); throw new ArgumentNullException(nameof(delegateType));
IMethod invoke = delegateType.GetDelegateInvokeMethod(); IMethod invoke = delegateType.GetDelegateInvokeMethod();
if (invoke == null) if (invoke == null)
return false; return false;
@ -1126,9 +1122,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
bool IsDelegateCompatible(IMethod m, IMethod invoke, bool isExtensionMethodInvocation) bool IsDelegateCompatible(IMethod m, IMethod invoke, bool isExtensionMethodInvocation)
{ {
if (m == null) if (m == null)
throw new ArgumentNullException("m"); throw new ArgumentNullException(nameof(m));
if (invoke == null) if (invoke == null)
throw new ArgumentNullException("invoke"); throw new ArgumentNullException(nameof(invoke));
int firstParameterInM = isExtensionMethodInvocation ? 1 : 0; int firstParameterInM = isExtensionMethodInvocation ? 1 : 0;
if (m.Parameters.Count - firstParameterInM != invoke.Parameters.Count) if (m.Parameters.Count - firstParameterInM != invoke.Parameters.Count)
return false; return false;

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

@ -49,7 +49,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public CSharpResolver(ICompilation compilation) public CSharpResolver(ICompilation compilation)
{ {
if (compilation == null) if (compilation == null)
throw new ArgumentNullException("compilation"); throw new ArgumentNullException(nameof(compilation));
this.compilation = compilation; this.compilation = compilation;
this.conversions = CSharpConversions.Get(compilation); this.conversions = CSharpConversions.Get(compilation);
this.context = new CSharpTypeResolveContext(compilation.MainModule); this.context = new CSharpTypeResolveContext(compilation.MainModule);
@ -58,7 +58,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public CSharpResolver(CSharpTypeResolveContext context) public CSharpResolver(CSharpTypeResolveContext context)
{ {
if (context == null) if (context == null)
throw new ArgumentNullException("context"); throw new ArgumentNullException(nameof(context));
this.compilation = context.Compilation; this.compilation = context.Compilation;
this.conversions = CSharpConversions.Get(compilation); this.conversions = CSharpConversions.Get(compilation);
this.context = context; this.context = context;
@ -262,7 +262,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public CSharpResolver AddVariable(IVariable variable) public CSharpResolver AddVariable(IVariable variable)
{ {
if (variable == null) if (variable == null)
throw new ArgumentNullException("variable"); throw new ArgumentNullException(nameof(variable));
return WithLocalVariableStack(localVariableStack.Push(variable)); return WithLocalVariableStack(localVariableStack.Push(variable));
} }
@ -313,7 +313,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public CSharpResolver PushObjectInitializer(ResolveResult initializedObject) public CSharpResolver PushObjectInitializer(ResolveResult initializedObject)
{ {
if (initializedObject == null) if (initializedObject == null)
throw new ArgumentNullException("initializedObject"); throw new ArgumentNullException(nameof(initializedObject));
return WithObjectInitializerStack(new ObjectInitializerContext(initializedObject, objectInitializerStack)); return WithObjectInitializerStack(new ObjectInitializerContext(initializedObject, objectInitializerStack));
} }
@ -1313,9 +1313,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
// C# 4.0 spec: §3.8 Namespace and type names; §7.6.2 Simple Names // C# 4.0 spec: §3.8 Namespace and type names; §7.6.2 Simple Names
if (identifier == null) if (identifier == null)
throw new ArgumentNullException("identifier"); throw new ArgumentNullException(nameof(identifier));
if (typeArguments == null) if (typeArguments == null)
throw new ArgumentNullException("typeArguments"); throw new ArgumentNullException(nameof(typeArguments));
int k = typeArguments.Count; int k = typeArguments.Count;
@ -1866,9 +1866,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public static bool IsEligibleExtensionMethod(IType targetType, IMethod method, bool useTypeInference, out IType[] outInferredTypes) public static bool IsEligibleExtensionMethod(IType targetType, IMethod method, bool useTypeInference, out IType[] outInferredTypes)
{ {
if (targetType == null) if (targetType == null)
throw new ArgumentNullException("targetType"); throw new ArgumentNullException(nameof(targetType));
if (method == null) if (method == null)
throw new ArgumentNullException("method"); throw new ArgumentNullException(nameof(method));
var compilation = method.Compilation; var compilation = method.Compilation;
return IsEligibleExtensionMethod(compilation, CSharpConversions.Get(compilation), targetType, method, useTypeInference, out outInferredTypes); return IsEligibleExtensionMethod(compilation, CSharpConversions.Get(compilation), targetType, method, useTypeInference, out outInferredTypes);
} }
@ -2348,7 +2348,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public ResolveResult ResolveCondition(ResolveResult input) public ResolveResult ResolveCondition(ResolveResult input)
{ {
if (input == null) if (input == null)
throw new ArgumentNullException("input"); throw new ArgumentNullException(nameof(input));
IType boolean = compilation.FindType(KnownTypeCode.Boolean); IType boolean = compilation.FindType(KnownTypeCode.Boolean);
Conversion c = conversions.ImplicitConversion(input, boolean); Conversion c = conversions.ImplicitConversion(input, boolean);
if (!c.IsValid) { if (!c.IsValid) {
@ -2368,7 +2368,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public ResolveResult ResolveConditionFalse(ResolveResult input) public ResolveResult ResolveConditionFalse(ResolveResult input)
{ {
if (input == null) if (input == null)
throw new ArgumentNullException("input"); throw new ArgumentNullException(nameof(input));
IType boolean = compilation.FindType(KnownTypeCode.Boolean); IType boolean = compilation.FindType(KnownTypeCode.Boolean);
Conversion c = conversions.ImplicitConversion(input, boolean); Conversion c = conversions.ImplicitConversion(input, boolean);
if (!c.IsValid) { if (!c.IsValid) {

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

@ -37,7 +37,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public static bool IsInvocable(IMember member) public static bool IsInvocable(IMember member)
{ {
if (member == null) if (member == null)
throw new ArgumentNullException("member"); throw new ArgumentNullException(nameof(member));
// C# 4.0 spec, §7.4 member lookup // C# 4.0 spec, §7.4 member lookup
if (member is IEvent || member is IMethod) if (member is IEvent || member is IMethod)
return true; return true;
@ -99,7 +99,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public bool IsAccessible(IEntity entity, bool allowProtectedAccess) public bool IsAccessible(IEntity entity, bool allowProtectedAccess)
{ {
if (entity == null) if (entity == null)
throw new ArgumentNullException("entity"); throw new ArgumentNullException(nameof(entity));
// C# 4.0 spec, §3.5.2 Accessiblity domains // C# 4.0 spec, §3.5.2 Accessiblity domains
switch (entity.Accessibility) { switch (entity.Accessibility) {
case Accessibility.None: case Accessibility.None:
@ -159,7 +159,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public IEnumerable<IEntity> GetAccessibleMembers(ResolveResult targetResolveResult) public IEnumerable<IEntity> GetAccessibleMembers(ResolveResult targetResolveResult)
{ {
if (targetResolveResult == null) if (targetResolveResult == null)
throw new ArgumentNullException("targetResolveResult"); throw new ArgumentNullException(nameof(targetResolveResult));
bool targetIsTypeParameter = targetResolveResult.Type.Kind == TypeKind.TypeParameter; bool targetIsTypeParameter = targetResolveResult.Type.Kind == TypeKind.TypeParameter;
bool allowProtectedAccess = IsProtectedAccessAllowed(targetResolveResult); bool allowProtectedAccess = IsProtectedAccessAllowed(targetResolveResult);
@ -276,11 +276,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public ResolveResult LookupType(IType declaringType, string name, IReadOnlyList<IType> typeArguments, bool parameterizeResultType = true) public ResolveResult LookupType(IType declaringType, string name, IReadOnlyList<IType> typeArguments, bool parameterizeResultType = true)
{ {
if (declaringType == null) if (declaringType == null)
throw new ArgumentNullException("declaringType"); throw new ArgumentNullException(nameof(declaringType));
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
if (typeArguments == null) if (typeArguments == null)
throw new ArgumentNullException("typeArguments"); throw new ArgumentNullException(nameof(typeArguments));
int typeArgumentCount = typeArguments.Count; int typeArgumentCount = typeArguments.Count;
Predicate<ITypeDefinition> filter = delegate (ITypeDefinition d) { Predicate<ITypeDefinition> filter = delegate (ITypeDefinition d) {
@ -335,11 +335,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public ResolveResult Lookup(ResolveResult targetResolveResult, string name, IReadOnlyList<IType> typeArguments, bool isInvocation) public ResolveResult Lookup(ResolveResult targetResolveResult, string name, IReadOnlyList<IType> typeArguments, bool isInvocation)
{ {
if (targetResolveResult == null) if (targetResolveResult == null)
throw new ArgumentNullException("targetResolveResult"); throw new ArgumentNullException(nameof(targetResolveResult));
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
if (typeArguments == null) if (typeArguments == null)
throw new ArgumentNullException("typeArguments"); throw new ArgumentNullException(nameof(typeArguments));
bool targetIsTypeParameter = targetResolveResult.Type.Kind == TypeKind.TypeParameter; bool targetIsTypeParameter = targetResolveResult.Type.Kind == TypeKind.TypeParameter;
@ -413,7 +413,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public IReadOnlyList<MethodListWithDeclaringType> LookupIndexers(ResolveResult targetResolveResult) public IReadOnlyList<MethodListWithDeclaringType> LookupIndexers(ResolveResult targetResolveResult)
{ {
if (targetResolveResult == null) if (targetResolveResult == null)
throw new ArgumentNullException("targetResolveResult"); throw new ArgumentNullException(nameof(targetResolveResult));
IType targetType = targetResolveResult.Type; IType targetType = targetResolveResult.Type;
bool allowProtectedAccess = IsProtectedAccessAllowed(targetResolveResult); bool allowProtectedAccess = IsProtectedAccessAllowed(targetResolveResult);

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

@ -86,7 +86,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
: base(SpecialType.NoType) : base(SpecialType.NoType)
{ {
if (methods == null) if (methods == null)
throw new ArgumentNullException("methods"); throw new ArgumentNullException(nameof(methods));
this.targetResult = targetResult; this.targetResult = targetResult;
this.methodName = methodName; this.methodName = methodName;
this.methodLists = methods; this.methodLists = methods;

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

@ -135,9 +135,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
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) if (compilation == null)
throw new ArgumentNullException("compilation"); throw new ArgumentNullException(nameof(compilation));
if (arguments == null) if (arguments == null)
throw new ArgumentNullException("arguments"); throw new ArgumentNullException(nameof(arguments));
if (argumentNames == null) if (argumentNames == null)
argumentNames = new string[arguments.Length]; argumentNames = new string[arguments.Length];
else if (argumentNames.Length != arguments.Length) else if (argumentNames.Length != arguments.Length)
@ -218,7 +218,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public OverloadResolutionErrors AddCandidate(IParameterizedMember member, OverloadResolutionErrors additionalErrors) public OverloadResolutionErrors AddCandidate(IParameterizedMember member, OverloadResolutionErrors additionalErrors)
{ {
if (member == null) if (member == null)
throw new ArgumentNullException("member"); throw new ArgumentNullException(nameof(member));
Candidate c = new Candidate(member, false); Candidate c = new Candidate(member, false);
c.AddError(additionalErrors); c.AddError(additionalErrors);
@ -227,7 +227,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
} }
if (this.AllowExpandingParams && member.Parameters.Count > 0 if (this.AllowExpandingParams && member.Parameters.Count > 0
&& member.Parameters[member.Parameters.Count - 1].IsParams) && member.Parameters[member.Parameters.Count - 1].IsParams)
{ {
Candidate expandedCandidate = new Candidate(member, true); Candidate expandedCandidate = new Candidate(member, true);
expandedCandidate.AddError(additionalErrors); expandedCandidate.AddError(additionalErrors);
@ -293,7 +293,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public void AddMethodLists(IReadOnlyList<MethodListWithDeclaringType> methodLists) public void AddMethodLists(IReadOnlyList<MethodListWithDeclaringType> methodLists)
{ {
if (methodLists == null) if (methodLists == null)
throw new ArgumentNullException("methodLists"); throw new ArgumentNullException(nameof(methodLists));
// Base types come first, so go through the list backwards (derived types first) // Base types come first, so go through the list backwards (derived types first)
bool[] isHiddenByDerivedType; bool[] isHiddenByDerivedType;
if (methodLists.Count > 1) if (methodLists.Count > 1)
@ -335,11 +335,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
{ {
#if DEBUG #if DEBUG
Log.WriteLine(string.Format("{0} {1} = {2}{3}", Log.WriteLine(string.Format("{0} {1} = {2}{3}",
text, method, text, method,
errors == OverloadResolutionErrors.None ? "Success" : errors.ToString(), errors == OverloadResolutionErrors.None ? "Success" : errors.ToString(),
this.BestCandidate == method ? " (best candidate so far)" : this.BestCandidate == method ? " (best candidate so far)" :
this.BestCandidateAmbiguousWith == method ? " (ambiguous)" : "" this.BestCandidateAmbiguousWith == method ? " (ambiguous)" : ""
)); ));
#endif #endif
} }
#endregion #endregion
@ -500,9 +500,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
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) if (typeParameter == null)
throw new ArgumentNullException("typeParameter"); throw new ArgumentNullException(nameof(typeParameter));
if (typeArgument == null) if (typeArgument == null)
throw new ArgumentNullException("typeArgument"); throw new ArgumentNullException(nameof(typeArgument));
return ValidateConstraints(typeParameter, typeArgument, substitution, CSharpConversions.Get(typeParameter.Owner.Compilation)); return ValidateConstraints(typeParameter, typeArgument, substitution, CSharpConversions.Get(typeParameter.Owner.Compilation));
} }
@ -711,7 +711,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
{ {
bool c1IsBetter = false; bool c1IsBetter = false;
bool c2IsBetter = false; bool c2IsBetter = false;
foreach (var pair in t1.Zip(t2, (a,b) => new { Item1 = a, Item2 = b })) { foreach (var pair in t1.Zip(t2, (a, b) => new { Item1 = a, Item2 = b })) {
switch (MoreSpecificFormalParameter(pair.Item1, pair.Item2)) { switch (MoreSpecificFormalParameter(pair.Item1, pair.Item2)) {
case 1: case 1:
c1IsBetter = true; c1IsBetter = true;

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

@ -61,7 +61,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public TypeInference(ICompilation compilation) public TypeInference(ICompilation compilation)
{ {
if (compilation == null) if (compilation == null)
throw new ArgumentNullException("compilation"); throw new ArgumentNullException(nameof(compilation));
this.compilation = compilation; this.compilation = compilation;
this.conversions = CSharpConversions.Get(compilation); this.conversions = CSharpConversions.Get(compilation);
} }
@ -115,11 +115,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
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) if (typeParameters == null)
throw new ArgumentNullException("typeParameters"); throw new ArgumentNullException(nameof(typeParameters));
if (arguments == null) if (arguments == null)
throw new ArgumentNullException("arguments"); throw new ArgumentNullException(nameof(arguments));
if (parameterTypes == null) if (parameterTypes == null)
throw new ArgumentNullException("parameterTypes"); throw new ArgumentNullException(nameof(parameterTypes));
try { try {
this.typeParameters = new TP[typeParameters.Count]; this.typeParameters = new TP[typeParameters.Count];
for (int i = 0; i < this.typeParameters.Length; i++) { for (int i = 0; i < this.typeParameters.Length; i++) {
@ -173,13 +173,13 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public IType[] InferTypeArgumentsFromBounds(IReadOnlyList<ITypeParameter> typeParameters, IType targetType, IEnumerable<IType> lowerBounds, IEnumerable<IType> upperBounds, out bool success) public IType[] InferTypeArgumentsFromBounds(IReadOnlyList<ITypeParameter> typeParameters, IType targetType, IEnumerable<IType> lowerBounds, IEnumerable<IType> upperBounds, out bool success)
{ {
if (typeParameters == null) if (typeParameters == null)
throw new ArgumentNullException("typeParameters"); throw new ArgumentNullException(nameof(typeParameters));
if (targetType == null) if (targetType == null)
throw new ArgumentNullException("targetType"); throw new ArgumentNullException(nameof(targetType));
if (lowerBounds == null) if (lowerBounds == null)
throw new ArgumentNullException("lowerBounds"); throw new ArgumentNullException(nameof(lowerBounds));
if (upperBounds == null) if (upperBounds == null)
throw new ArgumentNullException("upperBounds"); throw new ArgumentNullException(nameof(upperBounds));
this.typeParameters = new TP[typeParameters.Count]; this.typeParameters = new TP[typeParameters.Count];
for (int i = 0; i < this.typeParameters.Length; i++) { for (int i = 0; i < this.typeParameters.Length; i++) {
if (i != typeParameters[i].Index) if (i != typeParameters[i].Index)
@ -223,7 +223,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public TP(ITypeParameter typeParameter) public TP(ITypeParameter typeParameter)
{ {
if (typeParameter == null) if (typeParameter == null)
throw new ArgumentNullException("typeParameter"); throw new ArgumentNullException(nameof(typeParameter));
this.TypeParameter = typeParameter; this.TypeParameter = typeParameter;
} }
@ -834,7 +834,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public IType GetBestCommonType(IList<ResolveResult> expressions, out bool success) public IType GetBestCommonType(IList<ResolveResult> expressions, out bool success)
{ {
if (expressions == null) if (expressions == null)
throw new ArgumentNullException("expressions"); throw new ArgumentNullException(nameof(expressions));
if (expressions.Count == 1) { if (expressions.Count == 1) {
success = IsValidType(expressions[0].Type); success = IsValidType(expressions[0].Type);
return expressions[0].Type; return expressions[0].Type;
@ -861,9 +861,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
public IType FindTypeInBounds(IReadOnlyList<IType> lowerBounds, IReadOnlyList<IType> upperBounds) public IType FindTypeInBounds(IReadOnlyList<IType> lowerBounds, IReadOnlyList<IType> upperBounds)
{ {
if (lowerBounds == null) if (lowerBounds == null)
throw new ArgumentNullException("lowerBounds"); throw new ArgumentNullException(nameof(lowerBounds));
if (upperBounds == null) if (upperBounds == null)
throw new ArgumentNullException("upperBounds"); throw new ArgumentNullException(nameof(upperBounds));
var result = FindTypesInBounds(lowerBounds, upperBounds); var result = FindTypesInBounds(lowerBounds, upperBounds);

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

@ -38,10 +38,10 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public abstract class AstNode : AbstractAnnotatable, IFreezable, INode, ICloneable public abstract class AstNode : AbstractAnnotatable, IFreezable, INode, ICloneable
{ {
// the Root role must be available when creating the null nodes, so we can't put it in the Roles class // the Root role must be available when creating the null nodes, so we can't put it in the Roles class
internal static readonly Role<AstNode> RootRole = new Role<AstNode> ("Root"); internal static readonly Role<AstNode> RootRole = new Role<AstNode>("Root");
#region Null #region Null
public static readonly AstNode Null = new NullAstNode (); public static readonly AstNode Null = new NullAstNode();
sealed class NullAstNode : AstNode sealed class NullAstNode : AstNode
{ {
@ -57,22 +57,22 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
} }
} }
public override void AcceptVisitor (IAstVisitor visitor) public override void AcceptVisitor(IAstVisitor visitor)
{ {
visitor.VisitNullNode(this); visitor.VisitNullNode(this);
} }
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{ {
return visitor.VisitNullNode(this); return visitor.VisitNullNode(this);
} }
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitNullNode(this, data); 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; return other == null || other.IsNull;
} }
@ -80,16 +80,16 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
#endregion #endregion
#region PatternPlaceholder #region PatternPlaceholder
public static implicit operator AstNode (PatternMatching.Pattern pattern) public static implicit operator AstNode(PatternMatching.Pattern pattern)
{ {
return pattern != null ? new PatternPlaceholder (pattern) : null; return pattern != null ? new PatternPlaceholder(pattern) : null;
} }
sealed class PatternPlaceholder : AstNode, INode sealed class PatternPlaceholder : AstNode, INode
{ {
readonly PatternMatching.Pattern child; readonly PatternMatching.Pattern child;
public PatternPlaceholder (PatternMatching.Pattern child) public PatternPlaceholder(PatternMatching.Pattern child)
{ {
this.child = child; this.child = child;
} }
@ -98,29 +98,29 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
get { return NodeType.Pattern; } get { return NodeType.Pattern; }
} }
public override void AcceptVisitor (IAstVisitor visitor) public override void AcceptVisitor(IAstVisitor visitor)
{ {
visitor.VisitPatternPlaceholder (this, child); visitor.VisitPatternPlaceholder(this, child);
} }
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{ {
return visitor.VisitPatternPlaceholder (this, child); return visitor.VisitPatternPlaceholder(this, child);
} }
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{ {
return visitor.VisitPatternPlaceholder (this, child, data); return visitor.VisitPatternPlaceholder(this, child, data);
} }
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); return child.DoMatch(other, match);
} }
bool PatternMatching.INode.DoMatchCollection (Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{ {
return child.DoMatchCollection (role, pos, match, backtrackingInfo); return child.DoMatchCollection(role, pos, match, backtrackingInfo);
} }
} }
#endregion #endregion
@ -205,7 +205,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
} }
set { set {
if (value == null) if (value == null)
throw new ArgumentNullException("value"); throw new ArgumentNullException(nameof(value));
if (!value.IsValid(this)) if (!value.IsValid(this))
throw new ArgumentException("This node is not valid in the new role."); throw new ArgumentException("This node is not valid in the new role.");
ThrowIfFrozen(); ThrowIfFrozen();
@ -248,7 +248,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
get { get {
AstNode next; AstNode next;
for (AstNode cur = firstChild; cur != null; cur = next) { for (AstNode cur = firstChild; cur != null; cur = next) {
Debug.Assert (cur.parent == this); Debug.Assert(cur.parent == this);
// Remember next before yielding cur. // Remember next before yielding cur.
// This allows removing/replacing nodes while iterating through the list. // This allows removing/replacing nodes while iterating through the list.
next = cur.nextSibling; next = cur.nextSibling;
@ -293,12 +293,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
get { return GetDescendantsImpl(true); } get { return GetDescendantsImpl(true); }
} }
public IEnumerable<AstNode> DescendantNodes (Func<AstNode, bool> descendIntoChildren = null) public IEnumerable<AstNode> DescendantNodes(Func<AstNode, bool> descendIntoChildren = null)
{ {
return GetDescendantsImpl(false, descendIntoChildren); return GetDescendantsImpl(false, descendIntoChildren);
} }
public IEnumerable<AstNode> DescendantNodesAndSelf (Func<AstNode, bool> descendIntoChildren = null) public IEnumerable<AstNode> DescendantNodesAndSelf(Func<AstNode, bool> descendIntoChildren = null)
{ {
return GetDescendantsImpl(true, descendIntoChildren); return GetDescendantsImpl(true, descendIntoChildren);
} }
@ -335,7 +335,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public T GetChildByRole<T>(Role<T> role) where T : AstNode public T GetChildByRole<T>(Role<T> role) where T : AstNode
{ {
if (role == null) if (role == null)
throw new ArgumentNullException ("role"); throw new ArgumentNullException(nameof(role));
uint roleIndex = role.Index; uint roleIndex = role.Index;
for (var cur = firstChild; cur != null; cur = cur.nextSibling) { for (var cur = firstChild; cur != null; cur = cur.nextSibling) {
if ((cur.flags & roleIndexMask) == roleIndex) if ((cur.flags & roleIndexMask) == roleIndex)
@ -354,54 +354,54 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return Ancestors.FirstOrDefault(pred); return Ancestors.FirstOrDefault(pred);
} }
public AstNodeCollection<T> GetChildrenByRole<T> (Role<T> role) where T : AstNode public AstNodeCollection<T> GetChildrenByRole<T>(Role<T> role) where T : AstNode
{ {
return new AstNodeCollection<T> (this, role); 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); AstNode oldChild = GetChildByRole(role);
if (oldChild.IsNull) if (oldChild.IsNull)
AddChild (newChild, role); AddChild(newChild, role);
else else
oldChild.ReplaceWith (newChild); 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) if (role == null)
throw new ArgumentNullException ("role"); throw new ArgumentNullException(nameof(role));
if (child == null || child.IsNull) if (child == null || child.IsNull)
return; return;
ThrowIfFrozen(); ThrowIfFrozen();
if (child == this) if (child == this)
throw new ArgumentException ("Cannot add a node to itself as a child.", "child"); throw new ArgumentException("Cannot add a node to itself as a child.", nameof(child));
if (child.parent != null) if (child.parent != null)
throw new ArgumentException ("Node is already used in another tree.", "child"); throw new ArgumentException("Node is already used in another tree.", nameof(child));
if (child.IsFrozen) if (child.IsFrozen)
throw new ArgumentException ("Cannot add a frozen node.", "child"); throw new ArgumentException("Cannot add a frozen node.", nameof(child));
AddChildUnsafe (child, role); AddChildUnsafe(child, role);
} }
public void AddChildWithExistingRole (AstNode child) public void AddChildWithExistingRole(AstNode child)
{ {
if (child == null || child.IsNull) if (child == null || child.IsNull)
return; return;
ThrowIfFrozen(); ThrowIfFrozen();
if (child == this) if (child == this)
throw new ArgumentException ("Cannot add a node to itself as a child.", "child"); throw new ArgumentException("Cannot add a node to itself as a child.", nameof(child));
if (child.parent != null) if (child.parent != null)
throw new ArgumentException ("Node is already used in another tree.", "child"); throw new ArgumentException("Node is already used in another tree.", nameof(child));
if (child.IsFrozen) if (child.IsFrozen)
throw new ArgumentException ("Cannot add a frozen node.", "child"); throw new ArgumentException("Cannot add a frozen node.", nameof(child));
AddChildUnsafe (child, child.Role); AddChildUnsafe(child, child.Role);
} }
/// <summary> /// <summary>
/// Adds a child without performing any safety checks. /// Adds a child without performing any safety checks.
/// </summary> /// </summary>
internal void AddChildUnsafe (AstNode child, Role role) internal void AddChildUnsafe(AstNode child, Role role)
{ {
child.parent = this; child.parent = this;
child.SetRole(role); child.SetRole(role);
@ -414,12 +414,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
} }
} }
public void InsertChildBefore<T> (AstNode nextSibling, T child, Role<T> role) where T : AstNode public void InsertChildBefore<T>(AstNode nextSibling, T child, Role<T> role) where T : AstNode
{ {
if (role == null) if (role == null)
throw new ArgumentNullException ("role"); throw new ArgumentNullException(nameof(role));
if (nextSibling == null || nextSibling.IsNull) { if (nextSibling == null || nextSibling.IsNull) {
AddChild (child, role); AddChild(child, role);
return; return;
} }
@ -427,17 +427,17 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return; return;
ThrowIfFrozen(); ThrowIfFrozen();
if (child.parent != null) if (child.parent != null)
throw new ArgumentException ("Node is already used in another tree.", "child"); throw new ArgumentException("Node is already used in another tree.", nameof(child));
if (child.IsFrozen) if (child.IsFrozen)
throw new ArgumentException ("Cannot add a frozen node.", "child"); throw new ArgumentException("Cannot add a frozen node.", nameof(child));
if (nextSibling.parent != this) if (nextSibling.parent != this)
throw new ArgumentException ("NextSibling is not a child of this node.", "nextSibling"); throw new ArgumentException("NextSibling is not a child of this node.", nameof(nextSibling));
// No need to test for "Cannot add children to null nodes", // No need to test for "Cannot add children to null nodes",
// as there isn't any valid nextSibling in null nodes. // as there isn't any valid nextSibling in null nodes.
InsertChildBeforeUnsafe (nextSibling, child, role); InsertChildBeforeUnsafe(nextSibling, child, role);
} }
internal void InsertChildBeforeUnsafe (AstNode nextSibling, AstNode child, Role role) internal void InsertChildBeforeUnsafe(AstNode nextSibling, AstNode child, Role role)
{ {
child.parent = this; child.parent = this;
child.SetRole(role); child.SetRole(role);
@ -445,39 +445,39 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
child.prevSibling = nextSibling.prevSibling; child.prevSibling = nextSibling.prevSibling;
if (nextSibling.prevSibling != null) { if (nextSibling.prevSibling != null) {
Debug.Assert (nextSibling.prevSibling.nextSibling == nextSibling); Debug.Assert(nextSibling.prevSibling.nextSibling == nextSibling);
nextSibling.prevSibling.nextSibling = child; nextSibling.prevSibling.nextSibling = child;
} else { } else {
Debug.Assert (firstChild == nextSibling); Debug.Assert(firstChild == nextSibling);
firstChild = child; firstChild = child;
} }
nextSibling.prevSibling = child; nextSibling.prevSibling = child;
} }
public void InsertChildAfter<T> (AstNode prevSibling, T child, Role<T> role) where T : AstNode public void InsertChildAfter<T>(AstNode prevSibling, T child, Role<T> role) where T : AstNode
{ {
InsertChildBefore ((prevSibling == null || prevSibling.IsNull) ? firstChild : prevSibling.nextSibling, child, role); InsertChildBefore((prevSibling == null || prevSibling.IsNull) ? firstChild : prevSibling.nextSibling, child, role);
} }
/// <summary> /// <summary>
/// Removes this node from its parent. /// Removes this node from its parent.
/// </summary> /// </summary>
public void Remove () public void Remove()
{ {
if (parent != null) { if (parent != null) {
ThrowIfFrozen(); ThrowIfFrozen();
if (prevSibling != null) { if (prevSibling != null) {
Debug.Assert (prevSibling.nextSibling == this); Debug.Assert(prevSibling.nextSibling == this);
prevSibling.nextSibling = nextSibling; prevSibling.nextSibling = nextSibling;
} else { } else {
Debug.Assert (parent.firstChild == this); Debug.Assert(parent.firstChild == this);
parent.firstChild = nextSibling; parent.firstChild = nextSibling;
} }
if (nextSibling != null) { if (nextSibling != null) {
Debug.Assert (nextSibling.prevSibling == this); Debug.Assert(nextSibling.prevSibling == this);
nextSibling.prevSibling = prevSibling; nextSibling.prevSibling = prevSibling;
} else { } else {
Debug.Assert (parent.lastChild == this); Debug.Assert(parent.lastChild == this);
parent.lastChild = prevSibling; parent.lastChild = prevSibling;
} }
parent = null; parent = null;
@ -489,35 +489,35 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <summary> /// <summary>
/// Replaces this node with the new node. /// Replaces this node with the new node.
/// </summary> /// </summary>
public void ReplaceWith (AstNode newNode) public void ReplaceWith(AstNode newNode)
{ {
if (newNode == null || newNode.IsNull) { if (newNode == null || newNode.IsNull) {
Remove (); Remove();
return; return;
} }
if (newNode == this) if (newNode == this)
return; // nothing to do... return; // nothing to do...
if (parent == null) { if (parent == null) {
throw new InvalidOperationException (this.IsNull ? "Cannot replace the null nodes" : "Cannot replace the root node"); throw new InvalidOperationException(this.IsNull ? "Cannot replace the null nodes" : "Cannot replace the root node");
} }
ThrowIfFrozen(); ThrowIfFrozen();
// Because this method doesn't statically check the new node's type with the role, // Because this method doesn't statically check the new node's type with the role,
// we perform a runtime test: // we perform a runtime test:
if (!this.Role.IsValid (newNode)) { if (!this.Role.IsValid(newNode)) {
throw new ArgumentException (string.Format ("The new node '{0}' is not valid in the role {1}", newNode.GetType ().Name, this.Role.ToString ()), "newNode"); throw new ArgumentException(string.Format("The new node '{0}' is not valid in the role {1}", newNode.GetType().Name, this.Role.ToString()), nameof(newNode));
} }
if (newNode.parent != null) { if (newNode.parent != null) {
// newNode is used within this tree? // newNode is used within this tree?
if (newNode.Ancestors.Contains (this)) { if (newNode.Ancestors.Contains(this)) {
// e.g. "parenthesizedExpr.ReplaceWith(parenthesizedExpr.Expression);" // e.g. "parenthesizedExpr.ReplaceWith(parenthesizedExpr.Expression);"
// enable automatic removal // enable automatic removal
newNode.Remove (); newNode.Remove();
} else { } else {
throw new ArgumentException ("Node is already used in another tree.", "newNode"); throw new ArgumentException("Node is already used in another tree.", nameof(newNode));
} }
} }
if (newNode.IsFrozen) if (newNode.IsFrozen)
throw new ArgumentException ("Cannot add a frozen node.", "newNode"); throw new ArgumentException("Cannot add a frozen node.", nameof(newNode));
newNode.parent = parent; newNode.parent = parent;
newNode.SetRole(this.Role); newNode.SetRole(this.Role);
@ -525,17 +525,17 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
newNode.nextSibling = nextSibling; newNode.nextSibling = nextSibling;
if (prevSibling != null) { if (prevSibling != null) {
Debug.Assert (prevSibling.nextSibling == this); Debug.Assert(prevSibling.nextSibling == this);
prevSibling.nextSibling = newNode; prevSibling.nextSibling = newNode;
} else { } else {
Debug.Assert (parent.firstChild == this); Debug.Assert(parent.firstChild == this);
parent.firstChild = newNode; parent.firstChild = newNode;
} }
if (nextSibling != null) { if (nextSibling != null) {
Debug.Assert (nextSibling.prevSibling == this); Debug.Assert(nextSibling.prevSibling == this);
nextSibling.prevSibling = newNode; nextSibling.prevSibling = newNode;
} else { } else {
Debug.Assert (parent.lastChild == this); Debug.Assert(parent.lastChild == this);
parent.lastChild = newNode; parent.lastChild = newNode;
} }
parent = null; parent = null;
@ -543,31 +543,31 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
nextSibling = null; nextSibling = null;
} }
public AstNode ReplaceWith (Func<AstNode, AstNode> replaceFunction) public AstNode ReplaceWith(Func<AstNode, AstNode> replaceFunction)
{ {
if (replaceFunction == null) if (replaceFunction == null)
throw new ArgumentNullException ("replaceFunction"); throw new ArgumentNullException(nameof(replaceFunction));
if (parent == null) { if (parent == null) {
throw new InvalidOperationException (this.IsNull ? "Cannot replace the null nodes" : "Cannot replace the root node"); throw new InvalidOperationException(this.IsNull ? "Cannot replace the null nodes" : "Cannot replace the root node");
} }
AstNode oldParent = parent; AstNode oldParent = parent;
AstNode oldSuccessor = nextSibling; AstNode oldSuccessor = nextSibling;
Role oldRole = this.Role; Role oldRole = this.Role;
Remove (); Remove();
AstNode replacement = replaceFunction (this); AstNode replacement = replaceFunction(this);
if (oldSuccessor != null && oldSuccessor.parent != oldParent) if (oldSuccessor != null && oldSuccessor.parent != oldParent)
throw new InvalidOperationException ("replace function changed nextSibling of node being replaced?"); throw new InvalidOperationException("replace function changed nextSibling of node being replaced?");
if (!(replacement == null || replacement.IsNull)) { if (!(replacement == null || replacement.IsNull)) {
if (replacement.parent != null) if (replacement.parent != null)
throw new InvalidOperationException ("replace function must return the root of a tree"); throw new InvalidOperationException("replace function must return the root of a tree");
if (!oldRole.IsValid (replacement)) { if (!oldRole.IsValid(replacement)) {
throw new InvalidOperationException (string.Format ("The new node '{0}' is not valid in the role {1}", replacement.GetType ().Name, oldRole.ToString ())); throw new InvalidOperationException(string.Format("The new node '{0}' is not valid in the role {1}", replacement.GetType().Name, oldRole.ToString()));
} }
if (oldSuccessor != null) if (oldSuccessor != null)
oldParent.InsertChildBeforeUnsafe (oldSuccessor, replacement, oldRole); oldParent.InsertChildBeforeUnsafe(oldSuccessor, replacement, oldRole);
else else
oldParent.AddChildUnsafe (replacement, oldRole); oldParent.AddChildUnsafe(replacement, oldRole);
} }
return replacement; return replacement;
} }
@ -576,9 +576,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// Clones the whole subtree starting at this AST node. /// Clones the whole subtree starting at this AST node.
/// </summary> /// </summary>
/// <remarks>Annotations are copied over to the new nodes; and any annotations implementing ICloneable will be cloned.</remarks> /// <remarks>Annotations are copied over to the new nodes; and any annotations implementing ICloneable will be cloned.</remarks>
public AstNode Clone () public AstNode Clone()
{ {
AstNode copy = (AstNode)MemberwiseClone (); AstNode copy = (AstNode)MemberwiseClone();
// First, reset the shallow pointer copies // First, reset the shallow pointer copies
copy.parent = null; copy.parent = null;
copy.firstChild = null; copy.firstChild = null;
@ -589,7 +589,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
// Then perform a deep copy: // Then perform a deep copy:
for (AstNode cur = firstChild; cur != null; cur = cur.nextSibling) { for (AstNode cur = firstChild; cur != null; cur = cur.nextSibling) {
copy.AddChildUnsafe (cur.Clone (), cur.Role); copy.AddChildUnsafe(cur.Clone(), cur.Role);
} }
// Finally, clone the annotation, if necessary // Finally, clone the annotation, if necessary
@ -603,31 +603,31 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return Clone(); return Clone();
} }
public abstract void AcceptVisitor (IAstVisitor visitor); public abstract void AcceptVisitor(IAstVisitor visitor);
public abstract T AcceptVisitor<T> (IAstVisitor<T> visitor); public abstract T AcceptVisitor<T>(IAstVisitor<T> visitor);
public abstract S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data); public abstract S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data);
#region Pattern Matching #region Pattern Matching
protected static bool MatchString (string pattern, string text) protected static bool MatchString(string pattern, string text)
{ {
return PatternMatching.Pattern.MatchString(pattern, text); return PatternMatching.Pattern.MatchString(pattern, text);
} }
protected internal abstract bool DoMatch (AstNode other, PatternMatching.Match match); protected internal abstract bool DoMatch(AstNode other, PatternMatching.Match match);
bool PatternMatching.INode.DoMatch (PatternMatching.INode other, PatternMatching.Match match) bool PatternMatching.INode.DoMatch(PatternMatching.INode other, PatternMatching.Match match)
{ {
AstNode o = other as AstNode; AstNode o = other as AstNode;
// try matching if other is null, or if other is an AstNode // try matching if other is null, or if other is an AstNode
return (other == null || o != null) && DoMatch (o, match); return (other == null || o != null) && DoMatch(o, match);
} }
bool PatternMatching.INode.DoMatchCollection (Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
{ {
AstNode o = pos as AstNode; AstNode o = pos as AstNode;
return (pos == null || o != null) && DoMatch (o, match); return (pos == null || o != null) && DoMatch(o, match);
} }
PatternMatching.INode PatternMatching.INode.NextSibling { PatternMatching.INode PatternMatching.INode.NextSibling {
@ -640,12 +640,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
#endregion #endregion
public AstNode GetNextNode () public AstNode GetNextNode()
{ {
if (NextSibling != null) if (NextSibling != null)
return NextSibling; return NextSibling;
if (Parent != null) if (Parent != null)
return Parent.GetNextNode (); return Parent.GetNextNode();
return null; return null;
} }
@ -654,20 +654,20 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary> /// </summary>
/// <returns>The next node.</returns> /// <returns>The next node.</returns>
/// <param name="pred">The predicate.</param> /// <param name="pred">The predicate.</param>
public AstNode GetNextNode (Func<AstNode, bool> pred) public AstNode GetNextNode(Func<AstNode, bool> pred)
{ {
var next = GetNextNode(); var next = GetNextNode();
while (next != null && !pred (next)) while (next != null && !pred(next))
next = next.GetNextNode(); next = next.GetNextNode();
return next; return next;
} }
public AstNode GetPrevNode () public AstNode GetPrevNode()
{ {
if (PrevSibling != null) if (PrevSibling != null)
return PrevSibling; return PrevSibling;
if (Parent != null) if (Parent != null)
return Parent.GetPrevNode (); return Parent.GetPrevNode();
return null; return null;
} }
@ -676,21 +676,21 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary> /// </summary>
/// <returns>The next node.</returns> /// <returns>The next node.</returns>
/// <param name="pred">The predicate.</param> /// <param name="pred">The predicate.</param>
public AstNode GetPrevNode (Func<AstNode, bool> pred) public AstNode GetPrevNode(Func<AstNode, bool> pred)
{ {
var prev = GetPrevNode(); var prev = GetPrevNode();
while (prev != null && !pred (prev)) while (prev != null && !pred(prev))
prev = prev.GetPrevNode(); prev = prev.GetPrevNode();
return prev; return prev;
} }
// filters all non c# nodes (comments, white spaces or pre processor directives) // filters all non c# nodes (comments, white spaces or pre processor directives)
public AstNode GetCSharpNodeBefore (AstNode node) public AstNode GetCSharpNodeBefore(AstNode node)
{ {
var n = node.PrevSibling; var n = node.PrevSibling;
while (n != null) { while (n != null) {
if (n.Role != Roles.Comment) if (n.Role != Roles.Comment)
return n; return n;
n = n.GetPrevNode (); n = n.GetPrevNode();
} }
return null; return null;
} }
@ -700,10 +700,10 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary> /// </summary>
/// <returns>The next node.</returns> /// <returns>The next node.</returns>
/// <param name="pred">The predicate.</param> /// <param name="pred">The predicate.</param>
public AstNode GetNextSibling (Func<AstNode, bool> pred) public AstNode GetNextSibling(Func<AstNode, bool> pred)
{ {
var next = NextSibling; var next = NextSibling;
while (next != null && !pred (next)) while (next != null && !pred(next))
next = next.NextSibling; next = next.NextSibling;
return next; return next;
} }
@ -713,10 +713,10 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary> /// </summary>
/// <returns>The next node.</returns> /// <returns>The next node.</returns>
/// <param name="pred">The predicate.</param> /// <param name="pred">The predicate.</param>
public AstNode GetPrevSibling (Func<AstNode, bool> pred) public AstNode GetPrevSibling(Func<AstNode, bool> pred)
{ {
var prev = PrevSibling; var prev = PrevSibling;
while (prev != null && !pred (prev)) while (prev != null && !pred(prev))
prev = prev.PrevSibling; prev = prev.PrevSibling;
return prev; return prev;
} }
@ -727,9 +727,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// the current method declaration. /// the current method declaration.
/// (End exclusive) /// (End exclusive)
/// </summary> /// </summary>
public AstNode GetNodeAt (int line, int column, Predicate<AstNode> pred = null) public AstNode GetNodeAt(int line, int column, Predicate<AstNode> pred = null)
{ {
return GetNodeAt (new TextLocation (line, column), pred); return GetNodeAt(new TextLocation(line, column), pred);
} }
/// <summary> /// <summary>
@ -737,7 +737,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// the current method declaration. /// the current method declaration.
/// (End exclusive) /// (End exclusive)
/// </summary> /// </summary>
public AstNode GetNodeAt (TextLocation location, Predicate<AstNode> pred = null) public AstNode GetNodeAt(TextLocation location, Predicate<AstNode> pred = null)
{ {
AstNode result = null; AstNode result = null;
AstNode node = this; AstNode node = this;
@ -746,7 +746,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
while (child != null && child.StartLocation > location) while (child != null && child.StartLocation > location)
child = child.prevSibling; child = child.prevSibling;
if (child != null && location < child.EndLocation) { if (child != null && location < child.EndLocation) {
if (pred == null || pred (child)) if (pred == null || pred(child))
result = child; result = child;
node = child; node = child;
} else { } else {
@ -762,9 +762,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// the current method declaration. /// the current method declaration.
/// (End exclusive) /// (End exclusive)
/// </summary> /// </summary>
public T GetNodeAt<T> (int line, int column) where T : AstNode public T GetNodeAt<T>(int line, int column) where T : AstNode
{ {
return GetNodeAt<T> (new TextLocation (line, column)); return GetNodeAt<T>(new TextLocation(line, column));
} }
/// <summary> /// <summary>
@ -772,7 +772,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// the current method declaration. /// the current method declaration.
/// (End exclusive) /// (End exclusive)
/// </summary> /// </summary>
public T GetNodeAt<T> (TextLocation location) where T : AstNode public T GetNodeAt<T>(TextLocation location) where T : AstNode
{ {
T result = null; T result = null;
AstNode node = this; AstNode node = this;
@ -802,7 +802,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary> /// </summary>
public AstNode GetAdjacentNodeAt(int line, int column, Predicate<AstNode> pred = null) public AstNode GetAdjacentNodeAt(int line, int column, Predicate<AstNode> pred = null)
{ {
return GetAdjacentNodeAt (new TextLocation (line, column), pred); return GetAdjacentNodeAt(new TextLocation(line, column), pred);
} }
/// <summary> /// <summary>
@ -810,7 +810,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// the current method declaration. /// the current method declaration.
/// (End inclusive) /// (End inclusive)
/// </summary> /// </summary>
public AstNode GetAdjacentNodeAt (TextLocation location, Predicate<AstNode> pred = null) public AstNode GetAdjacentNodeAt(TextLocation location, Predicate<AstNode> pred = null)
{ {
AstNode result = null; AstNode result = null;
AstNode node = this; AstNode node = this;
@ -819,7 +819,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
while (child != null && child.StartLocation > location) while (child != null && child.StartLocation > location)
child = child.prevSibling; child = child.prevSibling;
if (child != null && location <= child.EndLocation) { if (child != null && location <= child.EndLocation) {
if (pred == null || pred (child)) if (pred == null || pred(child))
result = child; result = child;
node = child; node = child;
} else { } else {
@ -837,7 +837,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary> /// </summary>
public T GetAdjacentNodeAt<T>(int line, int column) where T : AstNode public T GetAdjacentNodeAt<T>(int line, int column) where T : AstNode
{ {
return GetAdjacentNodeAt<T> (new TextLocation (line, column)); return GetAdjacentNodeAt<T>(new TextLocation(line, column));
} }
/// <summary> /// <summary>
@ -845,7 +845,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// the current method declaration. /// the current method declaration.
/// (End inclusive) /// (End inclusive)
/// </summary> /// </summary>
public T GetAdjacentNodeAt<T> (TextLocation location) where T : AstNode public T GetAdjacentNodeAt<T>(TextLocation location) where T : AstNode
{ {
T result = null; T result = null;
AstNode node = this; AstNode node = this;
@ -882,15 +882,15 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <summary> /// <summary>
/// Returns the root nodes of all subtrees that are fully contained in the specified region. /// Returns the root nodes of all subtrees that are fully contained in the specified region.
/// </summary> /// </summary>
public IEnumerable<AstNode> GetNodesBetween (int startLine, int startColumn, int endLine, int endColumn) public IEnumerable<AstNode> GetNodesBetween(int startLine, int startColumn, int endLine, int endColumn)
{ {
return GetNodesBetween (new TextLocation (startLine, startColumn), new TextLocation (endLine, endColumn)); return GetNodesBetween(new TextLocation(startLine, startColumn), new TextLocation(endLine, endColumn));
} }
/// <summary> /// <summary>
/// Returns the root nodes of all subtrees that are fully contained between <paramref name="start"/> and <paramref name="end"/> (inclusive). /// Returns the root nodes of all subtrees that are fully contained between <paramref name="start"/> and <paramref name="end"/> (inclusive).
/// </summary> /// </summary>
public IEnumerable<AstNode> GetNodesBetween (TextLocation start, TextLocation end) public IEnumerable<AstNode> GetNodesBetween(TextLocation start, TextLocation end)
{ {
AstNode node = this; AstNode node = this;
while (node != null) { while (node != null) {
@ -920,13 +920,13 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <param name='formattingOptions'> /// <param name='formattingOptions'>
/// Formatting options. /// Formatting options.
/// </param> /// </param>
public virtual string ToString (CSharpFormattingOptions formattingOptions) public virtual string ToString(CSharpFormattingOptions formattingOptions)
{ {
if (IsNull) if (IsNull)
return ""; return "";
var w = new StringWriter (); var w = new StringWriter();
AcceptVisitor (new CSharpOutputVisitor (w, formattingOptions ?? FormattingOptionsFactory.CreateMono ())); AcceptVisitor(new CSharpOutputVisitor(w, formattingOptions ?? FormattingOptionsFactory.CreateMono()));
return w.ToString (); return w.ToString();
} }
public sealed override string ToString() public sealed override string ToString()
@ -940,9 +940,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <returns> /// <returns>
/// True, if the given coordinates are between StartLocation and EndLocation (exclusive); otherwise, false. /// True, if the given coordinates are between StartLocation and EndLocation (exclusive); otherwise, false.
/// </returns> /// </returns>
public bool Contains (int line, int column) public bool Contains(int line, int column)
{ {
return Contains (new TextLocation (line, column)); return Contains(new TextLocation(line, column));
} }
/// <summary> /// <summary>
@ -951,7 +951,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <returns> /// <returns>
/// True, if location is between StartLocation and EndLocation (exclusive); otherwise, false. /// True, if location is between StartLocation and EndLocation (exclusive); otherwise, false.
/// </returns> /// </returns>
public bool Contains (TextLocation location) public bool Contains(TextLocation location)
{ {
return this.StartLocation <= location && location < this.EndLocation; return this.StartLocation <= location && location < this.EndLocation;
} }
@ -962,9 +962,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <returns> /// <returns>
/// True, if the given coordinates are between StartLocation and EndLocation (inclusive); otherwise, false. /// True, if the given coordinates are between StartLocation and EndLocation (inclusive); otherwise, false.
/// </returns> /// </returns>
public bool IsInside (int line, int column) public bool IsInside(int line, int column)
{ {
return IsInside (new TextLocation (line, column)); return IsInside(new TextLocation(line, column));
} }
/// <summary> /// <summary>
@ -973,16 +973,16 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <returns> /// <returns>
/// True, if location is between StartLocation and EndLocation (inclusive); otherwise, false. /// True, if location is between StartLocation and EndLocation (inclusive); otherwise, false.
/// </returns> /// </returns>
public bool IsInside (TextLocation location) public bool IsInside(TextLocation location)
{ {
return this.StartLocation <= location && location <= this.EndLocation; return this.StartLocation <= location && location <= this.EndLocation;
} }
public override void AddAnnotation (object annotation) public override void AddAnnotation(object annotation)
{ {
if (this.IsNull) if (this.IsNull)
throw new InvalidOperationException ("Cannot add annotations to the null node"); throw new InvalidOperationException("Cannot add annotations to the null node");
base.AddAnnotation (annotation); base.AddAnnotation(annotation);
} }
internal string DebugToString() internal string DebugToString()

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

@ -37,9 +37,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public AstNodeCollection(AstNode node, Role<T> role) public AstNodeCollection(AstNode node, Role<T> role)
{ {
if (node == null) if (node == null)
throw new ArgumentNullException("node"); throw new ArgumentNullException(nameof(node));
if (role == null) if (role == null)
throw new ArgumentNullException("role"); throw new ArgumentNullException(nameof(role));
this.node = node; this.node = node;
this.role = role; this.role = role;
} }
@ -96,7 +96,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public void MoveTo(ICollection<T> targetCollection) public void MoveTo(ICollection<T> targetCollection)
{ {
if (targetCollection == null) if (targetCollection == null)
throw new ArgumentNullException("targetCollection"); throw new ArgumentNullException(nameof(targetCollection));
foreach (T node in this) { foreach (T node in this) {
node.Remove(); node.Remove();
targetCollection.Add(node); targetCollection.Add(node);

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

@ -123,7 +123,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public Expression ReplaceWith(Func<Expression, Expression> replaceFunction) public Expression ReplaceWith(Func<Expression, Expression> replaceFunction)
{ {
if (replaceFunction == null) if (replaceFunction == null)
throw new ArgumentNullException("replaceFunction"); throw new ArgumentNullException(nameof(replaceFunction));
return (Expression)base.ReplaceWith(node => replaceFunction((Expression)node)); return (Expression)base.ReplaceWith(node => replaceFunction((Expression)node));
} }
} }

2
ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/NamespaceDeclaration.cs

@ -64,7 +64,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
static AstType ConstructType(string[] arr, int i) static AstType ConstructType(string[] arr, int i)
{ {
if (i < 0 || i >= arr.Length) if (i < 0 || i >= arr.Length)
throw new ArgumentOutOfRangeException("i"); throw new ArgumentOutOfRangeException(nameof(i));
if (i == 0) if (i == 0)
return new SimpleType(arr[i]); return new SimpleType(arr[i]);
return new MemberType(ConstructType(arr, i - 1), arr[i]); return new MemberType(ConstructType(arr, i - 1), arr[i]);

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

@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <typeparam name='T'> /// <typeparam name='T'>
/// The type of the annotation. /// The type of the annotation.
/// </typeparam> /// </typeparam>
T Annotation<T> () where T: class; T Annotation<T>() where T : class;
/// <summary> /// <summary>
/// Gets the first annotation of the specified type. /// Gets the first annotation of the specified type.
@ -51,7 +51,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <param name='type'> /// <param name='type'>
/// The type of the annotation. /// The type of the annotation.
/// </param> /// </param>
object Annotation (Type type); object Annotation(Type type);
/// <summary> /// <summary>
/// Adds an annotation to this instance. /// Adds an annotation to this instance.
@ -59,7 +59,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <param name='annotation'> /// <param name='annotation'>
/// The annotation to add. /// The annotation to add.
/// </param> /// </param>
void AddAnnotation (object annotation); void AddAnnotation(object annotation);
/// <summary> /// <summary>
/// Removes all annotations of the specified type. /// Removes all annotations of the specified type.
@ -67,7 +67,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <typeparam name='T'> /// <typeparam name='T'>
/// The type of the annotations to remove. /// The type of the annotations to remove.
/// </typeparam> /// </typeparam>
void RemoveAnnotations<T> () where T : class; void RemoveAnnotations<T>() where T : class;
/// <summary> /// <summary>
/// Removes all annotations of the specified type. /// Removes all annotations of the specified type.
@ -111,86 +111,86 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
// There are two uses for this custom list type: // There are two uses for this custom list type:
// 1) it's private, and thus (unlike List<object>) cannot be confused with real annotations // 1) it's private, and thus (unlike List<object>) cannot be confused with real annotations
// 2) It allows us to simplify the cloning logic by making the list behave the same as a clonable annotation. // 2) It allows us to simplify the cloning logic by making the list behave the same as a clonable annotation.
public AnnotationList (int initialCapacity) : base(initialCapacity) public AnnotationList(int initialCapacity) : base(initialCapacity)
{ {
} }
public object Clone () public object Clone()
{ {
lock (this) { lock (this) {
AnnotationList copy = new AnnotationList (this.Count); AnnotationList copy = new AnnotationList(this.Count);
for (int i = 0; i < this.Count; i++) { for (int i = 0; i < this.Count; i++) {
object obj = this [i]; object obj = this[i];
ICloneable c = obj as ICloneable; ICloneable c = obj as ICloneable;
copy.Add (c != null ? c.Clone () : obj); copy.Add(c != null ? c.Clone() : obj);
} }
return copy; return copy;
} }
} }
} }
public virtual void AddAnnotation (object annotation) public virtual void AddAnnotation(object annotation)
{ {
if (annotation == null) if (annotation == null)
throw new ArgumentNullException ("annotation"); throw new ArgumentNullException(nameof(annotation));
retry: // Retry until successful retry: // Retry until successful
object oldAnnotation = Interlocked.CompareExchange (ref this.annotations, annotation, null); object oldAnnotation = Interlocked.CompareExchange(ref this.annotations, annotation, null);
if (oldAnnotation == null) { if (oldAnnotation == null) {
return; // we successfully added a single annotation return; // we successfully added a single annotation
} }
AnnotationList list = oldAnnotation as AnnotationList; AnnotationList list = oldAnnotation as AnnotationList;
if (list == null) { if (list == null) {
// we need to transform the old annotation into a list // we need to transform the old annotation into a list
list = new AnnotationList (4); list = new AnnotationList(4);
list.Add (oldAnnotation); list.Add(oldAnnotation);
list.Add (annotation); list.Add(annotation);
if (Interlocked.CompareExchange (ref this.annotations, list, oldAnnotation) != oldAnnotation) { if (Interlocked.CompareExchange(ref this.annotations, list, oldAnnotation) != oldAnnotation) {
// the transformation failed (some other thread wrote to this.annotations first) // the transformation failed (some other thread wrote to this.annotations first)
goto retry; goto retry;
} }
} else { } else {
// once there's a list, use simple locking // once there's a list, use simple locking
lock (list) { lock (list) {
list.Add (annotation); list.Add(annotation);
} }
} }
} }
public virtual void RemoveAnnotations<T> () where T : class public virtual void RemoveAnnotations<T>() where T : class
{ {
retry: // Retry until successful retry: // Retry until successful
object oldAnnotations = this.annotations; object oldAnnotations = this.annotations;
AnnotationList list = oldAnnotations as AnnotationList; AnnotationList list = oldAnnotations as AnnotationList;
if (list != null) { if (list != null) {
lock (list) lock (list)
list.RemoveAll (obj => obj is T); list.RemoveAll(obj => obj is T);
} else if (oldAnnotations is T) { } else if (oldAnnotations is T) {
if (Interlocked.CompareExchange (ref this.annotations, null, oldAnnotations) != oldAnnotations) { if (Interlocked.CompareExchange(ref this.annotations, null, oldAnnotations) != oldAnnotations) {
// Operation failed (some other thread wrote to this.annotations first) // Operation failed (some other thread wrote to this.annotations first)
goto retry; goto retry;
} }
} }
} }
public virtual void RemoveAnnotations (Type type) public virtual void RemoveAnnotations(Type type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException ("type"); throw new ArgumentNullException(nameof(type));
retry: // Retry until successful retry: // Retry until successful
object oldAnnotations = this.annotations; object oldAnnotations = this.annotations;
AnnotationList list = oldAnnotations as AnnotationList; AnnotationList list = oldAnnotations as AnnotationList;
if (list != null) { if (list != null) {
lock (list) lock (list)
list.RemoveAll(type.IsInstanceOfType); list.RemoveAll(type.IsInstanceOfType);
} else if (type.IsInstanceOfType (oldAnnotations)) { } else if (type.IsInstanceOfType(oldAnnotations)) {
if (Interlocked.CompareExchange (ref this.annotations, null, oldAnnotations) != oldAnnotations) { if (Interlocked.CompareExchange(ref this.annotations, null, oldAnnotations) != oldAnnotations) {
// Operation failed (some other thread wrote to this.annotations first) // Operation failed (some other thread wrote to this.annotations first)
goto retry; goto retry;
} }
} }
} }
public T Annotation<T> () where T: class public T Annotation<T>() where T : class
{ {
object annotations = this.annotations; object annotations = this.annotations;
AnnotationList list = annotations as AnnotationList; AnnotationList list = annotations as AnnotationList;
@ -208,21 +208,21 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
} }
} }
public object Annotation (Type type) public object Annotation(Type type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException ("type"); throw new ArgumentNullException(nameof(type));
object annotations = this.annotations; object annotations = this.annotations;
AnnotationList list = annotations as AnnotationList; AnnotationList list = annotations as AnnotationList;
if (list != null) { if (list != null) {
lock (list) { lock (list) {
foreach (object obj in list) { foreach (object obj in list) {
if (type.IsInstanceOfType (obj)) if (type.IsInstanceOfType(obj))
return obj; return obj;
} }
} }
} else { } else {
if (type.IsInstanceOfType (annotations)) if (type.IsInstanceOfType(annotations))
return annotations; return annotations;
} }
return null; return null;
@ -237,13 +237,13 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
AnnotationList list = annotations as AnnotationList; AnnotationList list = annotations as AnnotationList;
if (list != null) { if (list != null) {
lock (list) { lock (list) {
return list.ToArray (); return list.ToArray();
} }
} else { } else {
if (annotations != null) if (annotations != null)
return new object[] { annotations }; return new object[] { annotations };
else else
return Enumerable.Empty<object> (); return Enumerable.Empty<object>();
} }
} }
} }

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

@ -71,7 +71,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
get { return this.name; } get { return this.name; }
set { set {
if (value == null) if (value == null)
throw new ArgumentNullException("value"); throw new ArgumentNullException(nameof(value));
ThrowIfFrozen(); ThrowIfFrozen();
this.name = value; this.name = value;
} }
@ -119,7 +119,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
protected Identifier (string name, TextLocation location) protected Identifier (string name, TextLocation location)
{ {
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
this.Name = name; this.Name = name;
this.startLocation = location; this.startLocation = location;
} }

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

@ -35,7 +35,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public IdentifierExpressionBackreference(string referencedGroupName) public IdentifierExpressionBackreference(string referencedGroupName)
{ {
if (referencedGroupName == null) if (referencedGroupName == null)
throw new ArgumentNullException("referencedGroupName"); throw new ArgumentNullException(nameof(referencedGroupName));
this.referencedGroupName = referencedGroupName; this.referencedGroupName = referencedGroupName;
} }

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

@ -35,7 +35,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching
public Backreference(string referencedGroupName) public Backreference(string referencedGroupName)
{ {
if (referencedGroupName == null) if (referencedGroupName == null)
throw new ArgumentNullException("referencedGroupName"); throw new ArgumentNullException(nameof(referencedGroupName));
this.referencedGroupName = referencedGroupName; this.referencedGroupName = referencedGroupName;
} }

4
ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching/Choice.cs

@ -32,14 +32,14 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching
public void Add(string name, INode alternative) public void Add(string name, INode alternative)
{ {
if (alternative == null) if (alternative == null)
throw new ArgumentNullException("alternative"); throw new ArgumentNullException(nameof(alternative));
alternatives.Add(new NamedNode(name, alternative)); alternatives.Add(new NamedNode(name, alternative));
} }
public void Add(INode alternative) public void Add(INode alternative)
{ {
if (alternative == null) if (alternative == null)
throw new ArgumentNullException("alternative"); throw new ArgumentNullException(nameof(alternative));
alternatives.Add(alternative); alternatives.Add(alternative);
} }

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

@ -51,7 +51,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching
public static Match Match(this INode pattern, INode other) public static Match Match(this INode pattern, INode other)
{ {
if (pattern == null) if (pattern == null)
throw new ArgumentNullException("pattern"); throw new ArgumentNullException(nameof(pattern));
Match match = PatternMatching.Match.CreateNew(); Match match = PatternMatching.Match.CreateNew();
if (pattern.DoMatch(other, match)) if (pattern.DoMatch(other, match))
return match; return match;
@ -62,7 +62,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching
public static bool IsMatch(this INode pattern, INode other) public static bool IsMatch(this INode pattern, INode other)
{ {
if (pattern == null) if (pattern == null)
throw new ArgumentNullException("pattern"); throw new ArgumentNullException(nameof(pattern));
return pattern.DoMatch(other, PatternMatching.Match.CreateNew()); return pattern.DoMatch(other, PatternMatching.Match.CreateNew());
} }

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

@ -39,7 +39,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching
public NamedNode(string groupName, INode childNode) public NamedNode(string groupName, INode childNode)
{ {
if (childNode == null) if (childNode == null)
throw new ArgumentNullException("childNode"); throw new ArgumentNullException(nameof(childNode));
this.groupName = groupName; this.groupName = groupName;
this.childNode = childNode; this.childNode = childNode;
} }

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

@ -31,7 +31,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching
public OptionalNode(INode childNode) public OptionalNode(INode childNode)
{ {
if (childNode == null) if (childNode == null)
throw new ArgumentNullException("childNode"); throw new ArgumentNullException(nameof(childNode));
this.childNode = childNode; this.childNode = childNode;
} }

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

@ -38,7 +38,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching
public Repeat(INode childNode) public Repeat(INode childNode)
{ {
if (childNode == null) if (childNode == null)
throw new ArgumentNullException("childNode"); throw new ArgumentNullException(nameof(childNode));
this.childNode = childNode; this.childNode = childNode;
this.MinCount = 0; this.MinCount = 0;
this.MaxCount = int.MaxValue; this.MaxCount = int.MaxValue;

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

@ -89,16 +89,16 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public Role(string name) public Role(string name)
{ {
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
this.name = name; this.name = name;
} }
public Role(string name, T nullObject) public Role(string name, T nullObject)
{ {
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
if (nullObject == null) if (nullObject == null)
throw new ArgumentNullException ("nullObject"); throw new ArgumentNullException (nameof(nullObject));
this.nullObject = nullObject; this.nullObject = nullObject;
this.name = name; this.name = name;
} }

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

@ -116,7 +116,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public Statement ReplaceWith(Func<Statement, Statement> replaceFunction) public Statement ReplaceWith(Func<Statement, Statement> replaceFunction)
{ {
if (replaceFunction == null) if (replaceFunction == null)
throw new ArgumentNullException("replaceFunction"); throw new ArgumentNullException(nameof(replaceFunction));
return (Statement)base.ReplaceWith(node => replaceFunction((Statement)node)); return (Statement)base.ReplaceWith(node => replaceFunction((Statement)node));
} }

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

@ -47,7 +47,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public TypeSystemAstBuilder(CSharpResolver resolver) public TypeSystemAstBuilder(CSharpResolver resolver)
{ {
if (resolver == null) if (resolver == null)
throw new ArgumentNullException("resolver"); throw new ArgumentNullException(nameof(resolver));
this.resolver = resolver; this.resolver = resolver;
InitProperties(); InitProperties();
} }
@ -204,7 +204,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public AstType ConvertType(IType type) public AstType ConvertType(IType type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
AstType astType = ConvertTypeHelper(type); AstType astType = ConvertTypeHelper(type);
AddTypeAnnotation(astType, type); AddTypeAnnotation(astType, type);
return astType; return astType;
@ -579,7 +579,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public AstType ConvertAttributeType(IType type) public AstType ConvertAttributeType(IType type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
AstType astType = ConvertTypeHelper(type); AstType astType = ConvertTypeHelper(type);
string shortName = null; string shortName = null;
@ -663,7 +663,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public Expression ConvertConstantValue(ResolveResult rr) public Expression ConvertConstantValue(ResolveResult rr)
{ {
if (rr == null) if (rr == null)
throw new ArgumentNullException("rr"); throw new ArgumentNullException(nameof(rr));
bool isBoxing = false; bool isBoxing = false;
if (rr is ConversionResolveResult crr) { if (rr is ConversionResolveResult crr) {
// unpack ConversionResolveResult if necessary // unpack ConversionResolveResult if necessary
@ -734,7 +734,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public Expression ConvertConstantValue(IType expectedType, IType type, object constantValue) public Expression ConvertConstantValue(IType expectedType, IType type, object constantValue)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
if (constantValue == null) { if (constantValue == null) {
if (type.IsReferenceType == true || type.IsKnownType(KnownTypeCode.NullableOfT)) { if (type.IsReferenceType == true || type.IsKnownType(KnownTypeCode.NullableOfT)) {
var expr = new NullReferenceExpression(); var expr = new NullReferenceExpression();
@ -1248,7 +1248,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public ParameterDeclaration ConvertParameter(IParameter parameter) public ParameterDeclaration ConvertParameter(IParameter parameter)
{ {
if (parameter == null) if (parameter == null)
throw new ArgumentNullException("parameter"); throw new ArgumentNullException(nameof(parameter));
ParameterDeclaration decl = new ParameterDeclaration(); ParameterDeclaration decl = new ParameterDeclaration();
if (parameter.IsRef) { if (parameter.IsRef) {
decl.ParameterModifier = ParameterModifier.Ref; decl.ParameterModifier = ParameterModifier.Ref;
@ -1286,7 +1286,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public AstNode ConvertSymbol(ISymbol symbol) public AstNode ConvertSymbol(ISymbol symbol)
{ {
if (symbol == null) if (symbol == null)
throw new ArgumentNullException("symbol"); throw new ArgumentNullException(nameof(symbol));
switch (symbol.SymbolKind) { switch (symbol.SymbolKind) {
case SymbolKind.Namespace: case SymbolKind.Namespace:
return ConvertNamespaceDeclaration((INamespace)symbol); return ConvertNamespaceDeclaration((INamespace)symbol);
@ -1307,7 +1307,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public EntityDeclaration ConvertEntity(IEntity entity) public EntityDeclaration ConvertEntity(IEntity entity)
{ {
if (entity == null) if (entity == null)
throw new ArgumentNullException("entity"); throw new ArgumentNullException(nameof(entity));
switch (entity.SymbolKind) { switch (entity.SymbolKind) {
case SymbolKind.TypeDefinition: case SymbolKind.TypeDefinition:
return ConvertTypeDefinition((ITypeDefinition)entity); return ConvertTypeDefinition((ITypeDefinition)entity);

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

@ -38,7 +38,7 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem
public AliasNamespaceReference(string identifier) public AliasNamespaceReference(string identifier)
{ {
if (identifier == null) if (identifier == null)
throw new ArgumentNullException("identifier"); throw new ArgumentNullException(nameof(identifier));
this.identifier = identifier; this.identifier = identifier;
} }

4
ICSharpCode.Decompiler/CSharp/TypeSystem/MemberTypeOrNamespaceReference.cs

@ -40,9 +40,9 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem
public MemberTypeOrNamespaceReference(TypeOrNamespaceReference target, string identifier, IList<ITypeReference> typeArguments, NameLookupMode lookupMode = NameLookupMode.Type) public MemberTypeOrNamespaceReference(TypeOrNamespaceReference target, string identifier, IList<ITypeReference> typeArguments, NameLookupMode lookupMode = NameLookupMode.Type)
{ {
if (target == null) if (target == null)
throw new ArgumentNullException("target"); throw new ArgumentNullException(nameof(target));
if (identifier == null) if (identifier == null)
throw new ArgumentNullException("identifier"); throw new ArgumentNullException(nameof(identifier));
this.target = target; this.target = target;
this.identifier = identifier; this.identifier = identifier;
this.typeArguments = typeArguments ?? EmptyList<ITypeReference>.Instance; this.typeArguments = typeArguments ?? EmptyList<ITypeReference>.Instance;

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

@ -44,9 +44,9 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem
public ResolvedUsingScope(CSharpTypeResolveContext context, UsingScope usingScope) public ResolvedUsingScope(CSharpTypeResolveContext context, UsingScope usingScope)
{ {
if (context == null) if (context == null)
throw new ArgumentNullException("context"); throw new ArgumentNullException(nameof(context));
if (usingScope == null) if (usingScope == null)
throw new ArgumentNullException("usingScope"); throw new ArgumentNullException(nameof(usingScope));
this.parentContext = context; this.parentContext = context;
this.usingScope = usingScope; this.usingScope = usingScope;
if (usingScope.Parent != null) { if (usingScope.Parent != null) {

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

@ -39,7 +39,7 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem
public SimpleTypeOrNamespaceReference(string identifier, IList<ITypeReference> typeArguments, NameLookupMode lookupMode = NameLookupMode.Type) public SimpleTypeOrNamespaceReference(string identifier, IList<ITypeReference> typeArguments, NameLookupMode lookupMode = NameLookupMode.Type)
{ {
if (identifier == null) if (identifier == null)
throw new ArgumentNullException("identifier"); throw new ArgumentNullException(nameof(identifier));
this.identifier = identifier; this.identifier = identifier;
this.typeArguments = typeArguments ?? EmptyList<ITypeReference>.Instance; this.typeArguments = typeArguments ?? EmptyList<ITypeReference>.Instance;
this.lookupMode = lookupMode; this.lookupMode = lookupMode;

4
ICSharpCode.Decompiler/CSharp/TypeSystem/UsingScope.cs

@ -67,9 +67,9 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem
public UsingScope(UsingScope parent, string shortName) public UsingScope(UsingScope parent, string shortName)
{ {
if (parent == null) if (parent == null)
throw new ArgumentNullException("parent"); throw new ArgumentNullException(nameof(parent));
if (shortName == null) if (shortName == null)
throw new ArgumentNullException("shortName"); throw new ArgumentNullException(nameof(shortName));
this.parent = parent; this.parent = parent;
this.shortName = shortName; this.shortName = shortName;
} }

2
ICSharpCode.Decompiler/DebugInfo/DebugInfoGenerator.cs

@ -60,7 +60,7 @@ namespace ICSharpCode.Decompiler.DebugInfo
public DebugInfoGenerator(IDecompilerTypeSystem typeSystem) public DebugInfoGenerator(IDecompilerTypeSystem typeSystem)
{ {
this.typeSystem = typeSystem ?? throw new ArgumentNullException("typeSystem"); this.typeSystem = typeSystem ?? throw new ArgumentNullException(nameof(typeSystem));
this.currentImportScope = globalImportScope; this.currentImportScope = globalImportScope;
} }

2
ICSharpCode.Decompiler/DecompilerException.cs

@ -77,7 +77,7 @@ namespace ICSharpCode.Decompiler
string ToString(Exception exception) string ToString(Exception exception)
{ {
if (exception == null) if (exception == null)
throw new ArgumentNullException("exception"); throw new ArgumentNullException(nameof(exception));
string exceptionType = GetTypeName(exception); string exceptionType = GetTypeName(exception);
string stacktrace = GetStackTrace(exception); string stacktrace = GetStackTrace(exception);
while (exception.InnerException != null) { while (exception.InnerException != null) {

10
ICSharpCode.Decompiler/Documentation/IdStringProvider.cs

@ -94,7 +94,7 @@ namespace ICSharpCode.Decompiler.Documentation
public static string GetTypeName(IType type) public static string GetTypeName(IType type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
AppendTypeName(b, type, false); AppendTypeName(b, type, false);
return b.ToString(); return b.ToString();
@ -194,7 +194,7 @@ namespace ICSharpCode.Decompiler.Documentation
public static IMemberReference ParseMemberIdString(string memberIdString) public static IMemberReference ParseMemberIdString(string memberIdString)
{ {
if (memberIdString == null) if (memberIdString == null)
throw new ArgumentNullException("memberIdString"); throw new ArgumentNullException(nameof(memberIdString));
if (memberIdString.Length < 2 || memberIdString[1] != ':') if (memberIdString.Length < 2 || memberIdString[1] != ':')
throw new ReflectionNameParseException(0, "Missing type tag"); throw new ReflectionNameParseException(0, "Missing type tag");
char typeChar = memberIdString[0]; char typeChar = memberIdString[0];
@ -242,7 +242,7 @@ namespace ICSharpCode.Decompiler.Documentation
public static ITypeReference ParseTypeName(string typeName) public static ITypeReference ParseTypeName(string typeName)
{ {
if (typeName == null) if (typeName == null)
throw new ArgumentNullException("typeName"); throw new ArgumentNullException(nameof(typeName));
int pos = 0; int pos = 0;
if (typeName.StartsWith("T:", StringComparison.Ordinal)) if (typeName.StartsWith("T:", StringComparison.Ordinal))
pos = 2; pos = 2;
@ -378,9 +378,9 @@ namespace ICSharpCode.Decompiler.Documentation
public static IEntity FindEntity(string idString, ITypeResolveContext context) public static IEntity FindEntity(string idString, ITypeResolveContext context)
{ {
if (idString == null) if (idString == null)
throw new ArgumentNullException("idString"); throw new ArgumentNullException(nameof(idString));
if (context == null) if (context == null)
throw new ArgumentNullException("context"); throw new ArgumentNullException(nameof(context));
if (idString.StartsWith("T:", StringComparison.Ordinal)) { if (idString.StartsWith("T:", StringComparison.Ordinal)) {
return ParseTypeName(idString.Substring(2)).Resolve(context).GetDefinition(); return ParseTypeName(idString.Substring(2)).Resolve(context).GetDefinition();
} else { } else {

4
ICSharpCode.Decompiler/Documentation/XmlDocumentationElement.cs

@ -55,7 +55,7 @@ namespace ICSharpCode.Decompiler.Documentation
public XmlDocumentationElement(XElement element, IEntity declaringEntity, Func<string, IEntity> crefResolver) public XmlDocumentationElement(XElement element, IEntity declaringEntity, Func<string, IEntity> crefResolver)
{ {
if (element == null) if (element == null)
throw new ArgumentNullException("element"); throw new ArgumentNullException(nameof(element));
this.element = element; this.element = element;
this.declaringEntity = declaringEntity; this.declaringEntity = declaringEntity;
this.crefResolver = crefResolver; this.crefResolver = crefResolver;
@ -67,7 +67,7 @@ namespace ICSharpCode.Decompiler.Documentation
public XmlDocumentationElement(string text, IEntity declaringEntity) public XmlDocumentationElement(string text, IEntity declaringEntity)
{ {
if (text == null) if (text == null)
throw new ArgumentNullException("text"); throw new ArgumentNullException(nameof(text));
this.declaringEntity = declaringEntity; this.declaringEntity = declaringEntity;
this.textContent = text; this.textContent = text;
} }

6
ICSharpCode.Decompiler/Documentation/XmlDocumentationProvider.cs

@ -62,7 +62,7 @@ namespace ICSharpCode.Decompiler.Documentation
public XmlDocumentationCache(int size = 50) public XmlDocumentationCache(int size = 50)
{ {
if (size <= 0) if (size <= 0)
throw new ArgumentOutOfRangeException("size", size, "Value must be positive"); throw new ArgumentOutOfRangeException(nameof(size), size, "Value must be positive");
this.entries = new KeyValuePair<string, string>[size]; this.entries = new KeyValuePair<string, string>[size];
} }
@ -129,7 +129,7 @@ namespace ICSharpCode.Decompiler.Documentation
public XmlDocumentationProvider(string fileName) public XmlDocumentationProvider(string fileName)
{ {
if (fileName == null) if (fileName == null)
throw new ArgumentNullException("fileName"); throw new ArgumentNullException(nameof(fileName));
using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete)) { using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete)) {
using (XmlTextReader xmlReader = new XmlTextReader(fs)) { using (XmlTextReader xmlReader = new XmlTextReader(fs)) {
@ -328,7 +328,7 @@ namespace ICSharpCode.Decompiler.Documentation
public string GetDocumentation(string key) public string GetDocumentation(string key)
{ {
if (key == null) if (key == null)
throw new ArgumentNullException("key"); throw new ArgumentNullException(nameof(key));
return GetDocumentation(key, true); return GetDocumentation(key, true);
} }

2
ICSharpCode.Decompiler/IL/Instructions/CallIndirect.cs

@ -68,7 +68,7 @@ namespace ICSharpCode.Decompiler.IL
this.IsInstance = isInstance; this.IsInstance = isInstance;
this.HasExplicitThis = hasExplicitThis; this.HasExplicitThis = hasExplicitThis;
this.CallingConvention = callingConvention; this.CallingConvention = callingConvention;
this.ReturnType = returnType ?? throw new ArgumentNullException("returnType"); this.ReturnType = returnType ?? throw new ArgumentNullException(nameof(returnType));
this.ParameterTypes = parameterTypes.ToImmutableArray(); this.ParameterTypes = parameterTypes.ToImmutableArray();
this.Arguments = new InstructionCollection<ILInstruction>(this, 0); this.Arguments = new InstructionCollection<ILInstruction>(this, 0);
this.Arguments.AddRange(arguments); this.Arguments.AddRange(arguments);

2
ICSharpCode.Decompiler/IL/Instructions/CompoundAssignmentInstruction.cs

@ -313,7 +313,7 @@ namespace ICSharpCode.Decompiler.IL
: base(OpCode.DynamicCompoundAssign, CompoundEvalModeFromOperation(op), target, targetKind, value) : base(OpCode.DynamicCompoundAssign, CompoundEvalModeFromOperation(op), target, targetKind, value)
{ {
if (!IsExpressionTypeSupported(op)) if (!IsExpressionTypeSupported(op))
throw new ArgumentOutOfRangeException("op"); throw new ArgumentOutOfRangeException(nameof(op));
this.BinderFlags = binderFlags; this.BinderFlags = binderFlags;
this.Operation = op; this.Operation = op;
this.TargetArgumentInfo = targetArgumentInfo; this.TargetArgumentInfo = targetArgumentInfo;

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

@ -262,7 +262,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return NullableLiftingTransform.MatchGetValueOrDefault(inst, out ILInstruction arg) return NullableLiftingTransform.MatchGetValueOrDefault(inst, out ILInstruction arg)
&& arg.MatchLdLoc(testedVar); && arg.MatchLdLoc(testedVar);
default: default:
throw new ArgumentOutOfRangeException("mode"); throw new ArgumentOutOfRangeException(nameof(mode));
} }
} }
@ -306,7 +306,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
).WithILRange(varLoad); ).WithILRange(varLoad);
break; break;
default: default:
throw new ArgumentOutOfRangeException("mode"); throw new ArgumentOutOfRangeException(nameof(mode));
} }
oldParentChildren[oldChildIndex] = replacement; oldParentChildren[oldChildIndex] = replacement;
} }

2
ICSharpCode.Decompiler/Metadata/AssemblyReferences.cs

@ -116,7 +116,7 @@ namespace ICSharpCode.Decompiler.Metadata
public static AssemblyNameReference Parse(string fullName) public static AssemblyNameReference Parse(string fullName)
{ {
if (fullName == null) if (fullName == null)
throw new ArgumentNullException("fullName"); throw new ArgumentNullException(nameof(fullName));
if (fullName.Length == 0) if (fullName.Length == 0)
throw new ArgumentException("Name can not be empty"); throw new ArgumentException("Name can not be empty");

4
ICSharpCode.Decompiler/Semantics/ArrayAccessResolveResult.cs

@ -34,9 +34,9 @@ namespace ICSharpCode.Decompiler.Semantics
public ArrayAccessResolveResult(IType elementType, ResolveResult array, IList<ResolveResult> indexes) : base(elementType) public ArrayAccessResolveResult(IType elementType, ResolveResult array, IList<ResolveResult> indexes) : base(elementType)
{ {
if (array == null) if (array == null)
throw new ArgumentNullException("array"); throw new ArgumentNullException(nameof(array));
if (indexes == null) if (indexes == null)
throw new ArgumentNullException("indexes"); throw new ArgumentNullException(nameof(indexes));
this.Array = array; this.Array = array;
this.Indexes = indexes; this.Indexes = indexes;
} }

2
ICSharpCode.Decompiler/Semantics/ArrayCreateResolveResult.cs

@ -43,7 +43,7 @@ namespace ICSharpCode.Decompiler.Semantics
: base(arrayType) : base(arrayType)
{ {
if (sizeArguments == null) if (sizeArguments == null)
throw new ArgumentNullException("sizeArguments"); throw new ArgumentNullException(nameof(sizeArguments));
this.SizeArguments = sizeArguments; this.SizeArguments = sizeArguments;
this.InitializerElements = initializerElements; this.InitializerElements = initializerElements;
} }

6
ICSharpCode.Decompiler/Semantics/Conversion.cs

@ -89,21 +89,21 @@ namespace ICSharpCode.Decompiler.Semantics
public static Conversion UserDefinedConversion(IMethod operatorMethod, bool isImplicit, Conversion conversionBeforeUserDefinedOperator, Conversion conversionAfterUserDefinedOperator, bool isLifted = false, bool isAmbiguous = false) public static Conversion UserDefinedConversion(IMethod operatorMethod, bool isImplicit, Conversion conversionBeforeUserDefinedOperator, Conversion conversionAfterUserDefinedOperator, bool isLifted = false, bool isAmbiguous = false)
{ {
if (operatorMethod == null) if (operatorMethod == null)
throw new ArgumentNullException("operatorMethod"); throw new ArgumentNullException(nameof(operatorMethod));
return new UserDefinedConv(isImplicit, operatorMethod, conversionBeforeUserDefinedOperator, conversionAfterUserDefinedOperator, isLifted, isAmbiguous); return new UserDefinedConv(isImplicit, operatorMethod, conversionBeforeUserDefinedOperator, conversionAfterUserDefinedOperator, isLifted, isAmbiguous);
} }
public static Conversion MethodGroupConversion(IMethod chosenMethod, bool isVirtualMethodLookup, bool delegateCapturesFirstArgument) public static Conversion MethodGroupConversion(IMethod chosenMethod, bool isVirtualMethodLookup, bool delegateCapturesFirstArgument)
{ {
if (chosenMethod == null) if (chosenMethod == null)
throw new ArgumentNullException("chosenMethod"); throw new ArgumentNullException(nameof(chosenMethod));
return new MethodGroupConv(chosenMethod, isVirtualMethodLookup, delegateCapturesFirstArgument, isValid: true); return new MethodGroupConv(chosenMethod, isVirtualMethodLookup, delegateCapturesFirstArgument, isValid: true);
} }
public static Conversion InvalidMethodGroupConversion(IMethod chosenMethod, bool isVirtualMethodLookup, bool delegateCapturesFirstArgument) public static Conversion InvalidMethodGroupConversion(IMethod chosenMethod, bool isVirtualMethodLookup, bool delegateCapturesFirstArgument)
{ {
if (chosenMethod == null) if (chosenMethod == null)
throw new ArgumentNullException("chosenMethod"); throw new ArgumentNullException(nameof(chosenMethod));
return new MethodGroupConv(chosenMethod, isVirtualMethodLookup, delegateCapturesFirstArgument, isValid: false); return new MethodGroupConv(chosenMethod, isVirtualMethodLookup, delegateCapturesFirstArgument, isValid: false);
} }

4
ICSharpCode.Decompiler/Semantics/ConversionResolveResult.cs

@ -42,9 +42,9 @@ namespace ICSharpCode.Decompiler.Semantics
: base(targetType) : base(targetType)
{ {
if (input == null) if (input == null)
throw new ArgumentNullException("input"); throw new ArgumentNullException(nameof(input));
if (conversion == null) if (conversion == null)
throw new ArgumentNullException("conversion"); throw new ArgumentNullException(nameof(conversion));
this.Input = input; this.Input = input;
this.Conversion = conversion; this.Conversion = conversion;
} }

8
ICSharpCode.Decompiler/Semantics/ForEachResolveResult.cs

@ -64,13 +64,13 @@ namespace ICSharpCode.Decompiler.Semantics
: base(voidType) : base(voidType)
{ {
if (getEnumeratorCall == null) if (getEnumeratorCall == null)
throw new ArgumentNullException("getEnumeratorCall"); throw new ArgumentNullException(nameof(getEnumeratorCall));
if (collectionType == null) if (collectionType == null)
throw new ArgumentNullException("collectionType"); throw new ArgumentNullException(nameof(collectionType));
if (enumeratorType == null) if (enumeratorType == null)
throw new ArgumentNullException("enumeratorType"); throw new ArgumentNullException(nameof(enumeratorType));
if (elementType == null) if (elementType == null)
throw new ArgumentNullException("elementType"); throw new ArgumentNullException(nameof(elementType));
this.GetEnumeratorCall = getEnumeratorCall; this.GetEnumeratorCall = getEnumeratorCall;
this.CollectionType = collectionType; this.CollectionType = collectionType;
this.EnumeratorType = enumeratorType; this.EnumeratorType = enumeratorType;

2
ICSharpCode.Decompiler/Semantics/LocalResolveResult.cs

@ -38,7 +38,7 @@ namespace ICSharpCode.Decompiler.Semantics
static IType UnpackTypeIfByRefParameter(IVariable variable) static IType UnpackTypeIfByRefParameter(IVariable variable)
{ {
if (variable == null) if (variable == null)
throw new ArgumentNullException("variable"); throw new ArgumentNullException(nameof(variable));
IType type = variable.Type; IType type = variable.Type;
if (type.Kind == TypeKind.ByReference) { if (type.Kind == TypeKind.ByReference) {
IParameter p = variable as IParameter; IParameter p = variable as IParameter;

8
ICSharpCode.Decompiler/Semantics/NamedArgumentResolveResult.cs

@ -53,9 +53,9 @@ namespace ICSharpCode.Decompiler.Semantics
: base(argument.Type) : base(argument.Type)
{ {
if (parameter == null) if (parameter == null)
throw new ArgumentNullException("parameter"); throw new ArgumentNullException(nameof(parameter));
if (argument == null) if (argument == null)
throw new ArgumentNullException("argument"); throw new ArgumentNullException(nameof(argument));
this.Member = member; this.Member = member;
this.Parameter = parameter; this.Parameter = parameter;
this.ParameterName = parameter.Name; this.ParameterName = parameter.Name;
@ -66,9 +66,9 @@ namespace ICSharpCode.Decompiler.Semantics
: base(argument.Type) : base(argument.Type)
{ {
if (parameterName == null) if (parameterName == null)
throw new ArgumentNullException("parameterName"); throw new ArgumentNullException(nameof(parameterName));
if (argument == null) if (argument == null)
throw new ArgumentNullException("argument"); throw new ArgumentNullException(nameof(argument));
this.ParameterName = parameterName; this.ParameterName = parameterName;
this.Argument = argument; this.Argument = argument;
} }

4
ICSharpCode.Decompiler/Semantics/OperatorResolveResult.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.Decompiler.Semantics
: base(resultType) : base(resultType)
{ {
if (operands == null) if (operands == null)
throw new ArgumentNullException("operands"); throw new ArgumentNullException(nameof(operands));
this.operatorType = operatorType; this.operatorType = operatorType;
this.operands = operands; this.operands = operands;
} }
@ -46,7 +46,7 @@ namespace ICSharpCode.Decompiler.Semantics
: base(resultType) : base(resultType)
{ {
if (operands == null) if (operands == null)
throw new ArgumentNullException("operands"); throw new ArgumentNullException(nameof(operands));
this.operatorType = operatorType; this.operatorType = operatorType;
this.userDefinedOperatorMethod = userDefinedOperatorMethod; this.userDefinedOperatorMethod = userDefinedOperatorMethod;
this.isLiftedOperator = isLiftedOperator; this.isLiftedOperator = isLiftedOperator;

2
ICSharpCode.Decompiler/Semantics/ResolveResult.cs

@ -33,7 +33,7 @@ namespace ICSharpCode.Decompiler.Semantics
public ResolveResult(IType type) public ResolveResult(IType type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
this.type = type; this.type = type;
} }

2
ICSharpCode.Decompiler/Semantics/SizeOfResolveResult.cs

@ -33,7 +33,7 @@ namespace ICSharpCode.Decompiler.Semantics
: base(int32) : base(int32)
{ {
if (referencedType == null) if (referencedType == null)
throw new ArgumentNullException("referencedType"); throw new ArgumentNullException(nameof(referencedType));
this.referencedType = referencedType; this.referencedType = referencedType;
this.constantValue = constantValue; this.constantValue = constantValue;
} }

4
ICSharpCode.Decompiler/Semantics/TypeIsResolveResult.cs

@ -37,9 +37,9 @@ namespace ICSharpCode.Decompiler.Semantics
: base(booleanType) : base(booleanType)
{ {
if (input == null) if (input == null)
throw new ArgumentNullException("input"); throw new ArgumentNullException(nameof(input));
if (targetType == null) if (targetType == null)
throw new ArgumentNullException("targetType"); throw new ArgumentNullException(nameof(targetType));
this.Input = input; this.Input = input;
this.TargetType = targetType; this.TargetType = targetType;
} }

2
ICSharpCode.Decompiler/Semantics/TypeOfResolveResult.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.Decompiler.Semantics
: base(systemType) : base(systemType)
{ {
if (referencedType == null) if (referencedType == null)
throw new ArgumentNullException("referencedType"); throw new ArgumentNullException(nameof(referencedType));
this.referencedType = referencedType; this.referencedType = referencedType;
} }

2
ICSharpCode.Decompiler/Semantics/UnknownMemberResolveResult.cs

@ -38,7 +38,7 @@ namespace ICSharpCode.Decompiler.Semantics
: base(SpecialType.UnknownType) : base(SpecialType.UnknownType)
{ {
if (targetType == null) if (targetType == null)
throw new ArgumentNullException("targetType"); throw new ArgumentNullException(nameof(targetType));
this.targetType = targetType; this.targetType = targetType;
this.memberName = memberName; this.memberName = memberName;
this.typeArguments = new ReadOnlyCollection<IType>(typeArguments.ToArray()); this.typeArguments = new ReadOnlyCollection<IType>(typeArguments.ToArray());

8
ICSharpCode.Decompiler/TypeSystem/ArrayType.cs

@ -35,9 +35,9 @@ namespace ICSharpCode.Decompiler.TypeSystem
public ArrayType(ICompilation compilation, IType elementType, int dimensions = 1, Nullability nullability = Nullability.Oblivious) : base(elementType) public ArrayType(ICompilation compilation, IType elementType, int dimensions = 1, Nullability nullability = Nullability.Oblivious) : base(elementType)
{ {
if (compilation == null) if (compilation == null)
throw new ArgumentNullException("compilation"); throw new ArgumentNullException(nameof(compilation));
if (dimensions <= 0) if (dimensions <= 0)
throw new ArgumentOutOfRangeException("dimensions", dimensions, "dimensions must be positive"); throw new ArgumentOutOfRangeException(nameof(dimensions), dimensions, "dimensions must be positive");
this.compilation = compilation; this.compilation = compilation;
this.dimensions = dimensions; this.dimensions = dimensions;
this.nullability = nullability; this.nullability = nullability;
@ -181,9 +181,9 @@ namespace ICSharpCode.Decompiler.TypeSystem
public ArrayTypeReference(ITypeReference elementType, int dimensions = 1) public ArrayTypeReference(ITypeReference elementType, int dimensions = 1)
{ {
if (elementType == null) if (elementType == null)
throw new ArgumentNullException("elementType"); throw new ArgumentNullException(nameof(elementType));
if (dimensions <= 0) if (dimensions <= 0)
throw new ArgumentOutOfRangeException("dimensions", dimensions, "dimensions must be positive"); throw new ArgumentOutOfRangeException(nameof(dimensions), dimensions, "dimensions must be positive");
this.elementType = elementType; this.elementType = elementType;
this.dimensions = dimensions; this.dimensions = dimensions;
} }

2
ICSharpCode.Decompiler/TypeSystem/ByReferenceType.cs

@ -77,7 +77,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public ByReferenceTypeReference(ITypeReference elementType) public ByReferenceTypeReference(ITypeReference elementType)
{ {
if (elementType == null) if (elementType == null)
throw new ArgumentNullException("elementType"); throw new ArgumentNullException(nameof(elementType));
this.elementType = elementType; this.elementType = elementType;
} }

4
ICSharpCode.Decompiler/TypeSystem/FullTypeName.cs

@ -45,7 +45,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public NestedTypeName(string name, int additionalTypeParameterCount) public NestedTypeName(string name, int additionalTypeParameterCount)
{ {
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
this.Name = name; this.Name = name;
this.AdditionalTypeParameterCount = additionalTypeParameterCount; this.AdditionalTypeParameterCount = additionalTypeParameterCount;
} }
@ -217,7 +217,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public FullTypeName NestedType(string name, int additionalTypeParameterCount) public FullTypeName NestedType(string name, int additionalTypeParameterCount)
{ {
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
var newNestedType = new NestedTypeName(name, additionalTypeParameterCount); var newNestedType = new NestedTypeName(name, additionalTypeParameterCount);
if (nestedTypes == null) if (nestedTypes == null)
return new FullTypeName(topLevelType, new[] { newNestedType }); return new FullTypeName(topLevelType, new[] { newNestedType });

4
ICSharpCode.Decompiler/TypeSystem/Implementation/AbstractTypeParameter.cs

@ -36,7 +36,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
protected AbstractTypeParameter(IEntity owner, int index, string name, VarianceModifier variance) protected AbstractTypeParameter(IEntity owner, int index, string name, VarianceModifier variance)
{ {
if (owner == null) if (owner == null)
throw new ArgumentNullException("owner"); throw new ArgumentNullException(nameof(owner));
this.owner = owner; this.owner = owner;
this.compilation = owner.Compilation; this.compilation = owner.Compilation;
this.ownerType = owner.SymbolKind; this.ownerType = owner.SymbolKind;
@ -48,7 +48,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
protected AbstractTypeParameter(ICompilation compilation, SymbolKind ownerType, int index, string name, VarianceModifier variance) protected AbstractTypeParameter(ICompilation compilation, SymbolKind ownerType, int index, string name, VarianceModifier variance)
{ {
if (compilation == null) if (compilation == null)
throw new ArgumentNullException("compilation"); throw new ArgumentNullException(nameof(compilation));
this.compilation = compilation; this.compilation = compilation;
this.ownerType = ownerType; this.ownerType = ownerType;
this.index = index; this.index = index;

4
ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultAttribute.cs

@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
ImmutableArray<CustomAttributeNamedArgument<IType>> namedArguments) ImmutableArray<CustomAttributeNamedArgument<IType>> namedArguments)
{ {
if (attributeType == null) if (attributeType == null)
throw new ArgumentNullException("attributeType"); throw new ArgumentNullException(nameof(attributeType));
this.attributeType = attributeType; this.attributeType = attributeType;
this.FixedArguments = fixedArguments; this.FixedArguments = fixedArguments;
this.NamedArguments = namedArguments; this.NamedArguments = namedArguments;
@ -53,7 +53,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
ImmutableArray<CustomAttributeNamedArgument<IType>> namedArguments) ImmutableArray<CustomAttributeNamedArgument<IType>> namedArguments)
{ {
if (constructor == null) if (constructor == null)
throw new ArgumentNullException("constructor"); throw new ArgumentNullException(nameof(constructor));
this.constructor = constructor; this.constructor = constructor;
this.attributeType = constructor.DeclaringType ?? SpecialType.UnknownType; this.attributeType = constructor.DeclaringType ?? SpecialType.UnknownType;
this.FixedArguments = fixedArguments; this.FixedArguments = fixedArguments;

8
ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultParameter.cs

@ -39,9 +39,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public DefaultParameter(IType type, string name) public DefaultParameter(IType type, string name)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
this.type = type; this.type = type;
this.name = name; this.name = name;
this.attributes = EmptyList<IAttribute>.Instance; this.attributes = EmptyList<IAttribute>.Instance;
@ -51,9 +51,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
ReferenceKind referenceKind = ReferenceKind.None, bool isParams = false, bool isOptional = false, object defaultValue = null) ReferenceKind referenceKind = ReferenceKind.None, bool isParams = false, bool isOptional = false, object defaultValue = null)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
this.type = type; this.type = type;
this.name = name; this.name = name;
this.owner = owner; this.owner = owner;

4
ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultVariable.cs

@ -33,9 +33,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public DefaultVariable(IType type, string name) public DefaultVariable(IType type, string name)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
this.type = type; this.type = type;
this.name = name; this.name = name;
} }

2
ICSharpCode.Decompiler/TypeSystem/Implementation/GetClassTypeReference.cs

@ -98,7 +98,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public IType Resolve(ITypeResolveContext context) public IType Resolve(ITypeResolveContext context)
{ {
if (context == null) if (context == null)
throw new ArgumentNullException("context"); throw new ArgumentNullException(nameof(context));
IType type = null; IType type = null;
if (module == null) { if (module == null) {

8
ICSharpCode.Decompiler/TypeSystem/Implementation/MergedNamespace.cs

@ -44,9 +44,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public MergedNamespace(ICompilation compilation, INamespace[] namespaces, string externAlias = null) public MergedNamespace(ICompilation compilation, INamespace[] namespaces, string externAlias = null)
{ {
if (compilation == null) if (compilation == null)
throw new ArgumentNullException("compilation"); throw new ArgumentNullException(nameof(compilation));
if (namespaces == null) if (namespaces == null)
throw new ArgumentNullException("namespaces"); throw new ArgumentNullException(nameof(namespaces));
this.compilation = compilation; this.compilation = compilation;
this.namespaces = namespaces; this.namespaces = namespaces;
this.externAlias = externAlias; this.externAlias = externAlias;
@ -60,9 +60,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public MergedNamespace(INamespace parentNamespace, INamespace[] namespaces) public MergedNamespace(INamespace parentNamespace, INamespace[] namespaces)
{ {
if (parentNamespace == null) if (parentNamespace == null)
throw new ArgumentNullException("parentNamespace"); throw new ArgumentNullException(nameof(parentNamespace));
if (namespaces == null) if (namespaces == null)
throw new ArgumentNullException("namespaces"); throw new ArgumentNullException(nameof(namespaces));
this.parentNamespace = parentNamespace; this.parentNamespace = parentNamespace;
this.namespaces = namespaces; this.namespaces = namespaces;
this.compilation = parentNamespace.Compilation; this.compilation = parentNamespace.Compilation;

4
ICSharpCode.Decompiler/TypeSystem/Implementation/NestedTypeReference.cs

@ -44,9 +44,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public NestedTypeReference(ITypeReference declaringTypeRef, string name, int additionalTypeParameterCount, bool? isReferenceType = null) public NestedTypeReference(ITypeReference declaringTypeRef, string name, int additionalTypeParameterCount, bool? isReferenceType = null)
{ {
if (declaringTypeRef == null) if (declaringTypeRef == null)
throw new ArgumentNullException("declaringTypeRef"); throw new ArgumentNullException(nameof(declaringTypeRef));
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
this.declaringTypeRef = declaringTypeRef; this.declaringTypeRef = declaringTypeRef;
this.name = name; this.name = name;
this.additionalTypeParameterCount = additionalTypeParameterCount; this.additionalTypeParameterCount = additionalTypeParameterCount;

4
ICSharpCode.Decompiler/TypeSystem/Implementation/SimpleCompilation.cs

@ -52,9 +52,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
protected void Init(IModuleReference mainAssembly, IEnumerable<IModuleReference> assemblyReferences) protected void Init(IModuleReference mainAssembly, IEnumerable<IModuleReference> assemblyReferences)
{ {
if (mainAssembly == null) if (mainAssembly == null)
throw new ArgumentNullException("mainAssembly"); throw new ArgumentNullException(nameof(mainAssembly));
if (assemblyReferences == null) if (assemblyReferences == null)
throw new ArgumentNullException("assemblyReferences"); throw new ArgumentNullException(nameof(assemblyReferences));
var context = new SimpleTypeResolveContext(this); var context = new SimpleTypeResolveContext(this);
this.mainModule = mainAssembly.Resolve(context); this.mainModule = mainAssembly.Resolve(context);
List<IModule> assemblies = new List<IModule>(); List<IModule> assemblies = new List<IModule>();

2
ICSharpCode.Decompiler/TypeSystem/Implementation/SpecializedMember.cs

@ -40,7 +40,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
protected SpecializedMember(IMember memberDefinition) protected SpecializedMember(IMember memberDefinition)
{ {
if (memberDefinition == null) if (memberDefinition == null)
throw new ArgumentNullException("memberDefinition"); throw new ArgumentNullException(nameof(memberDefinition));
if (memberDefinition is SpecializedMember) if (memberDefinition is SpecializedMember)
throw new ArgumentException("Member definition cannot be specialized. Please use IMember.Specialize() instead of directly constructing SpecializedMember instances."); throw new ArgumentException("Member definition cannot be specialized. Please use IMember.Specialize() instead of directly constructing SpecializedMember instances.");

2
ICSharpCode.Decompiler/TypeSystem/Implementation/SpecializedMethod.cs

@ -54,7 +54,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
: base(methodDefinition) : base(methodDefinition)
{ {
if (substitution == null) if (substitution == null)
throw new ArgumentNullException("substitution"); throw new ArgumentNullException(nameof(substitution));
this.methodDefinition = methodDefinition; this.methodDefinition = methodDefinition;
this.isParameterized = substitution.MethodTypeArguments != null; this.isParameterized = substitution.MethodTypeArguments != null;
if (methodDefinition.TypeParameters.Count > 0) { if (methodDefinition.TypeParameters.Count > 0) {

2
ICSharpCode.Decompiler/TypeSystem/Implementation/TypeWithElementType.cs

@ -27,7 +27,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
protected TypeWithElementType(IType elementType) protected TypeWithElementType(IType elementType)
{ {
if (elementType == null) if (elementType == null)
throw new ArgumentNullException("elementType"); throw new ArgumentNullException(nameof(elementType));
this.elementType = elementType; this.elementType = elementType;
} }

4
ICSharpCode.Decompiler/TypeSystem/Implementation/UnknownType.cs

@ -41,7 +41,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public UnknownType(string namespaceName, string name, int typeParameterCount = 0, bool? isReferenceType = null) public UnknownType(string namespaceName, string name, int typeParameterCount = 0, bool? isReferenceType = null)
{ {
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
this.namespaceKnown = namespaceName != null; this.namespaceKnown = namespaceName != null;
this.fullTypeName = new TopLevelTypeName(namespaceName ?? string.Empty, name, typeParameterCount); this.fullTypeName = new TopLevelTypeName(namespaceName ?? string.Empty, name, typeParameterCount);
this.isReferenceType = isReferenceType; this.isReferenceType = isReferenceType;
@ -71,7 +71,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
IType ITypeReference.Resolve(ITypeResolveContext context) IType ITypeReference.Resolve(ITypeResolveContext context)
{ {
if (context == null) if (context == null)
throw new ArgumentNullException("context"); throw new ArgumentNullException(nameof(context));
return this; return this;
} }

6
ICSharpCode.Decompiler/TypeSystem/InheritanceHelper.cs

@ -48,7 +48,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static IEnumerable<IMember> GetBaseMembers(IMember member, bool includeImplementedInterfaces) public static IEnumerable<IMember> GetBaseMembers(IMember member, bool includeImplementedInterfaces)
{ {
if (member == null) if (member == null)
throw new ArgumentNullException("member"); throw new ArgumentNullException(nameof(member));
if (includeImplementedInterfaces) { if (includeImplementedInterfaces) {
if (member.IsExplicitInterfaceImplementation && member.ExplicitlyImplementedInterfaceMembers.Count() == 1) { if (member.IsExplicitInterfaceImplementation && member.ExplicitlyImplementedInterfaceMembers.Count() == 1) {
@ -100,9 +100,9 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static IMember GetDerivedMember(IMember baseMember, ITypeDefinition derivedType) public static IMember GetDerivedMember(IMember baseMember, ITypeDefinition derivedType)
{ {
if (baseMember == null) if (baseMember == null)
throw new ArgumentNullException("baseMember"); throw new ArgumentNullException(nameof(baseMember));
if (derivedType == null) if (derivedType == null)
throw new ArgumentNullException("derivedType"); throw new ArgumentNullException(nameof(derivedType));
if (baseMember.Compilation != derivedType.Compilation) if (baseMember.Compilation != derivedType.Compilation)
throw new ArgumentException("baseMember and derivedType must be from the same compilation"); throw new ArgumentException("baseMember and derivedType must be from the same compilation");

10
ICSharpCode.Decompiler/TypeSystem/NullableType.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static bool IsNullable(IType type) public static bool IsNullable(IType type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
ParameterizedType pt = type.SkipModifiers() as ParameterizedType; ParameterizedType pt = type.SkipModifiers() as ParameterizedType;
return pt != null && pt.TypeParameterCount == 1 && pt.GenericType.IsKnownType(KnownTypeCode.NullableOfT); return pt != null && pt.TypeParameterCount == 1 && pt.GenericType.IsKnownType(KnownTypeCode.NullableOfT);
} }
@ -48,7 +48,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static IType GetUnderlyingType(IType type) public static IType GetUnderlyingType(IType type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
ParameterizedType pt = type.SkipModifiers() as ParameterizedType; ParameterizedType pt = type.SkipModifiers() as ParameterizedType;
if (pt != null && pt.TypeParameterCount == 1 && pt.GenericType.IsKnownType(KnownTypeCode.NullableOfT)) if (pt != null && pt.TypeParameterCount == 1 && pt.GenericType.IsKnownType(KnownTypeCode.NullableOfT))
return pt.GetTypeArgument(0); return pt.GetTypeArgument(0);
@ -62,9 +62,9 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static IType Create(ICompilation compilation, IType elementType) public static IType Create(ICompilation compilation, IType elementType)
{ {
if (compilation == null) if (compilation == null)
throw new ArgumentNullException("compilation"); throw new ArgumentNullException(nameof(compilation));
if (elementType == null) if (elementType == null)
throw new ArgumentNullException("elementType"); throw new ArgumentNullException(nameof(elementType));
IType nullableType = compilation.FindType(KnownTypeCode.NullableOfT); IType nullableType = compilation.FindType(KnownTypeCode.NullableOfT);
ITypeDefinition nullableTypeDef = nullableType.GetDefinition(); ITypeDefinition nullableTypeDef = nullableType.GetDefinition();
@ -80,7 +80,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static ParameterizedTypeReference Create(ITypeReference elementType) public static ParameterizedTypeReference Create(ITypeReference elementType)
{ {
if (elementType == null) if (elementType == null)
throw new ArgumentNullException("elementType"); throw new ArgumentNullException(nameof(elementType));
return new ParameterizedTypeReference(KnownTypeReference.Get(KnownTypeCode.NullableOfT), new [] { elementType }); return new ParameterizedTypeReference(KnownTypeReference.Get(KnownTypeCode.NullableOfT), new [] { elementType });
} }
} }

2
ICSharpCode.Decompiler/TypeSystem/ParameterListComparer.cs

@ -111,7 +111,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public SignatureComparer(StringComparer nameComparer) public SignatureComparer(StringComparer nameComparer)
{ {
if (nameComparer == null) if (nameComparer == null)
throw new ArgumentNullException("nameComparer"); throw new ArgumentNullException(nameof(nameComparer));
this.nameComparer = nameComparer; this.nameComparer = nameComparer;
} }

8
ICSharpCode.Decompiler/TypeSystem/ParameterizedType.cs

@ -44,9 +44,9 @@ namespace ICSharpCode.Decompiler.TypeSystem
public ParameterizedType(IType genericType, IEnumerable<IType> typeArguments) public ParameterizedType(IType genericType, IEnumerable<IType> typeArguments)
{ {
if (genericType == null) if (genericType == null)
throw new ArgumentNullException("genericType"); throw new ArgumentNullException(nameof(genericType));
if (typeArguments == null) if (typeArguments == null)
throw new ArgumentNullException("typeArguments"); throw new ArgumentNullException(nameof(typeArguments));
this.genericType = genericType; this.genericType = genericType;
this.typeArguments = typeArguments.ToArray(); // copy input array to ensure it isn't modified this.typeArguments = typeArguments.ToArray(); // copy input array to ensure it isn't modified
if (this.typeArguments.Length == 0) if (this.typeArguments.Length == 0)
@ -358,9 +358,9 @@ namespace ICSharpCode.Decompiler.TypeSystem
public ParameterizedTypeReference(ITypeReference genericType, IEnumerable<ITypeReference> typeArguments) public ParameterizedTypeReference(ITypeReference genericType, IEnumerable<ITypeReference> typeArguments)
{ {
if (genericType == null) if (genericType == null)
throw new ArgumentNullException("genericType"); throw new ArgumentNullException(nameof(genericType));
if (typeArguments == null) if (typeArguments == null)
throw new ArgumentNullException("typeArguments"); throw new ArgumentNullException(nameof(typeArguments));
this.genericType = genericType; this.genericType = genericType;
this.typeArguments = typeArguments.ToArray(); this.typeArguments = typeArguments.ToArray();
for (int i = 0; i < this.typeArguments.Length; i++) { for (int i = 0; i < this.typeArguments.Length; i++) {

2
ICSharpCode.Decompiler/TypeSystem/PointerType.cs

@ -75,7 +75,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public PointerTypeReference(ITypeReference elementType) public PointerTypeReference(ITypeReference elementType)
{ {
if (elementType == null) if (elementType == null)
throw new ArgumentNullException("elementType"); throw new ArgumentNullException(nameof(elementType));
this.elementType = elementType; this.elementType = elementType;
} }

2
ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs

@ -210,7 +210,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static ITypeReference ParseReflectionName(string reflectionTypeName) public static ITypeReference ParseReflectionName(string reflectionTypeName)
{ {
if (reflectionTypeName == null) if (reflectionTypeName == null)
throw new ArgumentNullException("reflectionTypeName"); throw new ArgumentNullException(nameof(reflectionTypeName));
int pos = 0; int pos = 0;
ITypeReference r = ParseReflectionName(reflectionTypeName, ref pos); ITypeReference r = ParseReflectionName(reflectionTypeName, ref pos);
if (pos < reflectionTypeName.Length) if (pos < reflectionTypeName.Length)

4
ICSharpCode.Decompiler/TypeSystem/SimpleTypeResolveContext.cs

@ -33,7 +33,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public SimpleTypeResolveContext(ICompilation compilation) public SimpleTypeResolveContext(ICompilation compilation)
{ {
if (compilation == null) if (compilation == null)
throw new ArgumentNullException("compilation"); throw new ArgumentNullException(nameof(compilation));
this.compilation = compilation; this.compilation = compilation;
} }
@ -48,7 +48,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public SimpleTypeResolveContext(IEntity entity) public SimpleTypeResolveContext(IEntity entity)
{ {
if (entity == null) if (entity == null)
throw new ArgumentNullException("entity"); throw new ArgumentNullException(nameof(entity));
this.compilation = entity.Compilation; this.compilation = entity.Compilation;
this.currentModule = entity.ParentModule; this.currentModule = entity.ParentModule;
this.currentTypeDefinition = (entity as ITypeDefinition) ?? entity.DeclaringTypeDefinition; this.currentTypeDefinition = (entity as ITypeDefinition) ?? entity.DeclaringTypeDefinition;

2
ICSharpCode.Decompiler/TypeSystem/SpecialType.cs

@ -84,7 +84,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
IType ITypeReference.Resolve(ITypeResolveContext context) IType ITypeReference.Resolve(ITypeResolveContext context)
{ {
if (context == null) if (context == null)
throw new ArgumentNullException("context"); throw new ArgumentNullException(nameof(context));
return this; return this;
} }

4
ICSharpCode.Decompiler/TypeSystem/TaskType.cs

@ -121,9 +121,9 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static IType Create(ICompilation compilation, IType elementType) public static IType Create(ICompilation compilation, IType elementType)
{ {
if (compilation == null) if (compilation == null)
throw new ArgumentNullException("compilation"); throw new ArgumentNullException(nameof(compilation));
if (elementType == null) if (elementType == null)
throw new ArgumentNullException("elementType"); throw new ArgumentNullException(nameof(elementType));
if (elementType.Kind == TypeKind.Void) if (elementType.Kind == TypeKind.Void)
return compilation.FindType(KnownTypeCode.Task); return compilation.FindType(KnownTypeCode.Task);

4
ICSharpCode.Decompiler/TypeSystem/TopLevelTypeName.cs

@ -36,9 +36,9 @@ namespace ICSharpCode.Decompiler.TypeSystem
public TopLevelTypeName(string namespaceName, string name, int typeParameterCount = 0) public TopLevelTypeName(string namespaceName, string name, int typeParameterCount = 0)
{ {
if (namespaceName == null) if (namespaceName == null)
throw new ArgumentNullException("namespaceName"); throw new ArgumentNullException(nameof(namespaceName));
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
this.namespaceName = namespaceName; this.namespaceName = namespaceName;
this.name = name; this.name = name;
this.typeParameterCount = typeParameterCount; this.typeParameterCount = typeParameterCount;

22
ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs

@ -44,7 +44,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static IEnumerable<IType> GetAllBaseTypes(this IType type) public static IEnumerable<IType> GetAllBaseTypes(this IType type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
BaseTypeCollector collector = new BaseTypeCollector(); BaseTypeCollector collector = new BaseTypeCollector();
collector.CollectBaseTypes(type); collector.CollectBaseTypes(type);
return collector; return collector;
@ -61,7 +61,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static IEnumerable<IType> GetNonInterfaceBaseTypes(this IType type) public static IEnumerable<IType> GetNonInterfaceBaseTypes(this IType type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
BaseTypeCollector collector = new BaseTypeCollector(); BaseTypeCollector collector = new BaseTypeCollector();
collector.SkipImplementedInterfaces = true; collector.SkipImplementedInterfaces = true;
collector.CollectBaseTypes(type); collector.CollectBaseTypes(type);
@ -80,7 +80,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static IEnumerable<ITypeDefinition> GetAllBaseTypeDefinitions(this IType type) public static IEnumerable<ITypeDefinition> GetAllBaseTypeDefinitions(this IType type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
return type.GetAllBaseTypes().Select(t => t.GetDefinition()).Where(d => d != null).Distinct(); return type.GetAllBaseTypes().Select(t => t.GetDefinition()).Where(d => d != null).Distinct();
} }
@ -91,7 +91,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static bool IsDerivedFrom(this ITypeDefinition type, ITypeDefinition baseType) public static bool IsDerivedFrom(this ITypeDefinition type, ITypeDefinition baseType)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
if (baseType == null) if (baseType == null)
return false; return false;
if (type.Compilation != baseType.Compilation) { if (type.Compilation != baseType.Compilation) {
@ -106,7 +106,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static bool IsDerivedFrom(this ITypeDefinition type, KnownTypeCode baseType) public static bool IsDerivedFrom(this ITypeDefinition type, KnownTypeCode baseType)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
if (baseType == KnownTypeCode.None) if (baseType == KnownTypeCode.None)
return false; return false;
return IsDerivedFrom(type, type.Compilation.FindType(baseType).GetDefinition()); return IsDerivedFrom(type, type.Compilation.FindType(baseType).GetDefinition());
@ -178,7 +178,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static bool IsOpen(this IType type) public static bool IsOpen(this IType type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
TypeClassificationVisitor v = new TypeClassificationVisitor(); TypeClassificationVisitor v = new TypeClassificationVisitor();
type.AcceptVisitor(v); type.AcceptVisitor(v);
return v.isOpen; return v.isOpen;
@ -193,7 +193,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
static IEntity GetTypeParameterOwner(IType type) static IEntity GetTypeParameterOwner(IType type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
TypeClassificationVisitor v = new TypeClassificationVisitor(); TypeClassificationVisitor v = new TypeClassificationVisitor();
type.AcceptVisitor(v); type.AcceptVisitor(v);
return v.typeParameterOwner; return v.typeParameterOwner;
@ -210,7 +210,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static bool IsUnbound(this IType type) public static bool IsUnbound(this IType type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
return type is ITypeDefinition && type.TypeParameterCount > 0; return type is ITypeDefinition && type.TypeParameterCount > 0;
} }
@ -265,7 +265,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static IMethod GetDelegateInvokeMethod(this IType type) public static IMethod GetDelegateInvokeMethod(this IType type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException(nameof(type));
if (type.Kind == TypeKind.Delegate) if (type.Kind == TypeKind.Delegate)
return type.GetMethods(m => m.Name == "Invoke", GetMemberOptions.IgnoreInheritedMembers).FirstOrDefault(); return type.GetMethods(m => m.Name == "Invoke", GetMemberOptions.IgnoreInheritedMembers).FirstOrDefault();
else else
@ -310,7 +310,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static IReadOnlyList<IType> Resolve(this IList<ITypeReference> typeReferences, ITypeResolveContext context) public static IReadOnlyList<IType> Resolve(this IList<ITypeReference> typeReferences, ITypeResolveContext context)
{ {
if (typeReferences == null) if (typeReferences == null)
throw new ArgumentNullException("typeReferences"); throw new ArgumentNullException(nameof(typeReferences));
if (typeReferences.Count == 0) if (typeReferences.Count == 0)
return EmptyList<IType>.Instance; return EmptyList<IType>.Instance;
else else
@ -336,7 +336,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public static IType FindType(this ICompilation compilation, FullTypeName fullTypeName) public static IType FindType(this ICompilation compilation, FullTypeName fullTypeName)
{ {
if (compilation == null) if (compilation == null)
throw new ArgumentNullException("compilation"); throw new ArgumentNullException(nameof(compilation));
foreach (IModule asm in compilation.Modules) { foreach (IModule asm in compilation.Modules) {
ITypeDefinition def = asm.GetTypeDefinition(fullTypeName); ITypeDefinition def = asm.GetTypeDefinition(fullTypeName);
if (def != null) if (def != null)

2
ICSharpCode.Decompiler/Util/CallbackOnDispose.cs

@ -35,7 +35,7 @@ namespace ICSharpCode.Decompiler.Util
public CallbackOnDispose(Action action) public CallbackOnDispose(Action action)
{ {
if (action == null) if (action == null)
throw new ArgumentNullException("action"); throw new ArgumentNullException(nameof(action));
this.action = action; this.action = action;
} }

4
ICSharpCode.Decompiler/Util/EmptyList.cs

@ -30,8 +30,8 @@ namespace ICSharpCode.Decompiler.Util
private EmptyList() {} private EmptyList() {}
public T this[int index] { public T this[int index] {
get { throw new ArgumentOutOfRangeException("index"); } get { throw new ArgumentOutOfRangeException(nameof(index)); }
set { throw new ArgumentOutOfRangeException("index"); } set { throw new ArgumentOutOfRangeException(nameof(index)); }
} }
public int Count { public int Count {

8
ICSharpCode.Decompiler/Util/GraphVizGraph.cs

@ -114,7 +114,7 @@ namespace ICSharpCode.Decompiler.Util
public void Save(TextWriter writer) public void Save(TextWriter writer)
{ {
if (writer == null) if (writer == null)
throw new ArgumentNullException("writer"); throw new ArgumentNullException(nameof(writer));
writer.WriteLine("digraph G {"); writer.WriteLine("digraph G {");
writer.WriteLine("node [fontsize = 16];"); writer.WriteLine("node [fontsize = 16];");
WriteGraphAttribute(writer, "rankdir", rankdir); WriteGraphAttribute(writer, "rankdir", rankdir);
@ -147,9 +147,9 @@ namespace ICSharpCode.Decompiler.Util
public GraphVizEdge(string source, string target) public GraphVizEdge(string source, string target)
{ {
if (source == null) if (source == null)
throw new ArgumentNullException("source"); throw new ArgumentNullException(nameof(source));
if (target == null) if (target == null)
throw new ArgumentNullException("target"); throw new ArgumentNullException(nameof(target));
this.Source = source; this.Source = source;
this.Target = target; this.Target = target;
} }
@ -195,7 +195,7 @@ namespace ICSharpCode.Decompiler.Util
public GraphVizNode(string id) public GraphVizNode(string id)
{ {
if (id == null) if (id == null)
throw new ArgumentNullException("id"); throw new ArgumentNullException(nameof(id));
this.ID = id; this.ID = id;
} }

6
ICSharpCode.Decompiler/Util/KeyComparer.cs

@ -58,11 +58,11 @@ namespace ICSharpCode.Decompiler.Util
public KeyComparer(Func<TElement, TKey> keySelector, IComparer<TKey> keyComparer, IEqualityComparer<TKey> keyEqualityComparer) public KeyComparer(Func<TElement, TKey> keySelector, IComparer<TKey> keyComparer, IEqualityComparer<TKey> keyEqualityComparer)
{ {
if (keySelector == null) if (keySelector == null)
throw new ArgumentNullException("keySelector"); throw new ArgumentNullException(nameof(keySelector));
if (keyComparer == null) if (keyComparer == null)
throw new ArgumentNullException("keyComparer"); throw new ArgumentNullException(nameof(keyComparer));
if (keyEqualityComparer == null) if (keyEqualityComparer == null)
throw new ArgumentNullException("keyEqualityComparer"); throw new ArgumentNullException(nameof(keyEqualityComparer));
this.keySelector = keySelector; this.keySelector = keySelector;
this.keyComparer = keyComparer; this.keyComparer = keyComparer;
this.keyEqualityComparer = keyEqualityComparer; this.keyEqualityComparer = keyEqualityComparer;

8
ICSharpCode.Decompiler/Util/ProjectedList.cs

@ -30,9 +30,9 @@ namespace ICSharpCode.Decompiler.Util
public ProjectedList(IList<TInput> input, Func<TInput, TOutput> projection) public ProjectedList(IList<TInput> input, Func<TInput, TOutput> projection)
{ {
if (input == null) if (input == null)
throw new ArgumentNullException("input"); throw new ArgumentNullException(nameof(input));
if (projection == null) if (projection == null)
throw new ArgumentNullException("projection"); throw new ArgumentNullException(nameof(projection));
this.input = input; this.input = input;
this.projection = projection; this.projection = projection;
this.items = new TOutput[input.Count]; this.items = new TOutput[input.Count];
@ -75,9 +75,9 @@ namespace ICSharpCode.Decompiler.Util
public ProjectedList(TContext context, IList<TInput> input, Func<TContext, TInput, TOutput> projection) public ProjectedList(TContext context, IList<TInput> input, Func<TContext, TInput, TOutput> projection)
{ {
if (input == null) if (input == null)
throw new ArgumentNullException("input"); throw new ArgumentNullException(nameof(input));
if (projection == null) if (projection == null)
throw new ArgumentNullException("projection"); throw new ArgumentNullException(nameof(projection));
this.input = input; this.input = input;
this.context = context; this.context = context;
this.projection = projection; this.projection = projection;

30
ICSharpCode.Decompiler/Util/ResXResourceWriter.cs

@ -69,10 +69,10 @@ namespace ICSharpCode.Decompiler.Util
public ResXResourceWriter(Stream stream) public ResXResourceWriter(Stream stream)
{ {
if (stream == null) if (stream == null)
throw new ArgumentNullException("stream"); throw new ArgumentNullException(nameof(stream));
if (!stream.CanWrite) if (!stream.CanWrite)
throw new ArgumentException("stream is not writable.", "stream"); throw new ArgumentException("stream is not writable.", nameof(stream));
this.stream = stream; this.stream = stream;
} }
@ -80,7 +80,7 @@ namespace ICSharpCode.Decompiler.Util
public ResXResourceWriter(TextWriter textWriter) public ResXResourceWriter(TextWriter textWriter)
{ {
if (textWriter == null) if (textWriter == null)
throw new ArgumentNullException("textWriter"); throw new ArgumentNullException(nameof(textWriter));
this.textwriter = textWriter; this.textwriter = textWriter;
} }
@ -88,7 +88,7 @@ namespace ICSharpCode.Decompiler.Util
public ResXResourceWriter(string fileName) public ResXResourceWriter(string fileName)
{ {
if (fileName == null) if (fileName == null)
throw new ArgumentNullException("fileName"); throw new ArgumentNullException(nameof(fileName));
this.filename = fileName; this.filename = fileName;
} }
@ -217,10 +217,10 @@ namespace ICSharpCode.Decompiler.Util
public void AddResource(string name, byte[] value) public void AddResource(string name, byte[] value)
{ {
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
if (value == null) if (value == null)
throw new ArgumentNullException("value"); throw new ArgumentNullException(nameof(value));
if (written) if (written)
throw new InvalidOperationException("The resource is already generated."); throw new InvalidOperationException("The resource is already generated.");
@ -244,7 +244,7 @@ namespace ICSharpCode.Decompiler.Util
} }
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
if (written) if (written)
throw new InvalidOperationException("The resource is already generated."); throw new InvalidOperationException("The resource is already generated.");
@ -307,10 +307,10 @@ namespace ICSharpCode.Decompiler.Util
private void AddResource(string name, string value, string comment) private void AddResource(string name, string value, string comment)
{ {
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
if (value == null) if (value == null)
throw new ArgumentNullException("value"); throw new ArgumentNullException(nameof(value));
if (written) if (written)
throw new InvalidOperationException("The resource is already generated."); throw new InvalidOperationException("The resource is already generated.");
@ -324,10 +324,10 @@ namespace ICSharpCode.Decompiler.Util
public void AddMetadata(string name, string value) public void AddMetadata(string name, string value)
{ {
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
if (value == null) if (value == null)
throw new ArgumentNullException("value"); throw new ArgumentNullException(nameof(value));
if (written) if (written)
throw new InvalidOperationException("The resource is already generated."); throw new InvalidOperationException("The resource is already generated.");
@ -347,10 +347,10 @@ namespace ICSharpCode.Decompiler.Util
public void AddMetadata(string name, byte[] value) public void AddMetadata(string name, byte[] value)
{ {
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
if (value == null) if (value == null)
throw new ArgumentNullException("value"); throw new ArgumentNullException(nameof(value));
if (written) if (written)
throw new InvalidOperationException("The resource is already generated."); throw new InvalidOperationException("The resource is already generated.");
@ -383,10 +383,10 @@ namespace ICSharpCode.Decompiler.Util
} }
if (name == null) if (name == null)
throw new ArgumentNullException("name"); throw new ArgumentNullException(nameof(name));
if (value == null) if (value == null)
throw new ArgumentNullException("value"); throw new ArgumentNullException(nameof(value));
if (!value.GetType().IsSerializable) if (!value.GetType().IsSerializable)
throw new InvalidOperationException(String.Format("The element '{0}' of type '{1}' is not serializable.", name, value.GetType().Name)); throw new InvalidOperationException(String.Format("The element '{0}' of type '{1}' is not serializable.", name, value.GetType().Name));

Loading…
Cancel
Save