Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / IntPtr.cs / 1305376 / IntPtr.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: IntPtr
**
**
** Purpose: Platform independent integer
**
**
===========================================================*/
namespace System {
using System;
using System.Globalization;
using System.Runtime;
using System.Runtime.Serialization;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Diagnostics.Contracts;
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct 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
[System.Security.SecuritySafeCritical] // auto-generated
[Pure]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal unsafe bool IsNull()
{
return (this.m_value == null);
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public unsafe IntPtr(int value)
{
#if WIN32
m_value = (void *)value;
#else
m_value = (void *)(long)value;
#endif
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public unsafe IntPtr(long value)
{
#if WIN32
m_value = (void *)checked((int)value);
#else
m_value = (void *)value;
#endif
}
[System.Security.SecurityCritical] // auto-generated
[CLSCompliant(false)]
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
public unsafe IntPtr(void* value)
{
m_value = value;
}
[System.Security.SecurityCritical] // auto-generated
private unsafe IntPtr(SerializationInfo info, StreamingContext context) {
long l = info.GetInt64("value");
if (Size==4 && (l>Int32.MaxValue || l() != null);
#if WIN32
return ((int)m_value).ToString(format, CultureInfo.InvariantCulture);
#else
return ((long)m_value).ToString(format, CultureInfo.InvariantCulture);
#endif
}
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static explicit operator IntPtr (int value)
{
return new IntPtr(value);
}
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static explicit operator IntPtr (long value)
{
return new IntPtr(value);
}
[System.Security.SecurityCritical] // auto-generated
[CLSCompliant(false), ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static unsafe explicit operator IntPtr (void* value)
{
return new IntPtr(value);
}
[System.Security.SecuritySafeCritical] // auto-generated
[CLSCompliant(false)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static unsafe explicit operator void* (IntPtr value)
{
return value.ToPointer();
}
[System.Security.SecuritySafeCritical] // auto-generated
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public unsafe static explicit operator int (IntPtr value)
{
#if WIN32
return (int)value.m_value;
#else
long l = (long)value.m_value;
return checked((int)l);
#endif
}
[System.Security.SecuritySafeCritical] // auto-generated
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public unsafe static explicit operator long (IntPtr value)
{
#if WIN32
return (long)(int)value.m_value;
#else
return (long)value.m_value;
#endif
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public unsafe static bool operator == (IntPtr value1, IntPtr value2)
{
return value1.m_value == value2.m_value;
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public unsafe static bool operator != (IntPtr value1, IntPtr value2)
{
return value1.m_value != value2.m_value;
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static IntPtr Add(IntPtr pointer, int offset)
{
return pointer + offset;
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static IntPtr operator +(IntPtr pointer, int offset)
{
#if WIN32
return new IntPtr(pointer.ToInt32() + offset);
#else
return new IntPtr(pointer.ToInt64() + offset);
#endif
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static IntPtr Subtract(IntPtr pointer, int offset) {
return pointer - offset;
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static IntPtr operator -(IntPtr pointer, int offset) {
#if WIN32
return new IntPtr(pointer.ToInt32() - offset);
#else
return new IntPtr(pointer.ToInt64() - offset);
#endif
}
public static int Size
{
[Pure]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
get
{
#if WIN32
return 4;
#else
return 8;
#endif
}
}
[System.Security.SecuritySafeCritical] // auto-generated
[CLSCompliant(false)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public unsafe void* ToPointer()
{
return m_value;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: IntPtr
**
**
** Purpose: Platform independent integer
**
**
===========================================================*/
namespace System {
using System;
using System.Globalization;
using System.Runtime;
using System.Runtime.Serialization;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Diagnostics.Contracts;
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct 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
[System.Security.SecuritySafeCritical] // auto-generated
[Pure]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal unsafe bool IsNull()
{
return (this.m_value == null);
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public unsafe IntPtr(int value)
{
#if WIN32
m_value = (void *)value;
#else
m_value = (void *)(long)value;
#endif
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public unsafe IntPtr(long value)
{
#if WIN32
m_value = (void *)checked((int)value);
#else
m_value = (void *)value;
#endif
}
[System.Security.SecurityCritical] // auto-generated
[CLSCompliant(false)]
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
public unsafe IntPtr(void* value)
{
m_value = value;
}
[System.Security.SecurityCritical] // auto-generated
private unsafe IntPtr(SerializationInfo info, StreamingContext context) {
long l = info.GetInt64("value");
if (Size==4 && (l>Int32.MaxValue || l() != null);
#if WIN32
return ((int)m_value).ToString(format, CultureInfo.InvariantCulture);
#else
return ((long)m_value).ToString(format, CultureInfo.InvariantCulture);
#endif
}
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static explicit operator IntPtr (int value)
{
return new IntPtr(value);
}
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static explicit operator IntPtr (long value)
{
return new IntPtr(value);
}
[System.Security.SecurityCritical] // auto-generated
[CLSCompliant(false), ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static unsafe explicit operator IntPtr (void* value)
{
return new IntPtr(value);
}
[System.Security.SecuritySafeCritical] // auto-generated
[CLSCompliant(false)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static unsafe explicit operator void* (IntPtr value)
{
return value.ToPointer();
}
[System.Security.SecuritySafeCritical] // auto-generated
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public unsafe static explicit operator int (IntPtr value)
{
#if WIN32
return (int)value.m_value;
#else
long l = (long)value.m_value;
return checked((int)l);
#endif
}
[System.Security.SecuritySafeCritical] // auto-generated
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public unsafe static explicit operator long (IntPtr value)
{
#if WIN32
return (long)(int)value.m_value;
#else
return (long)value.m_value;
#endif
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public unsafe static bool operator == (IntPtr value1, IntPtr value2)
{
return value1.m_value == value2.m_value;
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public unsafe static bool operator != (IntPtr value1, IntPtr value2)
{
return value1.m_value != value2.m_value;
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static IntPtr Add(IntPtr pointer, int offset)
{
return pointer + offset;
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static IntPtr operator +(IntPtr pointer, int offset)
{
#if WIN32
return new IntPtr(pointer.ToInt32() + offset);
#else
return new IntPtr(pointer.ToInt64() + offset);
#endif
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static IntPtr Subtract(IntPtr pointer, int offset) {
return pointer - offset;
}
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public static IntPtr operator -(IntPtr pointer, int offset) {
#if WIN32
return new IntPtr(pointer.ToInt32() - offset);
#else
return new IntPtr(pointer.ToInt64() - offset);
#endif
}
public static int Size
{
[Pure]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
get
{
#if WIN32
return 4;
#else
return 8;
#endif
}
}
[System.Security.SecuritySafeCritical] // auto-generated
[CLSCompliant(false)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public unsafe void* ToPointer()
{
return m_value;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RootProfilePropertySettingsCollection.cs
- ContextBase.cs
- DoubleAnimationUsingPath.cs
- StartUpEventArgs.cs
- ValidatedControlConverter.cs
- CookieProtection.cs
- ToolBarButton.cs
- GeneralTransformGroup.cs
- RootBrowserWindowAutomationPeer.cs
- ADMembershipProvider.cs
- ToolboxItemFilterAttribute.cs
- SessionIDManager.cs
- _Rfc2616CacheValidators.cs
- TrackingLocation.cs
- FigureHelper.cs
- WebControlsSection.cs
- DefaultPropertyAttribute.cs
- X509Certificate.cs
- GridItemPatternIdentifiers.cs
- DataGridViewControlCollection.cs
- BooleanAnimationUsingKeyFrames.cs
- ConfigErrorGlyph.cs
- NavigationEventArgs.cs
- SystemIPInterfaceProperties.cs
- CurrentChangedEventManager.cs
- PassportAuthenticationEventArgs.cs
- GraphicsState.cs
- jithelpers.cs
- RuleElement.cs
- EnvironmentPermission.cs
- RTLAwareMessageBox.cs
- NodeInfo.cs
- ProgressBarRenderer.cs
- TreeNodeCollectionEditor.cs
- Span.cs
- RemoteTokenFactory.cs
- VirtualizingPanel.cs
- ExtensibleClassFactory.cs
- AssemblyInfo.cs
- VirtualizingPanel.cs
- AutoGeneratedField.cs
- DiagnosticsConfiguration.cs
- StrongNameMembershipCondition.cs
- SortedSet.cs
- TextCompositionManager.cs
- ErrorRuntimeConfig.cs
- GB18030Encoding.cs
- MoveSizeWinEventHandler.cs
- Utils.cs
- X509Chain.cs
- RangeBase.cs
- SoapObjectReader.cs
- DataControlFieldHeaderCell.cs
- SqlGenericUtil.cs
- smtppermission.cs
- ApplicationDirectory.cs
- StorageFunctionMapping.cs
- ApplicationId.cs
- EditingScopeUndoUnit.cs
- DataGridViewCellParsingEventArgs.cs
- Table.cs
- PaperSource.cs
- TcpAppDomainProtocolHandler.cs
- DateRangeEvent.cs
- HostExecutionContextManager.cs
- _TransmitFileOverlappedAsyncResult.cs
- BCLDebug.cs
- Positioning.cs
- TypeValidationEventArgs.cs
- PointHitTestResult.cs
- ToolbarAUtomationPeer.cs
- StaticExtensionConverter.cs
- Stacktrace.cs
- RNGCryptoServiceProvider.cs
- EdmFunctionAttribute.cs
- PenLineCapValidation.cs
- MobileControlDesigner.cs
- Pkcs7Signer.cs
- TextBlockAutomationPeer.cs
- DataObjectPastingEventArgs.cs
- OdbcStatementHandle.cs
- __Filters.cs
- TreeIterators.cs
- WebMessageFormatHelper.cs
- CrossContextChannel.cs
- DocumentSequenceHighlightLayer.cs
- ResXBuildProvider.cs
- TextMarkerSource.cs
- TextBoxRenderer.cs
- DrawingAttributes.cs
- FixedSOMTableRow.cs
- ToolStripPanelRow.cs
- MenuStrip.cs
- ExceptionHelpers.cs
- IdentifierCreationService.cs
- RowUpdatingEventArgs.cs
- Frame.cs
- ExpressionBinding.cs
- XmlSchemaSimpleTypeUnion.cs
- BaseDataList.cs