From f56fc8647799686eba3c5e221ece8afadd80e7ea Mon Sep 17 00:00:00 2001 From: flyingoverclouds Date: Mon, 16 Nov 2020 14:50:20 +0100 Subject: [PATCH] Add IEnumerable implementation on String with exception throwing. --- nanoFramework.CoreLibrary/System/String.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/nanoFramework.CoreLibrary/System/String.cs b/nanoFramework.CoreLibrary/System/String.cs index c6ac0dde..2d58692f 100644 --- a/nanoFramework.CoreLibrary/System/String.cs +++ b/nanoFramework.CoreLibrary/System/String.cs @@ -7,6 +7,7 @@ namespace System { using Runtime.CompilerServices; + using System.Collections; /// /// Represents text as a sequence of UTF-16 code units. /// @@ -17,11 +18,26 @@ namespace System // 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 sealed class String : IComparable + public sealed class String : IComparable, IEnumerable #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() { + /// + /// **Not supported in NanoFramework** + /// Return an enumerator that iterate on each char of the string. + /// + /// An IEnumerator object that can be used to iterate through the collection. + public IEnumerator GetEnumerator() + { + // Not implemented because of assembly size constraint + // Throw a NotSupportedException in compliance of .net practices + // (no message to preserve assembly size/memory consumption) + // See https://docs.microsoft.com/en-us/dotnet/api/system.notsupportedexception + throw new NotSupportedException(); + } + + /// /// Represents the empty string. This field is read-only. /// @@ -64,6 +80,9 @@ public override bool Equals(object obj) [MethodImpl(MethodImplOptions.InternalCall)] public static extern bool operator !=(String a, String b); + + + /// /// Gets the Char object at a specified position in the current String object. ///