-
-
Notifications
You must be signed in to change notification settings - Fork 30
Merge generics support in mscorlib #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
josesimoes
wants to merge
57
commits into
main
Choose a base branch
from
develop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
85086ea
Update core library to add support for generics <T> (#242)
josesimoes 2bb1d2d
Work CI-CD
josesimoes f9a9158
Work CI-CD
josesimoes e37e4b8
Work CI-CD
josesimoes 488ab3b
Merge branch 'main' of https://github.com/nanoframework/CoreLibrary i…
josesimoes 6303710
Work CI-CD
josesimoes 7005c52
Fix and improvements in `String` class (#248)
josesimoes fa61139
Merge branch 'main' into develop
josesimoes ed90c8e
Add `Span<T>` and `ReadOnlySpan<T>` (#249)
josesimoes 32a57c5
Add `ByRefLikeGenerics` to runtime features (#250)
josesimoes ab7909f
Remove exclusion of `DebuggerTypeProxyAttribute` (#251)
josesimoes e99e3aa
Add `IsReferenceOrContainsReferences` runtime helper (#252)
josesimoes 03e6ddb
Work CD-CI
josesimoes 412684a
Add collection related interfaces and classes (#253)
josesimoes 3cf3175
Add IntelliSense comments to `Nullable` classes (#254)
josesimoes 5d24cd3
Remove test struct with nested field ref
josesimoes d2b908e
Work CI-CD
josesimoes 668efa7
Bump test framework sub-module @602d512
josesimoes 7c0182d
Merge branch 'main' of https://github.com/nanoframework/CoreLibrary i…
josesimoes 5b23ee9
Add `SZArrayHelper` and `Unsafe.As<T>` (#257)
josesimoes 4738eed
Fixed null references and added == and != overloads in `Guid` (#247)
dcyonce 51be470
Add benchmark tests for ToString
josesimoes ce5c6d8
Fix `Guid` constructor (#259)
josesimoes d92a1c1
Update test framework sub-module @9f6e02c
josesimoes 903c2b2
Work CI-CD
josesimoes b0bf1e3
Work CI-CD
josesimoes 2a79b7a
Work CI-CD
josesimoes 7977eda
Add new constructors to `Span<T>` and `ReadOnlySpan<T>` (#260)
josesimoes 6996df8
Moved `String.Format()` to native (#261)
josesimoes b3427e4
Improvements in `ReadOnlySpan<T>` and `Span<T>` (#262)
josesimoes f4163d3
Work CI-CD
josesimoes 0d014fa
Add `MemoryExtensions` class (#263)
josesimoes ebb5481
Add interfaces for generic collections (#264)
josesimoes bfcba6a
Update test sub-module @2e5c15c
josesimoes 6c93600
Add implicit operator to `Span<T>` to allow conversion from array (#265)
josesimoes 50352eb
Work CI-CD
josesimoes 7c5e825
Add .github/copilot-instructions.md for Copilot cloud agent onboardin…
Copilot 46cf909
Merge branch 'main' into develop
josesimoes c326223
Merge branch 'main' of https://github.com/nanoframework/CoreLibrary i…
josesimoes 2aa5d2a
Fix unit test for `String.Format()` (#269)
josesimoes 1474d8c
Improvements in `String` class (#270)
josesimoes 1d0f540
Fix file
josesimoes 779da80
Rewrote `Guid.CompareTo` (#271)
josesimoes 30df403
Fix `ReadOnlySpan<T>` operator == to use identity semantics (#272)
josesimoes 17440c8
Add unit tests group to release notes config
josesimoes 7a33d32
Update test framework sub-module @521b03b
josesimoes 974d1db
Work CI-CD
josesimoes eac1915
Update test framework sub-module @6aa00b2
josesimoes 9cba9c3
Update test framework sub-module @9d8b809
josesimoes 6cf6098
Merge branch 'main' of https://github.com/nanoframework/CoreLibrary i…
josesimoes 3dd272a
Merge branch 'main' of https://github.com/nanoframework/CoreLibrary i…
josesimoes 9049bf0
Bump native assembly version to 100.22.0.5
nfbot 2b76a68
Update test framework sub-module @ba8142e
josesimoes 3f2f5c7
Update copilot instructions
josesimoes 90505da
Update 4 NuGet dependencies (#274)
josesimoes 96f7257
Add CLAUDE file
josesimoes d3a67ff
Add unit tests covering generic types (#275)
josesimoes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| `.github/copilot-instructions.md` is the authoritative rulebook for this repo (build details, coding conventions, contribution rules). Read it whenever you need more than the summary below. | ||
|
|
||
| ## What this repo is | ||
|
|
||
| The Base Class Library (BCL) for **.NET nanoFramework** — the `mscorlib` equivalent for embedded/MCU targets. This is **not** standard .NET: it targets `TargetFrameworkVersion v1.0` (the nanoFramework target), builds `.nfproj` projects, and pairs with a native C++ runtime. | ||
|
|
||
| Two output NuGet packages, both producing an assembly named `mscorlib`: | ||
| - `nanoFramework.CoreLibrary/` — full BCL including `System.Reflection` | ||
| - `nanoFramework.CoreLibrary.NoReflection/` — reflection excluded for smaller flash footprint (same sources, minus `System/Reflection/`) | ||
|
|
||
| When adding or removing files, decide whether the change also applies to the NoReflection variant and update its `.nfproj` accordingly. Reflection-only sources stay in the full project. | ||
|
|
||
| ## Native-interop constraints (read before editing methods) | ||
|
|
||
| - Methods marked `[MethodImpl(MethodImplOptions.InternalCall)]` are **native stubs** — the implementation lives in the nanoFramework C++ interpreter. Never add a body. Changing signatures requires a coordinated change to the native runtime. | ||
| - Some methods intentionally `throw new NotSupportedException();` (usually no message) to satisfy an interface contract while omitting the feature to save flash. This is by design — do not "fix" them. | ||
| - Assembly size is a first-class concern. Avoid adding features that noticeably grow the binary; comment the rationale when omitting functionality. | ||
|
|
||
| ## Build & test | ||
|
|
||
| Windows only. Requires Visual Studio 2022 with the nanoFramework VS extension (or MSBuild 17+ with `NFProjectSystem.CSharp.targets`). Linux CI cannot build this repo. CI is Azure Pipelines (`azure-pipelines.yml`), not GitHub Actions. | ||
|
|
||
| ```powershell | ||
| nuget restore nanoFramework.CoreLibrary.sln | ||
| msbuild nanoFramework.CoreLibrary.sln /p:Configuration=Release /p:Platform="Any CPU" | ||
| ``` | ||
|
|
||
| Tests run on the **nanoCLR Win32 emulator** via `vstest.console.exe` — `dotnet test` will not work. Run a single suite from a Developer Command Prompt: | ||
|
|
||
| ```powershell | ||
| vstest.console.exe .\Tests\NFUnitTestBitConverter\bin\Release\NFUnitTest.dll /Settings:.\.runsettings /TestAdapterPath:.\nanoFramework.TestFramework\source\TestAdapter\bin\Debug\net4.8 | ||
| ``` | ||
|
|
||
| Runsettings: | ||
| - `.runsettings` — preview nanoCLR downloaded from NuGet (default) | ||
| - `local_clr.runsettings` — locally-built nanoCLR | ||
|
|
||
| Every test suite is its own `.nfproj` under `Tests/`. Tests reference `mscorlib`, `nanoFramework.TestFramework`, and `nanoFramework.UnitTestLauncher` **as project references** (via the `nanoFramework.TestFramework/` submodule), not as NuGet packages — this is mandatory because the CoreLibrary itself replaces `mscorlib`. | ||
|
|
||
| New API surface requires test coverage for methods, properties, events, and thrown exceptions. | ||
|
|
||
| ## Repo layout landmarks | ||
|
|
||
| - `nanoFramework.CoreLibrary/System/` — all `System.*` sources, subfoldered by sub-namespace (`Collections/`, `Diagnostics/`, `Globalization/`, `IO/`, `Reflection/`, `Runtime/`, `Threading/`, …) | ||
| - `nanoFramework.CoreLibrary/Friends.cs` — `InternalsVisibleTo` declarations for test projects; add new ones here when they need access to internals | ||
| - `nanoFramework.CoreLibrary/key.snk` — strong-name key; do not replace or remove | ||
| - `nanoFramework.TestFramework/` — git submodule; test framework sources referenced by every test project | ||
| - `version.json` — Nerdbank.GitVersioning; do not hand-edit version numbers | ||
| - `.runsettings`, `local_clr.runsettings` — test runner configs (emulator, sequential execution, 20 min timeout) | ||
|
|
||
| ## Coding conventions (highlights) | ||
|
|
||
| - File header on every `.cs`: | ||
| ```csharp | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| ``` | ||
| - 4-space C# indent, CRLF, UTF-8 BOM, `using` outside namespace, System usings first, always braces. | ||
| - Private/internal fields `_camelCase`; private/internal statics `s_camelCase`; constants and public members PascalCase. | ||
| - Avoid `var` — use explicit types. | ||
| - C# language version: 13.0 for the main project; `default` for the NoReflection variant. | ||
|
|
||
| ## Pipeline note | ||
|
|
||
| `RestoreLockedMode` is on in CI. If a package version genuinely needs to change, regenerate and commit the corresponding `packages.lock.json`; do not bypass the lock. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,229 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using nanoFramework.TestFramework; | ||
|
|
||
| namespace NFUnitTestClasses | ||
| { | ||
| [TestClass] | ||
| class UnitTestGenericStaticTests | ||
| { | ||
| [TestMethod] | ||
| public void Generic_StaticField_FirstTouch_Read() | ||
| { | ||
| // First interaction with this closed generic type is a static field read | ||
| // (CEE_LDSFLD), not a constructor call. | ||
| Assert.AreEqual(1, GenericWithStaticField<int>.InitCount); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Generic_StaticMethod_FirstTouch_Call() | ||
| { | ||
| // First interaction with this closed generic type is a static method | ||
| // call (CEE_CALL), not a constructor call. | ||
| Assert.IsTrue(GenericWithStaticMethod<long>.IsInitialized()); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Generic_StaticField_NonGenericHolder() | ||
| { | ||
| BoxHolder.IntBox.Add(42); | ||
|
|
||
| Assert.AreEqual(1, BoxHolder.IntBox.Count); | ||
| Assert.AreEqual(42, BoxHolder.IntBox.Items[0]); | ||
|
|
||
| BoxHolder.StringBox.Add("hello"); | ||
|
|
||
| Assert.AreEqual(1, BoxHolder.StringBox.Count); | ||
| Assert.AreEqual("hello", BoxHolder.StringBox.Items[0]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Generic_StaticField_GenericHolder() | ||
| { | ||
| GenericBoxHolder<int>.Box.Add(99); | ||
|
|
||
| Assert.AreEqual(1, GenericBoxHolder<int>.Box.Count); | ||
| Assert.AreEqual(99, GenericBoxHolder<int>.Box.Items[0]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Generic_StaticField_MultipleInstantiations() | ||
| { | ||
| Assert.AreEqual(1, GenericWithStaticField<byte>.InitCount); | ||
| Assert.AreEqual(1, GenericWithStaticField<string>.InitCount); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Generic_SingleParam_ValueType() | ||
| { | ||
| var container = new GenericContainer<int>(42); | ||
|
|
||
| Assert.AreEqual(42, container.GetValue()); | ||
|
|
||
| container.SetValue(100); | ||
|
|
||
| Assert.AreEqual(100, container.GetValue()); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Generic_SingleParam_ReferenceType() | ||
| { | ||
| var container = new GenericContainer<string>("hello"); | ||
|
|
||
| Assert.AreEqual("hello", container.GetValue()); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Generic_SingleParam_Convert() | ||
| { | ||
| var container = new GenericContainer<int>(21); | ||
|
|
||
| int doubled = container.Convert(v => v * 2); | ||
|
|
||
| Assert.AreEqual(42, doubled); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Generic_TwoParam_MixedTypes() | ||
| { | ||
| var pair = new GenericPair<int, string>(1, "one"); | ||
|
|
||
| Assert.AreEqual(1, pair.First); | ||
| Assert.AreEqual("one", pair.Second); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Generic_TwoParam_SameType() | ||
| { | ||
| var pair = new GenericPair<int, int>(10, 20); | ||
|
|
||
| Assert.AreEqual(10, pair.First); | ||
| Assert.AreEqual(20, pair.Second); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Generic_GenericMethod_Resolution() | ||
| { | ||
| int a = 1; | ||
| int b = 2; | ||
| Swap(ref a, ref b); | ||
|
|
||
| Assert.AreEqual(2, a); | ||
| Assert.AreEqual(1, b); | ||
|
|
||
| string s1 = "A"; | ||
| string s2 = "B"; | ||
| Swap(ref s1, ref s2); | ||
|
|
||
| Assert.AreEqual("B", s1); | ||
| Assert.AreEqual("A", s2); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Generic_MultipleInstantiations_SameMethod() | ||
| { | ||
| var intContainer = new GenericContainer<int>(1); | ||
| var stringContainer = new GenericContainer<string>("one"); | ||
| var pair = new GenericPair<bool, int>(true, 2); | ||
|
|
||
| Assert.AreEqual(1, intContainer.GetValue()); | ||
| Assert.AreEqual("one", stringContainer.GetValue()); | ||
| Assert.IsTrue(pair.First); | ||
| Assert.AreEqual(2, pair.Second); | ||
| } | ||
|
|
||
| private static void Swap<T>(ref T a, ref T b) | ||
| { | ||
| T temp = a; | ||
| a = b; | ||
| b = temp; | ||
| } | ||
|
|
||
| internal class GenericWithStaticField<T> | ||
| { | ||
| internal static T DefaultValue = default(T); | ||
| internal static int InitCount = 0; | ||
|
|
||
| static GenericWithStaticField() | ||
| { | ||
| InitCount = 1; | ||
| } | ||
| } | ||
|
|
||
| internal class GenericWithStaticMethod<T> | ||
| { | ||
| private static bool _initialized = false; | ||
|
|
||
| static GenericWithStaticMethod() | ||
| { | ||
| _initialized = true; | ||
| } | ||
|
|
||
| internal static bool IsInitialized() | ||
| { | ||
| return _initialized; | ||
| } | ||
| } | ||
|
|
||
| internal class GenericStaticFieldBox<T> | ||
| { | ||
| internal T[] Items; | ||
| internal int Count; | ||
|
|
||
| internal GenericStaticFieldBox() | ||
| { | ||
| Items = new T[4]; | ||
| Count = 0; | ||
| } | ||
|
|
||
| internal void Add(T item) | ||
| { | ||
| Items[Count++] = item; | ||
| } | ||
| } | ||
|
|
||
| internal static class BoxHolder | ||
| { | ||
| internal static readonly GenericStaticFieldBox<int> IntBox = new GenericStaticFieldBox<int>(); | ||
| internal static readonly GenericStaticFieldBox<string> StringBox = new GenericStaticFieldBox<string>(); | ||
| } | ||
|
|
||
| internal static class GenericBoxHolder<T> | ||
| { | ||
| internal static readonly GenericStaticFieldBox<T> Box = new GenericStaticFieldBox<T>(); | ||
| } | ||
|
|
||
| internal class GenericContainer<T> | ||
| { | ||
| private T _value; | ||
|
|
||
| internal GenericContainer(T value) | ||
| { | ||
| _value = value; | ||
| } | ||
|
|
||
| internal T GetValue() => _value; | ||
|
|
||
| internal void SetValue(T value) => _value = value; | ||
|
|
||
| internal TResult Convert<TResult>(Func<T, TResult> converter) | ||
| { | ||
| return converter(_value); | ||
| } | ||
| } | ||
|
|
||
| internal class GenericPair<TFirst, TSecond> | ||
| { | ||
| internal TFirst First; | ||
| internal TSecond Second; | ||
|
|
||
| internal GenericPair(TFirst first, TSecond second) | ||
| { | ||
| First = first; | ||
| Second = second; | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.