Skip to content

Commit c027657

Browse files
committed
Switching to field backed properties
1 parent 5095169 commit c027657

File tree

4 files changed

+40
-22
lines changed

4 files changed

+40
-22
lines changed

nanoFramework.CoreLibrary.NoReflection/CoreLibrary.NoReflection.nfproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<Compile Include="..\nanoFramework.CoreLibrary\System\DayOfWeek.cs" Link="System\DayOfWeek.cs" />
9393
<Compile Include="..\nanoFramework.CoreLibrary\System\DBNull.cs" Link="System\DBNull.cs" />
9494
<Compile Include="..\nanoFramework.CoreLibrary\System\Delegate.cs" Link="System\v.cs" />
95+
<Compile Include="..\nanoFramework.CoreLibrary\System\Diagnostics\CodeAnalysis\NullableAttributes.cs" Link="System\Diagnostics\CodeAnalysis\NullableAttributes.cs" />
9596
<Compile Include="..\nanoFramework.CoreLibrary\System\Diagnostics\ConditionalAttribute.cs" Link="System\Diagnostics\ConditionalAttribute.cs" />
9697
<Compile Include="..\nanoFramework.CoreLibrary\System\Diagnostics\Debug.cs" Link="System\Diagnostics\Debug.cs" />
9798
<Compile Include="..\nanoFramework.CoreLibrary\System\Diagnostics\Debugger.cs" Link="System\Diagnostics\Debugger.cs" />
@@ -169,6 +170,8 @@
169170
<Compile Include="..\nanoFramework.CoreLibrary\System\RuntimeType.cs" Link="System\RuntimeType.cs" />
170171
<Compile Include="..\nanoFramework.CoreLibrary\System\RuntimeTypeHandle.cs" Link="System\RuntimeTypeHandle.cs" />
171172
<Compile Include="..\nanoFramework.CoreLibrary\System\Runtime\CompilerServices\AccessedThroughPropertyAttribute.cs" Link="System\Runtime\CompilerServices\AccessedThroughPropertyAttribute.cs" />
173+
<Compile Include="..\nanoFramework.CoreLibrary\System\Runtime\CompilerServices\CallerArgumentExpressionAttribute.cs" Link="System\Runtime\CompilerServices\CallerArgumentExpressionAttribute.cs" />
174+
<Compile Include="..\nanoFramework.CoreLibrary\System\Runtime\CompilerServices\CallerMemberNameAttribute.cs" Link="System\Runtime\CompilerServices\CallerMemberNameAttribute.cs" />
172175
<Compile Include="..\nanoFramework.CoreLibrary\System\Runtime\CompilerServices\ExtensionAttribute.cs" Link="System\Runtime\CompilerServices\ExtensionAttribute.cs" />
173176
<Compile Include="..\nanoFramework.CoreLibrary\System\Runtime\CompilerServices\IndexerNameAttribute.cs" Link="System\CompilerServices\IndexerNameAttribute.cs" />
174177
<Compile Include="..\nanoFramework.CoreLibrary\System\Runtime\CompilerServices\InternalsVisibleToAttribute.cs" Link="System\CompilerServices\InternalsVisibleToAttribute.cs" />
@@ -397,7 +400,7 @@
397400
<None Include="packages.config" />
398401
</ItemGroup>
399402
<ItemGroup>
400-
<Folder Include="System\" />
403+
<Folder Include="System\Diagnostics\CodeAnalysis\" />
401404
</ItemGroup>
402405
<ItemGroup>
403406
<Content Include="packages.lock.json" />

nanoFramework.CoreLibrary/System/Diagnostics/CodeAnalysis/NullableAttributes.cs

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
// ReSharper disable ConvertToAutoProperty
45
namespace System.Diagnostics.CodeAnalysis
56
{
67
/// <summary>
@@ -40,33 +41,37 @@ public sealed class NotNullAttribute : Attribute
4041
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
4142
public sealed class MaybeNullWhenAttribute : Attribute
4243
{
44+
private readonly bool _returnValue;
45+
4346
/// <summary>
4447
/// Initializes the attribute with the specified return value condition.
4548
/// </summary>
4649
/// <param name="returnValue">
4750
/// The return value condition. If the method returns this value, the associated parameter may be null.
4851
/// </param>
49-
public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;
52+
public MaybeNullWhenAttribute(bool returnValue) => _returnValue = returnValue;
5053

5154
/// <summary>
5255
/// Gets the return value condition.
5356
/// </summary>
54-
public bool ReturnValue { get; }
57+
public bool ReturnValue => _returnValue;
5558
}
5659

5760
/// <summary>
5861
/// Specifies that when a method returns <see cref="ReturnValue"/>, the parameter will not be null even if the corresponding type allows it.
5962
/// </summary>
6063
public sealed class NotNullWhenAttribute : Attribute
6164
{
65+
private readonly bool _returnValue;
66+
6267
/// <summary>Initializes the attribute with the specified return value condition.</summary>
6368
/// <param name="returnValue">
6469
/// The return value condition. If the method returns this value, the associated parameter will not be null.
6570
/// </param>
66-
public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;
71+
public NotNullWhenAttribute(bool returnValue) => _returnValue = returnValue;
6772

6873
/// <summary>Gets the return value condition.</summary>
69-
public bool ReturnValue { get; }
74+
public bool ReturnValue => _returnValue;
7075
}
7176

7277
/// <summary>
@@ -75,14 +80,16 @@ public sealed class NotNullWhenAttribute : Attribute
7580
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)]
7681
public sealed class NotNullIfNotNullAttribute : Attribute
7782
{
83+
private readonly string _parameterName;
84+
7885
/// <summary>Initializes the attribute with the associated parameter name.</summary>
7986
/// <param name="parameterName">
8087
/// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null.
8188
/// </param>
82-
public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName;
89+
public NotNullIfNotNullAttribute(string parameterName) => _parameterName = parameterName;
8390

8491
/// <summary>Gets the associated parameter name.</summary>
85-
public string ParameterName { get; }
92+
public string ParameterName => _parameterName;
8693
}
8794

