Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // 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); } } } // 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
- TransactionInformation.cs
- OrElse.cs
- updateconfighost.cs
- TypeElement.cs
- LZCodec.cs
- ImageBrush.cs
- FrameworkPropertyMetadata.cs
- StrongBox.cs
- Random.cs
- AssertUtility.cs
- MsmqOutputMessage.cs
- Point.cs
- MetadataItemEmitter.cs
- SHA256Cng.cs
- XmlValueConverter.cs
- ProfileService.cs
- IssuanceTokenProviderState.cs
- ComponentDispatcher.cs
- mongolianshape.cs
- EndpointPerformanceCounters.cs
- ValidatorCompatibilityHelper.cs
- WindowsStartMenu.cs
- XmlIgnoreAttribute.cs
- FixedPageProcessor.cs
- SafeBitVector32.cs
- XamlWriter.cs
- PolygonHotSpot.cs
- ELinqQueryState.cs
- VectorCollectionConverter.cs
- ConvertersCollection.cs
- DesignerLoader.cs
- KeyPressEvent.cs
- SimpleBitVector32.cs
- AvtEvent.cs
- VisualBasicSettingsConverter.cs
- Content.cs
- DBBindings.cs
- DataRecord.cs
- HtmlUtf8RawTextWriter.cs
- XmlBaseWriter.cs
- StatusBar.cs
- PagesSection.cs
- ConversionContext.cs
- UrlMappingCollection.cs
- RoleGroupCollection.cs
- LabelLiteral.cs
- GcHandle.cs
- Hex.cs
- DataViewManagerListItemTypeDescriptor.cs
- SqlConnectionHelper.cs
- RemoveStoryboard.cs
- TrustManager.cs
- DataGridViewSelectedRowCollection.cs
- HwndStylusInputProvider.cs
- ObjectListShowCommandsEventArgs.cs
- MediaElement.cs
- ListViewDeletedEventArgs.cs
- SecurityTokenTypes.cs
- GetCardDetailsRequest.cs
- AppAction.cs
- SqlFileStream.cs
- LineProperties.cs
- PropertyGrid.cs
- MemoryFailPoint.cs
- UidPropertyAttribute.cs
- LogExtentCollection.cs
- WebServiceParameterData.cs
- PenThread.cs
- RtType.cs
- EventArgs.cs
- SchemaCompiler.cs
- HtmlTable.cs
- StaticTextPointer.cs
- PeerCollaborationPermission.cs
- PackageDigitalSignatureManager.cs
- OperandQuery.cs
- PathGeometry.cs
- HostingEnvironmentSection.cs
- CodeSubDirectoriesCollection.cs
- ToolstripProfessionalRenderer.cs
- PlatformCulture.cs
- CategoryGridEntry.cs
- LinkTarget.cs
- RegexGroup.cs
- EndpointDispatcher.cs
- ToolStripDropDown.cs
- AssemblyFilter.cs
- ManagementQuery.cs
- SapiAttributeParser.cs
- WindowsStreamSecurityUpgradeProvider.cs
- TrustManagerMoreInformation.cs
- EndpointConfigContainer.cs
- GridViewRowCollection.cs
- SiteMapNodeItem.cs
- ElapsedEventArgs.cs
- CorrelationExtension.cs
- SqlDelegatedTransaction.cs
- PiiTraceSource.cs
- XmlTextWriter.cs
- SettingsPropertyIsReadOnlyException.cs