Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / clr / src / BCL / System / Reflection / Pointer.cs / 1 / Pointer.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
////////////////////////////////////////////////////////////////////////////////
//
// This is a wrapper class for Pointers
//
//
//
//
namespace System.Reflection {
using System;
using CultureInfo = System.Globalization.CultureInfo;
using System.Runtime.Serialization;
[CLSCompliant(false)]
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class Pointer: ISerializable {
unsafe private void* _ptr;
private Type _ptrType;
private Pointer() {}
private unsafe Pointer(SerializationInfo info, StreamingContext context)
{
_ptr = ((IntPtr)(info.GetValue("_ptr", typeof(IntPtr)))).ToPointer();
_ptrType = (Type)info.GetValue("_ptrType", typeof(Type));
}
// This method will box an pointer. We save both the
// value and the type so we can access it from the native code
// during an Invoke.
public static unsafe Object Box(void *ptr,Type type) {
if (type == null)
throw new ArgumentNullException("type");
if (!type.IsPointer)
throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"),"ptr");
Pointer x = new Pointer();
x._ptr = ptr;
x._ptrType = type;
return x;
}
// Returned the stored pointer.
public static unsafe void* Unbox(Object ptr) {
if (!(ptr is Pointer))
throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"),"ptr");
return ((Pointer)ptr)._ptr;
}
internal Type GetPointerType() {
return _ptrType;
}
internal unsafe Object GetPointerValue() {
return (IntPtr)_ptr;
}
unsafe void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) {
info.AddValue("_ptr", new IntPtr(_ptr));
info.AddValue("_ptrType", _ptrType);
}
}
}
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- GenericsInstances.cs
- InvokeMethodActivityDesigner.cs
- OutKeywords.cs
- IteratorFilter.cs
- TextElementEnumerator.cs
- TextDocumentView.cs
- MissingManifestResourceException.cs
- XmlDataLoader.cs
- PnrpPermission.cs
- DataMisalignedException.cs
- ServiceThrottle.cs
- AssemblyCollection.cs
- ExpandoObject.cs
- Int32Animation.cs
- FieldInfo.cs
- DataTableTypeConverter.cs
- PropertyValueUIItem.cs
- ProxyElement.cs
- TextRangeProviderWrapper.cs
- TemplateField.cs
- SlotInfo.cs
- WindowVisualStateTracker.cs
- InstanceDescriptor.cs
- AnnotationService.cs
- WindowsGraphics2.cs
- HashSet.cs
- Panel.cs
- metadatamappinghashervisitor.hashsourcebuilder.cs
- RelationshipDetailsCollection.cs
- GcSettings.cs
- ByeOperation11AsyncResult.cs
- UntrustedRecipientException.cs
- CommandLibraryHelper.cs
- WasHostedComPlusFactory.cs
- SerializationInfo.cs
- Dump.cs
- MimeMapping.cs
- SHA256.cs
- Repeater.cs
- MouseEventArgs.cs
- TranslateTransform3D.cs
- ResXFileRef.cs
- ToolBarDesigner.cs
- XmlSerializationWriter.cs
- TextFormattingConverter.cs
- GridPattern.cs
- XmlSiteMapProvider.cs
- PropertySourceInfo.cs
- DeviceSpecificDesigner.cs
- Region.cs
- OdbcReferenceCollection.cs
- Figure.cs
- ExpressionBuilder.cs
- RouteTable.cs
- CompModSwitches.cs
- MailAddressCollection.cs
- WebPartExportVerb.cs
- __Filters.cs
- DateTimeValueSerializer.cs
- EditingMode.cs
- CompressEmulationStream.cs
- CodeDirectoryCompiler.cs
- RequestQueue.cs
- DataReceivedEventArgs.cs
- SingleTagSectionHandler.cs
- LinkArea.cs
- webproxy.cs
- SoapFault.cs
- ContextMarshalException.cs
- StandardOleMarshalObject.cs
- TextBoxAutoCompleteSourceConverter.cs
- Size.cs
- _WinHttpWebProxyDataBuilder.cs
- DoubleCollectionValueSerializer.cs
- XmlDataDocument.cs
- QuaternionRotation3D.cs
- ScriptingRoleServiceSection.cs
- Attachment.cs
- GridViewUpdateEventArgs.cs
- OleDbConnectionInternal.cs
- FixedStringLookup.cs
- SimpleType.cs
- SystemTcpConnection.cs
- ByteStorage.cs
- ProviderSettingsCollection.cs
- Transform3D.cs
- FontCacheUtil.cs
- TextMarkerSource.cs
- XmlEnumAttribute.cs
- EntityDataSourceColumn.cs
- RadioButtonList.cs
- ThreadAttributes.cs
- Binding.cs
- XmlNavigatorFilter.cs
- MenuTracker.cs
- MemberAssignmentAnalysis.cs
- XmlSchemaSimpleContentRestriction.cs
- DataListItem.cs
- ButtonBase.cs
- LoginStatusDesigner.cs