8895
/// <summary>
@@ -98,17 +105,19 @@ public sealed class DoesNotReturnAttribute : Attribute
98105
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
99106
public sealed class DoesNotReturnIfAttribute : Attribute
100107
{
108+
private readonly bool _parameterValue;
109+
101110
/// <summary>Initializes the attribute with the specified parameter value.</summary>
102111
/// <param name="parameterValue">
103112
/// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to
104113
/// the associated parameter matches this value.
105114
/// </param>
106-
public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue;
115+
public DoesNotReturnIfAttribute(bool parameterValue) => _parameterValue = parameterValue;
107116

108117
/// <summary>
109118
/// Gets the condition parameter value.
110119
/// </summary>
111-
public bool ParameterValue { get; }
120+
public bool ParameterValue => _parameterValue;
112121
}
113122

114123
/// <summary>
@@ -117,22 +126,24 @@ public sealed class DoesNotReturnIfAttribute : Attribute
117126
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
118127
public sealed class MemberNotNullAttribute : Attribute
119128
{
129+
private readonly string[] _members;
130+
120131
/// <summary>Initializes the attribute with a field or property member.</summary>
121132
/// <param name="member">
122133
/// The field or property member that is promised to be not-null.
123134
/// </param>
124-
public MemberNotNullAttribute(string member) => Members = new[] { member };
135+
public MemberNotNullAttribute(string member) => _members = new[] { member };
125136

126137
/// <summary>Initializes the attribute with the list of field and property members.</summary>
127138
/// <param name="members">
128139
/// The list of field and property members that are promised to be not-null.
129140
/// </param>
130-
public MemberNotNullAttribute(params string[] members) => Members = members;
141+
public MemberNotNullAttribute(params string[] members) => _members = members;
131142

132143
/// <summary>
133144
/// Gets field or property member names.
134145
/// </summary>
135-
public string[] Members { get; }
146+
public string[] Members => _members;
136147
}
137148

138149
/// <summary>
@@ -141,6 +152,9 @@ public sealed class MemberNotNullAttribute : Attribute
141152
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
142153
public sealed class MemberNotNullWhenAttribute : Attribute
143154
{
155+
private readonly bool _returnValue;
156+
private readonly string[] _members;
157+
144158
/// <summary>Initializes the attribute with the specified return value condition and a field or property member.</summary>
145159
/// <param name="returnValue">
146160
/// The return value condition. If the method returns this value, the associated parameter will not be null.
@@ -150,8 +164,8 @@ public sealed class MemberNotNullWhenAttribute : Attribute
150164
/// </param>
151165
public MemberNotNullWhenAttribute(bool returnValue, string member)
152166
{
153-
ReturnValue = returnValue;
154-
Members = new[] { member };
167+
_returnValue = returnValue;
168+
_members = new[] { member };
155169
}
156170

157171
/// <summary>Initializes the attribute with the specified return value condition and list of field and property members.</summary>
@@ -163,18 +177,18 @@ public MemberNotNullWhenAttribute(bool returnValue, string member)
163177
/// </param>
164178
public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
165179
{
166-
ReturnValue = returnValue;
167-
Members = members;
180+
_returnValue = returnValue;
181+
_members = members;
168182
}
169183

170184
/// <summary>
171185
/// Gets the return value condition.
172186
/// </summary>
173-
public bool ReturnValue { get; }
187+
public bool ReturnValue => _returnValue;
174188

175189
/// <summary>
176190
/// Gets field or property member names.
177191
/// </summary>
178-
public string[] Members { get; }
192+
public string[] Members => _members;
179193
}
180194
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
// ReSharper disable once CheckNamespace
4+
// ReSharper disable ConvertToAutoProperty
55
namespace System.Runtime.CompilerServices
66
{
77
/// <summary>
@@ -10,18 +10,20 @@ namespace System.Runtime.CompilerServices
1010
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
1111
public sealed class CallerArgumentExpressionAttribute : Attribute
1212
{
13+
private readonly string _parameterName;
14+
1315
/// <summary>
1416
/// Initializes a new instance of the <see cref="CallerArgumentExpressionAttribute"/> class.
1517
/// </summary>
1618
/// <param name="parameterName">The name of the parameter whose expression should be captured as a string.</param>
1719
public CallerArgumentExpressionAttribute(string parameterName)
1820
{
19-
ParameterName = parameterName;
21+
_parameterName = parameterName;
2022
}
2123

2224
/// <summary>
2325
/// Gets the name of the parameter whose expression should be captured as a string.
2426
/// </summary>
25-
public string ParameterName { get; }
27+
public string ParameterName => _parameterName;
2628
}
2729
}

nanoFramework.CoreLibrary/System/Runtime/CompilerServices/CallerMemberNameAttribute.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
// ReSharper disable once CheckNamespace
54
namespace System.Runtime.CompilerServices
65
{
76
/// <summary>

0 commit comments

Comments
 (0)