NS2.0 Complete DBNull's surface area. (dotnet/coreclr#3085)
authorAtsushi Kanamori <AtsushiKan@users.noreply.github.com>
Thu, 23 Mar 2017 22:34:07 +0000 (15:34 -0700)
committerdotnet-bot <dotnet-bot@microsoft.com>
Fri, 24 Mar 2017 20:13:42 +0000 (20:13 +0000)
* Copy over CoreCLRs' DBNull.cs

* Make it presentable, then move it into the shared partition.

Commit migrated from https://github.com/dotnet/coreclr/commit/a4cffe635dad862249899f0a181a72b791c6fafd

src/coreclr/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
src/coreclr/src/mscorlib/shared/System/DBNull.cs [new file with mode: 0644]

index 4f11d11..dee2418 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)System\DataMisalignedException.cs"/>
     <Compile Include="$(MSBuildThisFileDirectory)System\DateTimeKind.cs"/>
     <Compile Include="$(MSBuildThisFileDirectory)System\DayOfWeek.cs"/>
+    <Compile Include="$(MSBuildThisFileDirectory)System\DBNull.cs"/>
     <Compile Include="$(MSBuildThisFileDirectory)System\DefaultBinder.cs"/>
     <Compile Include="$(MSBuildThisFileDirectory)System\DivideByZeroException.cs"/>
     <Compile Include="$(MSBuildThisFileDirectory)System\DuplicateWaitObjectException.cs"/>
diff --git a/src/coreclr/src/mscorlib/shared/System/DBNull.cs b/src/coreclr/src/mscorlib/shared/System/DBNull.cs
new file mode 100644 (file)
index 0000000..486eb72
--- /dev/null
@@ -0,0 +1,119 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// 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.Runtime.Serialization;
+
+namespace System
+{
+    [Serializable]
+    public sealed class DBNull : ISerializable, IConvertible
+    {
+        private DBNull()
+        {
+        }
+
+        private DBNull(SerializationInfo info, StreamingContext context)
+        {
+            throw new NotSupportedException(SR.NotSupported_DBNullSerial);
+        }
+
+        public static readonly DBNull Value = new DBNull();
+
+        public void GetObjectData(SerializationInfo info, StreamingContext context)
+        {
+            UnitySerializationHolder.GetUnitySerializationInfo(info, UnitySerializationHolder.NullUnity, null, null);
+        }
+
+        public override string ToString()
+        {
+            return string.Empty;
+        }
+
+        public string ToString(IFormatProvider provider)
+        {
+            return string.Empty;
+        }
+
+        public TypeCode GetTypeCode()
+        {
+            return TypeCode.DBNull;
+        }
+
+        bool IConvertible.ToBoolean(IFormatProvider provider)
+        {
+            throw new InvalidCastException(SR.InvalidCast_FromDBNull);
+        }
+
+        char IConvertible.ToChar(IFormatProvider provider)
+        {
+            throw new InvalidCastException(SR.InvalidCast_FromDBNull);
+        }
+
+        sbyte IConvertible.ToSByte(IFormatProvider provider)
+        {
+            throw new InvalidCastException(SR.InvalidCast_FromDBNull);
+        }
+
+        byte IConvertible.ToByte(IFormatProvider provider)
+        {
+            throw new InvalidCastException(SR.InvalidCast_FromDBNull);
+        }
+
+        short IConvertible.ToInt16(IFormatProvider provider)
+        {
+            throw new InvalidCastException(SR.InvalidCast_FromDBNull);
+        }
+
+        ushort IConvertible.ToUInt16(IFormatProvider provider)
+        {
+            throw new InvalidCastException(SR.InvalidCast_FromDBNull);
+        }
+
+        int IConvertible.ToInt32(IFormatProvider provider)
+        {
+            throw new InvalidCastException(SR.InvalidCast_FromDBNull);
+        }
+
+        uint IConvertible.ToUInt32(IFormatProvider provider)
+        {
+            throw new InvalidCastException(SR.InvalidCast_FromDBNull);
+        }
+
+        long IConvertible.ToInt64(IFormatProvider provider)
+        {
+            throw new InvalidCastException(SR.InvalidCast_FromDBNull);
+        }
+
+        ulong IConvertible.ToUInt64(IFormatProvider provider)
+        {
+            throw new InvalidCastException(SR.InvalidCast_FromDBNull);
+        }
+
+        float IConvertible.ToSingle(IFormatProvider provider)
+        {
+            throw new InvalidCastException(SR.InvalidCast_FromDBNull);
+        }
+
+        double IConvertible.ToDouble(IFormatProvider provider)
+        {
+            throw new InvalidCastException(SR.InvalidCast_FromDBNull);
+        }
+
+        decimal IConvertible.ToDecimal(IFormatProvider provider)
+        {
+            throw new InvalidCastException(SR.InvalidCast_FromDBNull);
+        }
+
+        DateTime IConvertible.ToDateTime(IFormatProvider provider)
+        {
+            throw new InvalidCastException(SR.InvalidCast_FromDBNull);
+        }
+
+        object IConvertible.ToType(Type type, IFormatProvider provider)
+        {
+            return Convert.DefaultToType((IConvertible)this, type, provider);
+        }
+    }
+}
+