mirror of
https://github.com/icsharpcode/ILSpy.git
synced 2026-10-12 02:15:58 +00:00
These helpers are documented to return null when nothing matches, but returned `null!`, hiding the very nullable warnings #nullable enable is meant to surface: a miss handed back null typed as non-null and would NRE downstream with no compile-time signal. Returning T? lets the compiler enforce the guard at each call site (both existing callers already null-check). GetVariable forwards the result, so it becomes VariableInitializer? to match. Assisted-by: Claude:claude-opus-4-8:Claude Code
57 lines
2.0 KiB
C#
57 lines
2.0 KiB
C#
//
|
|
// VariableDeclarationStatement.cs
|
|
//
|
|
// Author:
|
|
// Mike Krüger <[email protected]>
|
|
//
|
|
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in
|
|
// all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
#nullable enable
|
|
|
|
namespace ICSharpCode.Decompiler.CSharp.Syntax
|
|
{
|
|
/// <summary>
|
|
/// <c>local_variable_declaration ::= type variable_initializer+</c> (C# grammar §13.6.2.1)
|
|
/// </summary>
|
|
[DecompilerAstNode]
|
|
public sealed partial class VariableDeclarationStatement : Statement
|
|
{
|
|
public VariableDeclarationStatement(AstType type, string name, Expression? initializer = null)
|
|
{
|
|
this.Type = type;
|
|
this.Variables.Add(new VariableInitializer(name, initializer));
|
|
}
|
|
|
|
public Modifiers Modifiers { get; set; }
|
|
|
|
[Slot("Type")]
|
|
public partial AstType Type { get; set; }
|
|
|
|
[Slot("Variable")]
|
|
public partial AstNodeCollection<VariableInitializer> Variables { get; }
|
|
|
|
public VariableInitializer? GetVariable(string name)
|
|
{
|
|
return Variables.FirstOrNull(vi => vi.Name == name);
|
|
}
|
|
}
|
|
}
|