From 95122773f1fb1d6b98831b7b38458a4827b0123b Mon Sep 17 00:00:00 2001 From: nfbot Date: Wed, 16 Oct 2019 14:55:36 +0000 Subject: [PATCH 01/36] Set version to '1.4.0-preview.{height}' --- source/version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/version.json b/source/version.json index f78f942b..81ac17f5 100644 --- a/source/version.json +++ b/source/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.3.0-preview.{height}", + "version": "1.4.0-preview.{height}", "assemblyVersion": { "precision": "revision" }, From ef16d486c58bdfc2585517e0333ab497b6d5b92d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Fri, 18 Oct 2019 14:10:24 +0100 Subject: [PATCH 02/36] Extract ResourceManager class. (#92) ***PUBLISH_RELEASE*** --- .../CoreLibrary.nfproj | 1 - source/nanoFramework.CoreLibrary/Friends.cs | 1 + .../System/AssemblyInfo.cs | 2 +- .../System/Resources/ResourceManager.cs | 247 ------------------ 4 files changed, 2 insertions(+), 249 deletions(-) delete mode 100644 source/nanoFramework.CoreLibrary/System/Resources/ResourceManager.cs diff --git a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj index 926cfaf6..8b7b2ced 100644 --- a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj +++ b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj @@ -147,7 +147,6 @@ - diff --git a/source/nanoFramework.CoreLibrary/Friends.cs b/source/nanoFramework.CoreLibrary/Friends.cs index 2f8c5f06..d7254b75 100644 --- a/source/nanoFramework.CoreLibrary/Friends.cs +++ b/source/nanoFramework.CoreLibrary/Friends.cs @@ -6,3 +6,4 @@ using System.Runtime.CompilerServices; [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.Math, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")] +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("nanoFramework.ResourceManager, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")] diff --git a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs index 38522c57..85739b16 100644 --- a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs @@ -14,4 +14,4 @@ [assembly: AssemblyProduct("nanoFramework mscorlib")] [assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2017")] -[assembly: AssemblyNativeVersion("100.2.3.0")] +[assembly: AssemblyNativeVersion("100.4.0.0")] diff --git a/source/nanoFramework.CoreLibrary/System/Resources/ResourceManager.cs b/source/nanoFramework.CoreLibrary/System/Resources/ResourceManager.cs deleted file mode 100644 index 3b492644..00000000 --- a/source/nanoFramework.CoreLibrary/System/Resources/ResourceManager.cs +++ /dev/null @@ -1,247 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Globalization; - -namespace System.Resources -{ - /// - /// Represents a resource manager that provides convenient access to culture-specific resources at run time. - /// - public class ResourceManager - { - internal const string _fileExtension = ".nanoresources"; - internal const string _resourcesExtension = ".resources"; - - private int _resourceFileId; - private Assembly _assembly; - private Assembly _baseAssembly; - private string _baseName; - internal string _cultureName; - private ResourceManager _rmFallback; - - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern private object GetObjectInternal(short id); - - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern private object GetObjectInternal(short id, int offset, int length); - - [MethodImpl(MethodImplOptions.InternalCall)] - private static extern int FindResource(string baseName, Assembly assembly); - - /// - /// Initializes a new instance of the ResourceManager class that looks up resources contained in files with the specified root name in the given assembly. - /// - /// The root name of the resource file without its extension but including any fully qualified namespace name. - /// For example, the root name for the resource file named MyApplication.MyResource.en-US.resources is MyApplication.MyResource. - /// The main assembly for the resources. - public ResourceManager(string baseName, Assembly assembly) - : this(baseName, assembly, CultureInfo.CurrentUICulture.Name, true) - { - } - - internal ResourceManager(string baseName, Assembly assembly, string cultureName, bool fThrowOnFailure) - { - if (!Initialize(baseName, assembly, cultureName)) - { - if (fThrowOnFailure) - { -#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one - throw new ArgumentException(); -#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one - } - } - } - - internal ResourceManager(string baseName, string cultureName, int iResourceFileId, Assembly assemblyBase, Assembly assemblyResource) - { - //found resource - this._baseAssembly = assemblyBase; - this._assembly = assemblyResource; - this._baseName = baseName; - this._cultureName = cultureName; - this._resourceFileId = iResourceFileId; - } - - private bool IsValid - { - get { return _resourceFileId >= 0; } - } - - private string GetParentCultureName(string cultureName) - { - int iDash = cultureName.LastIndexOf('-'); - if (iDash < 0) - cultureName = ""; - else - cultureName = cultureName.Substring(0, iDash); - - return cultureName; - } - - internal bool Initialize(string baseName, Assembly assembly, string cultureName) - { - string cultureNameSav = cultureName; - Assembly assemblySav = assembly; - - _resourceFileId = -1; //set to invalid state - - bool fTryBaseAssembly = false; - - while (true) - { - bool fInvariantCulture = (cultureName == ""); - - string[] splitName = assemblySav.FullName.Split(','); - - string assemblyName = splitName[0]; - - if (!fInvariantCulture) - { - assemblyName = assemblyName + "." + cultureName; - } - else if (!fTryBaseAssembly) - { - assemblyName = assemblyName + _resourcesExtension; - } - - // append version - if (splitName.Length >= 1 && splitName[1] != null) - { - assemblyName += ", " + splitName[1].Trim(); - } - - assembly = Assembly.Load(assemblyName, false); - - if (assembly != null) - { - if (Initialize(baseName, assemblySav, cultureNameSav, assembly)) - return true; - } - - if (!fInvariantCulture) - { - cultureName = GetParentCultureName(cultureName); - } - else if (!fTryBaseAssembly) - { - fTryBaseAssembly = true; - } - else - { - break; - } - } - - return false; - } - - internal bool Initialize(string baseName, Assembly assemblyBase, string cultureName, Assembly assemblyResource) - { - while (true) - { - string resourceName = baseName; - bool fInvariantCulture = (cultureName == ""); - - if (!fInvariantCulture) - { - resourceName = baseName + "." + cultureName; - } - - resourceName = resourceName + _fileExtension; - - int iResourceFileId = FindResource(resourceName, assemblyResource); - - if (iResourceFileId >= 0) - { - //found resource - this._baseAssembly = assemblyBase; - this._assembly = assemblyResource; - this._baseName = baseName; - this._cultureName = cultureName; - this._resourceFileId = iResourceFileId; - - break; - } - else if (fInvariantCulture) - { - break; - } - - cultureName = GetParentCultureName(cultureName); - } - - return this.IsValid; - } - - private object GetObjectFromId(short id) - { - ResourceManager rm = this; - - while (rm != null) - { - object obj = rm.GetObjectInternal(id); - - if (obj != null) - return obj; - - if (rm._rmFallback == null) - { - if (rm._cultureName != "") - { - string cultureNameParent = GetParentCultureName(rm._cultureName); - ResourceManager rmFallback = new ResourceManager(_baseName, _baseAssembly, cultureNameParent, false); - - if (rmFallback.IsValid) - rm._rmFallback = rmFallback; - } - } - - rm = rm._rmFallback; - } - -#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one - throw new ArgumentException(); -#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one - } - - private object GetObjectChunkFromId(short id, int offset, int length) - { - ResourceManager rm = this; - - while (rm != null) - { - object obj = rm.GetObjectInternal(id, offset, length); - - if (obj != null) - return obj; - - if (rm._rmFallback == null) - { - if (rm._cultureName != "") - { - string cultureNameParent = GetParentCultureName(rm._cultureName); - ResourceManager rmFallback = new ResourceManager(_baseName, _baseAssembly, cultureNameParent, false); - - if (rmFallback.IsValid) - rm._rmFallback = rmFallback; - } - } - - rm = rm._rmFallback; - } - -#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one - throw new ArgumentException(); -#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one - } - - [MethodImpl(MethodImplOptions.InternalCall)] - internal static extern object GetObject(ResourceManager rm, Enum id); - } -} From a08ed975b26e9c361c78f7eb04a1a2eaec5c4a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Fri, 18 Oct 2019 15:06:43 +0100 Subject: [PATCH 03/36] Work CD-CI - Add nanoFramework.ResourceManager to dependents list. ***NO_CI*** --- azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 12175c98..876ed37c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -60,6 +60,7 @@ steps: lib-nanoFramework.Hardware.Stm32 lib-nanoFramework.System.Math lib-nanoFramework.TI.EasyLink + lib-nanoFramework.ResourceManager Json.NetMF 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') ) displayName: Update dependent class libs From 14ba19c8e86488ba4d5256bd6f538242d9bd45f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 23 Oct 2019 10:24:25 +0100 Subject: [PATCH 04/36] Extract Sytem.Reflection API (#93) ***PUBLISH_RELEASE*** --- README.md | 12 +- azure-pipelines.yml | 150 +++++++++---- ...oFramework.CoreLibrary.NoReflection.nuspec | 31 +++ source/nanoFramework.CoreLibrary.nuspec | 2 +- .../CoreLibrary.nfproj | 2 +- .../System/AppDomain.cs | 14 ++ .../nanoFramework.CoreLibrary/System/Array.cs | 15 +- .../System/AssemblyInfo.cs | 2 +- .../System/Collections/ArrayList.cs | 8 + .../System/Collections/Queue.cs | 2 + .../System/Collections/stack.cs | 2 + .../System/Delegate.cs | 210 +++++++++--------- .../System/Diagnostics/DebuggerAttributes.cs | 6 + .../nanoFramework.CoreLibrary/System/Enum.cs | 5 + .../System/Exception.cs | 4 + .../System/ICustomFormatter.cs | 5 + .../System/IFormatProvider.cs | 6 + .../System/IFormattable.cs | 6 + .../System/Object.cs | 18 ++ .../System/Reflection/Assembly.cs | 5 + .../System/Reflection/AssemblyAttributes.cs | 3 + .../System/Reflection/AssemblyNameFlags.cs | 5 + .../System/Reflection/Binder.cs | 5 + .../System/Reflection/BindingFlags.cs | 5 + .../System/Reflection/ConstructorInfo.cs | 5 + .../Reflection/DefaultMemberAttribute.cs | 5 + .../System/Reflection/FieldInfo.cs | 5 +- .../System/Reflection/IReflect.cs | 5 + .../System/Reflection/MemberInfo.cs | 5 + .../System/Reflection/MemberTypes.cs | 5 + .../System/Reflection/MethodBase.cs | 5 + .../System/Reflection/MethodInfo.cs | 5 + .../System/Reflection/PropertyInfo.cs | 5 + .../Reflection/RuntimeConstructorInfo.cs | 4 + .../System/Reflection/RuntimeFieldInfo.cs | 4 + .../System/Reflection/RuntimeMethodInfo.cs | 4 + .../System/RuntimeType.cs | 5 + .../System/String.cs | 5 + .../System/Threading/Thread.cs | 1 + .../nanoFramework.CoreLibrary/System/Type.cs | 8 + source/version.json | 2 +- 41 files changed, 441 insertions(+), 160 deletions(-) create mode 100644 source/nanoFramework.CoreLibrary.NoReflection.nuspec diff --git a/README.md b/README.md index 729c18fb..2148fd94 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,20 @@ ----- -### Welcome to the **nanoFramework** Core Library repository! +### Welcome to the **nanoFramework** Base Class Library repository! ## Build status | Component | Build Status | NuGet Package | |:-|---|---| -| 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/) | -| 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) | +| 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/) | +| 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/) | +| 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) | +| 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) | + +## BCL Flavours + +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. ## Feedback and documentation diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 876ed37c..597334da 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -24,51 +24,105 @@ resources: name: nanoframework/nf-tools endpoint: nanoframework -pool: - vmImage: 'VS2017-Win2016' - -variables: - solution: '**/source/*.sln' - buildPlatform: 'Any CPU' - buildConfiguration: 'Release' - nugetPackageName: 'nanoFramework.CoreLibrary' - repoName: 'lib-CoreLibrary' - -steps: - -# step from template @ nf-tools repo -# all build, update and publish steps -- template: azure-pipelines-templates/class-lib-build.yml@templates - parameters: - sonarCloudProject: 'nanoframework_lib-CoreLibrary' - -# update dependencies -- task: UpdatenFDependencies@1 - inputs: - gitHubToken: $(GitHubToken) - repositoriesToUpdate: | - lib-nanoFramework.Runtime.Events - lib-nanoFramework.Runtime.Native - lib-Windows.Storage.Streams - lib-Windows.Devices.Adc - lib-Windows.Devices.I2c - lib-Windows.Devices.Pwm - lib-Windows.Devices.Spi - lib-System.Devices.Dac - lib-nanoFramework.Devices.OneWire - lib-nanoFramework.Networking.Sntp - lib-nanoFramework.Hardware.Stm32 - lib-nanoFramework.System.Math - lib-nanoFramework.TI.EasyLink - lib-nanoFramework.ResourceManager - Json.NetMF - 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') ) - displayName: Update dependent class libs - -# step from template @ nf-tools repo -# report error -- template: azure-pipelines-templates/discord-webhook-task.yml@templates - parameters: - status: 'failure' - webhookUrl: '$(DiscordWebhook)' - message: '' +jobs: + +############################## +- job: Build_mscorlib + pool: + vmImage: 'VS2017-Win2016' + + variables: + solution: '**/source/*.sln' + buildPlatform: 'Any CPU' + buildConfiguration: 'Release' + nugetPackageName: 'nanoFramework.CoreLibrary' + repoName: 'lib-CoreLibrary' + + steps: + + # step from template @ nf-tools repo + # all build, update and publish steps + - template: azure-pipelines-templates/class-lib-build.yml@templates + parameters: + sonarCloudProject: 'nanoframework_lib-CoreLibrary' + msbuildExtraParams: '/p:DefineConstants="NANOCLR_REFLECTION"' + +############################## +- job: Build_mscorlib_no_reflection + pool: + vmImage: 'VS2017-Win2016' + + variables: + solution: '**/source/*.sln' + buildPlatform: 'Any CPU' + buildConfiguration: 'Release' + nugetPackageName: 'nanoFramework.CoreLibrary.NoReflection' + repoName: 'lib-CoreLibrary' + + steps: + + # step from template @ nf-tools repo + # all build, update and publish steps + - template: azure-pipelines-templates/class-lib-build.yml@templates + parameters: + sonarCloudProject: 'nanoframework_lib-CoreLibrary.NoReflection' + +############################## +- job: Update_Dependencies + condition: ne( variables['StartReleaseCandidate'], true ) + + dependsOn: + - Build_mscorlib + - Build_mscorlib_no_reflection + + pool: + vmImage: 'VS2017-Win2016' + + steps: + # update dependencies + - task: UpdatenFDependencies@1 + inputs: + gitHubToken: $(GitHubToken) + repositoriesToUpdate: | + lib-nanoFramework.Runtime.Events + lib-nanoFramework.Runtime.Native + lib-Windows.Storage.Streams + lib-Windows.Devices.Adc + lib-Windows.Devices.I2c + lib-Windows.Devices.Pwm + lib-Windows.Devices.Spi + lib-System.Devices.Dac + lib-nanoFramework.Devices.OneWire + lib-nanoFramework.Networking.Sntp + lib-nanoFramework.Hardware.Stm32 + lib-nanoFramework.System.Math + lib-nanoFramework.TI.EasyLink + lib-nanoFramework.ResourceManager + Json.NetMF + 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') ) + displayName: Update dependent class libs + +################################## +# report build failure to Discord +- job: Report_Build_Failure + + dependsOn: + - Build_mscorlib + - Build_mscorlib_no_reflection + - Update_Dependencies + condition: or( failed('Build_mscorlib'), failed('Build_mscorlib_no_reflection'), failed('Update_Dependencies')) + + pool: + vmImage: 'VS2017-Win2016' + + steps: + + - checkout: self + + # step from template @ nf-tools repo + # report error + - template: azure-pipelines-templates/discord-webhook-task.yml@templates + parameters: + status: 'failure' + webhookUrl: '$(DiscordWebhook)' + message: '' diff --git a/source/nanoFramework.CoreLibrary.NoReflection.nuspec b/source/nanoFramework.CoreLibrary.NoReflection.nuspec new file mode 100644 index 00000000..8d321dc9 --- /dev/null +++ b/source/nanoFramework.CoreLibrary.NoReflection.nuspec @@ -0,0 +1,31 @@ + + + + nanoFramework.CoreLibrary.NoReflection + $version$ + nanoFramework.CoreLibrary.NoReflection + nanoFramework project contributors + nanoFramework project contributors + false + Apache-2.0 + + false + https://github.com/nanoframework/lib-CoreLibrary + https://secure.gravatar.com/avatar/97d0e092247f0716db6d4b47b7d1d1ad + + Copyright (c) 2019 The nanoFramework project contributors + This package includes the nanoFramework.CoreLibrary assembly for nanoFramework C# projects **WITHOUT** the System.Reflection API. This package requires a target with mscorlib v$nativeVersion$. There is another version that includes the System.Reflection API. + This package includes the nanoFramework.CoreLibrary assembly for nanoFramework C# projects **WITHOUT** the System.Reflection API. + nanoFramework C# csharp netmf netnf nanoFramework.CoreLibrary + + + + + + + + + + + + diff --git a/source/nanoFramework.CoreLibrary.nuspec b/source/nanoFramework.CoreLibrary.nuspec index b6258e39..399dd42c 100644 --- a/source/nanoFramework.CoreLibrary.nuspec +++ b/source/nanoFramework.CoreLibrary.nuspec @@ -14,7 +14,7 @@ https://secure.gravatar.com/avatar/97d0e092247f0716db6d4b47b7d1d1ad Copyright (c) 2018 The nanoFramework project contributors - This package includes the nanoFramework.CoreLibrary assembly for nanoFramework C# projects. This package requires a target with mscorlib v$nativeVersion$. + This package includes the nanoFramework.CoreLibrary assembly for nanoFramework C# projects. This package requires a target with mscorlib v$nativeVersion$. In case you don't need the System.Reflection API there is another NuGet package without this API. This package includes the nanoFramework.CoreLibrary assembly for nanoFramework C# projects. nanoFramework C# csharp netmf netnf nanoFramework.CoreLibrary diff --git a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj index 8b7b2ced..588425c2 100644 --- a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj +++ b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj @@ -21,7 +21,7 @@ mscorlib true true - $(DefineConstants);NANOCLR_APPDOMAINS + $(DefineConstants); v1.0 bin\$(Configuration)\mscorlib.xml diff --git a/source/nanoFramework.CoreLibrary/System/AppDomain.cs b/source/nanoFramework.CoreLibrary/System/AppDomain.cs index 9554545c..4c3d35b6 100644 --- a/source/nanoFramework.CoreLibrary/System/AppDomain.cs +++ b/source/nanoFramework.CoreLibrary/System/AppDomain.cs @@ -19,11 +19,16 @@ namespace System /// /// Represents an application domain, which is an isolated environment where applications execute. This class cannot be inherited. /// + /// Available only in mscorlib build with support for System.Reflection. public sealed class AppDomain : MarshalByRefObject { // these fields are required in the native end #pragma warning disable 0649, 0169 + +#if NANOCLR_REFLECTION [FieldNoReflection] +#endif // NANOCLR_REFLECTION + private object _appDomain; private string _friendlyName; #pragma warning restore 0649 @@ -46,12 +51,14 @@ private AppDomain() public static extern AppDomain CreateDomain(String friendlyName); #pragma warning restore S4200 // Native methods should be wrapped +#if NANOCLR_REFLECTION /// /// Creates a new instance of the specified type. Parameters specify the assembly where the type is defined, and the name of the type. /// /// The display name of the assembly. See Assembly.FullName. /// The fully qualified name of the requested type, including the namespace but not the assembly, as returned by the Type.FullName property. /// An instance of the object specified by typeName. + /// Available only in mscorlib build with support for System.Reflection. public Object CreateInstanceAndUnwrap(String assemblyName, String typeName) { var assembly = Assembly.Load(assemblyName); @@ -61,6 +68,7 @@ public Object CreateInstanceAndUnwrap(String assemblyName, String typeName) return obj; } +#endif // NANOCLR_REFLECTION /// /// Gets the current application domain for the current Thread. @@ -90,11 +98,14 @@ public String FriendlyName } } +#if NANOCLR_REFLECTION + /// /// Loads an Assembly given its display name. /// /// The display name of the assembly. See Assembly.FullName. /// The loaded assembly. + /// Available only in mscorlib build with support for System.Reflection. public Assembly Load(String assemblyString) { var fVersion = false; @@ -117,10 +128,13 @@ public Assembly Load(String assemblyString) [MethodImpl(MethodImplOptions.InternalCall)] private extern Assembly LoadInternal(String assemblyString, bool fVersion, int maj, int min, int build, int rev); +#endif // NANOCLR_REFLECTION + /// /// Unloads the specified application domain. /// /// An application domain to unload. + /// Available only in mscorlib build with support for System.Reflection. [MethodImpl(MethodImplOptions.InternalCall)] #pragma warning disable S4200 // Native methods should be wrapped public static extern void Unload(AppDomain domain); diff --git a/source/nanoFramework.CoreLibrary/System/Array.cs b/source/nanoFramework.CoreLibrary/System/Array.cs index 2dfbfb63..f848a744 100644 --- a/source/nanoFramework.CoreLibrary/System/Array.cs +++ b/source/nanoFramework.CoreLibrary/System/Array.cs @@ -13,9 +13,14 @@ namespace System /// Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime. /// [Serializable] +#if NANOCLR_REFLECTION public abstract class Array : ICloneable, IList +#else + public abstract class Array : IList +#endif // NANOCLR_REFLECTION { +#if NANOCLR_REFLECTION /// /// Creates a one-dimensional Array of the specified Type and length, with zero-based indexing. /// @@ -24,12 +29,15 @@ public abstract class Array : ICloneable, IList /// A new one-dimensional Array of the specified Type with the specified length, using zero-based indexing. /// Unlike most classes, Array provides the CreateInstance method, instead of public constructors, to allow for late bound access. /// Reference-type elements are initialized to nullNothingnullptrunit a null reference(Nothing in Visual Basic). Value-type elements are initialized to zero. - /// This method is an O(n) operation, where n is length. + /// This method is an O(n) operation, where n is length. + /// Available only in mscorlib build with support for System.Reflection. [MethodImpl(MethodImplOptions.InternalCall)] #pragma warning disable S4200 // Native methods should be wrapped public static extern Array CreateInstance(Type elementType, int length); #pragma warning restore S4200 // Native methods should be wrapped +#endif // NANOCLR_REFLECTION + #pragma warning disable S4200 // Native methods should be wrapped /// /// 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) throw new NotSupportedException(); } +#if NANOCLR_REFLECTION + /// /// Creates a shallow copy of the . /// /// A shallow copy of the . + /// Available only in mscorlib build with support for System.Reflection. public Object Clone() { var length = Length; @@ -198,6 +209,8 @@ public Object Clone() return destArray; } +#endif // NANOCLR_REFLECTION + /// /// Searches an entire one-dimensional sorted Array for a value using the specified IComparer interface. /// diff --git a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs index 85739b16..ad149b7d 100644 --- a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs @@ -14,4 +14,4 @@ [assembly: AssemblyProduct("nanoFramework mscorlib")] [assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2017")] -[assembly: AssemblyNativeVersion("100.4.0.0")] +[assembly: AssemblyNativeVersion("100.4.1.0")] diff --git a/source/nanoFramework.CoreLibrary/System/Collections/ArrayList.cs b/source/nanoFramework.CoreLibrary/System/Collections/ArrayList.cs index 0dff1202..5121efbc 100644 --- a/source/nanoFramework.CoreLibrary/System/Collections/ArrayList.cs +++ b/source/nanoFramework.CoreLibrary/System/Collections/ArrayList.cs @@ -13,7 +13,9 @@ namespace System.Collections /// Implements the IList interface using an array whose size is dynamically increased as required. /// [Serializable] +#if NANOCLR_REFLECTION [DebuggerDisplay("Count = {Count}")] +#endif // NANOCLR_REFLECTION public class ArrayList : IList, ICloneable { private Object[] _items; @@ -271,10 +273,13 @@ public virtual void Remove(Object value) public virtual extern void RemoveAt(int index); #pragma warning restore S4200 // Native methods should be wrapped +#if NANOCLR_REFLECTION + /// /// Copies the elements of the to a new array. /// /// An Object array containing copies of the elements of the . + /// Available only in mscorlib build with support for System.Reflection. public virtual Object[] ToArray() { return (Object[])ToArray(typeof(object)); @@ -293,5 +298,8 @@ public virtual Array ToArray(Type type) return array; } + +#endif // NANOCLR_REFLECTION + } } diff --git a/source/nanoFramework.CoreLibrary/System/Collections/Queue.cs b/source/nanoFramework.CoreLibrary/System/Collections/Queue.cs index 241e72ee..b47348a9 100644 --- a/source/nanoFramework.CoreLibrary/System/Collections/Queue.cs +++ b/source/nanoFramework.CoreLibrary/System/Collections/Queue.cs @@ -12,7 +12,9 @@ namespace System.Collections /// /// A circular-array implementation of a queue. Enqueue can be O(n). Dequeue is O(1). /// +#if NANOCLR_REFLECTION [DebuggerDisplay("Count = {Count}")] +#endif // NANOCLR_REFLECTION [Serializable] public class Queue : ICollection, ICloneable { diff --git a/source/nanoFramework.CoreLibrary/System/Collections/stack.cs b/source/nanoFramework.CoreLibrary/System/Collections/stack.cs index 0ffd0cce..dd80349b 100644 --- a/source/nanoFramework.CoreLibrary/System/Collections/stack.cs +++ b/source/nanoFramework.CoreLibrary/System/Collections/stack.cs @@ -13,7 +13,9 @@ namespace System.Collections /// An array implementation of a stack. Push can be O(n). Pop is O(1). /// [Serializable] +#if NANOCLR_REFLECTION [DebuggerDisplay("Count = {Count}")] +#endif // NANOCLR_REFLECTION public class Stack : ICollection, ICloneable { private Object[] _array; // Storage for stack elements diff --git a/source/nanoFramework.CoreLibrary/System/Delegate.cs b/source/nanoFramework.CoreLibrary/System/Delegate.cs index e8ae8a9e..bd15d195 100644 --- a/source/nanoFramework.CoreLibrary/System/Delegate.cs +++ b/source/nanoFramework.CoreLibrary/System/Delegate.cs @@ -1,111 +1,115 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// -namespace System -{ - using Reflection; - using Runtime.CompilerServices; - /// - /// Represents a delegate, which is a data structure that refers to a static method or to a class instance and an instance method of that class. - /// - [Serializable] -#pragma warning disable CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode() -#pragma warning disable CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode() - /////////////////////////////////////////////////////////////////////////////////////////////////////// - // GetHashCode() implementation is provided by general native function CLR_RT_HeapBlock::GetHashCode // - /////////////////////////////////////////////////////////////////////////////////////////////////////// -#pragma warning disable S1206 // "Equals(Object)" and "GetHashCode()" should be overridden in pairs - public abstract class Delegate -#pragma warning restore S1206 // "Equals(Object)" and "GetHashCode()" should be overridden in pairs -#pragma warning restore CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode() -#pragma warning restore CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode() - { - - /// - /// Determines whether the specified object and the current delegate are of the same type and share the same targets, methods, and invocation list. - /// - /// The object to compare with the current delegate. - /// true if obj and the current delegate have the same targets, methods, and invocation list; otherwise, false. - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public override extern bool Equals(Object obj); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Concatenates the invocation lists of two delegates. - /// - /// The delegate whose invocation list comes first. - /// The delegate whose invocation list comes last. - /// A new delegate with an invocation list that concatenates the invocation lists of a and b in that order. Returns a if b is null reference (Nothing in Visual Basic), returns b if a is a null reference, and returns a null reference if both a and b are null references. - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public static extern Delegate Combine(Delegate a, Delegate b); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Gets the method represented by the delegate. - /// - /// - /// A MethodInfo describing the method represented by the delegate. - /// - public extern MethodInfo Method - { - [MethodImpl(MethodImplOptions.InternalCall)] - get; +// +// Copyright (c) 2017 The nanoFramework project contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// +namespace System +{ + using Reflection; + using Runtime.CompilerServices; + /// + /// Represents a delegate, which is a data structure that refers to a static method or to a class instance and an instance method of that class. + /// + [Serializable] +#pragma warning disable CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode() +#pragma warning disable CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode() + /////////////////////////////////////////////////////////////////////////////////////////////////////// + // GetHashCode() implementation is provided by general native function CLR_RT_HeapBlock::GetHashCode // + /////////////////////////////////////////////////////////////////////////////////////////////////////// +#pragma warning disable S1206 // "Equals(Object)" and "GetHashCode()" should be overridden in pairs + public abstract class Delegate +#pragma warning restore S1206 // "Equals(Object)" and "GetHashCode()" should be overridden in pairs +#pragma warning restore CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode() +#pragma warning restore CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode() + { + + /// + /// Determines whether the specified object and the current delegate are of the same type and share the same targets, methods, and invocation list. + /// + /// The object to compare with the current delegate. + /// true if obj and the current delegate have the same targets, methods, and invocation list; otherwise, false. + [MethodImpl(MethodImplOptions.InternalCall)] +#pragma warning disable S4200 // Native methods should be wrapped + public override extern bool Equals(Object obj); +#pragma warning restore S4200 // Native methods should be wrapped + + /// + /// Concatenates the invocation lists of two delegates. + /// + /// The delegate whose invocation list comes first. + /// The delegate whose invocation list comes last. + /// A new delegate with an invocation list that concatenates the invocation lists of a and b in that order. Returns a if b is null reference (Nothing in Visual Basic), returns b if a is a null reference, and returns a null reference if both a and b are null references. + [MethodImpl(MethodImplOptions.InternalCall)] +#pragma warning disable S4200 // Native methods should be wrapped + public static extern Delegate Combine(Delegate a, Delegate b); +#pragma warning restore S4200 // Native methods should be wrapped + +#if NANOCLR_REFLECTION + + /// + /// Gets the method represented by the delegate. + /// + /// + /// A MethodInfo describing the method represented by the delegate. + /// + /// Available only in mscorlib build with support for System.Reflection. + public extern MethodInfo Method + { + [MethodImpl(MethodImplOptions.InternalCall)] + get; } /// /// Returns the invocation list of the delegate. /// - /// - /// An array of delegates representing the invocation list of the current delegate. - /// + /// + /// An array of delegates representing the invocation list of the current delegate. + /// [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped +#pragma warning disable S4200 // Native methods should be wrapped public virtual extern Delegate[] GetInvocationList(); -#pragma warning restore S4200 // Native methods should be wrapped +#pragma warning restore S4200 // Native methods should be wrapped - /// - /// Gets the class instance on which the current delegate invokes the instance method. - /// - /// - /// The object on which the current delegate invokes the instance method, if the delegate represents an instance method; null reference (Nothing in Visual Basic) if the delegate represents a static method. - /// - public extern Object Target - { - [MethodImpl(MethodImplOptions.InternalCall)] - get; - } - - /// - /// Removes the last occurrence of the invocation list of a delegate from the invocation list of another delegate. - /// - /// The delegate from which to remove the invocation list of value. - /// The delegate that supplies the invocation list to remove from the invocation list of source. - /// A new delegate with an invocation list formed by taking the invocation list of source and removing the last occurrence of the invocation list of value, if the invocation list of value is found within the invocation list of source. Returns source if value is null reference (Nothing in Visual Basic) or if the invocation list of value is not found within the invocation list of source. Returns a null reference if the invocation list of value is equal to the invocation list of source or if source is a null reference. - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public static extern Delegate Remove(Delegate source, Delegate value); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Determines whether the specified delegates are equal. - /// - /// The first delegate to compare. - /// The second delegate to compare. - /// true if d1 is equal to d2; otherwise, false. - [MethodImpl(MethodImplOptions.InternalCall)] - public static extern bool operator ==(Delegate d1, Delegate d2); - - /// - /// Determines whether the specified delegates are not equal. - /// - /// The first delegate to compare. - /// The second delegate to compare. - /// true if d1 is not equal to d2; otherwise, false. - [MethodImpl(MethodImplOptions.InternalCall)] - public static extern bool operator !=(Delegate d1, Delegate d2); - } -} + /// + /// Gets the class instance on which the current delegate invokes the instance method. + /// + /// + /// The object on which the current delegate invokes the instance method, if the delegate represents an instance method; null reference (Nothing in Visual Basic) if the delegate represents a static method. + /// + public extern Object Target + { + [MethodImpl(MethodImplOptions.InternalCall)] + get; + } +#endif // NANOCLR_REFLECTION + + /// + /// Removes the last occurrence of the invocation list of a delegate from the invocation list of another delegate. + /// + /// The delegate from which to remove the invocation list of value. + /// The delegate that supplies the invocation list to remove from the invocation list of source. + /// A new delegate with an invocation list formed by taking the invocation list of source and removing the last occurrence of the invocation list of value, if the invocation list of value is found within the invocation list of source. Returns source if value is null reference (Nothing in Visual Basic) or if the invocation list of value is not found within the invocation list of source. Returns a null reference if the invocation list of value is equal to the invocation list of source or if source is a null reference. + [MethodImpl(MethodImplOptions.InternalCall)] +#pragma warning disable S4200 // Native methods should be wrapped + public static extern Delegate Remove(Delegate source, Delegate value); +#pragma warning restore S4200 // Native methods should be wrapped + + /// + /// Determines whether the specified delegates are equal. + /// + /// The first delegate to compare. + /// The second delegate to compare. + /// true if d1 is equal to d2; otherwise, false. + [MethodImpl(MethodImplOptions.InternalCall)] + public static extern bool operator ==(Delegate d1, Delegate d2); + + /// + /// Determines whether the specified delegates are not equal. + /// + /// The first delegate to compare. + /// The second delegate to compare. + /// true if d1 is not equal to d2; otherwise, false. + [MethodImpl(MethodImplOptions.InternalCall)] + public static extern bool operator !=(Delegate d1, Delegate d2); + } +} diff --git a/source/nanoFramework.CoreLibrary/System/Diagnostics/DebuggerAttributes.cs b/source/nanoFramework.CoreLibrary/System/Diagnostics/DebuggerAttributes.cs index b08c0b8a..0224eb6d 100644 --- a/source/nanoFramework.CoreLibrary/System/Diagnostics/DebuggerAttributes.cs +++ b/source/nanoFramework.CoreLibrary/System/Diagnostics/DebuggerAttributes.cs @@ -226,9 +226,12 @@ public DebuggerBrowsableState State } } +#if NANOCLR_REFLECTION + /// /// Specifies the display proxy for a type. /// + /// Available only in mscorlib build with support for System.Reflection. [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)] public sealed class DebuggerTypeProxyAttribute : Attribute { @@ -401,4 +404,7 @@ public string TargetTypeName set { _targetName = value; } } } + +#endif // NANOCLR_REFLECTION + } diff --git a/source/nanoFramework.CoreLibrary/System/Enum.cs b/source/nanoFramework.CoreLibrary/System/Enum.cs index d2c8685e..9638e20d 100644 --- a/source/nanoFramework.CoreLibrary/System/Enum.cs +++ b/source/nanoFramework.CoreLibrary/System/Enum.cs @@ -17,13 +17,18 @@ public abstract class Enum : ValueType /// Converts the value of this instance to its equivalent string representation. /// /// The string representation of the value of this instance. + /// Available only in mscorlib build with support for System.Reflection. public override String ToString() { +#if NANOCLR_REFLECTION var type = GetType(); var field = type.GetField("value__"); var value = field.GetValue(this); return value.ToString(); +#else + throw new NotImplementedException(); +#endif // NANOCLR_REFLECTION } } diff --git a/source/nanoFramework.CoreLibrary/System/Exception.cs b/source/nanoFramework.CoreLibrary/System/Exception.cs index c5732bce..63e1de05 100644 --- a/source/nanoFramework.CoreLibrary/System/Exception.cs +++ b/source/nanoFramework.CoreLibrary/System/Exception.cs @@ -65,7 +65,11 @@ public virtual String Message { get { +#if NANOCLR_REFLECTION if (_message == null) return "Exception was thrown: " + GetType().FullName; +#else + if (_message == null) return "Exception was thrown"; +#endif // NANOCLR_REFLECTION return _message; } diff --git a/source/nanoFramework.CoreLibrary/System/ICustomFormatter.cs b/source/nanoFramework.CoreLibrary/System/ICustomFormatter.cs index 18e023c0..bbf16998 100644 --- a/source/nanoFramework.CoreLibrary/System/ICustomFormatter.cs +++ b/source/nanoFramework.CoreLibrary/System/ICustomFormatter.cs @@ -4,11 +4,14 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System { /// /// Defines a method that supports custom formatting of the value of an object. /// + /// Available only in mscorlib build with support for System.Reflection. public interface ICustomFormatter { /// @@ -22,3 +25,5 @@ public interface ICustomFormatter } } + +#endif //NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/IFormatProvider.cs b/source/nanoFramework.CoreLibrary/System/IFormatProvider.cs index 77476a97..4ae7c5da 100644 --- a/source/nanoFramework.CoreLibrary/System/IFormatProvider.cs +++ b/source/nanoFramework.CoreLibrary/System/IFormatProvider.cs @@ -4,11 +4,14 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System { /// /// Provides a mechanism for retrieving an object to control formatting. /// + /// Available only in mscorlib build with support for System.Reflection. public interface IFormatProvider { /// @@ -19,3 +22,6 @@ public interface IFormatProvider Object GetFormat(Type formatType); } } + +#endif // NANOCLR_REFLECTION + diff --git a/source/nanoFramework.CoreLibrary/System/IFormattable.cs b/source/nanoFramework.CoreLibrary/System/IFormattable.cs index 3635c542..5a8b6305 100644 --- a/source/nanoFramework.CoreLibrary/System/IFormattable.cs +++ b/source/nanoFramework.CoreLibrary/System/IFormattable.cs @@ -3,11 +3,15 @@ // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // + +#if NANOCLR_REFLECTION + namespace System { /// /// Provides functionality to format the value of an object into a string representation. /// + /// Available only in mscorlib build with support for System.Reflection. public interface IFormattable { /// @@ -19,3 +23,5 @@ public interface IFormattable String ToString(String format, IFormatProvider formatProvider); } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Object.cs b/source/nanoFramework.CoreLibrary/System/Object.cs index f45dea13..4139fe1f 100644 --- a/source/nanoFramework.CoreLibrary/System/Object.cs +++ b/source/nanoFramework.CoreLibrary/System/Object.cs @@ -22,14 +22,27 @@ public Object() { } +#if NANOCLR_REFLECTION + /// /// Returns a string that represents the current object. /// /// A string that represents the current object. + /// Available only in mscorlib build with support for System.Reflection. public virtual String ToString() { return GetType().FullName; } +#else + /// + /// Returns a string that represents the current object. + /// + /// A string that represents the current object. + public virtual String ToString() + { + throw new NotImplementedException(); + } +#endif // NANOCLR_REFLECTION /// /// Determines whether the specified object is equal to the current object. @@ -82,15 +95,20 @@ public static bool Equals(Object objA, Object objB) public virtual extern int GetHashCode(); #pragma warning restore S4200 // Native methods should be wrapped +#if NANOCLR_REFLECTION + /// /// Gets the Type of the current instance. /// /// The exact runtime type of the current instance. + /// Available only in mscorlib build with support for System.Reflection. [MethodImpl(MethodImplOptions.InternalCall)] #pragma warning disable S4200 // Native methods should be wrapped public extern Type GetType(); #pragma warning restore S4200 // Native methods should be wrapped +#endif // NANOCLR_REFLECTION + /// /// Creates a shallow copy of the current Object. /// diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/Assembly.cs b/source/nanoFramework.CoreLibrary/System/Reflection/Assembly.cs index 274cec0e..01d1fbeb 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/Assembly.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/Assembly.cs @@ -4,6 +4,8 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using System; @@ -13,6 +15,7 @@ namespace System.Reflection /// /// Describes an assembly's unique identity in full. /// + /// Available only in mscorlib build with support for System.Reflection. public sealed class AssemblyName { private readonly Assembly _assembly; @@ -300,3 +303,5 @@ internal static Assembly Load(String assemblyString, bool fThrowOnError) internal extern String[] GetManifestResourceNames(); } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/AssemblyAttributes.cs b/source/nanoFramework.CoreLibrary/System/Reflection/AssemblyAttributes.cs index 1186bdb6..fb7d9269 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/AssemblyAttributes.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/AssemblyAttributes.cs @@ -153,10 +153,12 @@ public bool DelaySign } } +#if NANOCLR_REFLECTION /// /// Specifies a bitwise combination of AssemblyNameFlags flags for an assembly, describing just-in-time (JIT) compiler options, /// whether the assembly is retargetable, and whether it has a full or tokenized public key. This class cannot be inherited. /// + /// Available only in mscorlib build with support for System.Reflection. [AttributeUsage(AttributeTargets.Assembly)] public sealed class AssemblyFlagsAttribute : Attribute { @@ -195,6 +197,7 @@ public AssemblyFlagsAttribute(AssemblyNameFlags assemblyFlags) _flags = assemblyFlags; } } +#endif //NANOCLR_REFLECTION /// /// Instructs a compiler to use a specific version number for the Win32 file version resource. The Win32 file version is not required to be the same as the assembly's version number. diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/AssemblyNameFlags.cs b/source/nanoFramework.CoreLibrary/System/Reflection/AssemblyNameFlags.cs index 0d7809fd..4bcbc450 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/AssemblyNameFlags.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/AssemblyNameFlags.cs @@ -4,12 +4,15 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using System; /// /// Provides information about an Assembly reference. /// + /// Available only in mscorlib build with support for System.Reflection. [Serializable, FlagsAttribute] public enum AssemblyNameFlags { @@ -64,3 +67,5 @@ public enum ProcessorArchitecture Amd64 = 0x0004 } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/Binder.cs b/source/nanoFramework.CoreLibrary/System/Reflection/Binder.cs index b6ae0e09..d5306b68 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/Binder.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/Binder.cs @@ -4,6 +4,8 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using System; @@ -11,8 +13,11 @@ namespace System.Reflection /// /// Selects a member from a list of candidates, and performs type conversion from actual argument type to formal argument type. /// + /// Available only in mscorlib build with support for System.Reflection. [Serializable] public abstract class Binder { } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/BindingFlags.cs b/source/nanoFramework.CoreLibrary/System/Reflection/BindingFlags.cs index 205329ca..ab0a8353 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/BindingFlags.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/BindingFlags.cs @@ -4,12 +4,15 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using System; /// /// Specifies flags that control binding and the way in which the search for members and types is conducted by reflection. /// + /// Available only in mscorlib build with support for System.Reflection. [Flags, Serializable] public enum BindingFlags { @@ -121,3 +124,5 @@ public enum BindingFlags IgnoreReturn = 0x01000000, // This is used in COM Interop } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/ConstructorInfo.cs b/source/nanoFramework.CoreLibrary/System/Reflection/ConstructorInfo.cs index dff6bd7f..a1f432b0 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/ConstructorInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/ConstructorInfo.cs @@ -4,6 +4,8 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using Runtime.CompilerServices; @@ -12,6 +14,7 @@ namespace System.Reflection /// /// Discovers the attributes of a class constructor and provides access to constructor metadata. /// + /// Available only in mscorlib build with support for System.Reflection. [Serializable] public abstract class ConstructorInfo : MethodBase { @@ -54,3 +57,5 @@ public override MemberTypes MemberType #pragma warning restore S4200 // Native methods should be wrapped } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/DefaultMemberAttribute.cs b/source/nanoFramework.CoreLibrary/System/Reflection/DefaultMemberAttribute.cs index 30844230..a2316463 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/DefaultMemberAttribute.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/DefaultMemberAttribute.cs @@ -4,6 +4,8 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using System; @@ -11,6 +13,7 @@ namespace System.Reflection /// /// Defines the member of a type that is the default member used by InvokeMember. /// + /// Available only in mscorlib build with support for System.Reflection. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface), Serializable] public sealed class DefaultMemberAttribute : Attribute { @@ -39,3 +42,5 @@ public String MemberName } } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/FieldInfo.cs b/source/nanoFramework.CoreLibrary/System/Reflection/FieldInfo.cs index 32c81d9b..7bbef69e 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/FieldInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/FieldInfo.cs @@ -4,6 +4,8 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using Runtime.CompilerServices; @@ -12,6 +14,7 @@ namespace System.Reflection /// /// Discovers the attributes of a field and provides access to field metadata. /// + /// Available only in mscorlib build with support for System.Reflection. [Serializable] public abstract class FieldInfo : MemberInfo { @@ -77,4 +80,4 @@ public abstract Type FieldType } } - +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/IReflect.cs b/source/nanoFramework.CoreLibrary/System/Reflection/IReflect.cs index 948a2ea2..f2ae9af2 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/IReflect.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/IReflect.cs @@ -4,6 +4,8 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using System; @@ -11,6 +13,7 @@ namespace System.Reflection /// /// Interoperates with the IDispatch interface. /// + /// Available only in mscorlib build with support for System.Reflection. public interface IReflect { /// @@ -30,3 +33,5 @@ public interface IReflect FieldInfo GetField(String name, BindingFlags bindingAttr); } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/MemberInfo.cs b/source/nanoFramework.CoreLibrary/System/Reflection/MemberInfo.cs index 9532642a..917a13b1 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/MemberInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/MemberInfo.cs @@ -4,6 +4,8 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using System; @@ -11,6 +13,7 @@ namespace System.Reflection /// /// Obtains information about the attributes of a member and provides access to member metadata. /// + /// Available only in mscorlib build with support for System.Reflection. [Serializable] public abstract class MemberInfo { @@ -55,3 +58,5 @@ public abstract Type DeclaringType public abstract object[] GetCustomAttributes(bool inherit); } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/MemberTypes.cs b/source/nanoFramework.CoreLibrary/System/Reflection/MemberTypes.cs index c76971e8..a1d389dd 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/MemberTypes.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/MemberTypes.cs @@ -4,6 +4,8 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using System; @@ -11,6 +13,7 @@ namespace System.Reflection /// /// Marks each type of member that is defined as a derived class of MemberInfo. /// + /// Available only in mscorlib build with support for System.Reflection. [Serializable] public enum MemberTypes { @@ -52,3 +55,5 @@ public enum MemberTypes All = Constructor | Event | Field | Method | Property | TypeInfo | NestedType, } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/MethodBase.cs b/source/nanoFramework.CoreLibrary/System/Reflection/MethodBase.cs index b96011c0..8aabc9a9 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/MethodBase.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/MethodBase.cs @@ -4,6 +4,8 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using Runtime.CompilerServices; @@ -12,6 +14,7 @@ namespace System.Reflection /// /// Provides information about methods and constructors. /// + /// Available only in mscorlib build with support for System.Reflection. [Serializable] public abstract class MethodBase : MemberInfo { @@ -115,3 +118,5 @@ public override extern Type DeclaringType } } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/MethodInfo.cs b/source/nanoFramework.CoreLibrary/System/Reflection/MethodInfo.cs index 34047822..c0a9c036 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/MethodInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/MethodInfo.cs @@ -4,6 +4,8 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using System; @@ -11,6 +13,7 @@ namespace System.Reflection /// /// Discovers the attributes of a method and provides access to method metadata. /// + /// Available only in mscorlib build with support for System.Reflection. [Serializable] public abstract class MethodInfo : MethodBase { @@ -38,3 +41,5 @@ public abstract Type ReturnType } } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/PropertyInfo.cs b/source/nanoFramework.CoreLibrary/System/Reflection/PropertyInfo.cs index 0257fec7..d4af2777 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/PropertyInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/PropertyInfo.cs @@ -4,6 +4,8 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using System; @@ -12,6 +14,7 @@ namespace System.Reflection /// /// Discovers the attributes of a property and provides access to property metadata. /// + /// Available only in mscorlib build with support for System.Reflection. [Serializable] public abstract class PropertyInfo : MemberInfo { @@ -53,3 +56,5 @@ public abstract Type PropertyType #pragma warning restore S4200 // Native methods should be wrapped } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeConstructorInfo.cs b/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeConstructorInfo.cs index 7ddb286a..aee498e1 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeConstructorInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeConstructorInfo.cs @@ -4,6 +4,8 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using System; @@ -13,3 +15,5 @@ internal sealed class RuntimeConstructorInfo : ConstructorInfo { } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeFieldInfo.cs b/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeFieldInfo.cs index fcad6940..b7655c38 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeFieldInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeFieldInfo.cs @@ -4,6 +4,8 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using System; @@ -34,3 +36,5 @@ public override extern Type FieldType public override extern Object GetValue(Object obj); } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeMethodInfo.cs b/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeMethodInfo.cs index 33e16f22..9f513eec 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeMethodInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeMethodInfo.cs @@ -4,6 +4,8 @@ // See LICENSE file in the project root for full license information. // +#if NANOCLR_REFLECTION + namespace System.Reflection { using System; @@ -22,3 +24,5 @@ public override extern Type ReturnType public override extern object[] GetCustomAttributes(bool inherit); } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/RuntimeType.cs b/source/nanoFramework.CoreLibrary/System/RuntimeType.cs index 89f44092..c21d60da 100644 --- a/source/nanoFramework.CoreLibrary/System/RuntimeType.cs +++ b/source/nanoFramework.CoreLibrary/System/RuntimeType.cs @@ -3,6 +3,9 @@ // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // + +#if NANOCLR_REFLECTION + namespace System { using Reflection; @@ -84,3 +87,5 @@ public override extern Type BaseType public override extern object[] GetCustomAttributes(bool inherit); } } + +#endif // NANOCLR_REFLECTION diff --git a/source/nanoFramework.CoreLibrary/System/String.cs b/source/nanoFramework.CoreLibrary/System/String.cs index 5751fc99..1547fa3e 100644 --- a/source/nanoFramework.CoreLibrary/System/String.cs +++ b/source/nanoFramework.CoreLibrary/System/String.cs @@ -763,10 +763,15 @@ public static string Format(string format, params object[] args) if (fmt.Length > 0) { +#if NANOCLR_REFLECTION var method = args[index].GetType().GetMethod("ToString", new Type[] { typeof(string) }); token = (method is null) ? args[index].ToString() : method.Invoke(args[index], new object[] { token }).ToString(); +#else + throw new NotImplementedException(); +#endif // NANOCLR_REFLECTION + } else { diff --git a/source/nanoFramework.CoreLibrary/System/Threading/Thread.cs b/source/nanoFramework.CoreLibrary/System/Threading/Thread.cs index d8a7a901..2758b2cc 100644 --- a/source/nanoFramework.CoreLibrary/System/Threading/Thread.cs +++ b/source/nanoFramework.CoreLibrary/System/Threading/Thread.cs @@ -192,6 +192,7 @@ public extern ThreadState ThreadState /// Returns the current domain in which the current thread is running. /// /// An AppDomain representing the current application domain of the running thread. + /// Available only in mscorlib build with support for System.Reflection. [MethodImpl(MethodImplOptions.InternalCall)] #pragma warning disable S4200 // Native methods should be wrapped public static extern AppDomain GetDomain(); diff --git a/source/nanoFramework.CoreLibrary/System/Type.cs b/source/nanoFramework.CoreLibrary/System/Type.cs index 19f900d2..79ae37a8 100644 --- a/source/nanoFramework.CoreLibrary/System/Type.cs +++ b/source/nanoFramework.CoreLibrary/System/Type.cs @@ -3,14 +3,19 @@ // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // + +#if NANOCLR_REFLECTION + namespace System { + using Reflection; using Runtime.CompilerServices; /// /// Represents type declarations: class types, interface types, array types, value types, enumeration types, type parameters, generic type definitions, and open or closed constructed generic types. /// + /// Available only in mscorlib build with support for System.Reflection. [Serializable] public abstract class Type : MemberInfo, IReflect { @@ -29,6 +34,7 @@ public override extern Type DeclaringType get; } + /// /// Gets the Type with the specified name, performing a case-sensitive search. /// @@ -443,3 +449,5 @@ private static string ParseTypeName(String typeName, ref String assemblyString) } } } + +#endif // NANOCLR_REFLECTION diff --git a/source/version.json b/source/version.json index 81ac17f5..1dc1ace5 100644 --- a/source/version.json +++ b/source/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.4.0-preview.{height}", + "version": "1.4.1-preview.{height}", "assemblyVersion": { "precision": "revision" }, From 8f8375c4ea80163e7c0afc940f8ae85fb4d8eb98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 23 Oct 2019 10:46:50 +0100 Subject: [PATCH 05/36] Work CD-CI - Add missing tasks to update dependencies job. - Update conditions on all jobs. ***NO_CI*** --- azure-pipelines.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 597334da..057b5109 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -79,6 +79,21 @@ jobs: vmImage: 'VS2017-Win2016' steps: + # need this here in order to persist GitHub credentials + - checkout: self + + - script: | + git config --global user.email nanoframework@outlook.com + git config --global user.name nfbot + git config --global core.autocrlf true + displayName: Setup git identity + + - task: NuGetToolInstaller@0 + inputs: + versionSpec: '4.9.3' + condition: ne( variables['StartReleaseCandidate'], true ) + displayName: 'Install specific version of NuGet' + # update dependencies - task: UpdatenFDependencies@1 inputs: From ff8bdb26716491734a74fe6ef2bc5891f6bbef63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 23 Oct 2019 10:47:24 +0100 Subject: [PATCH 06/36] Work CD-CI - Update conditions on all jobs. ***NO_CI*** --- azure-pipelines.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 057b5109..37245249 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -28,6 +28,7 @@ jobs: ############################## - job: Build_mscorlib + condition: eq(variables['UPDATE_DEPENDENTS'], 'false') pool: vmImage: 'VS2017-Win2016' @@ -49,6 +50,7 @@ jobs: ############################## - job: Build_mscorlib_no_reflection + condition: eq(variables['UPDATE_DEPENDENTS'], 'false') pool: vmImage: 'VS2017-Win2016' @@ -69,7 +71,7 @@ jobs: ############################## - job: Update_Dependencies - condition: ne( variables['StartReleaseCandidate'], true ) + condition: and( ne( variables['StartReleaseCandidate'], true ), eq(variables['UPDATE_DEPENDENTS'], true) ) dependsOn: - Build_mscorlib From 226b210da19cb21721270fdda72ccce6c9f57568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Mon, 4 Nov 2019 16:34:14 +0000 Subject: [PATCH 07/36] Extract System.Collections (#94) ***PUBLISH_RELEASE*** ***UPDATE_DEPENDENTS*** --- azure-pipelines.yml | 1 + .../CoreLibrary.nfproj | 5 - source/nanoFramework.CoreLibrary/Friends.cs | 1 + .../nanoFramework.CoreLibrary/System/Array.cs | 5 + .../System/AssemblyInfo.cs | 2 +- .../System/Collections/DictionaryEntry.cs | 36 - .../System/Collections/HashTable.cs | 673 ------------------ .../System/Collections/IDictionary.cs | 75 -- .../System/Collections/IList.cs | 2 +- .../System/Collections/Queue.cs | 179 ----- .../System/Collections/stack.cs | 160 ----- source/version.json | 2 +- 12 files changed, 10 insertions(+), 1131 deletions(-) delete mode 100644 source/nanoFramework.CoreLibrary/System/Collections/DictionaryEntry.cs delete mode 100644 source/nanoFramework.CoreLibrary/System/Collections/HashTable.cs delete mode 100644 source/nanoFramework.CoreLibrary/System/Collections/IDictionary.cs delete mode 100644 source/nanoFramework.CoreLibrary/System/Collections/Queue.cs delete mode 100644 source/nanoFramework.CoreLibrary/System/Collections/stack.cs diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 37245249..e551c098 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -115,6 +115,7 @@ jobs: lib-nanoFramework.System.Math lib-nanoFramework.TI.EasyLink lib-nanoFramework.ResourceManager + lib-nanoFramework.System.Collections Json.NetMF 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') ) displayName: Update dependent class libs diff --git a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj index 588425c2..ca625534 100644 --- a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj +++ b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj @@ -64,17 +64,12 @@ - - - - - diff --git a/source/nanoFramework.CoreLibrary/Friends.cs b/source/nanoFramework.CoreLibrary/Friends.cs index d7254b75..e2692d89 100644 --- a/source/nanoFramework.CoreLibrary/Friends.cs +++ b/source/nanoFramework.CoreLibrary/Friends.cs @@ -7,3 +7,4 @@ [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.Math, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("nanoFramework.ResourceManager, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")] +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("nanoFramework.System.Collections, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")] diff --git a/source/nanoFramework.CoreLibrary/System/Array.cs b/source/nanoFramework.CoreLibrary/System/Array.cs index f848a744..e8af1b53 100644 --- a/source/nanoFramework.CoreLibrary/System/Array.cs +++ b/source/nanoFramework.CoreLibrary/System/Array.cs @@ -158,6 +158,11 @@ extern Object IList.this[int index] set; } + internal void SetByIndex(int index, object value) + { + ((IList)this)[index] = value; + } + int IList.Add(Object value) { throw new NotSupportedException(); diff --git a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs index ad149b7d..806a0916 100644 --- a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs @@ -14,4 +14,4 @@ [assembly: AssemblyProduct("nanoFramework mscorlib")] [assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2017")] -[assembly: AssemblyNativeVersion("100.4.1.0")] +[assembly: AssemblyNativeVersion("100.4.3.0")] diff --git a/source/nanoFramework.CoreLibrary/System/Collections/DictionaryEntry.cs b/source/nanoFramework.CoreLibrary/System/Collections/DictionaryEntry.cs deleted file mode 100644 index e4c7a512..00000000 --- a/source/nanoFramework.CoreLibrary/System/Collections/DictionaryEntry.cs +++ /dev/null @@ -1,36 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -namespace System.Collections -{ - /// - /// Defines a dictionary key/value pair that can be set or retrieved. - /// - public class DictionaryEntry - { - /// - /// Gets or sets the key in the key/value pair. - /// - /// The key in the key/value pair. - public Object Key; - /// - /// Gets or sets the value in the key/value pair. - /// - /// The value in the key/value pair. - public Object Value; - - /// - /// Initializes an instance of the DictionaryEntry type with the specified key and value. - /// - /// The object defined in each key/value pair. - /// The definition associated with key. - public DictionaryEntry(Object key, Object value) - { - Key = key; - Value = value; - } - } -} diff --git a/source/nanoFramework.CoreLibrary/System/Collections/HashTable.cs b/source/nanoFramework.CoreLibrary/System/Collections/HashTable.cs deleted file mode 100644 index 3ecd8200..00000000 --- a/source/nanoFramework.CoreLibrary/System/Collections/HashTable.cs +++ /dev/null @@ -1,673 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -namespace System.Collections -{ - /// - /// HashTable is an Associative Container. - /// Created in March 2010. - /// by Eric Harlow. - /// - public class Hashtable : ICloneable, IDictionary - { - private Entry[] _buckets; - private int _numberOfBuckets; - private int _count; - private int _loadFactor; - private int _maxLoadFactor; - private double _growthFactor; - private const int _defaultCapacity = 4; - private const int _defaultLoadFactor = 2; - - /// - /// Initializes a new, empty instance of the Hashtable class using the default initial capacity and load factor. - /// - public Hashtable() - { - InitializeHashTable(_defaultCapacity, _defaultLoadFactor); - } - - /// - /// Initializes a new, empty instance of the Hashtable class using the specified initial capacity, - /// and the default load factor. - /// - /// The initial capacity of the HashTable - public Hashtable(int capacity) - { - InitializeHashTable(capacity, _defaultLoadFactor); - } - - /// - /// Initializes a new, empty instance of the Hashtable class using the specified initial capacity, - /// load factor. - /// - /// The initial capacity of the HashTable - /// The load factor to cause a rehash - public Hashtable(int capacity, int maxLoadFactor) - { - InitializeHashTable(capacity, maxLoadFactor); - } - - //initialize attributes - private void InitializeHashTable(int capacity, int maxLoadFactor) - { - _buckets = new Entry[capacity]; - _numberOfBuckets = capacity; - _maxLoadFactor = maxLoadFactor; - _growthFactor = 2; - } - -#pragma warning disable S2292 // Trivial properties should be auto-implemented - /// - /// MaxLoadFactor Property is the value used to trigger a rehash. - /// Default value is 2. - /// A higher number can decrease lookup performance for large collections. - /// While a value of 1 maintains a constant time complexity at the cost of increased memory requirements. - /// - public int MaxLoadFactor -#pragma warning restore S2292 // Trivial properties should be auto-implemented - { - get { return _maxLoadFactor; } - set { _maxLoadFactor = value; } - } - -#pragma warning disable S2292 // Trivial properties should be auto-implemented - /// - /// GrowthFactor Property is a multiplier to increase the HashTable size by during a rehash. - /// Default value is 2. - /// - public double GrowthFactor -#pragma warning restore S2292 // Trivial properties should be auto-implemented - { - get { return _growthFactor; } - set { _growthFactor = value; } - } - - //adding for internal purposes - private void Add(ref Entry[] buckets, object key, object value, bool overwrite) - { - var whichBucket = Hash(key, _numberOfBuckets); - var match = EntryForKey(key, buckets[whichBucket]); - - if (match != null && overwrite) - { - //i.e. already exists in table - match.value = value; - return; - } - else if ((match != null && !overwrite)) - { - throw new ArgumentException("key exists"); - } - else - { // insert at front - var newOne = new Entry(key, value, ref buckets[whichBucket]); - buckets[whichBucket] = newOne; - _count++; - } - - _loadFactor = _count / _numberOfBuckets; - } - - // Hash function. - private int Hash(object key, int numOfBuckets) - { - var hashcode = key.GetHashCode(); - - if (hashcode < 0) - { - // don't know how to mod with a negative number - hashcode = hashcode * -1; - } - - return hashcode % numOfBuckets; - } - - //looks up value in bucket - private Entry EntryForKey(object key, Entry head) - { - for (Entry cur = head; cur != null; cur = cur.next) - { - if (cur.key.Equals(key)) - { - return cur; - } - } - - return null; - } - - //Rehashes the table to reduce the load factor - private void Rehash(int newSize) - { - Entry[] newTable = new Entry[newSize]; - _numberOfBuckets = newSize; - _count = 0; - - for (var i = 0; i < _buckets.Length; i++) - { - if (_buckets[i] != null) - { - for (Entry cur = _buckets[i]; cur != null; cur = cur.next) - { - Add(ref newTable, cur.key, cur.value, false); - } - } - } - - _buckets = newTable; - } - - //implementation for KeyCollection and ValueCollection copyTo method - private void CopyToCollection(Array array, int index, EnumeratorType type) - { - if (index < 0 && index > _numberOfBuckets) - { -#pragma warning disable S112 // General exceptions should never be thrown - throw new IndexOutOfRangeException("index"); -#pragma warning restore S112 // General exceptions should never be thrown - } - - for (int i = index; i < _numberOfBuckets; i++) - { - var j = 0; - - for (Entry cur = _buckets[i]; cur != null && j < array.Length; cur = cur.next) - { - if (type == EnumeratorType.KEY) - { - ((IList)array)[j] = cur.key; - } - else - { - ((IList)array)[j] = cur.value; - } - - j++; - } - } - } - - #region ICloneable Members - /// - /// Make a new object which is a copy of the object instanced. - /// - /// A new object that represents a clone of the object. - public object Clone() - { - var ht = new Hashtable(); - ht.InitializeHashTable(_numberOfBuckets, _maxLoadFactor); - ht._count = _count; - ht._loadFactor = _loadFactor; - Array.Copy(_buckets, ht._buckets, _numberOfBuckets); - return ht; - } - - #endregion ICloneable Members - - #region IEnumerable Members - - /// - /// Returns an enumerator that iterates through a collection. - /// - /// An IEnumerator object that can be used to iterate through the collection. - public IEnumerator GetEnumerator() - { - return new HashtableEnumerator(this, EnumeratorType.DE); - } - - #endregion IEnumerable Members - - #region ICollection Members - - /// - /// Gets the number of elements contained in the ICollection. - /// - /// - /// The number of elements contained in the ICollection. - /// - public int Count - { - get { return _count; } - } - - /// - /// Gets a value indicating whether access to the ICollection is synchronized (thread safe). - /// - /// - /// true if access to the ICollection is synchronized (thread safe); otherwise, false. - /// - public bool IsSynchronized - { - get { return false; } - } - - /// - /// Gets an object that can be used to synchronize access to the ICollection. - /// - /// - /// An object that can be used to synchronize access to the ICollection. - /// - public object SyncRoot - { - get { return this; } - } - - /// - /// Copies the elements of the ICollection to an Array, starting at a particular Array index. - /// - /// The one-dimensional Array that is the destination of the elements copied from ICollection. The Array must have zero-based indexing. - /// The zero-based index in array at which copying begins. - public void CopyTo(Array array, int index) - { - if (index < 0 && index > _buckets.Length) -#pragma warning disable S112 // General exceptions should never be thrown - throw new IndexOutOfRangeException("index"); -#pragma warning restore S112 // General exceptions should never be thrown - - for (int i = index; i < _buckets.Length; i++) - { - var j = 0; - - for (Entry cur = _buckets[i]; cur != null && j < array.Length; cur = cur.next) - { - ((IList)array)[j] = new DictionaryEntry(cur.key, cur.value); - j++; - } - } - } - - #endregion ICollection Members - - #region IDictionary Members - - /// - /// Gets a value indicating whether the IDictionary object is read-only. - /// - /// - /// true if the IDictionary object is read-only; otherwise, false. - /// - public bool IsReadOnly - { - get { return false; } - } - - /// - /// Gets a value indicating whether the IDictionary object has a fixed size. - /// - /// - /// true if the IDictionary object has a fixed size; otherwise, false. - /// - public bool IsFixedSize - { - get { return false; } - } - - /// - /// Gets an ICollection object containing the keys of the IDictionary object. - /// - /// - /// An ICollection object containing the keys of the IDictionary object. - /// - public ICollection Keys - { - get - { - return new KeyCollection(this); - } - } - - /// - /// Gets an ICollection object containing the values in the IDictionary object. - /// - /// - /// An ICollection object containing the values in the IDictionary object. - /// - public ICollection Values - { - get - { - return new ValueCollection(this); - } - } - - /// - /// Gets or sets the element with the specified key. - /// - /// The key of the element to get or set. - /// The element with the specified key, or if the key does not exist. - public object this[object key] - { - get - { - if (key == null) - { - throw new ArgumentNullException("key is null"); - } - - var whichBucket = Hash(key, _numberOfBuckets); - var match = EntryForKey(key, _buckets[whichBucket]); - - if (match != null) - { - return match.value; - } - - return null; - } - set - { - if (key == null) - { - throw new ArgumentNullException("key is null"); - } - - Add(ref _buckets ,key,value,true); - - if (_loadFactor >= _maxLoadFactor) - { - Rehash((int)(_numberOfBuckets * _growthFactor)); - } - } - } - - /// - /// Adds an element with the provided key and value to the IDictionary object. - /// - /// The Object to use as the key of the element to add. - /// The Object to use as the value of the element to add. - public void Add(object key, object value) - { - if (key == null) throw new ArgumentNullException("key is null"); - - Add(ref _buckets, key, value, false); - - if (_loadFactor >= _maxLoadFactor) - { - Rehash((int)(_numberOfBuckets * _growthFactor)); - } - } - - /// - /// Removes all elements from the IDictionary object. - /// - public void Clear() - { - _buckets = new Entry[_defaultCapacity]; - _numberOfBuckets = _defaultCapacity; - _loadFactor = 0; - _count = 0; - } - - /// - /// Determines whether the IDictionary object contains an element with the specified key. - /// - /// The key to locate in the IDictionary object. - /// true if the IDictionary contains an element with the key; otherwise, false. - public bool Contains(object key) - { - if (key == null) - { - throw new ArgumentNullException("key is null"); - } - - var whichBucket = Hash(key, _numberOfBuckets); - var match = EntryForKey(key, _buckets[whichBucket]); - - if (match != null) - { - return true; - } - - return false; - } - - /// - /// Removes the element with the specified key from the IDictionary object. - /// - /// The key of the element to remove. - public void Remove(object key) - { - if (key == null) - { - throw new ArgumentNullException("key is null"); - } - - var whichBucket = Hash(key, _numberOfBuckets); - var match = EntryForKey(key, _buckets[whichBucket]); - - //does entry exist? - if (match == null) - { - return; - } - - //is entry at front? - if (_buckets[whichBucket] == match) - { - _buckets[whichBucket] = match.next; - _count--; - return; - } - - //handle entry in middle and at the end - for (Entry cur = _buckets[whichBucket]; cur != null; cur = cur.next) - { - if (cur.next == match) - { - cur.next = match.next; - _count--; - return; - } - } - } - - #endregion IDictionary Members - - private class Entry - { - public Object key; - public Object value; - public Entry next; - - public Entry(object key, object value, ref Entry n) - { - this.key = key; - this.value = value; - next = n; - } - } - - private class HashtableEnumerator : IEnumerator - { - Hashtable ht; - Entry temp; - Int32 index = -1; - EnumeratorType returnType; - - public HashtableEnumerator(Hashtable hashtable, EnumeratorType type) - { - ht = hashtable; - returnType = type; - } - - // Return the current item. - public Object Current - { - get - { - switch (returnType) - { - case EnumeratorType.DE: - return new DictionaryEntry(temp.key, temp.value); - - case EnumeratorType.KEY: - return temp.key; - - case EnumeratorType.VALUE: - return temp.value; - - default: - break; - } - return new DictionaryEntry(temp.key, temp.value); - } - } - - // Advance to the next item. - public Boolean MoveNext() - { - startLoop: - //iterate index or list - if (temp == null) - { - index++; - if (index < ht._numberOfBuckets) - { - temp = ht._buckets[index]; - } - else - { - return false; - } - } - else - { - temp = temp.next; - } - - //null check - if (temp == null) - { - goto startLoop; - } - - return true; - } - - // Reset the index to restart the enumeration. - public void Reset() - { - index = -1; - } - } - - // EnumeratorType - Enum that describes which object the Enumerator's Current property will return. - private enum EnumeratorType - { - // DictionaryEntry object. - DE, - // Key object. - KEY, - // Value object. - VALUE - } - - private class KeyCollection : ICollection - { - Hashtable ht; - - public KeyCollection(Hashtable hashtable) - { - ht = hashtable; - } - - #region ICollection Members - - public int Count - { - get - { - return ht._count; - } - } - - public bool IsSynchronized - { - get - { - return ht.IsSynchronized; - } - } - - public object SyncRoot - { - get - { - return ht.SyncRoot; - } - } - - public void CopyTo(Array array, int index) - { - ht.CopyToCollection(array, index, EnumeratorType.KEY); - } - - #endregion - - #region IEnumerable Members - - public IEnumerator GetEnumerator() - { - return new HashtableEnumerator(ht, EnumeratorType.KEY); - } - - #endregion - } - - private class ValueCollection : ICollection - { - Hashtable ht; - - public ValueCollection(Hashtable hashtable) - { - ht = hashtable; - } - - #region ICollection Members - - public int Count - { - get - { - return ht._count; - } - } - - public bool IsSynchronized - { - get - { - return ht.IsSynchronized; - } - } - - public object SyncRoot - { - get - { - return ht.SyncRoot; - } - } - - public void CopyTo(Array array, int index) - { - ht.CopyToCollection(array, index, EnumeratorType.VALUE); - } - - #endregion - - #region IEnumerable Members - - public IEnumerator GetEnumerator() - { - return new HashtableEnumerator(ht, EnumeratorType.VALUE); - } - - #endregion - } - } -} diff --git a/source/nanoFramework.CoreLibrary/System/Collections/IDictionary.cs b/source/nanoFramework.CoreLibrary/System/Collections/IDictionary.cs deleted file mode 100644 index 6ff611b8..00000000 --- a/source/nanoFramework.CoreLibrary/System/Collections/IDictionary.cs +++ /dev/null @@ -1,75 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -namespace System.Collections -{ - /// - /// Represents a nongeneric collection of key/value pairs. - /// - public interface IDictionary : ICollection - { - /// - /// Gets a value indicating whether the IDictionary object is read-only. - /// - /// - /// true if the IDictionary object is read-only; otherwise, false. - /// - bool IsReadOnly { get; } - /// - /// Gets a value indicating whether the IDictionary object has a fixed size. - /// - /// - /// true if the IDictionary object has a fixed size; otherwise, false. - /// - bool IsFixedSize { get; } - /// - /// Gets an ICollection object containing the keys of the IDictionary object. - /// - /// - /// An ICollection object containing the keys of the IDictionary object. - /// - ICollection Keys { get; } - /// - /// Gets an ICollection object containing the values in the IDictionary object. - /// - /// - /// An ICollection object containing the values in the IDictionary object. - /// - ICollection Values { get; } - - /// - /// Gets or sets the element with the specified key. - /// - /// The key of the element to get or set. - /// The element with the specified key, or if the key does not exist. - object this[object key] { get; set; } - - /// - /// Adds an element with the provided key and value to the IDictionary object. - /// - /// The Object to use as the key of the element to add. - /// The Object to use as the value of the element to add. - void Add(object key, object value); - - /// - /// Removes all elements from the IDictionary object. - /// - void Clear(); - - /// - /// Determines whether the IDictionary object contains an element with the specified key. - /// - /// The key to locate in the IDictionary object. - /// true if the IDictionary contains an element with the key; otherwise, false. - bool Contains(object key); - - /// - /// Removes the element with the specified key from the IDictionary object. - /// - /// The key of the element to remove. - void Remove(object key); - } -} diff --git a/source/nanoFramework.CoreLibrary/System/Collections/IList.cs b/source/nanoFramework.CoreLibrary/System/Collections/IList.cs index 973d2b93..2ddafb83 100644 --- a/source/nanoFramework.CoreLibrary/System/Collections/IList.cs +++ b/source/nanoFramework.CoreLibrary/System/Collections/IList.cs @@ -21,7 +21,7 @@ public interface IList : ICollection /// /// The zero-based index of the element to get or set. /// The element at the specified index. - Object this[int index] + object this[int index] { get; set; diff --git a/source/nanoFramework.CoreLibrary/System/Collections/Queue.cs b/source/nanoFramework.CoreLibrary/System/Collections/Queue.cs deleted file mode 100644 index b47348a9..00000000 --- a/source/nanoFramework.CoreLibrary/System/Collections/Queue.cs +++ /dev/null @@ -1,179 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace System.Collections -{ - /// - /// A circular-array implementation of a queue. Enqueue can be O(n). Dequeue is O(1). - /// -#if NANOCLR_REFLECTION - [DebuggerDisplay("Count = {Count}")] -#endif // NANOCLR_REFLECTION - [Serializable] - public class Queue : ICollection, ICloneable - { - private Object[] _array; - private int _head; // First valid element in the queue - private int _tail; // Last valid element in the queue - private int _size; // Number of elements. - - // Keep in-sync with c_DefaultCapacity in CLR_RT_HeapBlock_Queue in NANOCLR_Runtime__HeapBlock.h - private const int DefaultCapacity = 4; - - /// - /// Initializes a new instance of the Queue class that is empty, has the default initial - /// capacity, and uses the default growth factor (2x). - /// - public Queue() - { - _array = new Object[DefaultCapacity]; - _head = 0; - _tail = 0; - _size = 0; - } - - /// - /// Gets the number of elements contained in the Queue. - /// - public virtual int Count - { - get { return _size; } - } - - /// - /// Creates a shallow copy of the Queue. - /// - /// A shallow copy of the Queue. - public virtual Object Clone() - { - var q = new Queue(); - - if (_size > DefaultCapacity) - { - // only re-allocate a new array if the size isn't what we need. - // otherwise, the one allocated in the constructor will be just fine - q._array = new Object[_size]; - } - else - { - // if size is not the same as capacity, we need to adjust tail accordingly - q._tail = _size % DefaultCapacity; - } - - q._size = _size; - - CopyTo(q._array, 0); - - return q; - } - - /// - /// Gets a value indicating whether access to the Queue is synchronized (thread safe). - /// Always return false. - /// - public virtual bool IsSynchronized - { - get { return false; } - } - - /// - /// Gets an object that can be used to synchronize access to the Queue. - /// - public virtual Object SyncRoot - { - get { return this; } - } - - /// - /// Removes all objects from the Queue. - /// - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public virtual extern void Clear(); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Copies the Queue elements to an existing one-dimensional Array, starting at - /// the specified array index. - /// - /// The one-dimensional Array that is the destination of the elements copied from Queue. - /// The zero-based index in array at which copying begins. - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public virtual extern void CopyTo(Array array, int index); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Adds an object to the end of the Queue. - /// - /// The object to add to the Queue. - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public virtual extern void Enqueue(Object obj); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Returns an enumerator that iterates through the Queue. - /// - /// An IEnumerator for the Queue. - public virtual IEnumerator GetEnumerator() - { - var endIndex = _tail; - - if (_size > 0 && _tail <= _head) endIndex += _array.Length; - - return new Array.SzArrayEnumerator(_array, _head, endIndex); - } - - /// - /// Removes and returns the object at the beginning of the Queue. - /// - /// The object that is removed from the beginning of the Queue. - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public virtual extern Object Dequeue(); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Returns the object at the beginning of the Queue without removing it. - /// - /// The object at the beginning of the Queue. - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public virtual extern Object Peek(); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Determines whether an element is in the Queue. - /// - /// The Object to locate in the Queue. - /// true if obj is found in the Queue; otherwise, false. - public virtual bool Contains(Object obj) - { - if (_size == 0) return false; - if (_head < _tail) return Array.IndexOf(_array, obj, _head, _size) >= 0; - return Array.IndexOf(_array, obj, _head, _array.Length - _head) >= 0 || Array.IndexOf(_array, obj, 0, _tail) >= 0; - } - - /// - /// Copies the Queue elements to a new array. The order of the elements in the new - /// array is the same as the order of the elements from the beginning of the Queue - /// to its end. - /// - /// A new array containing elements copied from the Queue. - public virtual Object[] ToArray() - { - var arr = new Object[_size]; - - CopyTo(arr, 0); - - return arr; - } - } -} diff --git a/source/nanoFramework.CoreLibrary/System/Collections/stack.cs b/source/nanoFramework.CoreLibrary/System/Collections/stack.cs deleted file mode 100644 index dd80349b..00000000 --- a/source/nanoFramework.CoreLibrary/System/Collections/stack.cs +++ /dev/null @@ -1,160 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace System.Collections -{ - /// - /// An array implementation of a stack. Push can be O(n). Pop is O(1). - /// - [Serializable] -#if NANOCLR_REFLECTION - [DebuggerDisplay("Count = {Count}")] -#endif // NANOCLR_REFLECTION - public class Stack : ICollection, ICloneable - { - private Object[] _array; // Storage for stack elements - private int _size; // Number of items in the stack. - - // Keep in-sync with c_DefaultCapacity in CLR_RT_HeapBlock_Stack in NANOCLR_Runtime__HeapBlock.h - private const int DefaultCapacity = 4; - - /// - /// Initializes a new instance of the Stack class that is empty and has the default initial capacity. - /// - public Stack() - { - _array = new Object[DefaultCapacity]; - _size = 0; - } - - /// - /// Size of the stack - /// - public virtual int Count - { - get { return _size; } - } - - /// - /// Returns whether the current stack is synchornized. Always return false. - /// - public virtual bool IsSynchronized - { - get { return false; } - } - - /// - /// Gets an object that can be used to synchronize access to the Stack. - /// - public virtual Object SyncRoot - { - get { return this; } - } - - /// - /// Removes all Objects from the Stack. - /// - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public virtual extern void Clear(); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Creates a shallow copy of the Stack. - /// - /// A shallow copy of the Stack. - public virtual Object Clone() - { - var stack = new Stack(); - var capacity = DefaultCapacity; - - if (_size > DefaultCapacity) - { - // only re-allocate a new array if the size isn't what we need. - // otherwise, the one allocated in the constructor will be just fine - stack._array = new Object[_size]; - capacity = _size; - } - - stack._size = _size; - Array.Copy(_array, _array.Length - _size, stack._array, capacity - _size, _size); - return stack; - } - - /// - /// Determines whether an element is in the Stack. - /// - /// The Object to locate in the Stack. - /// true, if obj is found in the Stack; otherwise, false - public virtual bool Contains(Object obj) - { - return Array.IndexOf(_array, obj, _array.Length - _size, _size) >= 0; - } - - /// - /// Copies the Stack to an existing one-dimensional Array, starting at the specified array index. - /// - /// The one-dimensional Array that is the destination of the elements copied from Stack. - /// The zero-based index in array at which copying begins. - public virtual void CopyTo(Array array, int index) - { - Array.Copy(_array, _array.Length - _size, array, index, _size); - } - - /// - /// Returns an IEnumerator for this Stack. - /// - /// An IEnumerator for the Stack. - public virtual IEnumerator GetEnumerator() - { - var capacity = _array.Length; - return new Array.SzArrayEnumerator(_array, capacity - _size, capacity); - } - - /// - /// Returns the object at the top of the Stack without removing it. - /// - /// The Object at the top of the Stack. - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public virtual extern Object Peek(); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Removes and returns the object at the top of the Stack. - /// - /// The Object removed from the top of the Stack. - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public virtual extern Object Pop(); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Inserts an object at the top of the Stack. - /// - /// The Object to push onto the Stack. - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public virtual extern void Push(Object obj); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Copies the Stack to a new array, in the same order Pop would return the items. - /// - /// A new array containing copies of the elements of the Stack. - public virtual Object[] ToArray() - { - var objArray = new Object[_size]; - - Array.Copy(_array, _array.Length - _size, objArray, 0, _size); - - return objArray; - } - } -} diff --git a/source/version.json b/source/version.json index 1dc1ace5..2b9d5950 100644 --- a/source/version.json +++ b/source/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.4.1-preview.{height}", + "version": "1.5.0-preview.{height}", "assemblyVersion": { "precision": "revision" }, From 63e6221f4fc8bb0b3ac696eb350ffdf1b38f41f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Thu, 7 Nov 2019 16:31:37 +0000 Subject: [PATCH 08/36] Improvements on double and single types (#95) ***PUBLISH_RELEASE*** ***UPDATE_DEPENDENTS*** --- .../System/AssemblyInfo.cs | 2 +- .../System/Convert.cs | 12 ++ .../System/Double.cs | 58 +++++-- .../System/Single.cs | 144 +++++++++++++++++- source/version.json | 2 +- 5 files changed, 197 insertions(+), 21 deletions(-) diff --git a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs index 806a0916..216071d8 100644 --- a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs @@ -14,4 +14,4 @@ [assembly: AssemblyProduct("nanoFramework mscorlib")] [assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2017")] -[assembly: AssemblyNativeVersion("100.4.3.0")] +[assembly: AssemblyNativeVersion("100.4.5.0")] diff --git a/source/nanoFramework.CoreLibrary/System/Convert.cs b/source/nanoFramework.CoreLibrary/System/Convert.cs index 54089150..047c6358 100644 --- a/source/nanoFramework.CoreLibrary/System/Convert.cs +++ b/source/nanoFramework.CoreLibrary/System/Convert.cs @@ -202,6 +202,18 @@ public static double ToDouble(string value) return NativeToDouble(value); } +#pragma warning disable S4200 // Native methods should be wrapped + /// + /// Converts the specified string representation of a number to an equivalent single-precision floating-point number. + /// + /// A string that contains the number to convert. + /// A single-precision floating-point number that is equivalent to the number in value, or 0 (zero) if value is . + public static float ToSingle(string value) +#pragma warning restore S4200 // Native methods should be wrapped + { + return (float)NativeToDouble(value); + } + /// /// Converts an array of 8-bit unsigned integers to its equivalent String representation encoded with base 64 digits. /// diff --git a/source/nanoFramework.CoreLibrary/System/Double.cs b/source/nanoFramework.CoreLibrary/System/Double.cs index 1e51c443..65736d9f 100644 --- a/source/nanoFramework.CoreLibrary/System/Double.cs +++ b/source/nanoFramework.CoreLibrary/System/Double.cs @@ -15,6 +15,10 @@ namespace System [Serializable] public struct Double { + internal const string _naNSymbol = "Nan"; + internal const string _negativeInfinitySymbol = "-" + _positiveInfinitySymbol; + internal const string _positiveInfinitySymbol = "Infinity"; + // this field is required in the native end #pragma warning disable 0649 internal double _value; @@ -30,34 +34,49 @@ public struct Double /// /// The value of this constant is positive 1.7976931348623157E+308. public const double MaxValue = 1.7976931348623157E+308; + /// /// Represents the smallest positive Double value that is greater than zero. This field is constant. /// /// The value of this constant is 4.94065645841247e-324. public const double Epsilon = 4.9406564584124650E-324; + /// /// Represents negative infinity. This field is constant. /// public const double NegativeInfinity = -1.0 / 0.0; + /// /// Represents positive infinity. This field is constant. /// public const double PositiveInfinity = 1.0 / 0.0; + +#pragma warning disable S1764 // Identical expressions should not be used on both sides of a binary operator + // intended as the purpose is to a NaN value + /// /// Represents a value that is not a number (NaN). This field is constant. /// public const double NaN = 0.0 / 0.0; +#pragma warning restore S1764 // Identical expressions should not be used on both sides of a binary operator /// - /// Documentation missing + /// Compares this instance to a specified double-precision floating-point number and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified double-precision floating-point number. /// - /// Documentation missing - /// Documentation missing - /// Documentation missing + /// A double-precision floating-point number to compare. + /// A double-precision floating-point number to compare. + /// A signed number indicating the relative values of this instance and value. + /// Less than zero: This instance is less than value. -or- This instance is not a number () and value is a number. + /// Zero: This instance is equal to value. -or- Both this instance and value are not a number (), , or . + /// Greater than zero: This instance is greater than value. -or- This instance is a number and value is not a number (). + /// + public int CompareTo(double value) + { + return CompareTo(this, value); + } + [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public static extern int CompareTo(double d, double value); -#pragma warning restore S4200 // Native methods should be wrapped + internal static extern int CompareTo(double d, double value); /// /// Returns a value indicating whether the specified number evaluates to negative or positive infinity @@ -126,12 +145,9 @@ public static double Parse(String s) /// Converts the numeric value of this instance to its equivalent string representation. /// /// The string representation of the value of this instance. - public override String ToString() + public override string ToString() { - if (IsPositiveInfinity(this)) return "Infinity"; - if (IsNegativeInfinity(this)) return "-Infinity"; - - return IsNaN(this) ? "NaN" : Number.Format(_value, false, "G", NumberFormatInfo.CurrentInfo); + return ToString("G"); } /// @@ -139,12 +155,22 @@ public override String ToString() /// /// A numeric format string. /// The string representation of the value of this instance as specified by format. - public String ToString(String format) + public string ToString(string format) { - if (IsPositiveInfinity(this)) return "Infinity"; - if (IsNegativeInfinity(this)) return "-Infinity"; + if (IsPositiveInfinity(this)) + { + return _positiveInfinitySymbol; + } + else if (IsNegativeInfinity(this)) + { + return _negativeInfinitySymbol; + } + else if (IsNaN(this)) + { + return _naNSymbol; + } - return IsNaN(this) ? "NaN" : Number.Format(_value, false, format, NumberFormatInfo.CurrentInfo); + return Number.Format(_value, false, format, NumberFormatInfo.CurrentInfo); } /// diff --git a/source/nanoFramework.CoreLibrary/System/Single.cs b/source/nanoFramework.CoreLibrary/System/Single.cs index 2a71f92c..e88b3129 100644 --- a/source/nanoFramework.CoreLibrary/System/Single.cs +++ b/source/nanoFramework.CoreLibrary/System/Single.cs @@ -7,6 +7,7 @@ namespace System { using Globalization; + using System.Runtime.CompilerServices; /// /// Represents a single-precision floating-point number. @@ -24,23 +25,122 @@ public struct Single /// /// The value of this constant is negative 3.402823e38. public const float MinValue = (float)-3.40282346638528859e+38; + /// /// Represents the smallest positive Single value that is greater than zero. This field is constant. /// public const float Epsilon = (float)1.4e-45; + /// /// Represents the largest possible value of Single. This field is constant. /// /// The value of this constant is positive 3.40282347E+38. public const float MaxValue = (float)3.40282346638528859e+38; + /// + /// Represents negative infinity. This field is constant. + /// + public const float NegativeInfinity = -1.0f / 0.0f; + + /// + /// Represents positive infinity. This field is constant. + /// + public const float PositiveInfinity = 1.0f / 0.0f; + +#pragma warning disable S1764 // Identical expressions should not be used on both sides of a binary operator + // intended as the purpose is to a NaN value + + /// + /// Represents a value that is not a number (NaN). This field is constant. + /// + public const float NaN = 0.0f / 0.0f; +#pragma warning restore S1764 // Identical expressions should not be used on both sides of a binary operator + + /// + /// Returns a value indicating whether the specified number evaluates to negative or positive infinity. + /// + /// A single-precision floating-point number. + /// + /// if f evaluates to or ; otherwise, . + /// + public static bool IsInfinity(float f) + { + return double.IsInfinity(f); + } + + /// + /// Returns a value that indicates whether the specified value is not a number (). + /// + /// A single-precision floating-point number. + /// + /// if f evaluates to ; otherwise, . + /// + public static bool IsNaN(float f) + { + return double.IsNaN(f); + } + + /// + /// Returns a value indicating whether the specified number evaluates to negative infinity. + /// + /// A single-precision floating-point number. + /// + /// if f evaluates to ; otherwise, . + /// + public static bool IsNegativeInfinity(float f) + { + return double.IsNegativeInfinity(f); + } + + /// + /// Returns a value indicating whether the specified number evaluates to positive infinity. + /// + /// A single-precision floating-point number. + /// + /// if d evaluates to ; otherwise, . + /// + public static bool IsPositiveInfinity(float f) + { + return double.IsPositiveInfinity(f); + } + + /// + /// Compares this instance to a specified single-precision floating-point number and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified single-precision floating-point number. + /// + /// A single-precision floating-point number to compare. + /// A single-precision floating-point number to compare. + /// A signed number indicating the relative values of this instance and value. + /// Less than zero: This instance is less than value. -or- This instance is not a number () and value is a number. + /// Zero: This instance is equal to value. -or- Both this instance and value are not a number (), , or . + /// Greater than zero: This instance is greater than value. -or- This instance is a number and value is not a number (). + /// + public int CompareTo(float value) + { + return double.CompareTo(this, value); + } + + /// + /// Converts the string representation of a number to its single-precision floating-point number equivalent. + /// + /// A string that contains a number to convert. + /// A single-precision floating-point number equivalent to the numeric value or symbol specified in s. + /// + public static float Parse(string s) + { +#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one + if (s == null) throw new ArgumentNullException(); +#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one + + return Convert.ToSingle(s); + } + /// /// Converts the numeric value of this instance to its equivalent string representation. /// /// The string representation of the value of this instance. - public override String ToString() + public override string ToString() { - return Number.Format(_value, false, "G", NumberFormatInfo.CurrentInfo); + return ToString("G"); } /// @@ -48,9 +148,47 @@ public override String ToString() /// /// A numeric format string. /// The string representation of the value of this instance as specified by format. - public String ToString(String format) + public string ToString(string format) { + if (IsPositiveInfinity(this)) + { + return double._positiveInfinitySymbol; + } + else if (IsNegativeInfinity(this)) + { + return double._negativeInfinitySymbol; + } + else if(IsNaN(this)) + { + return double._naNSymbol; + } + return Number.Format(_value, false, format, NumberFormatInfo.CurrentInfo); } + + /// + /// Converts the string representation of a number to its single-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. + /// + /// A string containing a number to convert. + /// When this method returns, contains single-precision floating-point number equivalent to the numeric value or symbol contained in s, if the conversion succeeded, or zero if the conversion failed. The conversion fails if the s parameter is or Empty, is not a number in a valid format, or represents a number less than or greater than . This parameter is passed uninitialized; any value originally supplied in result will be overwritten. + /// if s was converted successfully; otherwise, . + public static bool TryParse(string s, out float result) + { + result = 0.0f; + + if (s == null) return false; + + try + { + result = Convert.ToSingle(s); + return true; + } + catch + { + result = 0.0f; + } + + return false; + } } } diff --git a/source/version.json b/source/version.json index 2b9d5950..5c52dff7 100644 --- a/source/version.json +++ b/source/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.5.0-preview.{height}", + "version": "1.5.1-preview.{height}", "assemblyVersion": { "precision": "revision" }, From 7870470eab3fc52a6a580d613d7f02d9a9d6fb00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Thu, 14 Nov 2019 11:17:24 +0000 Subject: [PATCH 09/36] Work CD-CI - Replace with system variable. ***NO_CI*** --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e551c098..785d50dc 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -117,7 +117,7 @@ jobs: lib-nanoFramework.ResourceManager lib-nanoFramework.System.Collections Json.NetMF - 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') ) + condition: or( and( succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ), and( succeeded(), contains(variables['Build.SourceVersionMessage'], '***UPDATE_DEPENDENTS***') ), eq(variables['UPDATE_DEPENDENTS'], 'true') ) displayName: Update dependent class libs ################################## From 01c23c3a8ef6ddd409fef202e913d9b1ddb3ba0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Thu, 14 Nov 2019 11:21:00 +0000 Subject: [PATCH 10/36] Extract System.Text namespace (#96) ***PUBLISH_RELEASE*** --- .../CoreLibrary.nfproj | 5 - source/nanoFramework.CoreLibrary/Friends.cs | 1 + .../System/AssemblyInfo.cs | 2 +- .../System/String.cs | 5 + .../System/Text/Decoder.cs | 31 - .../System/Text/Encoding.cs | 155 --- .../System/Text/StringBuilder.cs | 1136 ----------------- .../System/Text/UTF8Decoder.cs | 18 - .../System/Text/UTF8Encoding.cs | 114 -- source/version.json | 2 +- 10 files changed, 8 insertions(+), 1461 deletions(-) delete mode 100644 source/nanoFramework.CoreLibrary/System/Text/Decoder.cs delete mode 100644 source/nanoFramework.CoreLibrary/System/Text/Encoding.cs delete mode 100644 source/nanoFramework.CoreLibrary/System/Text/StringBuilder.cs delete mode 100644 source/nanoFramework.CoreLibrary/System/Text/UTF8Decoder.cs delete mode 100644 source/nanoFramework.CoreLibrary/System/Text/UTF8Encoding.cs diff --git a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj index ca625534..c4fffd34 100644 --- a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj +++ b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj @@ -164,11 +164,6 @@ - - - - - diff --git a/source/nanoFramework.CoreLibrary/Friends.cs b/source/nanoFramework.CoreLibrary/Friends.cs index e2692d89..cfbd853b 100644 --- a/source/nanoFramework.CoreLibrary/Friends.cs +++ b/source/nanoFramework.CoreLibrary/Friends.cs @@ -8,3 +8,4 @@ [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.Math, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("nanoFramework.ResourceManager, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("nanoFramework.System.Collections, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")] +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("nanoFramework.System.Text, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")] diff --git a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs index 216071d8..43df547e 100644 --- a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs @@ -14,4 +14,4 @@ [assembly: AssemblyProduct("nanoFramework mscorlib")] [assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2017")] -[assembly: AssemblyNativeVersion("100.4.5.0")] +[assembly: AssemblyNativeVersion("100.4.6.0")] diff --git a/source/nanoFramework.CoreLibrary/System/String.cs b/source/nanoFramework.CoreLibrary/System/String.cs index 1547fa3e..1edd7e4e 100644 --- a/source/nanoFramework.CoreLibrary/System/String.cs +++ b/source/nanoFramework.CoreLibrary/System/String.cs @@ -78,6 +78,11 @@ public extern char this[int index] get; } + internal char GetCharByIndex(int index) + { + return this[index]; + } + /// /// Copies the characters in this instance to a Unicode character array. /// diff --git a/source/nanoFramework.CoreLibrary/System/Text/Decoder.cs b/source/nanoFramework.CoreLibrary/System/Text/Decoder.cs deleted file mode 100644 index 8e1b3a9f..00000000 --- a/source/nanoFramework.CoreLibrary/System/Text/Decoder.cs +++ /dev/null @@ -1,31 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -namespace System.Text -{ - /// - /// Converts a sequence of encoded bytes into a set of characters. - /// - public abstract class Decoder - { - /// - /// Converts an array of encoded bytes to UTF-16 encoded characters and stores the result in a character array. - /// - /// A byte array to convert. - /// The first element of bytes to convert. - /// The number of elements of bytes to convert. - /// An array to store the converted characters. - /// The first element of chars in which data is stored. - /// The maximum number of elements of chars to use in the conversion. - /// true to indicate that no further data is to be converted; otherwise, false. - /// When this method returns, contains the number of bytes that were used in the conversion. This parameter is passed uninitialized. - /// When this method returns, contains the number of characters from chars that were produced by the conversion. This parameter is passed uninitialized. - /// When this method returns, contains true if all the characters specified by byteCount were converted; otherwise, false. This parameter is passed uninitialized. - public abstract void Convert(byte[] bytes, int byteIndex, int byteCount, - char[] chars, int charIndex, int charCount, bool flush, - out int bytesUsed, out int charsUsed, out bool completed); - } -} diff --git a/source/nanoFramework.CoreLibrary/System/Text/Encoding.cs b/source/nanoFramework.CoreLibrary/System/Text/Encoding.cs deleted file mode 100644 index ce747f48..00000000 --- a/source/nanoFramework.CoreLibrary/System/Text/Encoding.cs +++ /dev/null @@ -1,155 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// -namespace System.Text -{ - // This abstract base class represents a character encoding. The class provides - // methods to convert arrays and strings of Unicode characters to and from - // arrays of bytes. A number of Encoding implementations are provided in - // the System.Text package, including: - // - // ASCIIEncoding, which encodes Unicode characters as single 7-bit - // ASCII characters. This encoding only supports character values between 0x00 - // and 0x7F. - // BaseCodePageEncoding, which encapsulates a Windows code page. Any - // installed code page can be accessed through this encoding, and conversions - // are performed using the WideCharToMultiByte and - // MultiByteToWideChar Windows API functions. - // UnicodeEncoding, which encodes each Unicode character as two - // consecutive bytes. Both little-endian (code page 1200) and big-endian (code - // page 1201) encodings are recognized. - // UTF7Encoding, which encodes Unicode characters using the UTF-7 - // encoding (UTF-7 stands for UCS Transformation Format, 7-bit form). This - // encoding supports all Unicode character values, and can also be accessed - // as code page 65000. - // UTF8Encoding, which encodes Unicode characters using the UTF-8 - // encoding (UTF-8 stands for UCS Transformation Format, 8-bit form). This - // encoding supports all Unicode character values, and can also be accessed - // as code page 65001. - // UTF32Encoding, both 12000 (little endian) & 12001 (big endian) - // - // In addition to directly instantiating Encoding objects, an - // application can use the ForCodePage, GetASCII, - // GetDefault, GetUnicode, GetUTF7, and GetUTF8 - // methods in this class to obtain encodings. - // - // Through an encoding, the GetBytes method is used to convert arrays - // of characters to arrays of bytes, and the GetChars method is used to - // convert arrays of bytes to arrays of characters. The GetBytes and - // GetChars methods maintain no state between conversions, and are - // generally intended for conversions of complete blocks of bytes and - // characters in one operation. When the data to be converted is only available - // in sequential blocks (such as data read from a stream) or when the amount of - // data is so large that it needs to be divided into smaller blocks, an - // application may choose to use a Decoder or an Encoder to - // perform the conversion. Decoders and encoders allow sequential blocks of - // data to be converted and they maintain the state required to support - // conversions of data that spans adjacent blocks. Decoders and encoders are - // obtained using the GetDecoder and GetEncoder methods. - // - // The core GetBytes and GetChars methods require the caller - // to provide the destination buffer and ensure that the buffer is large enough - // to hold the entire result of the conversion. When using these methods, - // either directly on an Encoding object or on an associated - // Decoder or Encoder, an application can use one of two methods - // to allocate destination buffers. - // - // The GetByteCount and GetCharCount methods can be used to - // compute the exact size of the result of a particular conversion, and an - // appropriately sized buffer for that conversion can then be allocated. - // The GetMaxByteCount and GetMaxCharCount methods can be - // be used to compute the maximum possible size of a conversion of a given - // number of bytes or characters, and a buffer of that size can then be reused - // for multiple conversions. - // - // The first method generally uses less memory, whereas the second method - // generally executes faster. - // - - /// - /// Represents a character encoding. - /// - [Serializable] - public abstract class Encoding - { - /// - /// When overridden in a derived class, encodes all the characters in the specified string into a sequence of bytes. - /// - /// The string containing the characters to encode. - /// A byte array containing the results of encoding the specified set of characters. - public virtual byte[] GetBytes(String s) - { - return null; - } - - /// - /// When overridden in a derived class, encodes a set of characters from the specified string into the specified byte array. - /// - /// The string containing the set of characters to encode. - /// The index of the first character to encode. - /// The number of characters to encode. - /// The byte array to contain the resulting sequence of bytes. - /// The index at which to start writing the resulting sequence of bytes. - /// The actual number of bytes written into bytes. - /// - public virtual int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex) - { - throw new NotImplementedException(); - } - - /// - /// When overridden in a derived class, decodes all the bytes in the specified byte array into a set of characters. - /// - /// The byte array containing the sequence of bytes to decode. - /// A character array containing the results of decoding the specified sequence of bytes. - /// - public virtual char[] GetChars(byte[] bytes) - { - throw new NotImplementedException(); - } - - /// - /// When overridden in a derived class, decodes a sequence of bytes from the specified byte array into a set of characters. - /// - /// The byte array containing the sequence of bytes to decode. - /// The index of the first byte to decode. - /// The number of bytes to decode. - /// A character array containing the results of decoding the specified sequence of bytes. - /// - public virtual char[] GetChars(byte[] bytes, int byteIndex, int byteCount) - { - throw new NotImplementedException(); - } - - /// - /// When overridden in a derived class, decodes a sequence of bytes from the specified byte array into a . - /// - /// The byte array containing the sequence of bytes to decode. - /// The index of the first byte to decode. - /// The number of bytes to decode. - /// A that contains the results of decoding the specified sequence of bytes. - public virtual string GetString(byte[] bytes, int index, int count) - { - return new string(GetChars(bytes, index, count)); - } - - /// - /// When overridden in a derived class, obtains a decoder that converts an encoded sequence of bytes into a sequence of characters. - /// - /// A Decoder that converts an encoded sequence of bytes into a sequence of characters. - public abstract Decoder GetDecoder(); - /// - /// Gets an encoding for the UTF-8 format. - /// - /// An encoding for the UTF-8 format. - public static Encoding UTF8 - { - get - { - return new UTF8Encoding(); - } - } - } -} diff --git a/source/nanoFramework.CoreLibrary/System/Text/StringBuilder.cs b/source/nanoFramework.CoreLibrary/System/Text/StringBuilder.cs deleted file mode 100644 index 3e1e7387..00000000 --- a/source/nanoFramework.CoreLibrary/System/Text/StringBuilder.cs +++ /dev/null @@ -1,1136 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -namespace System.Text -{ - /// - /// A Micro Framework port of the Full Framework StringBuilder. Contributed by Julius Friedman. - /// Represents a mutable string of characters. This class cannot be inherited. - /// - public sealed class StringBuilder - { - #region Fields - - int _maxCapacity; - char[] _chunkChars; - int _chunkLength; - StringBuilder _chunkPrevious; - int _chunkOffset; - - #endregion - - #region Properties - - /// - /// Gets the maximum capacity of this instance. - /// - /// The maximum number of characters this instance can hold. - public int MaxCapacity - { - get - { - return _maxCapacity; - } - } - - /// - /// Gets or sets the character at the specified character position in this instance. - /// - /// The position of the character. - /// The Unicode character at position index. - public char this[int index] - { - get - { - var chunkPrevious = this; - while (true) - { - var num = index - chunkPrevious._chunkOffset; - if (num >= 0) - { - if (num >= chunkPrevious._chunkLength) - { -#pragma warning disable S112 // General exceptions should never be thrown - throw new IndexOutOfRangeException(); -#pragma warning restore S112 // General exceptions should never be thrown - } - return chunkPrevious._chunkChars[num]; - } - chunkPrevious = chunkPrevious._chunkPrevious; - if (chunkPrevious == null) - { -#pragma warning disable S112 // General exceptions should never be thrown - throw new IndexOutOfRangeException(); -#pragma warning restore S112 // General exceptions should never be thrown - } - } - } - set - { - var chunkPrevious = this; -Label_0002: - var num = index - chunkPrevious._chunkOffset; - if (num >= 0) - { - if (num >= chunkPrevious._chunkLength) - { - throw new ArgumentOutOfRangeException("index"); - } - chunkPrevious._chunkChars[num] = value; - } - else - { - chunkPrevious = chunkPrevious._chunkPrevious; - if (chunkPrevious == null) - { - throw new ArgumentOutOfRangeException("index"); - } - goto Label_0002; - } - } - } - - /// - /// Gets or sets the maximum number of characters that can be contained in the memory allocated by the current instance. - /// - /// - /// The maximum number of characters that can be contained in the memory allocated by the current instance. Its value can range from Length to MaxCapacity. - /// - /// - public int Capacity - { - get - { - return _chunkChars.Length + _chunkOffset; - } - set - { - if (value < 0) throw new ArgumentOutOfRangeException("value"); - if (value > MaxCapacity) throw new ArgumentOutOfRangeException("value"); - if (value < Length) throw new ArgumentOutOfRangeException("value"); - if (Capacity != value) - { - var num = value - _chunkOffset; - var destinationArray = new char[num]; - Array.Copy(_chunkChars, destinationArray, _chunkLength); - _chunkChars = destinationArray; - } - } - } - - /// - /// Gets or sets the length of the current StringBuilder object. - /// - /// The length of this instance. - /// - public int Length - { - get - { - return _chunkOffset + _chunkLength; - } - set - { - if (value < 0) throw new ArgumentOutOfRangeException("value"); - if (value > MaxCapacity) throw new ArgumentOutOfRangeException("value"); - var capacity = Capacity; - if (value == 0 && _chunkPrevious == null) - { - _chunkLength = 0; - _chunkOffset = 0; - } - else - { - var repeatCount = value - Length; - if (repeatCount > 0) - { - Append('\0', repeatCount); - } - else - { - var builder = FindChunkForIndex(value); - if (builder != this) - { - var num3 = capacity - builder._chunkOffset; - var destinationArray = new char[num3]; - Array.Copy(builder._chunkChars, destinationArray, builder._chunkLength); - _chunkChars = destinationArray; - _chunkPrevious = builder._chunkPrevious; - _chunkOffset = builder._chunkOffset; - } - _chunkLength = value - builder._chunkOffset; - } - } - - } - } - - #endregion - - #region Constructor - - /// - /// Initializes a new instance of the StringBuilder class from the specified substring and capacity. - /// - /// The string that contains the substring used to initialize the value of this instance. If value is null, the new StringBuilder will contain the empty string (that is, it contains Empty). - /// The position within value where the substring begins. - /// The number of characters in the substring. - /// The suggested starting size of the StringBuilder. - public unsafe StringBuilder(string value, int startIndex, int length, int capacity) - { - if (capacity < 0) throw new ArgumentOutOfRangeException("capacity"); - if (length < 0) throw new ArgumentOutOfRangeException("length"); - if (startIndex < 0) throw new ArgumentOutOfRangeException("startIndex"); - if (value == null) value = string.Empty; - if (startIndex > value.Length - length) throw new ArgumentOutOfRangeException("length"); - _maxCapacity = 0x7fffffff; - if (capacity == 0) capacity = 0x10; - if (capacity < length) capacity = length; - //Allocate the chunk of capactity - _chunkChars = new char[capacity]; - //Set the length of the chunk - _chunkLength = length; - //Copy the value to the chunkChars - value.ToCharArray(startIndex, length).CopyTo(_chunkChars, 0); - } - - private StringBuilder(int size, int maxCapacity, StringBuilder previousBlock) - { - _chunkChars = new char[size]; - _maxCapacity = maxCapacity; - _chunkPrevious = previousBlock; - if (previousBlock != null) - { - _chunkOffset = previousBlock._chunkOffset + previousBlock._chunkLength; - } - } - - /// - /// Initializes a new instance of the StringBuilder class using the specified string and capacity. - /// - /// The string used to initialize the value of the instance. If value is null, the new StringBuilder will contain the empty string (that is, it contains Empty). - /// The suggested starting size of the StringBuilder. - public StringBuilder(string value, int capacity) - : this(value, 0, value != null ? value.Length : 0, capacity) { } - - /// - /// Initializes a new instance of the StringBuilder class that starts with a specified capacity and can grow to a specified maximum. - /// - /// The suggested starting size of the StringBuilder. - /// The maximum number of characters the current string can contain. - public StringBuilder(int capacity, int maxCapacity) - { - if (capacity > maxCapacity) throw new ArgumentOutOfRangeException("capacity"); - if (maxCapacity < 1) throw new ArgumentOutOfRangeException("maxCapacity"); - if (capacity < 0) throw new ArgumentOutOfRangeException("capacity"); - if (capacity == 0) capacity = MathInternal.Min(0x10, maxCapacity); - _maxCapacity = maxCapacity; - _chunkChars = new char[capacity]; - } - - private StringBuilder(StringBuilder from) - { - _chunkLength = from._chunkLength; - _chunkOffset = from._chunkOffset; - _chunkChars = from._chunkChars; - _chunkPrevious = from._chunkPrevious; - _maxCapacity = from._maxCapacity; - } - - /// - /// Initializes a new instance of the StringBuilder class using the specified capacity. - /// - /// The suggested starting size of this instance. - public StringBuilder(int capacity) - : this(string.Empty, capacity) { } - - /// - /// Initializes a new instance of the StringBuilder class using the specified string. - /// - /// The string used to initialize the value of the instance. If value is null, the new StringBuilder will contain the empty string (that is, it contains Empty). - public StringBuilder(string value) - : this(value, 0x10) { } - - /// - /// Initializes a new instance of the StringBuilder class. - /// - public StringBuilder() - : this(0x10) { } - - #endregion - - #region Methods - - /// - /// Removes all characters from the current StringBuilder instance. - /// - /// An object whose Length is 0 (zero). - public StringBuilder Clear() - { - Length = 0; - return this; - } - - /// - /// Appends the string representation of a specified Boolean value to this instance. - /// - /// The Boolean value to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(bool value) - { - return Append(value.ToString()); - } - - /// - /// Appends the string representation of a specified 8-bit unsigned integer to this instance. - /// - /// The value to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(byte value) - { - return Append(value.ToString()); - } - - /// - /// Appends the string representation of a specified Unicode character to this instance. - /// - /// The UTF-16-encoded code unit to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(char value) - { - if (_chunkLength < _chunkChars.Length) _chunkChars[_chunkLength++] = value; - else Append(value, 1); - - return this; - } - - /// - /// Appends the string representation of a specified double-precision floating-point number to this instance. - /// - /// The value to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(double value) - { - return Append(value.ToString()); - } - - /// - /// Appends the string representation of a specified 16-bit signed integer to this instance. - /// - /// The value to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(short value) - { - return Append(value.ToString()); - } - - /// - /// Appends the string representation of the Unicode characters in a specified array to this instance. - /// - /// The array of characters to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(char[] value) - { - if (value != null && value.Length > 0) - { - Append(value, value.Length); - } - return this; - } - - /// - /// Appends the string representation of a specified 32-bit signed integer to this instance. - /// - /// The value to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(int value) - { - return Append(value.ToString()); - } - - /// - /// Appends the string representation of a specified 64-bit unsigned integer to this instance. - /// - /// The value to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(long value) - { - return Append(value.ToString()); - } - - /// - /// Appends the string representation of a specified object to this instance. - /// - /// The object to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(object value) - { - return value == null ? this : Append(value.ToString()); - } - - /// - /// Appends a copy of the specified string to this instance. - /// - /// The string to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(string value) - { - if (value != null && value != string.Empty) - { - var chunkChars = _chunkChars; - var chunkLength = _chunkLength; - var length = value.Length; - var num3 = chunkLength + length; - if (num3 < chunkChars.Length) - { - if (length <= 2) - { - if (length > 0) chunkChars[chunkLength] = value[0]; - if (length > 1) chunkChars[chunkLength + 1] = value[1]; - } - else - { - var tmp = value.ToCharArray(); - Array.Copy(tmp, 0, chunkChars, chunkLength, length); - } - _chunkLength = num3; - } - else - { - AppendHelper(ref value); - } - } - return this; - } - -#pragma warning disable CS3001 // Argument type 'sbyte' is not CLS-compliant - /// - /// Appends the string representation of a specified 8-bit signed integer to this instance. - /// - /// The value to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(sbyte value) -#pragma warning restore CS3001 // Argument type 'sbyte' is not CLS-compliant - { - return Append(value.ToString()); - } - - /// - /// Appends the string representation of a specified double-precision floating-point number to this instance. - /// - /// The value to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(float value) - { - return Append(value.ToString()); - } - -#pragma warning disable CS3001 // Argument type 'ushort' is not CLS-compliant - /// - /// Appends the string representation of a specified 16-bit unsigned integer to this instance. - /// - /// The value to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(ushort value) -#pragma warning restore CS3001 // Argument type 'ushort' is not CLS-compliant - { - return Append(value.ToString()); - } - -#pragma warning disable CS3001 // Argument type 'uint' is not CLS-compliant - /// - /// Appends the string representation of a specified 32-bit unsigned integer to this instance. - /// - /// The value to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(uint value) -#pragma warning restore CS3001 // Argument type 'uint' is not CLS-compliant - { - return Append(value.ToString()); - } - -#pragma warning disable CS3001 // Argument type 'ulong' is not CLS-compliant - /// - /// Appends the string representation of a specified 64-bit unsigned integer to this instance. - /// - /// The value to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(ulong value) -#pragma warning restore CS3001 // Argument type 'ulong' is not CLS-compliant - { - return Append(value.ToString()); - } - - /// - /// Appends a copy of a specified substring to this instance. - /// - /// The string that contains the substring to append. - /// The starting position of the substring within value. - /// The number of characters in value to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(string value, int startIndex, int count) - { - if (startIndex < 0) throw new ArgumentOutOfRangeException("startIndex"); - if (count < 0) throw new ArgumentOutOfRangeException("count"); - if (value == null) - { - if (startIndex != 0 || count != 0) throw new ArgumentNullException("value"); - return this; - } - if (count != 0) - { - if (startIndex > value.Length - count) throw new ArgumentOutOfRangeException("startIndex"); - Append(value.Substring(startIndex, count)); - } - return this; - } - - /// - /// Appends the string representation of a specified subarray of Unicode characters to this instance - /// - /// A character array. - /// The starting position in value. - /// The number of characters to append. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(char[] value, int startIndex, int charCount) - { - if (startIndex < 0) throw new ArgumentOutOfRangeException("startIndex"); -#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one - if (charCount < 0) throw new ArgumentOutOfRangeException("count"); -#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one - if (value == null) - { - if (startIndex != 0 || charCount != 0) throw new ArgumentNullException("value"); - return this; - } -#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one - if (charCount > value.Length - startIndex) throw new ArgumentOutOfRangeException("count"); -#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one - if (charCount != 0) - { - for (var i = startIndex; i < startIndex + charCount; ++i) - { - Append(value[i], 1); - } - } - return this; - } - - /// - /// Appends a specified number of copies of the string representation of a Unicode character to this instance. - /// - /// The character to append. - /// The number of times to append value. - /// A reference to this instance after the append operation has completed. - public StringBuilder Append(char value, int repeatCount) - { - if (repeatCount < 0) throw new ArgumentOutOfRangeException("repeatCount"); - if (repeatCount != 0) - { - var chunkLength = _chunkLength; - while (repeatCount > 0) - { - if (chunkLength < _chunkChars.Length) - { - _chunkChars[chunkLength++] = value; - repeatCount--; - } - else - { - _chunkLength = chunkLength; - ExpandByABlock(repeatCount); - chunkLength = 0; - } - } - _chunkLength = chunkLength; - } - return this; - } - - /// - /// Removes the specified range of characters from this instance. - /// - /// The zero-based position in this instance where removal begins. - /// The number of characters to remove. - /// A reference to this instance after the excise operation has completed. - public StringBuilder Remove(int startIndex, int length) - { - if (length < 0) throw new ArgumentOutOfRangeException("length"); - if (startIndex < 0) throw new ArgumentOutOfRangeException("startIndex"); -#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one - if (length > Length - startIndex) throw new ArgumentOutOfRangeException("index"); -#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one - if (Length == length && startIndex == 0) - { - Length = 0; - return this; - } - if (length > 0) - { - StringBuilder builder; - int num; - Remove(startIndex, length, out builder, out num); - } - return this; - } - - /// - /// Converts the value of this instance to a String. (Overrides Object.ToString().) - /// - /// A string whose value is the same as this instance. - public override string ToString() - { - var result = new char[Length]; - var chunkPrevious = this; - do - { - if (chunkPrevious._chunkLength > 0) - { - var chunkChars = chunkPrevious._chunkChars; - var chunkOffset = chunkPrevious._chunkOffset; - var chunkLength = chunkPrevious._chunkLength; - Array.Copy(chunkChars, 0, result, chunkOffset, chunkLength); - } - chunkPrevious = chunkPrevious._chunkPrevious; - } - while (chunkPrevious != null); - return new string(result); - } - - /// - /// Converts the value of a substring of this instance to a String. - /// - /// The starting position of the substring in this instance. - /// The length of the substring. - /// A string whose value is the same as the specified substring of this instance. - public string ToString(int startIndex, int length) - { - var num = Length; - if (startIndex < 0) throw new ArgumentOutOfRangeException("startIndex"); - if (startIndex > num) throw new ArgumentOutOfRangeException("startIndex"); - if (length < 0) throw new ArgumentOutOfRangeException("length"); - if (startIndex > num - length) throw new ArgumentOutOfRangeException("length"); - - var chunkPrevious = this; - var num2 = startIndex + length; - var result = new char[Length]; - var num3 = length; - while (num3 > 0) - { - var chunkLength = num2 - chunkPrevious._chunkOffset; - if (chunkLength >= 0) - { - if (chunkLength > chunkPrevious._chunkLength) - { - chunkLength = chunkPrevious._chunkLength; - } - var num5 = num3; - var charCount = num5; - var index = chunkLength - num5; - if (index < 0) - { - charCount += index; - index = 0; - } - num3 -= charCount; - if (charCount > 0) - { - var chunkChars = chunkPrevious._chunkChars; - if (charCount + num3 > length || charCount + index > chunkChars.Length) - { -#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one - throw new ArgumentOutOfRangeException("chunkCount"); -#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one - } - Array.Copy(chunkChars, index, result, 0, charCount); - } - } - chunkPrevious = chunkPrevious._chunkPrevious; - } - return new string(result); - } - - /// - /// Inserts one or more copies of a specified string into this instance at the specified character position. - /// - /// The position in this instance where insertion begins. - /// The string to insert. - /// The number of times to insert value. - /// A reference to this instance after insertion has completed. - public StringBuilder Insert(int index, string value, int count) - { - if (count < 0) throw new ArgumentOutOfRangeException("count"); - - var length = Length; - if (index > length) throw new ArgumentOutOfRangeException("index"); - if (value != null && value.Length != 0 && count != 0) - { - StringBuilder builder; - int num3; - long num2 = value.Length * count; -#pragma warning disable S112 // General exceptions should never be thrown - if (num2 > MaxCapacity - Length) throw new OutOfMemoryException(); -#pragma warning restore S112 // General exceptions should never be thrown - MakeRoom(index, (int)num2, out builder, out num3, false); - var chars = value.ToCharArray(); - var charLength = chars.Length; - while (count > 0) - { - var cindex = 0; - ReplaceInPlaceAtChunk(ref builder, ref num3, chars, ref cindex, charLength); - --count; - } - } - return this; - } - - /// - /// Inserts the string representation of a specified subarray of Unicode characters into this instance at the specified character position. - /// - /// The position in this instance where insertion begins. - /// A character array. - /// The starting index within value. - /// The number of characters to insert. - /// A reference to this instance after the insert operation has completed. - public StringBuilder Insert(int index, char[] value, int startIndex, int charCount) - { - var length = Length; - if (index > length) throw new ArgumentOutOfRangeException("index"); - if (value == null) - { - if (startIndex != 0 || charCount != 0) throw new ArgumentNullException("index"); - return this; - } - if (startIndex < 0) throw new ArgumentOutOfRangeException("startIndex"); -#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one - if (charCount < 0) throw new ArgumentOutOfRangeException("count"); -#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one - if (startIndex > value.Length - charCount) throw new ArgumentOutOfRangeException("startIndex"); - if (charCount > 0) Insert(index, new string(value, startIndex, charCount), 1); - - return this; - } - - /// - /// Replaces, within a substring of this instance, all occurrences of a specified character with another specified character. - /// - /// The character to replace. - /// The character that replaces oldChar. - /// The position in this instance where the substring begins. - /// The length of the substring. - /// A reference to this instance with oldChar replaced by newChar in the range from startIndex to startIndex + count -1. - public StringBuilder Replace(char oldChar, char newChar, int startIndex, int count) - { - var length = Length; - if (startIndex > length) throw new ArgumentOutOfRangeException("startIndex"); - if (count < 0 || startIndex > length - count) throw new ArgumentOutOfRangeException("count"); - - var num2 = startIndex + count; - var chunkPrevious = this; -Label_0048: - var num3 = num2 - chunkPrevious._chunkOffset; - var num4 = startIndex - chunkPrevious._chunkOffset; - if (num3 >= 0) - { - var index = MathInternal.Max(num4, 0); - var num6 = MathInternal.Min(chunkPrevious._chunkLength, num3); - while (index < num6) - { - if (chunkPrevious._chunkChars[index] == oldChar) - { - chunkPrevious._chunkChars[index] = newChar; - } - index++; - } - } - if (num4 < 0) - { - chunkPrevious = chunkPrevious._chunkPrevious; - goto Label_0048; - } - return this; - } - - /// - /// Replaces all occurrences of a specified character in this instance with another specified character. - /// - /// The character to replace. - /// The character that replaces oldChar. - /// A reference to this instance with oldChar replaced by newChar. - public StringBuilder Replace(char oldChar, char newChar) - { - return Replace(oldChar, newChar, 0, Length); - } - - /// - /// Replaces, within a substring of this instance, all occurrences of a specified string with another specified string. - /// - /// The string to replace. - /// The string that replaces oldValue, or null. - /// The position in this instance where the substring begins. - /// The length of the substring. - /// A reference to this instance with all instances of oldValue replaced by newValue in the range from startIndex to startIndex + count - 1. - public StringBuilder Replace(string oldValue, string newValue, int startIndex, int count) - { - var length = Length; - if (startIndex > length) throw new ArgumentOutOfRangeException("startIndex"); - if (count < 0 || startIndex > length - count) throw new ArgumentOutOfRangeException("count"); - if (oldValue == null) throw new ArgumentNullException("oldValue"); - if (oldValue.Length == 0) throw new ArgumentException("oldValue"); - if (newValue == null) newValue = string.Empty; - - var newLength = newValue.Length; - var oldLength = oldValue.Length; - int[] sourceArray = null; - var replacementsCount = 0; - var chunk = FindChunkForIndex(startIndex); - var indexInChunk = startIndex - chunk._chunkOffset; - //While there is a replacement remaining - while (count > 0) - { - //If the old value if found in the chunk at the index - if (StartsWith(chunk, indexInChunk, count, oldValue)) - { - //If we need to allocate for a match then do so - if (sourceArray == null) - { - sourceArray = new int[5]; - } - else if (replacementsCount >= sourceArray.Length) - { - //We have more matches than allocated for resize the buffer - var destinationArray = new int[sourceArray.Length * 3 / 2 + 4]; - Array.Copy(sourceArray, destinationArray, sourceArray.Length); - sourceArray = destinationArray; - } - //Save the index in the next avilable replacement slot - sourceArray[replacementsCount] = indexInChunk; - ++replacementsCount; - //Move the index pointer - indexInChunk += oldLength; - //Decrement the count - count -= oldLength; - } - else - { - - //A match at the index was not found - //Move the pointer - ++indexInChunk; - //Decrement the count - --count; - } - //If we are past the chunk boundry or the no replacements remaining - if (indexInChunk >= chunk._chunkLength || count == 0) - { - //Determine the index - var index = indexInChunk + chunk._chunkOffset; - //Replace the remaining characters - ReplaceAllInChunk(sourceArray, replacementsCount, chunk, oldLength, newValue); - //Move the index - index += (newLength - oldLength) * replacementsCount; - //Resert the replacements count - replacementsCount = 0; - //Find the next chunk and continue - chunk = FindChunkForIndex(index); - //Move the index reletive to inside the chunk - indexInChunk = index - chunk._chunkOffset; - } - } - return this; - } - - /// - /// Replaces all occurrences of a specified string in this instance with another specified string. - /// - /// The string to replace. - /// The string that replaces oldValue, or null. - /// A reference to this instance with all instances of oldValue replaced by newValue. - public StringBuilder Replace(string oldValue, string newValue) - { - return Replace(oldValue, newValue, 0, Length); - } - - /// - /// Appends a copy of the specified string followed by the default line terminator to the end of the current StringBuilder object. - /// - /// A reference to this instance after the append operation has completed. - public StringBuilder AppendLine(string str) - { - Append(str); - return AppendLine(); - } - - /// - /// Appends the default line terminator to the end of the current StringBuilder object. - /// - /// A reference to this instance after the append operation has completed. - public StringBuilder AppendLine() - { - return Append("\r\n"); - } - - #endregion - - #region Internals - - internal int EnsureCapacity(int capacity) - { - if (capacity < 0) throw new ArgumentOutOfRangeException("capacity"); - if (Capacity < capacity) Capacity = capacity; - - return Capacity; - } - - internal bool StartsWith(StringBuilder chunk, int indexInChunk, int count, string value) - { - for (int i = 0, e = value.Length; i < e; ++i) - { - if (count == 0) return false; - if (indexInChunk >= chunk._chunkLength) - { - chunk = Next(chunk); - if (chunk == null) return false; - indexInChunk = 0; - } - if (value[i] != chunk._chunkChars[indexInChunk]) return false; - ++indexInChunk; - --count; - } - return true; - } - - internal void ReplaceAllInChunk(int[] replacements, int replacementsCount, StringBuilder sourceChunk, int removeCount, string value) - { - //If there is a replacement to occur - if (replacementsCount > 0) - { - //Determine the cmount of characters to remove - var count = (value.Length - removeCount) * replacementsCount; - //Scope the working chunk - var chunk = sourceChunk; - //Determine the index of the first replacement - var indexInChunk = replacements[0]; - //If there is a character being added make room - if (count > 0) MakeRoom(chunk._chunkOffset + indexInChunk, count, out chunk, out indexInChunk, true); - //Start at the first replacement - var index = 0; - var replacementIndex = 0; - var chars = value.ToCharArray(); -ReplaceValue: -//Replace the value - ReplaceInPlaceAtChunk(ref chunk, ref indexInChunk, chars, ref replacementIndex, value.Length); - if (replacementIndex == value.Length) replacementIndex = 0; - - //Determine the next replacement - var valueIndex = replacements[index] + removeCount; - //Move the pointer of the working replacement - ++index; - //If we are not past the replacement boundry - if (index < replacementsCount) - { - //Determine the next replacement - var nextIndex = replacements[index]; - //If there is a character remaining to be replaced - if (count != 0) - { - //Replace it - ReplaceInPlaceAtChunk(ref chunk, ref indexInChunk, sourceChunk._chunkChars, ref valueIndex, nextIndex - valueIndex); - }//Move the pointer - else indexInChunk += nextIndex - valueIndex; - goto ReplaceValue;//Finish replacing - } - //We are are done and there is charcters to be removed they are at the end - if (count < 0) - { - //Remove them by negating the count to make it positive the chars removed are from (chunk.m_ChunkOffset + indexInChunk) to -count - Remove(chunk._chunkOffset + indexInChunk, -count, out chunk, out indexInChunk); - } - } - } - - internal StringBuilder Next(StringBuilder chunk) - { - return chunk == this ? null : FindChunkForIndex(chunk._chunkOffset + chunk._chunkLength); - } - - private void ReplaceInPlaceAtChunk(ref StringBuilder chunk, ref int indexInChunk, char[] value, ref int valueIndex, int count) - { - if (count == 0) return; - - while (true) - { - //int num = chunk.m_ChunkLength - indexInChunk; - var length = MathInternal.Min(chunk._chunkLength - indexInChunk, count); - //ThreadSafeCopy(value, ref valueIndex, chunk.m_ChunkChars, ref indexInChunk, num2); - Array.Copy(value, valueIndex, chunk._chunkChars, indexInChunk, length); - indexInChunk += length; - if (indexInChunk >= chunk._chunkLength) - { - chunk = Next(chunk); - indexInChunk = 0; - } - count -= length; - valueIndex += length; - if (count == 0) return; - } - } - - internal void MakeRoom(int index, int count, out StringBuilder chunk, out int indexInChunk, bool doneMoveFollowingChars) - { -#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one - if (count + Length > _maxCapacity) throw new ArgumentOutOfRangeException("requiredLength"); -#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one - chunk = this; - while (chunk._chunkOffset > index) - { - chunk._chunkOffset += count; - chunk = chunk._chunkPrevious; - } - indexInChunk = index - chunk._chunkOffset; - if (!doneMoveFollowingChars && chunk._chunkLength <= 0x20 && chunk._chunkChars.Length - chunk._chunkLength >= count) - { - var chunkLength = chunk._chunkLength; - while (chunkLength > indexInChunk) - { - chunkLength--; - chunk._chunkChars[chunkLength + count] = chunk._chunkChars[chunkLength]; - } - chunk._chunkLength += count; - } - else - { - var builder = new StringBuilder(MathInternal.Max(count, 0x10), chunk._maxCapacity, chunk._chunkPrevious); - builder._chunkLength = count; - var length = MathInternal.Min(count, indexInChunk); - if (length > 0) - { - Array.Copy(chunk._chunkChars, 0, builder._chunkChars, 0, length); - var nextLength = indexInChunk - length; - if (nextLength >= 0) - { - Array.Copy(chunk._chunkChars, length, chunk._chunkChars, 0, nextLength); - indexInChunk = nextLength; - } - } - chunk._chunkPrevious = builder; - chunk._chunkOffset += count; - if (length < count) - { - chunk = builder; - indexInChunk = length; - } - } - } - - internal StringBuilder FindChunkForIndex(int index) - { - var chunkPrevious = this; - while (chunkPrevious._chunkOffset > index) chunkPrevious = chunkPrevious._chunkPrevious; - return chunkPrevious; - } - - internal void AppendHelper(ref string value) - { - if (value == null || value == string.Empty) return; - Append(value.ToCharArray(), value.Length); - } - - internal void ExpandByABlock(int minBlockCharCount) - { -#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one - if (minBlockCharCount + Length > _maxCapacity) throw new ArgumentOutOfRangeException("requiredLength"); -#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one - var num = MathInternal.Max(minBlockCharCount, MathInternal.Min(Length, 0x1f40)); - _chunkPrevious = new StringBuilder(this); - _chunkOffset += _chunkLength; - _chunkLength = 0; - //If Allocated does not match required storage - if (_chunkOffset + num < num) - { - _chunkChars = null; -#pragma warning disable S112 // General exceptions should never be thrown - throw new OutOfMemoryException(); -#pragma warning restore S112 // General exceptions should never be thrown - } - _chunkChars = new char[num]; - } - - internal void Remove(int startIndex, int count, out StringBuilder chunk, out int indexInChunk) - { - var num = startIndex + count; - chunk = this; - StringBuilder builder = null; - var sourceIndex = 0; - while (true) - { - if (num - chunk._chunkOffset >= 0) - { - if (builder == null) - { - builder = chunk; - sourceIndex = num - builder._chunkOffset; - } - if (startIndex - chunk._chunkOffset >= 0) - { - indexInChunk = startIndex - chunk._chunkOffset; - var destinationIndex = indexInChunk; - var num4 = builder._chunkLength - sourceIndex; - if (builder != chunk) - { - destinationIndex = 0; - chunk._chunkLength = indexInChunk; - builder._chunkPrevious = chunk; - builder._chunkOffset = chunk._chunkOffset + chunk._chunkLength; - if (indexInChunk == 0) - { - builder._chunkPrevious = chunk._chunkPrevious; - chunk = builder; - } - } - builder._chunkLength -= sourceIndex - destinationIndex; - if (destinationIndex != sourceIndex) - { - //ThreadSafeCopy(builder.m_ChunkChars, ref sourceIndex, builder.m_ChunkChars, ref destinationIndex, num4); - Array.Copy(builder._chunkChars, sourceIndex, builder._chunkChars, destinationIndex, num4); - } - return; - } - } - else chunk._chunkOffset -= count; - chunk = chunk._chunkPrevious; - } - } - - internal void Append(char[] value, int valueCount) - { - var num = valueCount + _chunkLength; - if (num <= _chunkChars.Length) - { - //ThreadSafeCopy(value, this.m_ChunkChars, this.m_ChunkLength, valueCount); - Array.Copy(value, 0, _chunkChars, _chunkLength, valueCount); - _chunkLength = num; - } - else - { - var count = _chunkChars.Length - _chunkLength; - if (count > 0) - { - //ThreadSafeCopy(value, this.m_ChunkChars, this.m_ChunkLength, count); - Array.Copy(value, 0, _chunkChars, _chunkLength, count); - _chunkLength = _chunkChars.Length; - } - var minBlockCharCount = valueCount - count; - ExpandByABlock(minBlockCharCount); - //ThreadSafeCopy(value + count, this.m_ChunkChars, 0, minBlockCharCount); - Array.Copy(value, count, _chunkChars, 0, minBlockCharCount); - _chunkLength = minBlockCharCount; - } - } - - #endregion - } -} diff --git a/source/nanoFramework.CoreLibrary/System/Text/UTF8Decoder.cs b/source/nanoFramework.CoreLibrary/System/Text/UTF8Decoder.cs deleted file mode 100644 index 0ee0c038..00000000 --- a/source/nanoFramework.CoreLibrary/System/Text/UTF8Decoder.cs +++ /dev/null @@ -1,18 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -using System.Runtime.CompilerServices; - -namespace System.Text -{ - internal class UTF8Decoder : Decoder - { - [MethodImpl(MethodImplOptions.InternalCall)] - public override extern void Convert(byte[] bytes, int byteIndex, int byteCount, - char[] chars, int charIndex, int charCount, bool flush, - out int bytesUsed, out int charsUsed, out bool completed); - } -} diff --git a/source/nanoFramework.CoreLibrary/System/Text/UTF8Encoding.cs b/source/nanoFramework.CoreLibrary/System/Text/UTF8Encoding.cs deleted file mode 100644 index 7688f469..00000000 --- a/source/nanoFramework.CoreLibrary/System/Text/UTF8Encoding.cs +++ /dev/null @@ -1,114 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -// The worker functions in this file was optimized for performance. If you make changes -// you should use care to consider all of the interesting cases. - -// The code of all worker functions in this file is written twice: Once as as a slow loop, and the -// second time as a fast loop. The slow loops handles all special cases, throws exceptions, etc. -// The fast loops attempts to blaze through as fast as possible with optimistic range checks, -// processing multiple characters at a time, and falling back to the slow loop for all special cases. - -// This define can be used to turn off the fast loops. Useful for finding whether -// the problem is fast-loop specific. -#define FASTLOOP - -namespace System.Text -{ - using System; - using Runtime.CompilerServices; - // Encodes text into and out of UTF-8. UTF-8 is a way of writing - // Unicode characters with variable numbers of bytes per character, - // optimized for the lower 127 ASCII characters. It's an efficient way - // of encoding US English in an internationalizable way. - // - // Don't override IsAlwaysNormalized because it is just a Unicode Transformation and could be confused. - // - // The UTF-8 byte order mark is simply the Unicode byte order mark - // (0xFEFF) written in UTF-8 (0xEF 0xBB 0xBF). The byte order mark is - // used mostly to distinguish UTF-8 text from other encodings, and doesn't - // switch the byte orderings. - - /// - /// Represents a UTF-8 encoding of Unicode characters. - /// - public class UTF8Encoding : Encoding - { - - //bytes bits UTF-8 representation - //----- ---- ----------------------------------- - //1 7 0vvvvvvv - //2 11 110vvvvv 10vvvvvv - //3 16 1110vvvv 10vvvvvv 10vvvvvv - //4 21 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv - //----- ---- ----------------------------------- - - //Surrogate: - //Real Unicode value = (HighSurrogate - 0xD800) * 0x400 + (LowSurrogate - 0xDC00) + 0x10000 - - /// - /// Represents a UTF-8 encoding of Unicode characters. - /// - public UTF8Encoding() - { - } - - /// - /// - /// - /// - /// - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public override extern byte[] GetBytes(String s); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Encodes a set of characters from the specified into the specified byte array. - /// - /// The containing the set of characters to encode. - /// The index of the first character to encode. - /// The number of characters to encode. - /// The byte array to contain the resulting sequence of bytes. - /// The index at which to start writing the resulting sequence of bytes. - /// The actual number of bytes written into . - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public override extern int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. - /// - /// The byte array containing the sequence of bytes to decode. - /// The actual number of characters returned. - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public override extern char[] GetChars(byte[] bytes); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Decodes a sequence of bytes from the specified byte array into a set of characters. - /// - /// The byte array containing the sequence of bytes to decode. - /// The index of the first byte to decode. - /// The number of bytes to decode. - /// The actual number of characters returned. - [MethodImpl(MethodImplOptions.InternalCall)] -#pragma warning disable S4200 // Native methods should be wrapped - public override extern char[] GetChars(byte[] bytes, int byteIndex, int byteCount); -#pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Obtains a decoder that converts a UTF-8 encoded sequence of bytes into a sequence of Unicode characters. - /// - /// A decoder that converts a UTF-8 encoded sequence of bytes into a sequence of Unicode characters. - public override Decoder GetDecoder() - { - return new UTF8Decoder(); - } - } -} diff --git a/source/version.json b/source/version.json index 5c52dff7..86a4cde9 100644 --- a/source/version.json +++ b/source/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.5.1-preview.{height}", + "version": "1.6.0-preview.{height}", "assemblyVersion": { "precision": "revision" }, From 69b66a1a26aded220c64125d9208f535c8738b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Thu, 14 Nov 2019 11:25:08 +0000 Subject: [PATCH 11/36] Work CD-CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add nanoFramework.System.Text to dependents collection. ***NO_CI*** Signed-off-by: José Simões --- azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 785d50dc..25e7035b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -116,6 +116,7 @@ jobs: lib-nanoFramework.TI.EasyLink lib-nanoFramework.ResourceManager lib-nanoFramework.System.Collections + lib-nanoFramework.System.Text Json.NetMF condition: or( and( succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ), and( succeeded(), contains(variables['Build.SourceVersionMessage'], '***UPDATE_DEPENDENTS***') ), eq(variables['UPDATE_DEPENDENTS'], 'true') ) displayName: Update dependent class libs From 4cda9023d127d83f6f054dec857b47ac720f12ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Thu, 14 Nov 2019 13:35:21 +0000 Subject: [PATCH 12/36] Work CD-CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove Windows.Storage.Streams from dependents collection. ***NO_CI*** Signed-off-by: José Simões --- azure-pipelines.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 25e7035b..a7497334 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -103,7 +103,6 @@ jobs: repositoriesToUpdate: | lib-nanoFramework.Runtime.Events lib-nanoFramework.Runtime.Native - lib-Windows.Storage.Streams lib-Windows.Devices.Adc lib-Windows.Devices.I2c lib-Windows.Devices.Pwm From 1c91cf0162469c3303451591b397afcb856a6aea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 29 Jan 2020 00:34:20 +0000 Subject: [PATCH 13/36] Update README.md ***NO_CI*** --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2148fd94..b3b8c40f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ | Component | Build Status | NuGet Package | |:-|---|---| | 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/) | -| 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/) | +| 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.NoReflection/) | | 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) | | 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) | From 097010ff365fab35f8fc2ef2334279cc40af79c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Thu, 6 Feb 2020 11:03:43 +0000 Subject: [PATCH 14/36] Update nfproj to match latest MDP changes (#97) ***NO_CI*** --- source/nanoFramework.CoreLibrary/CoreLibrary.nfproj | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj index c4fffd34..05eb9ed1 100644 --- a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj +++ b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj @@ -37,9 +37,10 @@ true - true + true + true Stubs\corlib_native - CorLib + corlib_native true From 0cdc0d3c28b8518b9ea1acc1888dc88425ce4062 Mon Sep 17 00:00:00 2001 From: josesimoes Date: Tue, 25 Feb 2020 09:00:05 +0000 Subject: [PATCH 15/36] Update project properties for stubs generation ***NO_CI*** Signed-off-by: josesimoes --- source/nanoFramework.CoreLibrary/CoreLibrary.nfproj | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj index 05eb9ed1..5e41f8eb 100644 --- a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj +++ b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj @@ -37,10 +37,9 @@ true - true - true - Stubs\corlib_native - corlib_native + true + bin\$(Configuration)\Stubs + corlib_native true From 0c3e03a0a8b66acfed709fc5ed2f6906600a883a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Mon, 9 Mar 2020 09:34:22 +0000 Subject: [PATCH 16/36] Implement MemberInfo.GetCustomAttributesNative (#98) ***UPDATE_DEPENDENTS*** ***PUBLISH_RELEASE*** --- .../System/AssemblyInfo.cs | 2 +- .../System/Reflection/FieldInfo.cs | 51 +++++++++++++++++-- source/version.json | 2 +- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs index 43df547e..21cf928e 100644 --- a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs @@ -14,4 +14,4 @@ [assembly: AssemblyProduct("nanoFramework mscorlib")] [assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2017")] -[assembly: AssemblyNativeVersion("100.4.6.0")] +[assembly: AssemblyNativeVersion("100.4.7.0")] diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/FieldInfo.cs b/source/nanoFramework.CoreLibrary/System/Reflection/FieldInfo.cs index 7bbef69e..9fbe458e 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/FieldInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/FieldInfo.cs @@ -68,14 +68,55 @@ public abstract Type FieldType /// /// When overridden in a derived class, returns an array of all custom attributes applied to this member. /// - /// true to search this member's inheritance chain to find the attributes; otherwise, false. This parameter is ignored for properties and events. + /// true to search this member's inheritance chain to find the attributes; otherwise, false. This parameter is ignored for properties and events. /// An array that contains all the custom attributes applied to this member, or an array with zero elements if no attributes are defined. - /// This method is not implemented in nanoFramework. - /// This method is not implemente. - /// + /// This method ignores the inherit parameter for properties and events. + public override object[] GetCustomAttributes(bool inherit) + { + // get the custom attributes data for the field + // these are returned "encoded" in an object array with 2 positions for each attribute + // 1st the attribute type + // 2nd the constructor parameter or null, if the attribute has no constructor + // + // current limitations: + // - works only for constructors with a single parameter + // - the parameter has to be a string or numeric type + // + // both limitations above can be relatively easily overcome by adding the appropriate code at the native handler + var ret = GetCustomAttributesNative(inherit); + + object[] attributes = new object[ ret.Length/2 ]; + + for (int i = 0; i < ret.Length; i += 2) + { + // peek next element to determine if it's null + if(ret[ i+1 ] == null) + { + // attribute without default constructor, just copy it + attributes[ i/2 ] = ret[i]; + } + else + { + // has default constructor, invoke it + + // get the types + Type objectType = ret[i].GetType(); + Type paramType = ret[ i+1 ].GetType(); + + // get constructor + ConstructorInfo ctor = objectType.GetConstructor(new Type[] { paramType }); + + // invoke constructor with the parameter + attributes[ i/2 ] = ctor.Invoke(new object[] { ret[ i+1 ] }); + } + } + + return attributes; + } + [MethodImpl(MethodImplOptions.InternalCall)] #pragma warning disable S4200 // Native methods should be wrapped - public extern override object[] GetCustomAttributes(bool inherit); + private extern object[] GetCustomAttributesNative(bool inherit); #pragma warning restore S4200 // Native methods should be wrapped } } diff --git a/source/version.json b/source/version.json index 86a4cde9..68c1bfa6 100644 --- a/source/version.json +++ b/source/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.6.0-preview.{height}", + "version": "1.7.0-preview.{height}", "assemblyVersion": { "precision": "revision" }, From 254eba187376b95b8ecd596468d99bebd35fd155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Mon, 9 Mar 2020 13:38:48 +0000 Subject: [PATCH 17/36] Add NoReflection project to solution (#99) ***PUBLISH_RELEASE*** ***UPDATE_DEPENDENTS*** --- azure-pipelines.yml | 119 ++++-- .../CoreLibrary.NoReflection.nfproj | 383 ++++++++++++++++++ .../coreAssembly.rsp | 2 + .../packages.config | 4 + source/nanoFramework.CoreLibrary.sln | 14 + .../CoreLibrary.nfproj | 2 +- 6 files changed, 500 insertions(+), 24 deletions(-) create mode 100644 source/nanoFramework.CoreLibrary.NoReflection/CoreLibrary.NoReflection.nfproj create mode 100644 source/nanoFramework.CoreLibrary.NoReflection/coreAssembly.rsp create mode 100644 source/nanoFramework.CoreLibrary.NoReflection/packages.config diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a7497334..6cf4dd06 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -42,32 +42,107 @@ jobs: steps: # step from template @ nf-tools repo - # all build, update and publish steps - - template: azure-pipelines-templates/class-lib-build.yml@templates + + # build steps only + - template: azure-pipelines-templates/class-lib-build-only.yml@templates parameters: sonarCloudProject: 'nanoframework_lib-CoreLibrary' - msbuildExtraParams: '/p:DefineConstants="NANOCLR_REFLECTION"' - -############################## -- job: Build_mscorlib_no_reflection - condition: eq(variables['UPDATE_DEPENDENTS'], 'false') - pool: - vmImage: 'VS2017-Win2016' - variables: - solution: '**/source/*.sln' - buildPlatform: 'Any CPU' - buildConfiguration: 'Release' - nugetPackageName: 'nanoFramework.CoreLibrary.NoReflection' - repoName: 'lib-CoreLibrary' - - steps: + # package steps + - template: azure-pipelines-templates/class-lib-package.yml@templates + parameters: + nugetPackageName: 'nanoFramework.CoreLibrary' - # step from template @ nf-tools repo - # all build, update and publish steps - - template: azure-pipelines-templates/class-lib-build.yml@templates + - template: azure-pipelines-templates/class-lib-package.yml@templates parameters: - sonarCloudProject: 'nanoframework_lib-CoreLibrary.NoReflection' + nugetPackageName: 'nanoFramework.CoreLibrary.NoReflection' + + - template: azure-pipelines-templates/class-lib-publish.yml@templates + + # need to push the other package to NuGet because the template above can only push one package (happens on tag builds for any branch) + - task: NuGetCommand@2 + inputs: + command: push + nuGetFeedType: external + allowPackageConflicts: true + packagesToPush: + $(Build.ArtifactStagingDirectory)/nanoFramework.CoreLibrary.NoReflection.$(MY_NUGET_VERSION).nupkg + publishFeedCredentials: 'AzureArtifacts-CoreLibrary' + condition: and( succeeded(), ne( variables['StartReleaseCandidate'], true ) ) + continueOnError: true + displayName: Push "NoReflection" variant NuGet package to Azure Artifacts + + - task: NuGetCommand@2 + inputs: + command: push + nuGetFeedType: external + allowPackageConflicts: true + packagesToPush: + $(Build.ArtifactStagingDirectory)/nanoFramework.CoreLibrary.NoReflection.$(MY_NUGET_VERSION).nupkg + publishFeedCredentials: 'NuGet-CoreLibrary' + condition: and( succeeded(), ne( variables['StartReleaseCandidate'], true ) ) + continueOnError: true + displayName: Push "NoReflection" variant NuGet package to Azure Artifacts + + # create or update GitHub release + - task: GitHubReleasePublish@1 + inputs: + githubEndpoint: 'nanoframework' + githubOwner: 'nanoframework' + githubRepositoryName: $(repoName) + githubTag: v$(MY_NUGET_VERSION) + githubReleaseTitle: '$(nugetPackageName) Library v$(MY_NUGET_VERSION)' + githubReleaseNotes: 'Check the [changelog]($(Build.Repository.Uri)/blob/$(Build.SourceBranchName)/CHANGELOG.md).

