<Compile Include="$(BclSourcesRoot)\System\Resources\ResourceSet.cs" />
</ItemGroup>
<ItemGroup>
- <Compile Include="$(BclSourcesRoot)\System\Nullable.cs" />
<Compile Include="$(BclSourcesRoot)\System\Collections\Generic\Comparer.cs" />
<Compile Include="$(BclSourcesRoot)\System\Collections\Generic\ComparerHelpers.cs" />
<Compile Include="$(BclSourcesRoot)\System\Collections\Generic\EqualityComparer.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<Compile Include="$(BclSourcesRoot)\Interop\Windows\Kernel32\Interop.GetSystemDirectoryW.cs" />
- <Compile Include="$(BclSourcesRoot)\Interop\Windows\Normaliz\Interop.Idna.cs" />
- <Compile Include="$(BclSourcesRoot)\Interop\Windows\Normaliz\Interop.Normalization.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Debug.Windows.cs" />
<Compile Include="$(BclSourcesRoot)\System\Globalization\CompareInfo.Windows.cs" />
<Compile Include="$(BclSourcesRoot)\System\Globalization\CultureData.Windows.cs" />
<Compile Include="$(BclSourcesRoot)\System\Globalization\CultureInfo.Windows.cs" />
<Compile Include="$(BclSourcesRoot)\System\Globalization\GlobalizationMode.Windows.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Globalization\IdnMapping.Windows.cs" />
<Compile Include="$(BclSourcesRoot)\System\Globalization\TextInfo.Windows.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Text\Normalization.Windows.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\ClrThreadPoolBoundHandle.Windows.cs" />
<Compile Include="$(BclSourcesRoot)\System\Environment.Windows.cs" />
<Compile Include="$(BclSourcesRoot)\System\TimeZoneInfo.Win32.cs" />
//
[DllImport("Normaliz.dll", CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern int IdnToAscii(
+ internal static extern unsafe int IdnToAscii(
uint dwFlags,
- IntPtr lpUnicodeCharStr,
+ char* lpUnicodeCharStr,
int cchUnicodeChar,
- [System.Runtime.InteropServices.OutAttribute()]
- IntPtr lpASCIICharStr,
+ char* lpASCIICharStr,
int cchASCIIChar);
[DllImport("Normaliz.dll", CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern int IdnToUnicode(
+ internal static extern unsafe int IdnToUnicode(
uint dwFlags,
- IntPtr lpASCIICharStr,
+ char* lpASCIICharStr,
int cchASCIIChar,
- [System.Runtime.InteropServices.OutAttribute()]
- IntPtr lpUnicodeCharStr,
+ char* lpUnicodeCharStr,
int cchUnicodeChar);
internal const int IDN_ALLOW_UNASSIGNED = 0x1;
internal const int IDN_USE_STD3_ASCII_RULES = 0x2;
- internal const int ERROR_INVALID_NAME = 123;
}
}
<Compile Include="$(MSBuildThisFileDirectory)System\NotImplementedException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\NonSerializedAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\NotSupportedException.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Nullable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Number.Formatting.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Number.NumberBuffer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Number.Parsing.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Text\EncodingNLS.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Text\EncodingProvider.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Text\Latin1Encoding.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Normalization.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Text\NormalizationForm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Text\StringBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Text\UnicodeEncoding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Text\UTF32Encoding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.WideCharToMultiByte.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_IntPtr.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_NativeOverlapped.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Normaliz\Interop.Idna.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Normaliz\Interop.Normalization.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\OleAut32\Interop.SysAllocStringLen.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\OleAut32\Interop.SysFreeString.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\OleAut32\Interop.SysStringLen.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CalendarData.Windows.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\HijriCalendar.Win32.cs" Condition="'$(EnableWinRT)' != 'true' and '$(EnableDummyGlobalizationImplementation)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\HijriCalendar.WinRT.cs" Condition="'$(EnableWinRT)' == 'true'" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\IdnMapping.Windows.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\JapaneseCalendar.Win32.cs" Condition="'$(EnableWinRT)' != 'true' and '$(EnableDummyGlobalizationImplementation)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\JapaneseCalendar.WinRT.cs" Condition="'$(EnableWinRT)' == 'true'" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\Normalization.Windows.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStreamCompletionSource.Win32.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\Path.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\IdnMapping.Unix.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\JapaneseCalendar.Unix.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\LocaleData.Unix.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\Normalization.Unix.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.OSX.cs" Condition="'$(TargetsOSX)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Linux.cs" Condition="'$(TargetsOSX)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\Path.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\PathInternal.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Security\SecureString.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Normalization.Unix.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
</ItemGroup>
</Project>
uint flags = Flags;
// Determine the required length
- int length = Interop.Normaliz.IdnToAscii(flags, new IntPtr(unicode), count, IntPtr.Zero, 0);
+ int length = Interop.Normaliz.IdnToAscii(flags, unicode, count, null, 0);
if (length == 0)
{
- ThrowForZeroLength(nameof(unicode), SR.Argument_IdnIllegalName, SR.Argument_InvalidCharSequenceNoIndex);
+ ThrowForZeroLength(unicode: true);
}
// Do the conversion
else
{
char[] output = new char[length];
- fixed (char* pOutput = output)
+ fixed (char* pOutput = &output[0])
{
return GetAsciiCore(unicode, count, flags, pOutput, length);
}
{
Debug.Assert(!GlobalizationMode.Invariant);
- int length = Interop.Normaliz.IdnToAscii(flags, new IntPtr(unicode), count, new IntPtr(output), outputLength);
+ int length = Interop.Normaliz.IdnToAscii(flags, unicode, count, output, outputLength);
if (length == 0)
{
- ThrowForZeroLength(nameof(unicode), SR.Argument_IdnIllegalName, SR.Argument_InvalidCharSequenceNoIndex);
+ ThrowForZeroLength(unicode: true);
}
Debug.Assert(length == outputLength);
return new string(output, 0, length);
uint flags = Flags;
// Determine the required length
- int length = Interop.Normaliz.IdnToUnicode(flags, new IntPtr(ascii), count, IntPtr.Zero, 0);
+ int length = Interop.Normaliz.IdnToUnicode(flags, ascii, count, null, 0);
if (length == 0)
{
- ThrowForZeroLength(nameof(ascii), SR.Argument_IdnIllegalName, SR.Argument_IdnBadPunycode);
+ ThrowForZeroLength(unicode: false);
}
// Do the conversion
else
{
char[] output = new char[length];
- fixed (char* pOutput = output)
+ fixed (char* pOutput = &output[0])
{
return GetUnicodeCore(ascii, count, flags, pOutput, length);
}
{
Debug.Assert(!GlobalizationMode.Invariant);
- int length = Interop.Normaliz.IdnToUnicode(flags, new IntPtr(ascii), count, new IntPtr(output), outputLength);
+ int length = Interop.Normaliz.IdnToUnicode(flags, ascii, count, output, outputLength);
if (length == 0)
{
- ThrowForZeroLength(nameof(ascii), SR.Argument_IdnIllegalName, SR.Argument_IdnBadPunycode);
+ ThrowForZeroLength(unicode: false);
}
Debug.Assert(length == outputLength);
return new string(output, 0, length);
}
}
- private static void ThrowForZeroLength(string paramName, string invalidNameString, string otherString)
+ private static void ThrowForZeroLength(bool unicode)
{
+ int lastError = Marshal.GetLastWin32Error();
+
throw new ArgumentException(
- Marshal.GetLastWin32Error() == Interop.Normaliz.ERROR_INVALID_NAME ? invalidNameString : otherString,
- paramName);
+ lastError == Interop.Errors.ERROR_INVALID_NAME ? SR.Argument_IdnIllegalName :
+ (unicode ? SR.Argument_InvalidCharSequenceNoIndex : SR.Argument_IdnBadPunycode),
+ unicode ? "unicode" : "ascii");
}
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Diagnostics;
using System.Security;
using System.Text;
using System.Globalization;
namespace System.Text
{
- static partial class Normalization
+ internal static partial class Normalization
{
- public static bool IsNormalized(this string strInput, NormalizationForm normalizationForm)
+ internal static bool IsNormalized(string strInput, NormalizationForm normalizationForm)
{
- ValidateArguments(strInput, normalizationForm);
-
if (GlobalizationMode.Invariant)
{
// In Invariant mode we assume all characters are normalized.
return true;
}
+ ValidateArguments(strInput, normalizationForm);
+
int ret = Interop.GlobalizationInterop.IsNormalized(normalizationForm, strInput, strInput.Length);
if (ret == -1)
return ret == 1;
}
- public static string Normalize(this string strInput, NormalizationForm normalizationForm)
+ internal static string Normalize(string strInput, NormalizationForm normalizationForm)
{
- ValidateArguments(strInput, normalizationForm);
-
if (GlobalizationMode.Invariant)
{
// In Invariant mode we assume all characters are normalized.
return strInput;
}
+ ValidateArguments(strInput, normalizationForm);
+
char[] buf = new char[strInput.Length];
for (int attempts = 2; attempts > 0; attempts--)
private static void ValidateArguments(string strInput, NormalizationForm normalizationForm)
{
- if (strInput == null)
- {
- throw new ArgumentNullException(nameof(strInput));
- }
+ Debug.Assert(strInput != null);
if (normalizationForm != NormalizationForm.FormC && normalizationForm != NormalizationForm.FormD &&
normalizationForm != NormalizationForm.FormKC && normalizationForm != NormalizationForm.FormKD)
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-using System.Security;
+using System.Diagnostics;
using System.Globalization;
-using System.Text;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
-using System.Diagnostics;
+using System.Text;
namespace System.Text
{
- // This internal class wraps up our normalization behavior
-
- internal class Normalization
+ internal static partial class Normalization
{
- internal static bool IsNormalized(String strInput, NormalizationForm normalizationForm)
+ internal static bool IsNormalized(string strInput, NormalizationForm normalizationForm)
{
if (GlobalizationMode.Invariant)
{
case Interop.Errors.ERROR_INVALID_PARAMETER:
case Interop.Errors.ERROR_NO_UNICODE_TRANSLATION:
- if (!Enum.IsDefined(typeof(NormalizationForm), normalizationForm))
+ if (normalizationForm != NormalizationForm.FormC &&
+ normalizationForm != NormalizationForm.FormD &&
+ normalizationForm != NormalizationForm.FormKC &&
+ normalizationForm != NormalizationForm.FormKD)
{
throw new ArgumentException(SR.Argument_InvalidNormalizationForm, nameof(normalizationForm));
}
return result;
}
- internal static String Normalize(String strInput, NormalizationForm normalizationForm)
+ internal static string Normalize(string strInput, NormalizationForm normalizationForm)
{
if (GlobalizationMode.Invariant)
{
{
if (lastError == Interop.Errors.ERROR_INVALID_PARAMETER)
{
- if (!Enum.IsDefined(typeof(NormalizationForm), normalizationForm))
+ if (normalizationForm != NormalizationForm.FormC &&
+ normalizationForm != NormalizationForm.FormD &&
+ normalizationForm != NormalizationForm.FormKC &&
+ normalizationForm != NormalizationForm.FormKD)
{
throw new ArgumentException(SR.Argument_InvalidNormalizationForm, nameof(normalizationForm));
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-
using System;
-
using System.Globalization;
using System.Reflection;
using System.Collections.Generic;
using System.Runtime;
+using System.Runtime.Versioning;
using System.Runtime.CompilerServices;
-using System.Security;
namespace System
{
- // Warning, don't put System.Runtime.Serialization.On*Serializ*Attribute
- // on this class without first fixing ObjectClone::InvokeVtsCallbacks
// Also, because we have special type system support that says a a boxed Nullable<T>
// can be used where a boxed<T> is use, Nullable<T> can not implement any intefaces
// at all (since T may not). Do NOT add any interfaces to Nullable!
//
[Serializable]
- [System.Runtime.Versioning.NonVersionable] // This only applies to field layout
+ [NonVersionable] // This only applies to field layout
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct Nullable<T> where T : struct
{
private readonly bool hasValue; // Do not rename (binary serialization)
internal readonly T value; // Do not rename (binary serialization)
- [System.Runtime.Versioning.NonVersionable]
+ [NonVersionable]
public Nullable(T value)
{
this.value = value;
public bool HasValue
{
- [System.Runtime.Versioning.NonVersionable]
+ [NonVersionable]
get
{
return hasValue;
}
}
- [System.Runtime.Versioning.NonVersionable]
+ [NonVersionable]
public T GetValueOrDefault()
{
return value;
}
- [System.Runtime.Versioning.NonVersionable]
+ [NonVersionable]
public T GetValueOrDefault(T defaultValue)
{
return hasValue ? value : defaultValue;
return hasValue ? value.ToString() : "";
}
- [System.Runtime.Versioning.NonVersionable]
+ [NonVersionable]
public static implicit operator Nullable<T>(T value)
{
return new Nullable<T>(value);
}
- [System.Runtime.Versioning.NonVersionable]
+ [NonVersionable]
public static explicit operator T(Nullable<T> value)
{
return value.Value;
}
-
- // The following already obsoleted methods were removed:
- // public int CompareTo(object other)
- // public int CompareTo(Nullable<T> other)
- // public bool Equals(Nullable<T> other)
- // public static Nullable<T> FromObject(object value)
- // public object ToObject()
- // public string ToString(string format)
- // public string ToString(IFormatProvider provider)
- // public string ToString(string format, IFormatProvider provider)
-
- // The following newly obsoleted methods were removed:
- // string IFormattable.ToString(string format, IFormatProvider provider)
- // int IComparable.CompareTo(object other)
- // int IComparable<Nullable<T>>.CompareTo(Nullable<T> other)
- // bool IEquatable<Nullable<T>>.Equals(Nullable<T> other)
}
public static class Nullable
{
throw new ArgumentNullException(nameof(nullableType));
}
- Type result = null;
+
+#if CORERT
+ // This is necessary to handle types without reflection metadata
+ if (nullableType.TryGetEEType(out EETypePtr nullableEEType))
+ {
+ if (nullableEEType.IsGeneric)
+ {
+ if (nullableEEType.IsNullable)
+ {
+ return Internal.Reflection.Core.NonPortable.RuntimeTypeUnifier.GetRuntimeTypeForEEType(nullableEEType.NullableType);
+ }
+ }
+ return null;
+ }
+#endif
+
if (nullableType.IsGenericType && !nullableType.IsGenericTypeDefinition)
{
// instantiated generic type only
Type genericType = nullableType.GetGenericTypeDefinition();
if (Object.ReferenceEquals(genericType, typeof(Nullable<>)))
{
- result = nullableType.GetGenericArguments()[0];
+ return nullableType.GetGenericArguments()[0];
}
}
- return result;
+ return null;
}
-
- // The following already obsoleted methods were removed:
- // public static bool HasValue<T>(Nullable<T> value)
- // public static T GetValueOrDefault<T>(Nullable<T> value)
- // public static T GetValueOrDefault<T>(Nullable<T> value, T valueWhenNull)
-
- // The following newly obsoleted methods were removed:
- // public static Nullable<T> FromObject<T>(object value)
- // public static object ToObject<T>(Nullable<T> value)
- // public static object Wrap(object value, Type type)
- // public static object Unwrap(object value)
}
}