Skip to content

Commit 5ac417b

Browse files
Add IEnumerable implementation on String with exception throwing. (#114)
***NO_CI***
1 parent bdc5c79 commit 5ac417b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

nanoFramework.CoreLibrary/System/String.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace System
88
{
99
using Runtime.CompilerServices;
10+
using System.Collections;
1011
/// <summary>
1112
/// Represents text as a sequence of UTF-16 code units.
1213
/// </summary>
@@ -17,11 +18,26 @@ namespace System
1718
// GetHashCode() implementation is provided by general native function CLR_RT_HeapBlock::GetHashCode //
1819
///////////////////////////////////////////////////////////////////////////////////////////////////////
1920
#pragma warning disable S1206 // "Equals(Object)" and "GetHashCode()" should be overridden in pairs
20-
public sealed class String : IComparable
21+
public sealed class String : IComparable, IEnumerable
2122
#pragma warning restore S1206 // "Equals(Object)" and "GetHashCode()" should be overridden in pairs
2223
#pragma warning restore CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode()
2324
#pragma warning restore CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
2425
{
26+
/// <summary>
27+
/// **Not supported in NanoFramework**
28+
/// Return an enumerator that iterate on each char of the string.
29+
/// </summary>
30+
/// <returns>An IEnumerator object that can be used to iterate through the collection.</returns>
31+
public IEnumerator GetEnumerator()
32+
{
33+
// Not implemented because of assembly size constraint
34+
// Throw a NotSupportedException in compliance of .net practices
35+
// (no message to preserve assembly size/memory consumption)
36+
// See https://docs.microsoft.com/en-us/dotnet/api/system.notsupportedexception
37+
throw new NotSupportedException();
38+
}
39+
40+
2541
/// <summary>
2642
/// Represents the empty string. This field is read-only.
2743
/// </summary>
@@ -64,6 +80,9 @@ public override bool Equals(object obj)
6480
[MethodImpl(MethodImplOptions.InternalCall)]
6581
public static extern bool operator !=(String a, String b);
6682

83+
84+
85+
6786
/// <summary>
6887
/// Gets the Char object at a specified position in the current String object.
6988
/// </summary>

0 commit comments

Comments
 (0)