Install from nanoFramework Azure Artifacts development feed


The following NuGet packages are available for download from this release:
:package: [.NET](https://dev.azure.com/nanoframework/feed/_packaging?_a=package&feed=sandbox&view=overview&package=$(nugetPackageName)&protocolType=NuGet&version=$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION)
:package: [.NET (without Reflection)](https://dev.azure.com/nanoframework/feed/_packaging?_a=package&feed=sandbox&view=overview&package=$(nugetPackageName).NoReflection&protocolType=NuGet&version=$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION)' + githubTargetCommitsh: $(Build.SourceVersion) + githubReleaseDraft: $(RELEASE_DRAFT) + githubReleasePrerelease: true + githubReuseDraftOnly: false + githubReuseRelease: true + githubEditRelease: true + githubDeleteEmptyTag: true + githubReleaseAsset: '$(Build.ArtifactStagingDirectory)/*.nupkg' + condition: and( succeeded(), not( startsWith(variables['Build.SourceBranch'], 'refs/pull') ), not( startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ) ) + displayName: Create/Update GitHub release + + # create or update GitHub release ON tags from release or master branches + - task: GitHubReleasePublish@1 + inputs: + githubEndpoint: 'nanoframework' + githubOwner: 'nanoframework' + githubRepositoryName: $(repoName) + githubTag: v$(MY_NUGET_VERSION) + githubReleaseTitle: '$(nugetPackageName) Library v$(MY_NUGET_VERSION)' + githubReleaseNotes: 'Check the [changelog]($(Build.Repository.Uri)/blob/$(Build.SourceBranchName)/CHANGELOG.md).

Install from NuGet


The following NuGet packages are available for download from this release:
:package: [.NET](https://www.nuget.org/packages/$(nugetPackageName)/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION).
:package: [.NET (without Reflection)](https://www.nuget.org/packages/$(nugetPackageName).NoReflection/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION)' + githubTargetCommitsh: $(Build.SourceVersion) + githubReleaseDraft: $(RELEASE_DRAFT) + githubReleasePrerelease: true + githubReuseDraftOnly: false + githubReuseRelease: true + githubEditRelease: true + githubDeleteEmptyTag: true + githubReleaseAsset: '$(Build.ArtifactStagingDirectory)/*.nupkg' + condition: and( succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'), contains(variables['Build.SourceBranch'], 'preview') ) + displayName: Create/Update GitHub PREVIEW release + + # create or update GitHub release ON tags from release or master branches + - task: GitHubReleasePublish@1 + inputs: + githubEndpoint: 'nanoframework' + githubOwner: 'nanoframework' + githubRepositoryName: $(repoName) + githubTag: v$(MY_NUGET_VERSION) + githubReleaseTitle: '$(nugetPackageName) Library v$(MY_NUGET_VERSION)' + githubReleaseNotes: 'Check the [changelog]($(Build.Repository.Uri)/blob/$(Build.SourceBranchName)/CHANGELOG.md).

Install from NuGet


The following NuGet packages are available for download from this release:
:package: [.NET](https://www.nuget.org/packages/$(nugetPackageName)/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION).
:package: [.NET (without Reflection)](https://www.nuget.org/packages/$(nugetPackageName).NoReflection/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION)' + githubTargetCommitsh: $(Build.SourceVersion) + githubReleaseDraft: false + githubReleasePrerelease: false + githubReuseDraftOnly: false + githubReuseRelease: false + githubEditRelease: false + githubDeleteEmptyTag: true + githubReleaseAsset: '$(Build.ArtifactStagingDirectory)/*.nupkg' + condition: and( succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'), not(contains(variables['Build.SourceBranch'], 'preview') ) ) + displayName: Create/Update GitHub stable release ############################## - job: Update_Dependencies @@ -75,7 +150,6 @@ jobs: dependsOn: - Build_mscorlib - - Build_mscorlib_no_reflection pool: vmImage: 'VS2017-Win2016' @@ -126,7 +200,6 @@ jobs: dependsOn: - Build_mscorlib - - Build_mscorlib_no_reflection - Update_Dependencies condition: or( failed('Build_mscorlib'), failed('Build_mscorlib_no_reflection'), failed('Update_Dependencies')) diff --git a/source/nanoFramework.CoreLibrary.NoReflection/CoreLibrary.NoReflection.nfproj b/source/nanoFramework.CoreLibrary.NoReflection/CoreLibrary.NoReflection.nfproj new file mode 100644 index 00000000..b59b75d2 --- /dev/null +++ b/source/nanoFramework.CoreLibrary.NoReflection/CoreLibrary.NoReflection.nfproj @@ -0,0 +1,383 @@ + + + + $(MSBuildToolsPath)..\..\..\nanoFramework\v1.0\ + + + + True + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + d1dad305-bc77-4bdc-bcda-adaef1d93455 + Library + 512 + + + mscorlib + true + mscorlib + true + true + $(DefineConstants) + v1.0 + bin\$(Configuration)\mscorlib.xml + + + true + + + ..\nanoFramework.CoreLibrary\key.snk + + + false + + + true + + true + bin\$(Configuration)\Stubs + corlib_native + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}. + + + + \ No newline at end of file diff --git a/source/nanoFramework.CoreLibrary.NoReflection/coreAssembly.rsp b/source/nanoFramework.CoreLibrary.NoReflection/coreAssembly.rsp new file mode 100644 index 00000000..75e6f703 --- /dev/null +++ b/source/nanoFramework.CoreLibrary.NoReflection/coreAssembly.rsp @@ -0,0 +1,2 @@ +# CSC requires the runtimemetadataversion flag when building a core assembly (containing System.Object) +/runtimemetadataversion:v4.0.30319 diff --git a/source/nanoFramework.CoreLibrary.NoReflection/packages.config b/source/nanoFramework.CoreLibrary.NoReflection/packages.config new file mode 100644 index 00000000..701ac65e --- /dev/null +++ b/source/nanoFramework.CoreLibrary.NoReflection/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/source/nanoFramework.CoreLibrary.sln b/source/nanoFramework.CoreLibrary.sln index 23f42021..68a1a642 100644 --- a/source/nanoFramework.CoreLibrary.sln +++ b/source/nanoFramework.CoreLibrary.sln @@ -5,6 +5,16 @@ VisualStudioVersion = 15.0.27130.2010 MinimumVisualStudioVersion = 10.0.40219.1 Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "CoreLibrary", "nanoFramework.CoreLibrary\CoreLibrary.nfproj", "{BE7B95D5-087C-45F8-8197-4B438BEDFE11}" EndProject +Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "CoreLibrary.NoReflection", "nanoFramework.CoreLibrary.NoReflection\CoreLibrary.NoReflection.nfproj", "{D1DAD305-BC77-4BDC-BCDA-ADAEF1D93455}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{05E83B20-2648-4807-8F3E-D656497E3481}" + ProjectSection(SolutionItems) = preProject + nanoFramework.CoreLibrary.NoReflection.nuspec = nanoFramework.CoreLibrary.NoReflection.nuspec + nanoFramework.CoreLibrary.nuspec = nanoFramework.CoreLibrary.nuspec + NuGet.Config = NuGet.Config + version.json = version.json + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +25,10 @@ Global {BE7B95D5-087C-45F8-8197-4B438BEDFE11}.Debug|Any CPU.Build.0 = Debug|Any CPU {BE7B95D5-087C-45F8-8197-4B438BEDFE11}.Release|Any CPU.ActiveCfg = Release|Any CPU {BE7B95D5-087C-45F8-8197-4B438BEDFE11}.Release|Any CPU.Build.0 = Release|Any CPU + {D1DAD305-BC77-4BDC-BCDA-ADAEF1D93455}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D1DAD305-BC77-4BDC-BCDA-ADAEF1D93455}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D1DAD305-BC77-4BDC-BCDA-ADAEF1D93455}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D1DAD305-BC77-4BDC-BCDA-ADAEF1D93455}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj index 5e41f8eb..2b38367b 100644 --- a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj +++ b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj @@ -21,7 +21,7 @@ mscorlib true true - $(DefineConstants); + $(DefineConstants);NANOCLR_REFLECTION v1.0 bin\$(Configuration)\mscorlib.xml From e42b5b605a9ce1133a86b9e1d125ed17336bfb6c Mon Sep 17 00:00:00 2001 From: josesimoes Date: Mon, 9 Mar 2020 13:47:08 +0000 Subject: [PATCH 18/36] Work CD-CI - Add check for commit message for update dependents. ***NO_CI*** Signed-off-by: josesimoes --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6cf4dd06..66a9fa72 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -146,7 +146,7 @@ jobs: ############################## - job: Update_Dependencies - condition: and( ne( variables['StartReleaseCandidate'], true ), eq(variables['UPDATE_DEPENDENTS'], true) ) + condition: and( ne( variables['StartReleaseCandidate'], true ), or( contains(variables['Build.SourceVersionMessage'], '***UPDATE_DEPENDENTS***'), eq(variables['UPDATE_DEPENDENTS'], 'true') ) ) dependsOn: - Build_mscorlib From bcf53c0f8d66664731162b966e405c8abe1b6ecc Mon Sep 17 00:00:00 2001 From: josesimoes Date: Mon, 9 Mar 2020 18:10:47 +0000 Subject: [PATCH 19/36] Work CD-CI - Remove unnecessary install of specific nuget cli. ***NO_CI*** Signed-off-by: josesimoes --- azure-pipelines.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 66a9fa72..8c31b1ff 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -164,12 +164,6 @@ jobs: git config --global core.autocrlf true displayName: Setup git identity - - task: NuGetToolInstaller@0 - inputs: - versionSpec: '4.9.3' - condition: ne( variables['StartReleaseCandidate'], true ) - displayName: 'Install specific version of NuGet' - # update dependencies - task: UpdatenFDependencies@1 inputs: From 8c1e9e5d65373c4cc20701ba1329262334f7b4f5 Mon Sep 17 00:00:00 2001 From: josesimoes Date: Mon, 9 Mar 2020 18:46:40 +0000 Subject: [PATCH 20/36] Work CD-CI - Remove unnecessary step to set GitHub identity. ***NO_CI*** Signed-off-by: josesimoes --- azure-pipelines.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 8c31b1ff..1a3a67c5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -158,12 +158,6 @@ jobs: # need this here in order to persist GitHub credentials - checkout: self - - script: | - git config --global user.email nanoframework@outlook.com - git config --global user.name nfbot - git config --global core.autocrlf true - displayName: Setup git identity - # update dependencies - task: UpdatenFDependencies@1 inputs: From 54a3c269b8fda42a906827121a7daeb07420e00f Mon Sep 17 00:00:00 2001 From: josesimoes Date: Mon, 9 Mar 2020 18:59:16 +0000 Subject: [PATCH 21/36] Bump version Signed-off-by: josesimoes --- source/version.json | 1 + 1 file changed, 1 insertion(+) diff --git a/source/version.json b/source/version.json index 68c1bfa6..4ac459f1 100644 --- a/source/version.json +++ b/source/version.json @@ -1,6 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", "version": "1.7.0-preview.{height}", + "buildNumberOffset": 2, "assemblyVersion": { "precision": "revision" }, From 6b6c542661a9213be35bf96a48cd799bbe743c1d Mon Sep 17 00:00:00 2001 From: josesimoes Date: Mon, 9 Mar 2020 23:05:32 +0000 Subject: [PATCH 22/36] Bump version Signed-off-by: josesimoes --- source/version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/version.json b/source/version.json index 4ac459f1..562379ea 100644 --- a/source/version.json +++ b/source/version.json @@ -1,7 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", "version": "1.7.0-preview.{height}", - "buildNumberOffset": 2, + "buildNumberOffset": 3, "assemblyVersion": { "precision": "revision" }, From 316af842c0b2bcb03aa09a9a0aa120f293fd0a5b Mon Sep 17 00:00:00 2001 From: josesimoes Date: Mon, 9 Mar 2020 23:39:13 +0000 Subject: [PATCH 23/36] Work CD-CI - Add back task with nuget version install. - Add fetch depth to checkout task. Signed-off-by: josesimoes --- azure-pipelines.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1a3a67c5..e4da1a29 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -157,6 +157,13 @@ jobs: steps: # need this here in order to persist GitHub credentials - checkout: self + fetchDepth: 1 + + - task: NuGetToolInstaller@0 + inputs: + versionSpec: '5.4.0' + condition: ne( variables['StartReleaseCandidate'], true ) + displayName: 'Install specific version of NuGet' # update dependencies - task: UpdatenFDependencies@1 From fea855054f49f59d7bf7bdf227eab5ee5292b115 Mon Sep 17 00:00:00 2001 From: josesimoes Date: Tue, 10 Mar 2020 01:16:38 +0000 Subject: [PATCH 24/36] Remove github templates - These are coming from the organization template repo. Signed-off-by: josesimoes --- .github/ISSUE_TEMPLATE.md | 2 -- .github/PULL_REQUEST_TEMPLATE.md | 36 -------------------------------- 2 files changed, 38 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE.md delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index e1cd4a8d..00000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,2 +0,0 @@ -Please DO NOT open issues in this repository. -We are now using the Home repository for centralized issue management. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 0246bf4e..00000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,36 +0,0 @@ - - -## Description - - -## Motivation and Context - - -- Fixes/Closes/Resolves nanoFramework/Home#NNNN - -## How Has This Been Tested? - - - - -## Screenshots - -## Types of changes - -- [ ] Improvement (non-breaking change that improves a feature, code or algorithm) -- [ ] Bug fix (non-breaking change which fixes an issue) -- [ ] New feature (non-breaking change which adds functionality) -- [ ] Breaking change (fix or feature that would cause existing functionality to change) - -## Checklist: - - -- [ ] My code follows the code style of this project. -- [ ] My change requires a change to the documentation. -- [ ] I have updated the documentation accordingly. -- [ ] I have read the **CONTRIBUTING** document. -- [ ] I have added tests to cover my changes. -- [ ] All new and existing tests passed. - - -Signed-off-by: GITHUB_USER From d0ffb329f5453fc6f76ef5ea6234b4ad2dccd027 Mon Sep 17 00:00:00 2001 From: josesimoes Date: Tue, 14 Apr 2020 11:09:40 +0100 Subject: [PATCH 25/36] Fix some comments ***NO_CI*** Signed-off-by: josesimoes --- source/nanoFramework.CoreLibrary/System/DateTime.cs | 2 +- source/nanoFramework.CoreLibrary/System/Double.cs | 1 - source/nanoFramework.CoreLibrary/System/Single.cs | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/source/nanoFramework.CoreLibrary/System/DateTime.cs b/source/nanoFramework.CoreLibrary/System/DateTime.cs index 0ea7948f..a7b80dd6 100644 --- a/source/nanoFramework.CoreLibrary/System/DateTime.cs +++ b/source/nanoFramework.CoreLibrary/System/DateTime.cs @@ -138,7 +138,7 @@ public struct DateTime /// Initializes a new instance of the structure to a specified number of ticks. ///
/// A date and time expressed in the number of 100-nanosecond intervals. - /// - Ticks must be between and . + /// - Ticks must be between and . public DateTime(long ticks) { ticks -= _ticksAtOrigin; diff --git a/source/nanoFramework.CoreLibrary/System/Double.cs b/source/nanoFramework.CoreLibrary/System/Double.cs index 65736d9f..8546437e 100644 --- a/source/nanoFramework.CoreLibrary/System/Double.cs +++ b/source/nanoFramework.CoreLibrary/System/Double.cs @@ -63,7 +63,6 @@ public struct Double /// /// Compares this instance to a specified double-precision floating-point number and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified double-precision floating-point number. /// - /// A double-precision floating-point number to compare. /// A double-precision floating-point number to compare. /// A signed number indicating the relative values of this instance and value. /// Less than zero: This instance is less than value. -or- This instance is not a number () and value is a number. diff --git a/source/nanoFramework.CoreLibrary/System/Single.cs b/source/nanoFramework.CoreLibrary/System/Single.cs index e88b3129..06ece295 100644 --- a/source/nanoFramework.CoreLibrary/System/Single.cs +++ b/source/nanoFramework.CoreLibrary/System/Single.cs @@ -107,7 +107,6 @@ public static bool IsPositiveInfinity(float f) /// /// Compares this instance to a specified single-precision floating-point number and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified single-precision floating-point number. /// - /// A single-precision floating-point number to compare. /// A single-precision floating-point number to compare. /// A signed number indicating the relative values of this instance and value. /// Less than zero: This instance is less than value. -or- This instance is not a number () and value is a number. From 71a6ea0e277d2f6c3ee36f52146ec56e6792e1cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Tue, 14 Apr 2020 11:55:49 +0100 Subject: [PATCH 26/36] Bump version to 1.7.1-preview (#100) ***PUBLISH_RELEASE*** ***UPDATE_DEPENDENTS*** --- source/version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/version.json b/source/version.json index 562379ea..0fa341cd 100644 --- a/source/version.json +++ b/source/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.7.0-preview.{height}", + "version": "1.7.1-preview.{height}", "buildNumberOffset": 3, "assemblyVersion": { "precision": "revision" From 52a2730bef5ec57f1bd1974135f2879eae9ecc14 Mon Sep 17 00:00:00 2001 From: josesimoes Date: Wed, 15 Apr 2020 11:55:06 +0100 Subject: [PATCH 27/36] Work CD-CI - Improvement and fix of the condition to update dependents. ***NO_CI*** Signed-off-by: josesimoes --- azure-pipelines.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e4da1a29..abd6e0cb 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -146,7 +146,7 @@ jobs: ############################## - job: Update_Dependencies - condition: and( ne( variables['StartReleaseCandidate'], true ), or( contains(variables['Build.SourceVersionMessage'], '***UPDATE_DEPENDENTS***'), eq(variables['UPDATE_DEPENDENTS'], 'true') ) ) + condition: or( and( succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'), eq(variables['StartReleaseCandidate'], 'false') ), and( succeeded(), contains(variables['getCommitMessage.COMMIT_MESSAGE'], '***UPDATE_DEPENDENTS***'), eq(variables['StartReleaseCandidate'], 'false') ), eq(variables['UPDATE_DEPENDENTS'], 'true') ) dependsOn: - Build_mscorlib @@ -186,7 +186,6 @@ jobs: lib-nanoFramework.System.Collections lib-nanoFramework.System.Text Json.NetMF - condition: or( and( succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ), and( succeeded(), contains(variables['Build.SourceVersionMessage'], '***UPDATE_DEPENDENTS***') ), eq(variables['UPDATE_DEPENDENTS'], 'true') ) displayName: Update dependent class libs ################################## From da7b8e72ea655639b6e5b29fbeb5337a5d58b656 Mon Sep 17 00:00:00 2001 From: josesimoes Date: Wed, 15 Apr 2020 12:36:33 +0100 Subject: [PATCH 28/36] Work CD-CI - Improve condition for build lib step. ***NO_CI*** Signed-off-by: josesimoes --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index abd6e0cb..96cc5b38 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -28,7 +28,7 @@ jobs: ############################## - job: Build_mscorlib - condition: eq(variables['UPDATE_DEPENDENTS'], 'false') + condition: or( eq(variables['UPDATE_DEPENDENTS'], 'false'), eq(variables['StartReleaseCandidate'], 'true') ) pool: vmImage: 'VS2017-Win2016' From 3121bc2f1b30674cf3ed0dff4052690fcb92607b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Thu, 16 Apr 2020 14:39:41 +0100 Subject: [PATCH 29/36] Bump version to 1.7.2-preview (#101) ***PUBLISH_RELEASE*** ***UPDATE_DEPENDENTS*** --- source/version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/version.json b/source/version.json index 0fa341cd..e88e542a 100644 --- a/source/version.json +++ b/source/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.7.1-preview.{height}", + "version": "1.7.2-preview.{height}", "buildNumberOffset": 3, "assemblyVersion": { "precision": "revision" From eb5e32c88d54d86f04f1e1e7b0971eeda9823f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Mon, 27 Apr 2020 14:27:38 +0100 Subject: [PATCH 30/36] Add support for custom attributes with constructors for methods and and classes (#102) ***PUBLISH_RELEASE*** ***UPDATE_DEPENDENTS*** --- .../CoreLibrary.nfproj | 1 + .../System/AssemblyInfo.cs | 2 +- .../Reflection/CustomAttributesHelpers.cs | 52 +++++++++++++++++++ .../System/Reflection/FieldInfo.cs | 40 +------------- .../System/Reflection/RuntimeMethodInfo.cs | 11 +++- .../System/RuntimeType.cs | 9 +++- 6 files changed, 72 insertions(+), 43 deletions(-) create mode 100644 source/nanoFramework.CoreLibrary/System/Reflection/CustomAttributesHelpers.cs diff --git a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj index 2b38367b..5c7d42ec 100644 --- a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj +++ b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj @@ -129,6 +129,7 @@ + diff --git a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs index 21cf928e..17216803 100644 --- a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs @@ -14,4 +14,4 @@ [assembly: AssemblyProduct("nanoFramework mscorlib")] [assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2017")] -[assembly: AssemblyNativeVersion("100.4.7.0")] +[assembly: AssemblyNativeVersion("100.4.8.0")] diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/CustomAttributesHelpers.cs b/source/nanoFramework.CoreLibrary/System/Reflection/CustomAttributesHelpers.cs new file mode 100644 index 00000000..da7726aa --- /dev/null +++ b/source/nanoFramework.CoreLibrary/System/Reflection/CustomAttributesHelpers.cs @@ -0,0 +1,52 @@ +// +// Copyright (c) 2020 The nanoFramework project contributors +// See LICENSE file in the project root for full license information. +// + +namespace System.Reflection +{ + internal class CustomAttributesHelpers + { + public static object[] GetCustomAttributesInternal(object[] rawAttributes) + { + // get the custom attributes data for the field + // these are returned "encoded" in an object array with 2 positions for each attribute + // 1st the attribute type + // 2nd the constructor parameter or null, if the attribute has no constructor + // + // current limitations: + // - works only for constructors with a single parameter + // - the parameter has to be a string or numeric type + // + // both limitations above can be relatively easily overcome by adding the appropriate code at the native handler + + object[] attributes = new object[rawAttributes.Length / 2]; + + for (int i = 0; i < rawAttributes.Length; i += 2) + { + // peek next element to determine if it's null + if (rawAttributes[i + 1] == null) + { + // attribute without default constructor, just copy it + attributes[i / 2] = rawAttributes[i]; + } + else + { + // has default constructor, invoke it + + // get the types + Type objectType = rawAttributes[i].GetType(); + Type paramType = rawAttributes[i + 1].GetType(); + + // get constructor + ConstructorInfo ctor = objectType.GetConstructor(new Type[] { paramType }); + + // invoke constructor with the parameter + attributes[i / 2] = ctor.Invoke(new object[] { rawAttributes[i + 1] }); + } + } + + return attributes; + } + } +} diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/FieldInfo.cs b/source/nanoFramework.CoreLibrary/System/Reflection/FieldInfo.cs index 9fbe458e..60229837 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/FieldInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/FieldInfo.cs @@ -73,45 +73,7 @@ public abstract Type FieldType /// This method ignores the inherit parameter for properties and events. public override object[] GetCustomAttributes(bool inherit) { - // get the custom attributes data for the field - // these are returned "encoded" in an object array with 2 positions for each attribute - // 1st the attribute type - // 2nd the constructor parameter or null, if the attribute has no constructor - // - // current limitations: - // - works only for constructors with a single parameter - // - the parameter has to be a string or numeric type - // - // both limitations above can be relatively easily overcome by adding the appropriate code at the native handler - var ret = GetCustomAttributesNative(inherit); - - object[] attributes = new object[ ret.Length/2 ]; - - for (int i = 0; i < ret.Length; i += 2) - { - // peek next element to determine if it's null - if(ret[ i+1 ] == null) - { - // attribute without default constructor, just copy it - attributes[ i/2 ] = ret[i]; - } - else - { - // has default constructor, invoke it - - // get the types - Type objectType = ret[i].GetType(); - Type paramType = ret[ i+1 ].GetType(); - - // get constructor - ConstructorInfo ctor = objectType.GetConstructor(new Type[] { paramType }); - - // invoke constructor with the parameter - attributes[ i/2 ] = ctor.Invoke(new object[] { ret[ i+1 ] }); - } - } - - return attributes; + return CustomAttributesHelpers.GetCustomAttributesInternal(GetCustomAttributesNative(inherit)); } [MethodImpl(MethodImplOptions.InternalCall)] diff --git a/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeMethodInfo.cs b/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeMethodInfo.cs index 9f513eec..684f8a78 100644 --- a/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeMethodInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/Reflection/RuntimeMethodInfo.cs @@ -19,9 +19,16 @@ public override extern Type ReturnType [MethodImpl(MethodImplOptions.InternalCall)] get; } - + + public override object[] GetCustomAttributes(bool inherit) + { + return CustomAttributesHelpers.GetCustomAttributesInternal(GetCustomAttributesNative(inherit)); + } + [MethodImpl(MethodImplOptions.InternalCall)] - public override extern object[] GetCustomAttributes(bool inherit); +#pragma warning disable S4200 // Native methods should be wrapped + private extern object[] GetCustomAttributesNative(bool inherit); +#pragma warning restore S4200 // Native methods should be wrapped } } diff --git a/source/nanoFramework.CoreLibrary/System/RuntimeType.cs b/source/nanoFramework.CoreLibrary/System/RuntimeType.cs index c21d60da..23480c02 100644 --- a/source/nanoFramework.CoreLibrary/System/RuntimeType.cs +++ b/source/nanoFramework.CoreLibrary/System/RuntimeType.cs @@ -83,8 +83,15 @@ public override extern Type BaseType [MethodImpl(MethodImplOptions.InternalCall)] public override extern Type GetElementType(); + public override object[] GetCustomAttributes(bool inherit) + { + return CustomAttributesHelpers.GetCustomAttributesInternal(GetCustomAttributesNative(inherit)); + } + [MethodImpl(MethodImplOptions.InternalCall)] - public override extern object[] GetCustomAttributes(bool inherit); +#pragma warning disable S4200 // Native methods should be wrapped + private extern object[] GetCustomAttributesNative(bool inherit); +#pragma warning restore S4200 // Native methods should be wrapped } } From 4d7c0a9fdc45deeb6a5f2afd9c0cd309af065003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Fri, 8 May 2020 15:22:56 +0100 Subject: [PATCH 31/36] Rework DateTime struct (#103) ***PUBLISH_RELEASE*** ***UPDATE_DEPENDENTS*** --- .../System/AssemblyInfo.cs | 2 +- .../System/DateTime.cs | 172 ++++++++++-------- 2 files changed, 95 insertions(+), 79 deletions(-) diff --git a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs index 17216803..377b9df2 100644 --- a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs @@ -14,4 +14,4 @@ [assembly: AssemblyProduct("nanoFramework mscorlib")] [assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2017")] -[assembly: AssemblyNativeVersion("100.4.8.0")] +[assembly: AssemblyNativeVersion("100.4.9.0")] diff --git a/source/nanoFramework.CoreLibrary/System/DateTime.cs b/source/nanoFramework.CoreLibrary/System/DateTime.cs index a7b80dd6..3ab6242b 100644 --- a/source/nanoFramework.CoreLibrary/System/DateTime.cs +++ b/source/nanoFramework.CoreLibrary/System/DateTime.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) 2017 The nanoFramework project contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. @@ -6,6 +6,7 @@ namespace System { using Runtime.CompilerServices; using Globalization; + using System.Diagnostics; // Summary: // Specifies whether a System.DateTime object represents a local time, a Coordinated @@ -76,11 +77,15 @@ public enum DateTimeKind /// Represents an instant in time, typically expressed as a date and time of day. ///
[Serializable] +#if NANOCLR_REFLECTION + [DebuggerDisplay("{DateTimeDisplay,nq}")] +#endif // NANOCLR_REFLECTION public struct DateTime { /// Our origin is at 1601/01/01:00:00:00.000 /// While desktop CLR's origin is at 0001/01/01:00:00:00.000. /// There are 504911232000000000 ticks between them which we are subtracting. + [DebuggerBrowsable(DebuggerBrowsableState.Never)] private const long _ticksAtOrigin = 504911232000000000; // Number of 100ns ticks per time unit @@ -97,12 +102,20 @@ public struct DateTime private const int MillisPerDay = MillisPerHour * 24; // Unix Epoch constants - private const long UnixEpochTicks = (TicksPerDay * 719162) - _ticksAtOrigin; // 621355968000000000 + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private const long UnixEpochTicks = (TicksPerDay * 719162); // 621355968000000000 + [DebuggerBrowsable(DebuggerBrowsableState.Never)] private const long UnixEpochSeconds = UnixEpochTicks / TicksPerSecond; // 62135596800 - private const long MinTicks = 0; - // ticks value corresponding to 3000/12/31:23:59:59.999 - private const long MaxTicks = 946708127999999999 - _ticksAtOrigin; + // ticks value corresponding to 1601/01/01:00:00:00.000 (nanoFramework origin date time) + private const long MinTicks = _ticksAtOrigin; + // ticks value corresponding to 3000/12/31:23:59:59.999 (nanoFramework maximum date time) + private const long MaxTicks = 946708127999999999; + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private const ulong _tickMask = 0x7FFFFFFFFFFFFFFFL; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private const ulong _UTCMask = 0x8000000000000000L; /// /// Represents the smallest possible value of . This field is read-only. @@ -110,7 +123,7 @@ public struct DateTime /// The value of this constant is equivalent to 00:00:00.0000000, January 1, 1601. /// This value is specific to nanoFramework. .NET equivalent is 00:00:00.0000000 UTC, January 1, 0001, in the Gregorian calendar. /// - public static readonly DateTime MinValue = new DateTime(MinTicks + _ticksAtOrigin); + public static readonly DateTime MinValue = new DateTime(MinTicks); /// /// Represents the largest possible value of . This field is read-only. @@ -118,7 +131,7 @@ public struct DateTime /// The value of this constant is equivalent to 23:59:59.9999999, December 31, 3000. /// This value is specific to nanoFramework. .NET equivalent is 23:59:59.9999999 UTC, December 31, 9999 in the Gregorian calendar. /// - public static readonly DateTime MaxValue = new DateTime(MaxTicks + _ticksAtOrigin); + public static readonly DateTime MaxValue = new DateTime(MaxTicks); /// /// Represents the Unix Epoch value. This field is read-only. @@ -126,13 +139,29 @@ public struct DateTime /// The value of this constant is equivalent to the corresponding to 1970-01-01T00:00:00Z (January 1, 1970, at 12:00 AM UTC). /// This value is specific to nanoFramework. /// - public static readonly DateTime UnixEpoch = new DateTime(UnixEpochTicks + _ticksAtOrigin, DateTimeKind.Utc); + public static readonly DateTime UnixEpoch = new DateTime(UnixEpochTicks, DateTimeKind.Utc); // The data is stored as an unsigned 64-bit integer // Bits 01-62: The value of 100-nanosecond ticks where 0 represents 1601/01/01:00:00:00.000, up until the value // 3000/12/31:23:59:59.999 // Bits 63-64: Ignored in .NET nanoFramework implementation. - private UInt64 _ticks; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private ulong _ticks; + + // this enum is used to make the call to get date part + // keep in sync with native + private enum DateTimePart + { + Year, + Month, + Day, + DayOfWeek, + DayOfYear, + Hour, + Minute, + Second, + Millisecond + } /// /// Initializes a new instance of the structure to a specified number of ticks. @@ -150,7 +179,10 @@ public DateTime(long ticks) } #pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one - _ticks = (UInt64)ticks; + _ticks = (ulong)ticks; + + // allways UTC + _ticks |= _UTCMask; } /// @@ -170,7 +202,7 @@ public DateTime(long ticks, DateTimeKind kind) if (kind != DateTimeKind.Utc) { #pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one - throw new ArgumentOutOfRangeException(); + throw new ArgumentException(); #pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one } } @@ -178,7 +210,7 @@ public DateTime(long ticks, DateTimeKind kind) /// /// Initializes a new instance of the structure to the specified year, month, and day. /// - /// The year (1 through 9999). + /// The year (1601 through 3000). /// The month (1 through 12). /// The day (1 through the number of days in month). public DateTime(int year, int month, int day) @@ -189,7 +221,7 @@ public DateTime(int year, int month, int day) /// /// Initializes a new instance of the structure to the specified year, month, day, hour, minute, and second. /// - /// The year (1 through 9999). + /// The year (1601 through 3000). /// The month (1 through 12). /// The day (1 through the number of days in month). /// The hours (0 through 23). @@ -203,13 +235,14 @@ public DateTime(int year, int month, int day, int hour, int minute, int second) /// /// Initializes a new instance of the structure to the specified year, month, day, hour, minute, second, and millisecond. /// - /// The year (1 through 9999). + /// The year (1601 through 3000). /// The month (1 through 12). /// The day (1 through the number of days in month). /// The hours (0 through 23). /// The minutes (0 through 59). /// The seconds (0 through 59). /// The milliseconds (0 through 999). + /// Any parameter out of the accepted ranges [MethodImpl(MethodImplOptions.InternalCall)] public extern DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond); @@ -220,12 +253,12 @@ public DateTime(int year, int month, int day, int hour, int minute, int second) /// An object whose value is the sum of the date and time represented by this instance and the time interval represented by . public DateTime Add(TimeSpan val) { - return new DateTime((long)_ticks + val.Ticks + _ticksAtOrigin); + return new DateTime(Ticks + val.Ticks); } private DateTime Add(double val, int scale) { - return new DateTime((long)_ticks + (long)(val * scale * TicksPerMillisecond + (val >= 0 ? 0.5 : -0.5)) + _ticksAtOrigin); + return new DateTime(Ticks + (long)(val * scale * TicksPerMillisecond + (val >= 0 ? 0.5 : -0.5))); } /// @@ -285,7 +318,7 @@ public DateTime AddSeconds(double val) /// An object whose value is the sum of the date and time represented by this instance and the time represented by . public DateTime AddTicks(long val) { - return new DateTime((long)_ticks + val + _ticksAtOrigin); + return new DateTime(Ticks + val); } /// @@ -297,8 +330,8 @@ public DateTime AddTicks(long val) public static int Compare(DateTime t1, DateTime t2) { // Get ticks - var t1Ticks = t1._ticks; - var t2Ticks = t2._ticks; + var t1Ticks = t1.Ticks; + var t2Ticks = t2.Ticks; // Compare ticks. if (t1Ticks > t2Ticks) return 1; @@ -373,7 +406,7 @@ public DateTime Date { get { - return new DateTime((long)(_ticks - (_ticks % TicksPerDay)) + _ticksAtOrigin); + return new DateTime(Ticks - (Ticks % TicksPerDay)); } } @@ -383,10 +416,9 @@ public DateTime Date /// /// The day component, expressed as a value between 1 and 31. /// - public extern int Day + public int Day { - [MethodImpl(MethodImplOptions.InternalCall)] - get; + get => GetDateTimePart(DateTimePart.Day); } /// @@ -395,10 +427,9 @@ public extern int Day /// /// An enumerated constant that indicates the day of the week of this value. /// - public extern DayOfWeek DayOfWeek + public DayOfWeek DayOfWeek { - [MethodImpl(MethodImplOptions.InternalCall)] - get; + get => (DayOfWeek)GetDateTimePart(DateTimePart.DayOfWeek); } /// @@ -407,10 +438,9 @@ public extern DayOfWeek DayOfWeek /// /// The day of the year, expressed as a value between 1 and 366. /// - public extern int DayOfYear + public int DayOfYear { - [MethodImpl(MethodImplOptions.InternalCall)] - get; + get => GetDateTimePart(DateTimePart.DayOfYear); } /// @@ -419,10 +449,9 @@ public extern int DayOfYear /// /// The hour component, expressed as a value between 0 and 23. /// - public extern int Hour + public int Hour { - [MethodImpl(MethodImplOptions.InternalCall)] - get; + get => GetDateTimePart(DateTimePart.Hour); } /// @@ -434,15 +463,7 @@ public extern int Hour /// /// Despite the default in the full .NET Framework is this won't never happen because nanoFramework only supports UTC time. /// - public DateTimeKind Kind - { - get - { - // always UTC - return DateTimeKind.Utc; - } - - } + public DateTimeKind Kind => DateTimeKind.Utc; // always UTC in nanoFramework /// /// Gets the milliseconds component of the date represented by this instance. @@ -450,10 +471,9 @@ public DateTimeKind Kind /// /// The milliseconds component, expressed as a value between 0 and 999. /// - public extern int Millisecond + public int Millisecond { - [MethodImpl(MethodImplOptions.InternalCall)] - get; + get => GetDateTimePart(DateTimePart.Millisecond); } /// @@ -462,10 +482,9 @@ public extern int Millisecond /// /// The minute component, expressed as a value between 0 and 59. /// - public extern int Minute + public int Minute { - [MethodImpl(MethodImplOptions.InternalCall)] - get; + get => GetDateTimePart(DateTimePart.Minute); } /// @@ -474,10 +493,9 @@ public extern int Minute /// /// The month component, expressed as a value between 1 and 12. /// - public extern int Month + public int Month { - [MethodImpl(MethodImplOptions.InternalCall)] - get; + get => GetDateTimePart(DateTimePart.Month); } /// @@ -486,10 +504,10 @@ public extern int Month /// /// An object whose value is the current UTC date and time. /// - public static extern DateTime UtcNow + public static DateTime UtcNow { [MethodImpl(MethodImplOptions.InternalCall)] - get; + get => new DateTime(); } /// @@ -498,10 +516,9 @@ public static extern DateTime UtcNow /// /// The seconds component, expressed as a value between 0 and 59. /// - public extern int Second + public int Second { - [MethodImpl(MethodImplOptions.InternalCall)] - get; + get => GetDateTimePart(DateTimePart.Second); } /// @@ -514,7 +531,7 @@ public long Ticks { get { - return (long)_ticks; + return (long)(_ticks & _tickMask) + _ticksAtOrigin; } } @@ -528,7 +545,7 @@ public TimeSpan TimeOfDay { get { - return new TimeSpan((long)(_ticks % TicksPerDay)); + return new TimeSpan(Ticks % TicksPerDay); } } @@ -538,10 +555,10 @@ public TimeSpan TimeOfDay /// /// An object that is set to today's date, with the time component set to 00:00:00. /// - public static extern DateTime Today + public static DateTime Today { [MethodImpl(MethodImplOptions.InternalCall)] - get; + get => new DateTime(); } /// @@ -550,10 +567,9 @@ public static extern DateTime Today /// /// The year, between 1 and 9999. /// - public extern int Year + public int Year { - [MethodImpl(MethodImplOptions.InternalCall)] - get; + get => GetDateTimePart(DateTimePart.Year); } /// @@ -563,7 +579,7 @@ public extern int Year /// A time interval that is equal to the date and time represented by this instance minus the date and time represented by . public TimeSpan Subtract(DateTime val) { - return new TimeSpan((long)_ticks - (long)val._ticks); + return new TimeSpan(Ticks - val.Ticks); } /// @@ -573,27 +589,21 @@ public TimeSpan Subtract(DateTime val) /// An object that is equal to the date and time represented by this instance minus the time interval represented by . public DateTime Subtract(TimeSpan val) { - return new DateTime((long)(_ticks - (ulong)val._ticks) + _ticksAtOrigin); + return new DateTime(Ticks - val._ticks); } /// /// Converts the value of the current object to its equivalent string representation. /// /// A string representation of the value of the current object. - public override String ToString() - { - return DateTimeFormat.Format(this, null, DateTimeFormatInfo.CurrentInfo); - } + public override string ToString() => DateTimeFormat.Format(this, null, DateTimeFormatInfo.CurrentInfo); /// /// Converts the value of the current object to its equivalent string representation using the specified format. /// /// A standard or custom date and time format string (see Remarks). /// A string representation of value of the current DateTime object as specified by format. - public String ToString(String format) - { - return DateTimeFormat.Format(this, format, DateTimeFormatInfo.CurrentInfo); - } + public string ToString(string format) => DateTimeFormat.Format(this, format, DateTimeFormatInfo.CurrentInfo); /// /// Adds a specified time interval to a specified date and time, yielding a new date and time. @@ -605,7 +615,7 @@ public String ToString(String format) /// public static DateTime operator +(DateTime d, TimeSpan t) { - return new DateTime((long)(d._ticks + (ulong)t._ticks) + _ticksAtOrigin); + return new DateTime(d.Ticks + t.Ticks); } @@ -619,7 +629,7 @@ public String ToString(String format) /// public static DateTime operator -(DateTime d, TimeSpan t) { - return new DateTime((long)(d._ticks - (ulong)t._ticks) + _ticksAtOrigin); + return new DateTime(d.Ticks - t.Ticks); } /// @@ -723,10 +733,9 @@ public String ToString(String format) /// public static DateTime FromUnixTimeSeconds(long seconds) { - const long MinSeconds = (MinTicks / TicksPerSecond) - UnixEpochSeconds; const long MaxSeconds = (MaxTicks / TicksPerSecond) - UnixEpochSeconds; - if (seconds < MinSeconds || seconds > MaxSeconds) + if (seconds < 0 || seconds > MaxSeconds) { #pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one throw new ArgumentOutOfRangeException(); @@ -734,7 +743,7 @@ public static DateTime FromUnixTimeSeconds(long seconds) } long ticks = (seconds * TicksPerSecond) + UnixEpochTicks; - return new DateTime(ticks + _ticksAtOrigin); + return new DateTime(ticks); } /// @@ -764,7 +773,7 @@ public long ToUnixTimeSeconds() // // In other words, we want to consistently round toward the time 1/1/0001 00:00:00, // rather than toward the Unix Epoch (1/1/1970 00:00:00). - long seconds = (long)(_ticks / TicksPerSecond); + long seconds = Ticks / TicksPerSecond; return seconds - UnixEpochSeconds; } @@ -776,6 +785,13 @@ public override int GetHashCode() { ulong internalTicks = _ticks; return ((int)internalTicks) ^ ((int)(internalTicks >> 0x20)); + } + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private string DateTimeDisplay => $"{{{new DateTime(Ticks).ToString()}}}"; + + [MethodImpl(MethodImplOptions.InternalCall)] + private extern int GetDateTimePart(DateTimePart part); } } From 06fc2e01b2a6a81ed8b0bfd2542527fc57abea33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Fri, 8 May 2020 18:30:21 +0100 Subject: [PATCH 32/36] Fix exception with DateTime from ticks (#104) ***PUBLISH_RELEASE*** ***UPDATE_DEPENDENTS*** --- source/nanoFramework.CoreLibrary/System/DateTime.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/nanoFramework.CoreLibrary/System/DateTime.cs b/source/nanoFramework.CoreLibrary/System/DateTime.cs index 3ab6242b..915c79d7 100644 --- a/source/nanoFramework.CoreLibrary/System/DateTime.cs +++ b/source/nanoFramework.CoreLibrary/System/DateTime.cs @@ -170,8 +170,6 @@ private enum DateTimePart /// - Ticks must be between and . public DateTime(long ticks) { - ticks -= _ticksAtOrigin; - #pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one if (ticks < MinTicks || ticks > MaxTicks) { @@ -179,6 +177,9 @@ public DateTime(long ticks) } #pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one + // need to subtract our ticks at origin + ticks -= _ticksAtOrigin; + _ticks = (ulong)ticks; // allways UTC From 951da553d56262a0bf6a11cfb7eff7057eb4c162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Tue, 12 May 2020 14:39:39 +0100 Subject: [PATCH 33/36] Adds Obsolete attribute to Console methods (#105) ***NO_CI*** --- source/nanoFramework.CoreLibrary/System/Console.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/nanoFramework.CoreLibrary/System/Console.cs b/source/nanoFramework.CoreLibrary/System/Console.cs index 7843cc3a..ebf9ccbc 100644 --- a/source/nanoFramework.CoreLibrary/System/Console.cs +++ b/source/nanoFramework.CoreLibrary/System/Console.cs @@ -22,6 +22,7 @@ public static class Console /// Writes the specified string value to the standard output stream. /// /// The value to write. + [Obsolete("This method is going to be removed in a future version. Call Debug.Write instead.")] public static void Write(string value) #pragma warning restore S4200 // Native methods should be wrapped { @@ -33,6 +34,7 @@ public static void Write(string value) /// Writes the specified string value, followed by the current line terminator, to the standard output stream. /// /// The value to write. + [Obsolete("This method is going to be removed in a future version. Call Debug.Write instead.")] public static void WriteLine(string value) #pragma warning restore S4200 // Native methods should be wrapped { From d0ae80d8c3a97a6b8fe81e6d8fcab3bce1748cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Fri, 29 May 2020 17:28:40 +0100 Subject: [PATCH 34/36] Add System.Diagnostics.Debug class (#106) ***PUBLISH_RELEASE*** --- .../CoreLibrary.NoReflection.nfproj | 1 + .../CoreLibrary.nfproj | 1 + .../System/AssemblyInfo.cs | 2 +- .../System/Diagnostics/Debug.cs | 87 +++++++++++++++++++ source/version.json | 2 +- 5 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 source/nanoFramework.CoreLibrary/System/Diagnostics/Debug.cs diff --git a/source/nanoFramework.CoreLibrary.NoReflection/CoreLibrary.NoReflection.nfproj b/source/nanoFramework.CoreLibrary.NoReflection/CoreLibrary.NoReflection.nfproj index b59b75d2..eccee644 100644 --- a/source/nanoFramework.CoreLibrary.NoReflection/CoreLibrary.NoReflection.nfproj +++ b/source/nanoFramework.CoreLibrary.NoReflection/CoreLibrary.NoReflection.nfproj @@ -78,6 +78,7 @@ + diff --git a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj index 5c7d42ec..12c69932 100644 --- a/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj +++ b/source/nanoFramework.CoreLibrary/CoreLibrary.nfproj @@ -78,6 +78,7 @@ + diff --git a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs index 377b9df2..a6122ef2 100644 --- a/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs +++ b/source/nanoFramework.CoreLibrary/System/AssemblyInfo.cs @@ -14,4 +14,4 @@ [assembly: AssemblyProduct("nanoFramework mscorlib")] [assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2017")] -[assembly: AssemblyNativeVersion("100.4.9.0")] +[assembly: AssemblyNativeVersion("100.4.10.0")] diff --git a/source/nanoFramework.CoreLibrary/System/Diagnostics/Debug.cs b/source/nanoFramework.CoreLibrary/System/Diagnostics/Debug.cs new file mode 100644 index 00000000..f7885ba2 --- /dev/null +++ b/source/nanoFramework.CoreLibrary/System/Diagnostics/Debug.cs @@ -0,0 +1,87 @@ +// +// Copyright (c) 2020 The nanoFramework project contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +using System.Runtime.CompilerServices; + +namespace System.Diagnostics +{ + /// + /// Provides a set of methods and properties that help debug your code. + /// + public static class Debug + { + + /// + /// Causes a break in execution if the specified assertion (condition) evaluates to false. + /// + /// The condition to be evaluated. If the value is false, program execution stops. + [Conditional("DEBUG")] + static public void Assert(bool condition) + { + if (!condition) + { + Debugger.Break(); + } + } + + /// + /// Causes a break in execution if the specified assertion (condition) evaluates to false. + /// + /// The condition to be evaluated. If the value is false, program execution stops. + /// The text to be output if the assertion is false. + [Conditional("DEBUG")] + static public void Assert(bool condition, string message) + { + if (!condition) + { + Debugger.Break(); + } + } + + /// + /// Causes a break in execution if the specified assertion (condition) evaluates to false. + /// + /// The condition to be evaluated. If the value is false, program execution stops. + /// The text to be output if the assertion is false. + /// The detailed message to be displayed if the assertion is false. + [Conditional("DEBUG")] + static public void Assert(bool condition, string message, string detailedMessage) + { + if (!condition) + { + Debugger.Break(); + } + } + + /// + /// Writes a message to the trace listeners in the Listeners collection. + /// + /// A message to write. + /// + /// In nanoFramework implementation the message is output to Visual Studio debugger window. + /// + [Conditional("DEBUG")] +#pragma warning disable S4200 // Native methods should be wrapped + public static void Write(string message) => WriteLineNative(message, false); +#pragma warning restore S4200 // Native methods should be wrapped + + /// + /// Writes a message followed by a line terminator to the trace listeners in the Listeners collection. + /// + /// A message to write. + /// + /// In nanoFramework implementation the message is output to Visual Studio debugger window. + /// + [Conditional("DEBUG")] +#pragma warning disable S4200 // Native methods should be wrapped + public static void WriteLine(string message) => WriteLineNative(message, true); +#pragma warning restore S4200 // Native methods should be wrapped + + + [MethodImpl(MethodImplOptions.InternalCall)] + extern static private void WriteLineNative(string text, bool addLineFeed); + } +} diff --git a/source/version.json b/source/version.json index e88e542a..fef92438 100644 --- a/source/version.json +++ b/source/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.7.2-preview.{height}", + "version": "1.7.3-preview.{height}", "buildNumberOffset": 3, "assemblyVersion": { "precision": "revision" From 3dac926c472e5ea0e1ebf21d9420990486d5d398 Mon Sep 17 00:00:00 2001 From: josesimoes Date: Thu, 11 Jun 2020 08:35:33 +0100 Subject: [PATCH 35/36] Work CD-CI - Update github release tasks to follow new config. - Update github release to mention both packages. - Rename update depents job for clarity. - Replace lib-nanoFramework.Json. - Remove unsupported config for changelog generator. ***NO_CI*** Signed-off-by: josesimoes --- .github_changelog_generator | 1 - azure-pipelines.yml | 42 ++++++++++--------------------------- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/.github_changelog_generator b/.github_changelog_generator index 140c12e8..c6348a8a 100644 --- a/.github_changelog_generator +++ b/.github_changelog_generator @@ -10,5 +10,4 @@ enhancement_labels=Type: enhancement bug_labels=Type: bug merge_prefix=**Documentation and other chores:** unreleased_label=**Changes available only in 'Preview' NuGet packages:** -issue_line_labels=Breaking-Change,documentation author=false diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 96cc5b38..c1c67819 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -92,7 +92,7 @@ jobs: githubRepositoryName: $(repoName) githubTag: v$(MY_NUGET_VERSION) githubReleaseTitle: '$(nugetPackageName) Library v$(MY_NUGET_VERSION)' - githubReleaseNotes: 'Check the [changelog]($(Build.Repository.Uri)/blob/$(Build.SourceBranchName)/CHANGELOG.md).

Install from nanoFramework Azure Artifacts development feed


The following NuGet packages are available for download from this release:
:package: [.NET](https://dev.azure.com/nanoframework/feed/_packaging?_a=package&feed=sandbox&view=overview&package=$(nugetPackageName)&protocolType=NuGet&version=$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION)
:package: [.NET (without Reflection)](https://dev.azure.com/nanoframework/feed/_packaging?_a=package&feed=sandbox&view=overview&package=$(nugetPackageName).NoReflection&protocolType=NuGet&version=$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION)' + githubReleaseNotes: 'Check the [changelog]($(Build.Repository.Uri)/blob/$(Build.SourceBranchName)/CHANGELOG.md).

Install from NuGet


The following NuGet packages are available for download from this release:
:package: [.NET](https://www.nuget.org/packages/$(nugetPackageName)/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION).
:package: [.NET](https://www.nuget.org/packages/$(nugetPackageName)/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION)
:package: [.NET](https://www.nuget.org/packages/$(nugetPackageName)/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION).
:package: [.NET (without Reflection)](https://www.nuget.org/packages/$(nugetPackageName).NoReflection/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION)' githubTargetCommitsh: $(Build.SourceVersion) githubReleaseDraft: $(RELEASE_DRAFT) githubReleasePrerelease: true @@ -101,27 +101,7 @@ jobs: githubEditRelease: true githubDeleteEmptyTag: true githubReleaseAsset: '$(Build.ArtifactStagingDirectory)/*.nupkg' - condition: and( succeeded(), not( startsWith(variables['Build.SourceBranch'], 'refs/pull') ), not( startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ) ) - displayName: Create/Update GitHub release - - # create or update GitHub release ON tags from release or master branches - - task: GitHubReleasePublish@1 - inputs: - githubEndpoint: 'nanoframework' - githubOwner: 'nanoframework' - githubRepositoryName: $(repoName) - githubTag: v$(MY_NUGET_VERSION) - githubReleaseTitle: '$(nugetPackageName) Library v$(MY_NUGET_VERSION)' - githubReleaseNotes: 'Check the [changelog]($(Build.Repository.Uri)/blob/$(Build.SourceBranchName)/CHANGELOG.md).

Install from NuGet


The following NuGet packages are available for download from this release:
:package: [.NET](https://www.nuget.org/packages/$(nugetPackageName)/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION).
:package: [.NET (without Reflection)](https://www.nuget.org/packages/$(nugetPackageName).NoReflection/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION)' - githubTargetCommitsh: $(Build.SourceVersion) - githubReleaseDraft: $(RELEASE_DRAFT) - githubReleasePrerelease: true - githubReuseDraftOnly: false - githubReuseRelease: true - githubEditRelease: true - githubDeleteEmptyTag: true - githubReleaseAsset: '$(Build.ArtifactStagingDirectory)/*.nupkg' - condition: and( succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'), contains(variables['Build.SourceBranch'], 'preview') ) + condition: and( succeeded(), not( startsWith(variables['Build.SourceBranch'], 'refs/pull') ), not( startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ), ne( variables['StartReleaseCandidate'], true ) ) displayName: Create/Update GitHub PREVIEW release # create or update GitHub release ON tags from release or master branches @@ -132,20 +112,20 @@ jobs: githubRepositoryName: $(repoName) githubTag: v$(MY_NUGET_VERSION) githubReleaseTitle: '$(nugetPackageName) Library v$(MY_NUGET_VERSION)' - githubReleaseNotes: 'Check the [changelog]($(Build.Repository.Uri)/blob/$(Build.SourceBranchName)/CHANGELOG.md).

Install from NuGet


The following NuGet packages are available for download from this release:
:package: [.NET](https://www.nuget.org/packages/$(nugetPackageName)/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION).
:package: [.NET (without Reflection)](https://www.nuget.org/packages/$(nugetPackageName).NoReflection/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION)' + githubReleaseNotes: 'Check the [changelog]($(Build.Repository.Uri)/blob/$(Build.SourceBranchName)/CHANGELOG.md).

Install from NuGet


The following NuGet packages are available for download from this release:
:package: [.NET](https://www.nuget.org/packages/$(nugetPackageName)/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION).
:package: [.NET](https://www.nuget.org/packages/$(nugetPackageName)/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION)
:package: [.NET](https://www.nuget.org/packages/$(nugetPackageName)/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION).
:package: [.NET (without Reflection)](https://www.nuget.org/packages/$(nugetPackageName).NoReflection/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION)' githubTargetCommitsh: $(Build.SourceVersion) githubReleaseDraft: false githubReleasePrerelease: false githubReuseDraftOnly: false - githubReuseRelease: false - githubEditRelease: false + githubReuseRelease: true + githubEditRelease: true githubDeleteEmptyTag: true githubReleaseAsset: '$(Build.ArtifactStagingDirectory)/*.nupkg' - condition: and( succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'), not(contains(variables['Build.SourceBranch'], 'preview') ) ) + condition: and( succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'), not(contains(variables['Build.SourceBranch'], 'preview') ), ne( variables['StartReleaseCandidate'], true ) ) displayName: Create/Update GitHub stable release ############################## -- job: Update_Dependencies +- job: Update_Dependents condition: or( and( succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'), eq(variables['StartReleaseCandidate'], 'false') ), and( succeeded(), contains(variables['getCommitMessage.COMMIT_MESSAGE'], '***UPDATE_DEPENDENTS***'), eq(variables['StartReleaseCandidate'], 'false') ), eq(variables['UPDATE_DEPENDENTS'], 'true') ) dependsOn: @@ -165,7 +145,7 @@ jobs: condition: ne( variables['StartReleaseCandidate'], true ) displayName: 'Install specific version of NuGet' - # update dependencies + # update dependents - task: UpdatenFDependencies@1 inputs: gitHubToken: $(GitHubToken) @@ -185,7 +165,7 @@ jobs: lib-nanoFramework.ResourceManager lib-nanoFramework.System.Collections lib-nanoFramework.System.Text - Json.NetMF + lib-nanoFramework.Json displayName: Update dependent class libs ################################## @@ -194,8 +174,8 @@ jobs: dependsOn: - Build_mscorlib - - Update_Dependencies - condition: or( failed('Build_mscorlib'), failed('Build_mscorlib_no_reflection'), failed('Update_Dependencies')) + - Update_Dependents + condition: or( failed('Build_mscorlib'), failed('Build_mscorlib_no_reflection'), failed('Update_Dependents')) pool: vmImage: 'VS2017-Win2016' From f14365757334fa3fd2b78f18861bb2e6ed85fe47 Mon Sep 17 00:00:00 2001 From: nfbot Date: Thu, 11 Jun 2020 09:46:18 +0000 Subject: [PATCH 36/36] Set version to '1.7.3' --- source/version.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/version.json b/source/version.json index fef92438..fc0f9205 100644 --- a/source/version.json +++ b/source/version.json @@ -1,10 +1,10 @@ { - "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.7.3-preview.{height}", - "buildNumberOffset": 3, + "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", + "version": "1.7.3", "assemblyVersion": { "precision": "revision" }, + "versionHeightOffset": 3, "semVer1NumericIdentifierPadding": 3, "nuGetPackageVersion": { "semVer": 2.0