summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/IntPtr.cs
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2017-04-13 14:17:19 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2017-04-13 14:17:19 +0900
commita56e30c8d33048216567753d9d3fefc2152af8ac (patch)
tree7e5d979695fc4a431740982eb1cfecc2898b23a5 /src/mscorlib/src/System/IntPtr.cs
parent4b11dc566a5bbfa1378d6266525c281b028abcc8 (diff)
downloadcoreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.tar.gz
coreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.tar.bz2
coreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.zip
Imported Upstream version 2.0.0.11353upstream/2.0.0.11353
Diffstat (limited to 'src/mscorlib/src/System/IntPtr.cs')
-rw-r--r--src/mscorlib/src/System/IntPtr.cs100
1 files changed, 56 insertions, 44 deletions
diff --git a/src/mscorlib/src/System/IntPtr.cs b/src/mscorlib/src/System/IntPtr.cs
index dbddcd319a..28f1b1baa8 100644
--- a/src/mscorlib/src/System/IntPtr.cs
+++ b/src/mscorlib/src/System/IntPtr.cs
@@ -11,8 +11,8 @@
**
===========================================================*/
-namespace System {
-
+namespace System
+{
using System;
using System.Globalization;
using System.Runtime;
@@ -26,31 +26,31 @@ namespace System {
public struct IntPtr : IEquatable<IntPtr>, ISerializable
{
unsafe private void* m_value; // The compiler treats void* closest to uint hence explicit casts are required to preserve int behavior
-
+
public static readonly IntPtr Zero;
// fast way to compare IntPtr to (IntPtr)0 while IntPtr.Zero doesn't work due to slow statics access
[Pure]
internal unsafe bool IsNull()
{
- return (this.m_value == null);
+ return (m_value == null);
}
[System.Runtime.Versioning.NonVersionable]
public unsafe IntPtr(int value)
{
#if BIT64
- m_value = (void *)(long)value;
+ m_value = (void*)(long)value;
#else // !BIT64 (32)
m_value = (void *)value;
#endif
}
-
+
[System.Runtime.Versioning.NonVersionable]
public unsafe IntPtr(long value)
{
#if BIT64
- m_value = (void *)value;
+ m_value = (void*)value;
#else // !BIT64 (32)
m_value = (void *)checked((int)value);
#endif
@@ -63,30 +63,36 @@ namespace System {
m_value = value;
}
- private unsafe IntPtr(SerializationInfo info, StreamingContext context) {
+ private unsafe IntPtr(SerializationInfo info, StreamingContext context)
+ {
long l = info.GetInt64("value");
- if (Size==4 && (l>Int32.MaxValue || l<Int32.MinValue)) {
- throw new ArgumentException(Environment.GetResourceString("Serialization_InvalidPtrValue"));
+ if (Size == 4 && (l > Int32.MaxValue || l < Int32.MinValue))
+ {
+ throw new ArgumentException(SR.Serialization_InvalidPtrValue);
}
- m_value = (void *)l;
+ m_value = (void*)l;
}
- unsafe void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) {
- if (info==null) {
+ unsafe void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ if (info == null)
+ {
throw new ArgumentNullException(nameof(info));
}
Contract.EndContractBlock();
#if BIT64
- info.AddValue("value", (long)(m_value));
+ info.AddValue("value", (long)(m_value));
#else // !BIT64 (32)
info.AddValue("value", (long)((int)m_value));
#endif
}
- public unsafe override bool Equals(Object obj) {
- if (obj is IntPtr) {
+ public unsafe override bool Equals(Object obj)
+ {
+ if (obj is IntPtr)
+ {
return (m_value == ((IntPtr)obj).m_value);
}
return false;
@@ -96,8 +102,9 @@ namespace System {
{
return m_value == other.m_value;
}
-
- public unsafe override int GetHashCode() {
+
+ public unsafe override int GetHashCode()
+ {
#if BIT64
long l = (long)m_value;
return (unchecked((int)l) ^ (int)(l >> 32));
@@ -107,38 +114,41 @@ namespace System {
}
[System.Runtime.Versioning.NonVersionable]
- public unsafe int ToInt32() {
+ public unsafe int ToInt32()
+ {
#if BIT64
- long l = (long)m_value;
- return checked((int)l);
+ long l = (long)m_value;
+ return checked((int)l);
#else // !BIT64 (32)
return (int)m_value;
#endif
}
[System.Runtime.Versioning.NonVersionable]
- public unsafe long ToInt64() {
+ public unsafe long ToInt64()
+ {
#if BIT64
- return (long)m_value;
+ return (long)m_value;
#else // !BIT64 (32)
return (long)(int)m_value;
#endif
}
- public unsafe override String ToString() {
+ public unsafe override String ToString()
+ {
#if BIT64
- return ((long)m_value).ToString(CultureInfo.InvariantCulture);
+ return ((long)m_value).ToString(CultureInfo.InvariantCulture);
#else // !BIT64 (32)
return ((int)m_value).ToString(CultureInfo.InvariantCulture);
#endif
}
- public unsafe String ToString(String format)
+ public unsafe String ToString(String format)
{
Contract.Ensures(Contract.Result<String>() != null);
#if BIT64
- return ((long)m_value).ToString(format, CultureInfo.InvariantCulture);
+ return ((long)m_value).ToString(format, CultureInfo.InvariantCulture);
#else // !BIT64 (32)
return ((int)m_value).ToString(format, CultureInfo.InvariantCulture);
#endif
@@ -146,20 +156,20 @@ namespace System {
[System.Runtime.Versioning.NonVersionable]
- public static explicit operator IntPtr (int value)
+ public static explicit operator IntPtr(int value)
{
return new IntPtr(value);
}
[System.Runtime.Versioning.NonVersionable]
- public static explicit operator IntPtr (long value)
+ public static explicit operator IntPtr(long value)
{
return new IntPtr(value);
}
[CLSCompliant(false), ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
[System.Runtime.Versioning.NonVersionable]
- public static unsafe explicit operator IntPtr (void* value)
+ public static unsafe explicit operator IntPtr(void* value)
{
return new IntPtr(value);
}
@@ -172,34 +182,34 @@ namespace System {
}
[System.Runtime.Versioning.NonVersionable]
- public unsafe static explicit operator int (IntPtr value)
+ public unsafe static explicit operator int(IntPtr value)
{
#if BIT64
- long l = (long)value.m_value;
- return checked((int)l);
+ long l = (long)value.m_value;
+ return checked((int)l);
#else // !BIT64 (32)
return (int)value.m_value;
#endif
}
[System.Runtime.Versioning.NonVersionable]
- public unsafe static explicit operator long (IntPtr value)
+ public unsafe static explicit operator long(IntPtr value)
{
#if BIT64
- return (long)value.m_value;
+ return (long)value.m_value;
#else // !BIT64 (32)
return (long)(int)value.m_value;
#endif
}
[System.Runtime.Versioning.NonVersionable]
- public unsafe static bool operator == (IntPtr value1, IntPtr value2)
+ public unsafe static bool operator ==(IntPtr value1, IntPtr value2)
{
return value1.m_value == value2.m_value;
}
[System.Runtime.Versioning.NonVersionable]
- public unsafe static bool operator != (IntPtr value1, IntPtr value2)
+ public unsafe static bool operator !=(IntPtr value1, IntPtr value2)
{
return value1.m_value != value2.m_value;
}
@@ -211,24 +221,26 @@ namespace System {
}
[System.Runtime.Versioning.NonVersionable]
- public static IntPtr operator +(IntPtr pointer, int offset)
+ public static IntPtr operator +(IntPtr pointer, int offset)
{
#if BIT64
- return new IntPtr(pointer.ToInt64() + offset);
+ return new IntPtr(pointer.ToInt64() + offset);
#else // !BIT64 (32)
return new IntPtr(pointer.ToInt32() + offset);
#endif
}
[System.Runtime.Versioning.NonVersionable]
- public static IntPtr Subtract(IntPtr pointer, int offset) {
+ public static IntPtr Subtract(IntPtr pointer, int offset)
+ {
return pointer - offset;
}
[System.Runtime.Versioning.NonVersionable]
- public static IntPtr operator -(IntPtr pointer, int offset) {
+ public static IntPtr operator -(IntPtr pointer, int offset)
+ {
#if BIT64
- return new IntPtr(pointer.ToInt64() - offset);
+ return new IntPtr(pointer.ToInt64() - offset);
#else // !BIT64 (32)
return new IntPtr(pointer.ToInt32() - offset);
#endif
@@ -241,13 +253,13 @@ namespace System {
get
{
#if BIT64
- return 8;
+ return 8;
#else // !BIT64 (32)
return 4;
#endif
}
}
-
+
[CLSCompliant(false)]
[System.Runtime.Versioning.NonVersionable]