Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- ClockController.cs
- LeftCellWrapper.cs
- documentsequencetextview.cs
- CompoundFileStorageReference.cs
- MethodAccessException.cs
- DelegateTypeInfo.cs
- CodeBlockBuilder.cs
- SqlDataSourceCommandEventArgs.cs
- BitmapFrame.cs
- JsonObjectDataContract.cs
- FloaterParagraph.cs
- BamlRecords.cs
- CodeMemberField.cs
- CssStyleCollection.cs
- TextTreeUndoUnit.cs
- WindowsListViewGroupHelper.cs
- Form.cs
- RelOps.cs
- XmlRawWriterWrapper.cs
- HttpServerUtilityWrapper.cs
- IDReferencePropertyAttribute.cs
- XmlSerializerSection.cs
- SqlDataSourceQueryEditor.cs
- FontFamily.cs
- VoiceChangeEventArgs.cs
- ColorPalette.cs
- Typography.cs
- CollectionBase.cs
- _SSPISessionCache.cs
- ActivityCodeDomReferenceService.cs
- ProcessHost.cs
- DetailsViewDeletedEventArgs.cs
- IdentityNotMappedException.cs
- NetworkInterface.cs
- PhysicalOps.cs
- WinFormsSecurity.cs
- ComponentConverter.cs
- IntAverageAggregationOperator.cs
- PipelineModuleStepContainer.cs
- AppDomainFactory.cs
- DrawListViewItemEventArgs.cs
- securitymgrsite.cs
- DesignSurface.cs
- ResourceProperty.cs
- PointAnimationClockResource.cs
- PerformanceCounterLib.cs
- ObjectMemberMapping.cs
- ProcessHostMapPath.cs
- ClientApiGenerator.cs
- DbConnectionOptions.cs
- MetadataItemEmitter.cs
- BookmarkEventArgs.cs
- StoryFragments.cs
- BinaryCommonClasses.cs
- Types.cs
- SMSvcHost.cs
- OpenFileDialog.cs
- ToolStripSeparator.cs
- SQLInt32.cs
- SerializationAttributes.cs
- SapiRecoContext.cs
- DataGridViewCellConverter.cs
- ScriptBehaviorDescriptor.cs
- LayoutEngine.cs
- RawStylusSystemGestureInputReport.cs
- DPTypeDescriptorContext.cs
- XmlSchemaInferenceException.cs
- TimeStampChecker.cs
- ContentType.cs
- ConfigurationProperty.cs
- CodeCompiler.cs
- ConfigurationManagerInternalFactory.cs
- PieceDirectory.cs
- StylusPointPropertyUnit.cs
- SQLDateTime.cs
- AncillaryOps.cs
- SecurityTokenParametersEnumerable.cs
- SafeProcessHandle.cs
- AspNetRouteServiceHttpHandler.cs
- WarningException.cs
- HttpWebRequestElement.cs
- DataGridViewRowConverter.cs
- RadioButtonRenderer.cs
- X500Name.cs
- TextProperties.cs
- JavascriptXmlWriterWrapper.cs
- shaperfactoryquerycacheentry.cs
- NullPackagingPolicy.cs
- GlyphManager.cs
- IpcClientManager.cs
- _FixedSizeReader.cs
- AncillaryOps.cs
- BindingManagerDataErrorEventArgs.cs
- AsyncStreamReader.cs
- DependentList.cs
- MergePropertyDescriptor.cs
- WebPart.cs
- SqlRetyper.cs
- SafeFileHandle.cs
- ValidatorCompatibilityHelper.cs