Skip to content

Commit 14ba19c

Browse files
authored
Extract Sytem.Reflection API (#93)
***PUBLISH_RELEASE***
1 parent a08ed97 commit 14ba19c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+441
-160
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@
55

66
-----
77

8-
### Welcome to the **nanoFramework** Core Library repository!
8+
### Welcome to the **nanoFramework** Base Class Library repository!
99

1010
## Build status
1111

1212
| Component | Build Status | NuGet Package |
1313
|:-|---|---|
14-
| Core Library | [![Build Status](https://dev.azure.com/nanoframework/CoreLibrary/_apis/build/status/nanoframework.lib-CoreLibrary?branchName=develop)](https://dev.azure.com/nanoframework/CoreLibrary/_build/latest?definitionId=24?branchName=master) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.CoreLibrary.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.CoreLibrary/) |
15-
| Core Library (preview) | [![Build Status](https://dev.azure.com/nanoframework/CoreLibrary/_apis/build/status/nanoframework.lib-CoreLibrary?branchName=develop)](https://dev.azure.com/nanoframework/CoreLibrary/_build/latest?definitionId=24?branchName=develop) | [![](https://badgen.net/badge/NuGet/preview/D7B023?icon=https://simpleicons.now.sh/azuredevops/fff)](https://dev.azure.com/nanoframework/feed/_packaging?_a=package&feed=sandbox&package=nanoFramework.CoreLibrary&protocolType=NuGet&view=overview) |
14+
| Base Class Library | [![Build Status](https://dev.azure.com/nanoframework/CoreLibrary/_apis/build/status/nanoframework.lib-CoreLibrary?branchName=develop)](https://dev.azure.com/nanoframework/CoreLibrary/_build/latest?definitionId=24?branchName=master) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.CoreLibrary.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.CoreLibrary/) |
15+
| Base Class Library w/o reflection | [![Build Status](https://dev.azure.com/nanoframework/CoreLibrary/_apis/build/status/nanoframework.lib-CoreLibrary?branchName=develop)](https://dev.azure.com/nanoframework/CoreLibrary/_build/latest?definitionId=24?branchName=master) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.CoreLibrary.NoReflection.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.CoreLibrary/) |
16+
| Base Class Library (preview) | [![Build Status](https://dev.azure.com/nanoframework/CoreLibrary/_apis/build/status/nanoframework.lib-CoreLibrary?branchName=develop)](https://dev.azure.com/nanoframework/CoreLibrary/_build/latest?definitionId=24?branchName=develop) | [![](https://badgen.net/badge/NuGet/preview/D7B023?icon=https://simpleicons.now.sh/azuredevops/fff)](https://dev.azure.com/nanoframework/feed/_packaging?_a=package&feed=sandbox&package=nanoFramework.CoreLibrary&protocolType=NuGet&view=overview) |
17+
| Base Class Library w/o reflection (preview) | [![Build Status](https://dev.azure.com/nanoframework/CoreLibrary/_apis/build/status/nanoframework.lib-CoreLibrary?branchName=develop)](https://dev.azure.com/nanoframework/CoreLibrary/_build/latest?definitionId=24?branchName=develop) | [![](https://badgen.net/badge/NuGet/preview/D7B023?icon=https://simpleicons.now.sh/azuredevops/fff)](https://dev.azure.com/nanoframework/feed/_packaging?_a=package&feed=sandbox&package=nanoFramework.CoreLibrary.NoReflection&protocolType=NuGet&view=overview) |
18+
19+
## BCL Flavours
20+
21+
The **nanoFramework** Base Class Library is provided in two flavours: with or without support for System.Reflection namespace. The reason for this is that the reflection API adds up a significant size to the DLL and image size. For targets with smaller flash this can be prohibitive.
1622

1723
## Feedback and documentation
1824

azure-pipelines.yml

Lines changed: 102 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,51 +24,105 @@ resources:
2424
name: nanoframework/nf-tools
2525
endpoint: nanoframework
2626

27-
pool:
28-
vmImage: 'VS2017-Win2016'
29-
30-
variables:
31-
solution: '**/source/*.sln'
32-
buildPlatform: 'Any CPU'
33-
buildConfiguration: 'Release'
34-
nugetPackageName: 'nanoFramework.CoreLibrary'
35-
repoName: 'lib-CoreLibrary'
36-
37-
steps:
38-
39-
# step from template @ nf-tools repo
40-
# all build, update and publish steps
41-
- template: azure-pipelines-templates/class-lib-build.yml@templates
42-
parameters:
43-
sonarCloudProject: 'nanoframework_lib-CoreLibrary'
44-
45-
# update dependencies
46-
- task: UpdatenFDependencies@1
47-
inputs:
48-
gitHubToken: $(GitHubToken)
49-
repositoriesToUpdate: |
50-
lib-nanoFramework.Runtime.Events
51-
lib-nanoFramework.Runtime.Native
52-
lib-Windows.Storage.Streams
53-
lib-Windows.Devices.Adc
54-
lib-Windows.Devices.I2c
55-
lib-Windows.Devices.Pwm
56-
lib-Windows.Devices.Spi
57-
lib-System.Devices.Dac
58-
lib-nanoFramework.Devices.OneWire
59-
lib-nanoFramework.Networking.Sntp
60-
lib-nanoFramework.Hardware.Stm32
61-
lib-nanoFramework.System.Math
62-
lib-nanoFramework.TI.EasyLink
63-
lib-nanoFramework.ResourceManager
64-
Json.NetMF
65-
condition: or( and( succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ), and( succeeded(), contains(variables['getCommitMessage.COMMIT_MESSAGE'], '***UPDATE_DEPENDENTS***') ), eq(variables['UPDATE_DEPENDENTS'], 'true') )
66-
displayName: Update dependent class libs
67-
68-
# step from template @ nf-tools repo
69-
# report error
70-
- template: azure-pipelines-templates/discord-webhook-task.yml@templates
71-
parameters:
72-
status: 'failure'
73-
webhookUrl: '$(DiscordWebhook)'
74-
message: ''
27+
jobs:
28+
29+
##############################
30+
- job: Build_mscorlib
31+
pool:
32+
vmImage: 'VS2017-Win2016'
33+
34+
variables:
35+
solution: '**/source/*.sln'
36+
buildPlatform: 'Any CPU'
37+
buildConfiguration: 'Release'
38+
nugetPackageName: 'nanoFramework.CoreLibrary'
39+
repoName: 'lib-CoreLibrary'
40+
41+
steps:
42+
43+
# step from template @ nf-tools repo
44+
# all build, update and publish steps
45+
- template: azure-pipelines-templates/class-lib-build.yml@templates
46+
parameters:
47+
sonarCloudProject: 'nanoframework_lib-CoreLibrary'
48+
msbuildExtraParams: '/p:DefineConstants="NANOCLR_REFLECTION"'
49+
50+
##############################
51+
- job: Build_mscorlib_no_reflection
52+
pool:
53+
vmImage: 'VS2017-Win2016'
54+
55+
variables:
56+
solution: '**/source/*.sln'
57+
buildPlatform: 'Any CPU'
58+
buildConfiguration: 'Release'
59+
nugetPackageName: 'nanoFramework.CoreLibrary.NoReflection'
60+
repoName: 'lib-CoreLibrary'
61+
62+
steps:
63+
64+
# step from template @ nf-tools repo
65+
# all build, update and publish steps
66+
- template: azure-pipelines-templates/class-lib-build.yml@templates
67+
parameters:
68+
sonarCloudProject: 'nanoframework_lib-CoreLibrary.NoReflection'
69+
70+
##############################
71+
- job: Update_Dependencies
72+
condition: ne( variables['StartReleaseCandidate'], true )
73+
74+
dependsOn:
75+
- Build_mscorlib
76+
- Build_mscorlib_no_reflection
77+
78+
pool:
79+
vmImage: 'VS2017-Win2016'
80+
81+
steps:
82+
# update dependencies
83+
- task: UpdatenFDependencies@1
84+
inputs:
85+
gitHubToken: $(GitHubToken)
86+
repositoriesToUpdate: |
87+
lib-nanoFramework.Runtime.Events
88+
lib-nanoFramework.Runtime.Native
89+
lib-Windows.Storage.Streams
90+
lib-Windows.Devices.Adc
91+
lib-Windows.Devices.I2c
92+
lib-Windows.Devices.Pwm
93+
lib-Windows.Devices.Spi
94+
lib-System.Devices.Dac
95+
lib-nanoFramework.Devices.OneWire
96+
lib-nanoFramework.Networking.Sntp
97+
lib-nanoFramework.Hardware.Stm32
98+
lib-nanoFramework.System.Math
99+
lib-nanoFramework.TI.EasyLink
100+
lib-nanoFramework.ResourceManager
101+
Json.NetMF
102+
condition: or( and( succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ), and( succeeded(), contains(variables['getCommitMessage.COMMIT_MESSAGE'], '***UPDATE_DEPENDENTS***') ), eq(variables['UPDATE_DEPENDENTS'], 'true') )
103+
displayName: Update dependent class libs
104+
105+
##################################
106+
# report build failure to Discord
107+
- job: Report_Build_Failure
108+
109+
dependsOn:
110+
- Build_mscorlib
111+
- Build_mscorlib_no_reflection
112+
- Update_Dependencies
113+
condition: or( failed('Build_mscorlib'), failed('Build_mscorlib_no_reflection'), failed('Update_Dependencies'))
114+
115+
pool:
116+
vmImage: 'VS2017-Win2016'
117+
118+
steps:
119+
120+
- checkout: self
121+
122+
# step from template @ nf-tools repo
123+
# report error
124+
- template: azure-pipelines-templates/discord-webhook-task.yml@templates
125+
parameters:
126+
status: 'failure'
127+
webhookUrl: '$(DiscordWebhook)'
128+
message: ''
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
3+
<metadata>
4+
<id>nanoFramework.CoreLibrary.NoReflection</id>
5+
<version>$version$</version>
6+
<title>nanoFramework.CoreLibrary.NoReflection</title>
7+
<authors>nanoFramework project contributors</authors>
8+
<owners>nanoFramework project contributors</owners>
9+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
10+
<license type="expression">Apache-2.0</license>
11+
<releaseNotes></releaseNotes>
12+
<developmentDependency>false</developmentDependency>
13+
<projectUrl>https://github.com/nanoframework/lib-CoreLibrary</projectUrl>
14+
<iconUrl>https://secure.gravatar.com/avatar/97d0e092247f0716db6d4b47b7d1d1ad</iconUrl>
15+
<repository type="git" url="https://github.com/nanoframework/lib-CoreLibrary" commit="$commit$" />
16+
<copyright>Copyright (c) 2019 The nanoFramework project contributors</copyright>
17+
<description>This package includes the nanoFramework.CoreLibrary assembly for nanoFramework C# projects **WITHOUT** the System.Reflection API.&#10;This package requires a target with mscorlib v$nativeVersion$.&#10;There is another version that includes the System.Reflection API.</description>
18+
<summary>This package includes the nanoFramework.CoreLibrary assembly for nanoFramework C# projects **WITHOUT** the System.Reflection API.</summary>
19+
<tags>nanoFramework C# csharp netmf netnf nanoFramework.CoreLibrary</tags>
20+
</metadata>
21+
<files>
22+
<file src="nanoFramework.CoreLibrary\bin\Release\mscorlib.dll" target="lib\mscorlib.dll" />
23+
<file src="nanoFramework.CoreLibrary\bin\Release\mscorlib.pdb" target="lib\mscorlib.pdb" />
24+
<file src="nanoFramework.CoreLibrary\bin\Release\mscorlib.pdbx" target="lib\mscorlib.pdbx" />
25+
<file src="nanoFramework.CoreLibrary\bin\Release\mscorlib.pe" target="lib\mscorlib.pe" />
26+
<file src="nanoFramework.CoreLibrary\bin\Release\mscorlib.xml" target="lib\mscorlib.xml" />
27+
28+
<!-- readme -->
29+
<file src="readme.txt" target="readme.txt" />
30+
</files>
31+
</package>

source/nanoFramework.CoreLibrary.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<iconUrl>https://secure.gravatar.com/avatar/97d0e092247f0716db6d4b47b7d1d1ad</iconUrl>
1515
<repository type="git" url="https://github.com/nanoframework/lib-CoreLibrary" commit="$commit$" />
1616
<copyright>Copyright (c) 2018 The nanoFramework project contributors</copyright>
17-
<description>This package includes the nanoFramework.CoreLibrary assembly for nanoFramework C# projects.&#10;This package requires a target with mscorlib v$nativeVersion$.</description>
17+
<description>This package includes the nanoFramework.CoreLibrary assembly for nanoFramework C# projects.&#10;This package requires a target with mscorlib v$nativeVersion$.&#10;In case you don't need the System.Reflection API there is another NuGet package without this API.</description>
1818
<summary>This package includes the nanoFramework.CoreLibrary assembly for nanoFramework C# projects.</summary>
1919
<tags>nanoFramework C# csharp netmf netnf nanoFramework.CoreLibrary</tags>
2020
</metadata>

source/nanoFramework.CoreLibrary/CoreLibrary.nfproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<OutputName>mscorlib</OutputName>
2222
<IsCoreAssembly>true</IsCoreAssembly>
2323
<IsMscorlib>true</IsMscorlib>
24-
<DefineConstants>$(DefineConstants);NANOCLR_APPDOMAINS</DefineConstants>
24+
<DefineConstants>$(DefineConstants);</DefineConstants>
2525
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
2626
<DocumentationFile>bin\$(Configuration)\mscorlib.xml</DocumentationFile>
2727
</PropertyGroup>

source/nanoFramework.CoreLibrary/System/AppDomain.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ namespace System
1919
/// <summary>
2020
/// Represents an application domain, which is an isolated environment where applications execute. This class cannot be inherited.
2121
/// </summary>
22+
/// <remarks>Available only in mscorlib build with support for System.Reflection.</remarks>
2223
public sealed class AppDomain : MarshalByRefObject
2324
{
2425
// these fields are required in the native end
2526
#pragma warning disable 0649, 0169
27+
28+
#if NANOCLR_REFLECTION
2629
[FieldNoReflection]
30+
#endif // NANOCLR_REFLECTION
31+
2732
private object _appDomain;
2833
private string _friendlyName;
2934
#pragma warning restore 0649
@@ -46,12 +51,14 @@ private AppDomain()
4651
public static extern AppDomain CreateDomain(String friendlyName);
4752
#pragma warning restore S4200 // Native methods should be wrapped
4853

54+
#if NANOCLR_REFLECTION
4955
/// <summary>
5056
/// Creates a new instance of the specified type. Parameters specify the assembly where the type is defined, and the name of the type.
5157
/// </summary>
5258
/// <param name="assemblyName">The display name of the assembly. See Assembly.FullName.</param>
5359
/// <param name="typeName">The fully qualified name of the requested type, including the namespace but not the assembly, as returned by the Type.FullName property.</param>
5460
/// <returns>An instance of the object specified by typeName.</returns>
61+
/// <remarks>Available only in mscorlib build with support for System.Reflection.</remarks>
5562
public Object CreateInstanceAndUnwrap(String assemblyName, String typeName)
5663
{
5764
var assembly = Assembly.Load(assemblyName);
@@ -61,6 +68,7 @@ public Object CreateInstanceAndUnwrap(String assemblyName, String typeName)
6168

6269
return obj;
6370
}
71+
#endif // NANOCLR_REFLECTION
6472

6573
/// <summary>
6674
/// Gets the current application domain for the current Thread.
@@ -90,11 +98,14 @@ public String FriendlyName
9098
}
9199
}
92100

101+
#if NANOCLR_REFLECTION
102+
93103
/// <summary>
94104
/// Loads an Assembly given its display name.
95105
/// </summary>
96106
/// <param name="assemblyString">The display name of the assembly. See Assembly.FullName.</param>
97107
/// <returns>The loaded assembly.</returns>
108+
/// <remarks>Available only in mscorlib build with support for System.Reflection.</remarks>
98109
public Assembly Load(String assemblyString)
99110
{
100111
var fVersion = false;
@@ -117,10 +128,13 @@ public Assembly Load(String assemblyString)
117128
[MethodImpl(MethodImplOptions.InternalCall)]
118129
private extern Assembly LoadInternal(String assemblyString, bool fVersion, int maj, int min, int build, int rev);
119130

131+
#endif // NANOCLR_REFLECTION
132+
120133
/// <summary>
121134
/// Unloads the specified application domain.
122135
/// </summary>
123136
/// <param name="domain">An application domain to unload.</param>
137+
/// <remarks>Available only in mscorlib build with support for System.Reflection.</remarks>
124138
[MethodImpl(MethodImplOptions.InternalCall)]
125139
#pragma warning disable S4200 // Native methods should be wrapped
126140
public static extern void Unload(AppDomain domain);

source/nanoFramework.CoreLibrary/System/Array.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ namespace System
1313
/// Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.
1414
/// </summary>
1515
[Serializable]
16+
#if NANOCLR_REFLECTION
1617
public abstract class Array : ICloneable, IList
18+
#else
19+
public abstract class Array : IList
20+
#endif // NANOCLR_REFLECTION
1721
{
1822

23+
#if NANOCLR_REFLECTION
1924
/// <summary>
2025
/// Creates a one-dimensional Array of the specified Type and length, with zero-based indexing.
2126
/// </summary>
@@ -24,12 +29,15 @@ public abstract class Array : ICloneable, IList
2429
/// <returns>A new one-dimensional Array of the specified Type with the specified length, using zero-based indexing.</returns>
2530
/// <remarks><para>Unlike most classes, Array provides the CreateInstance method, instead of public constructors, to allow for late bound access.</para>
2631
/// <para>Reference-type elements are initialized to nullNothingnullptrunit a null reference(Nothing in Visual Basic). Value-type elements are initialized to zero.</para>
27-
/// <para>This method is an O(n) operation, where n is length.</para></remarks>
32+
/// <para>This method is an O(n) operation, where n is length.</para>
33+
/// Available only in mscorlib build with support for System.Reflection.</remarks>
2834
[MethodImpl(MethodImplOptions.InternalCall)]
2935
#pragma warning disable S4200 // Native methods should be wrapped
3036
public static extern Array CreateInstance(Type elementType, int length);
3137
#pragma warning restore S4200 // Native methods should be wrapped
3238

39+
#endif // NANOCLR_REFLECTION
40+
3341
#pragma warning disable S4200 // Native methods should be wrapped
3442
/// <summary>
3543
/// Copies a range of elements from an Array starting at the first element and pastes them into another Array starting at the first element. The length is specified as a 32-bit integer.
@@ -185,10 +193,13 @@ void IList.RemoveAt(int index)
185193
throw new NotSupportedException();
186194
}
187195

196+
#if NANOCLR_REFLECTION
197+
188198
/// <summary>
189199
/// Creates a shallow copy of the <see cref="Array"/>.
190200
/// </summary>
191201
/// <returns>A shallow copy of the <see cref="Array"/>.</returns>
202+
/// <remarks>Available only in mscorlib build with support for System.Reflection.</remarks>
192203
public Object Clone()
193204
{
194205
var length = Length;
@@ -198,6 +209,8 @@ public Object Clone()
198209
return destArray;
199210
}
200211

212+
#endif // NANOCLR_REFLECTION
213+
201214
/// <summary>
202215
/// Searches an entire one-dimensional sorted Array for a value using the specified IComparer interface.
203216
/// </summary>

source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
[assembly: AssemblyProduct("nanoFramework mscorlib")]
1515
[assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2017")]
1616

17-
[assembly: AssemblyNativeVersion("100.4.0.0")]
17+
[assembly: AssemblyNativeVersion("100.4.1.0")]

source/nanoFramework.CoreLibrary/System/Collections/ArrayList.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ namespace System.Collections
1313
/// Implements the IList interface using an array whose size is dynamically increased as required.
1414
/// </summary>
1515
[Serializable]
16+
#if NANOCLR_REFLECTION
1617
[DebuggerDisplay("Count = {Count}")]
18+
#endif // NANOCLR_REFLECTION
1719
public class ArrayList : IList, ICloneable
1820
{
1921
private Object[] _items;
@@ -271,10 +273,13 @@ public virtual void Remove(Object value)
271273
public virtual extern void RemoveAt(int index);
272274
#pragma warning restore S4200 // Native methods should be wrapped
273275

276+
#if NANOCLR_REFLECTION
277+
274278
/// <summary>
275279
/// Copies the elements of the <see cref="ArrayList"/> to a new <see cref="Object"/> array.
276280
/// </summary>
277281
/// <returns>An Object array containing copies of the elements of the <see cref="ArrayList"/>.</returns>
282+
/// <remarks>Available only in mscorlib build with support for System.Reflection.</remarks>
278283
public virtual Object[] ToArray()
279284
{
280285
return (Object[])ToArray(typeof(object));
@@ -293,5 +298,8 @@ public virtual Array ToArray(Type type)
293298

294299
return array;
295300
}
301+
302+
#endif // NANOCLR_REFLECTION
303+
296304
}
297305
}

0 commit comments

Comments
 (0)