Skip to content

Commit db43573

Browse files
authored
Moving attributes from System.Runtime (#219)
***NO_CI***
1 parent 7f1030b commit db43573

File tree

8 files changed

+422
-2
lines changed

8 files changed

+422
-2
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System.Runtime.CompilerServices;
2+
using nanoFramework.TestFramework;
3+
4+
namespace NFUnitTestAttributes
5+
{
6+
[TestClass]
7+
public class CallerArgumentExpressionAttributeTests
8+
{
9+
public string Field = "Field value";
10+
11+
public string Property => "Property value";
12+
13+
[TestMethod]
14+
public void CallerArgumentExpressionSetsParameterNameFromField()
15+
{
16+
var sut = new CallerArgumentExpressionAttributeTests();
17+
const string expect = "sut.Field";
18+
var actual = TestCallerArgumentExpression(sut.Field);
19+
20+
Assert.AreEqual(expect, actual);
21+
}
22+
23+
[TestMethod]
24+
public void CallerArgumentExpressionSetsParameterNameFromMethodParameter()
25+
{
26+
const string expect = "methodParameter";
27+
var actual = TestMethodParameter("Method parameter value");
28+
29+
Assert.AreEqual(expect, actual);
30+
}
31+
32+
[TestMethod]
33+
public void CallerArgumentExpressionSetsParameterNameFromNull()
34+
{
35+
const string expect = "null";
36+
var actual = TestCallerArgumentExpression(null);
37+
38+
Assert.AreEqual(expect, actual);
39+
}
40+
41+
[TestMethod]
42+
public void CallerArgumentExpressionSetsParameterNameFromProperty()
43+
{
44+
var sut = new CallerArgumentExpressionAttributeTests();
45+
const string expect = "sut.Property";
46+
var actual = TestCallerArgumentExpression(sut.Property);
47+
48+
Assert.AreEqual(expect, actual);
49+
}
50+
51+
[TestMethod]
52+
public void CallerArgumentExpressionSetsParameterNameFromVariable()
53+
{
54+
const string variableName = "Variable value";
55+
const string expect = nameof(variableName);
56+
var actual = TestCallerArgumentExpression(variableName);
57+
58+
Assert.AreEqual(expect, actual);
59+
}
60+
61+
// ReSharper disable once EntityNameCapturedOnly.Local
62+
#pragma warning disable IDE0060
63+
private static string TestCallerArgumentExpression(object objectValue, [CallerArgumentExpression(nameof(objectValue))] string parameterName = null) => parameterName;
64+
#pragma warning restore IDE0060
65+
66+
private static string TestMethodParameter(string methodParameter) => TestCallerArgumentExpression(methodParameter);
67+
}
68+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Runtime.CompilerServices;
2+
using nanoFramework.TestFramework;
3+
4+
namespace NFUnitTestAttributes
5+
{
6+
[TestClass]
7+
public class CallerMemberNameAttributeTests
8+
{
9+
[TestMethod]
10+
public void CallerMemberNameAttributeGetsCallerMemberName()
11+
{
12+
const string expect = nameof(CallerMemberNameAttributeGetsCallerMemberName);
13+
var actual = TestCallerMemberName();
14+
15+
Assert.AreEqual(expect, actual);
16+
}
17+
18+
// ReSharper disable once EntityNameCapturedOnly.Local
19+
#pragma warning disable IDE0060
20+
private static string TestCallerMemberName([CallerMemberName] string memberName = null) => memberName;
21+
#pragma warning restore IDE0060
22+
}
23+
}

Tests/NFUnitTestAttributes/NFUnitTestAttributes.nfproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
<IsTestProject>true</IsTestProject>
2222
<TestProjectType>UnitTest</TestProjectType>
2323
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
24+
<LangVersion>default</LangVersion>
2425
</PropertyGroup>
2526
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
2627
<ItemGroup>
28+
<Compile Include="CallerArgumentExpressionAttributeTests.cs" />
29+
<Compile Include="CallerMemberNameAttributeTests.cs" />
2730
<Compile Include="ConstructorTests.cs" />
2831
<Compile Include="UnitTestAttributesTest1.cs" />
2932
<Compile Include="Properties\AssemblyInfo.cs" />

nanoFramework.CoreLibrary.NoReflection/CoreLibrary.NoReflection.nfproj

Lines changed: 43 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" />
@@ -170,6 +171,8 @@
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" />
172173
<Compile Include="..\nanoFramework.CoreLibrary\System\Runtime\CompilerServices\ExcludeFromStubsAttribute.cs" Link="System\Runtime\CompilerServices\ExcludeFromStubsAttribute.cs" />
174+
<Compile Include="..\nanoFramework.CoreLibrary\System\Runtime\CompilerServices\CallerArgumentExpressionAttribute.cs" Link="System\Runtime\CompilerServices\CallerArgumentExpressionAttribute.cs" />
175+
<Compile Include="..\nanoFramework.CoreLibrary\System\Runtime\CompilerServices\CallerMemberNameAttribute.cs" Link="System\Runtime\CompilerServices\CallerMemberNameAttribute.cs" />
173176
<Compile Include="..\nanoFramework.CoreLibrary\System\Runtime\CompilerServices\ExtensionAttribute.cs" Link="System\Runtime\CompilerServices\ExtensionAttribute.cs" />
174177
<Compile Include="..\nanoFramework.CoreLibrary\System\Runtime\CompilerServices\IndexerNameAttribute.cs" Link="System\CompilerServices\IndexerNameAttribute.cs" />
175178
<Compile Include="..\nanoFramework.CoreLibrary\System\Runtime\CompilerServices\InternalsVisibleToAttribute.cs" Link="System\CompilerServices\InternalsVisibleToAttribute.cs" />
@@ -242,6 +245,39 @@
242245
<NFMDP_PE_ExcludeClassByName Include="System.Decimal">
243246
<InProject>false</InProject>
244247
</NFMDP_PE_ExcludeClassByName>
248+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.AllowNullAttribute">
249+
<InProject>false</InProject>
250+
</NFMDP_PE_ExcludeClassByName>
251+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.DisallowNullAttribute">
252+
<InProject>false</InProject>
253+
</NFMDP_PE_ExcludeClassByName>
254+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute">
255+
<InProject>false</InProject>
256+
</NFMDP_PE_ExcludeClassByName>
257+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute">
258+
<InProject>false</InProject>
259+
</NFMDP_PE_ExcludeClassByName>
260+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.MaybeNullAttribute">
261+
<InProject>false</InProject>
262+
</NFMDP_PE_ExcludeClassByName>
263+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute">
264+
<InProject>false</InProject>
265+
</NFMDP_PE_ExcludeClassByName>
266+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.MemberNotNullAttribute">
267+
<InProject>false</InProject>
268+
</NFMDP_PE_ExcludeClassByName>
269+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute">
270+
<InProject>false</InProject>
271+
</NFMDP_PE_ExcludeClassByName>
272+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.NotNullAttribute">
273+
<InProject>false</InProject>
274+
</NFMDP_PE_ExcludeClassByName>
275+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute">
276+
<InProject>false</InProject>
277+
</NFMDP_PE_ExcludeClassByName>
278+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.NotNullWhenAttribute">
279+
<InProject>false</InProject>
280+
</NFMDP_PE_ExcludeClassByName>
245281
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.ConditionalAttribute">
246282
<InProject>false</InProject>
247283
</NFMDP_PE_ExcludeClassByName>
@@ -341,6 +377,12 @@
341377
<NFMDP_PE_ExcludeClassByName Include="System.Reflection.MethodImplAttributes">
342378
<InProject>false</InProject>
343379
</NFMDP_PE_ExcludeClassByName>
380+
<NFMDP_PE_ExcludeClassByName Include="System.Runtime.CompilerServices.CallerArgumentExpressionAttribute">
381+
<InProject>false</InProject>
382+
</NFMDP_PE_ExcludeClassByName>
383+
<NFMDP_PE_ExcludeClassByName Include="System.Runtime.CompilerServices.CallerMemberNameAttribute">
384+
<InProject>false</InProject>
385+
</NFMDP_PE_ExcludeClassByName>
344386
<NFMDP_PE_ExcludeClassByName Include="System.Runtime.CompilerServices.IndexerNameAttribute">
345387
<InProject>false</InProject>
346388
</NFMDP_PE_ExcludeClassByName>
@@ -426,4 +468,4 @@
426468
<Import Project="..\packages\Microsoft.SourceLink.Common.1.1.1\build\Microsoft.SourceLink.Common.targets" Condition="Exists('..\packages\Microsoft.SourceLink.Common.1.1.1\build\Microsoft.SourceLink.Common.targets')" />
427469
<Import Project="..\packages\Microsoft.SourceLink.GitHub.1.1.1\build\Microsoft.SourceLink.GitHub.targets" Condition="Exists('..\packages\Microsoft.SourceLink.GitHub.1.1.1\build\Microsoft.SourceLink.GitHub.targets')" />
428470
<Import Project="..\packages\Nerdbank.GitVersioning.3.5.119\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.5.119\build\Nerdbank.GitVersioning.targets')" />
429-
</Project>
471+
</Project>

nanoFramework.CoreLibrary/CoreLibrary.nfproj

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@
166166
<Compile Include="System\RuntimeMethodHandle.cs" />
167167
<Compile Include="System\RuntimeType.cs" />
168168
<Compile Include="System\RuntimeTypeHandle.cs" />
169+
<Compile Include="System\Runtime\CompilerServices\CallerArgumentExpressionAttribute.cs" />
170+
<Compile Include="System\Runtime\CompilerServices\CallerMemberNameAttribute.cs" />
169171
<Compile Include="System\Runtime\CompilerServices\AccessedThroughPropertyAttribute.cs" />
170172
<Compile Include="System\Runtime\CompilerServices\ExcludeFromStubsAttribute.cs" />
171173
<Compile Include="System\Runtime\CompilerServices\ExtensionAttribute.cs" />
@@ -178,6 +180,7 @@
178180
<Compile Include="System\Runtime\InteropServices\Attributes.cs" />
179181
<Compile Include="System\Runtime\InteropServices\CharSet.cs" />
180182
<Compile Include="System\Runtime\InteropServices\LayoutKind.cs" />
183+
<Compile Include="System\Diagnostics\CodeAnalysis\NullableAttributes.cs" />
181184
<Compile Include="System\Runtime\Remoting\RemotingServices.cs" />
182185
<Compile Include="System\Runtime\Remoting\__TransparentProxy.cs" />
183186
<Compile Include="System\SByte.cs" />
@@ -234,6 +237,39 @@
234237
<NFMDP_PE_ExcludeClassByName Include="System.Decimal">
235238
<InProject>false</InProject>
236239
</NFMDP_PE_ExcludeClassByName>
240+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.AllowNullAttribute">
241+
<InProject>false</InProject>
242+
</NFMDP_PE_ExcludeClassByName>
243+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.DisallowNullAttribute">
244+
<InProject>false</InProject>
245+
</NFMDP_PE_ExcludeClassByName>
246+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute">
247+
<InProject>false</InProject>
248+
</NFMDP_PE_ExcludeClassByName>
249+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute">
250+
<InProject>false</InProject>
251+
</NFMDP_PE_ExcludeClassByName>
252+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.MaybeNullAttribute">
253+
<InProject>false</InProject>
254+
</NFMDP_PE_ExcludeClassByName>
255+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute">
256+
<InProject>false</InProject>
257+
</NFMDP_PE_ExcludeClassByName>
258+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.MemberNotNullAttribute">
259+
<InProject>false</InProject>
260+
</NFMDP_PE_ExcludeClassByName>
261+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute">
262+
<InProject>false</InProject>
263+
</NFMDP_PE_ExcludeClassByName>
264+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.NotNullAttribute">
265+
<InProject>false</InProject>
266+
</NFMDP_PE_ExcludeClassByName>
267+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute">
268+
<InProject>false</InProject>
269+
</NFMDP_PE_ExcludeClassByName>
270+
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.CodeAnalysis.NotNullWhenAttribute">
271+
<InProject>false</InProject>
272+
</NFMDP_PE_ExcludeClassByName>
237273
<NFMDP_PE_ExcludeClassByName Include="System.Diagnostics.ConditionalAttribute">
238274
<InProject>false</InProject>
239275
</NFMDP_PE_ExcludeClassByName>
@@ -336,7 +372,13 @@
336372
<NFMDP_PE_ExcludeClassByName Include="System.Reflection.MethodImplAttributes">
337373
<InProject>false</InProject>
338374
</NFMDP_PE_ExcludeClassByName>
339-
<NFMDP_PE_ExcludeClassByName Include="System.Runtime.CompilerServices.IndexerNameAttribute">
375+
<NFMDP_PE_ExcludeClassByName Include="System.Runtime.CompilerServices.CallerArgumentExpressionAttribute">
376+
<InProject>false</InProject>
377+
</NFMDP_PE_ExcludeClassByName>
378+
<NFMDP_PE_ExcludeClassByName Include="System.Runtime.CompilerServices.CallerMemberNameAttribute">
379+
<InProject>false</InProject>
380+
</NFMDP_PE_ExcludeClassByName>
381+
<NFMDP_PE_ExcludeClassByName Include="System.Runtime.CompilerServices.IndexerNameAttribute">
340382
<InProject>false</InProject>
341383
</NFMDP_PE_ExcludeClassByName>
342384
<NFMDP_PE_ExcludeClassByName Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">

0 commit comments

Comments
 (0)