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
- ObjectFactoryCodeDomTreeGenerator.cs
- FixedTextView.cs
- PropertyEmitterBase.cs
- XmlElementAttribute.cs
- BindingBase.cs
- SpellerError.cs
- RegexTree.cs
- Pool.cs
- WindowCollection.cs
- Double.cs
- ExtensionWindowHeader.cs
- CharacterHit.cs
- RadioButtonBaseAdapter.cs
- ProjectionAnalyzer.cs
- InkSerializer.cs
- ToolStripRendererSwitcher.cs
- BorderGapMaskConverter.cs
- RepeaterItemEventArgs.cs
- FontFaceLayoutInfo.cs
- NativeMethods.cs
- HostedTransportConfigurationBase.cs
- LocalFileSettingsProvider.cs
- SQLStringStorage.cs
- VirtualPath.cs
- FixedSOMTableCell.cs
- SlotInfo.cs
- XmlSchemaAttribute.cs
- GZipDecoder.cs
- HashCoreRequest.cs
- InlineCollection.cs
- WebAdminConfigurationHelper.cs
- ComEventsInfo.cs
- UnSafeCharBuffer.cs
- DocumentOrderQuery.cs
- ZipPackage.cs
- SqlBooleanMismatchVisitor.cs
- DoubleCollectionConverter.cs
- BufferModeSettings.cs
- BaseAsyncResult.cs
- SocketException.cs
- Style.cs
- _ScatterGatherBuffers.cs
- Range.cs
- Point3DCollection.cs
- TableAdapterManagerHelper.cs
- ErrorsHelper.cs
- XmlLanguageConverter.cs
- XmlDocumentFieldSchema.cs
- FileReservationCollection.cs
- ServiceDurableInstanceContextProvider.cs
- ServicePoint.cs
- Point3D.cs
- ObjectDataSourceEventArgs.cs
- TraceSection.cs
- Stroke2.cs
- WindowsSpinner.cs
- SqlReferenceCollection.cs
- Tokenizer.cs
- DbBuffer.cs
- Sql8ExpressionRewriter.cs
- ListViewEditEventArgs.cs
- SHA1Managed.cs
- Enlistment.cs
- TypeDescriptor.cs
- DtrList.cs
- AstTree.cs
- XmlILTrace.cs
- __Filters.cs
- MappingException.cs
- InputReferenceExpression.cs
- IRCollection.cs
- SubMenuStyleCollection.cs
- FormsAuthenticationUserCollection.cs
- Stackframe.cs
- XmlBoundElement.cs
- HelpEvent.cs
- PingOptions.cs
- FormsAuthenticationTicket.cs
- CaseInsensitiveOrdinalStringComparer.cs
- DataGridViewRowPostPaintEventArgs.cs
- AppDomainFactory.cs
- MessageBodyDescription.cs
- BamlReader.cs
- NumericUpDownAcceleration.cs
- OdbcConnectionFactory.cs
- DataBindingCollectionConverter.cs
- DiscreteKeyFrames.cs
- BufferBuilder.cs
- ConfigurationManager.cs
- AbstractExpressions.cs
- ViewBox.cs
- UriExt.cs
- Calendar.cs
- WebPartZoneBaseDesigner.cs
- EventlogProvider.cs
- HttpListenerResponse.cs
- ErrorWrapper.cs
- CompiledQuery.cs
- SafeIUnknown.cs
- ToolStripSeparator.cs