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
- ApplicationInfo.cs
- FacetEnabledSchemaElement.cs
- EventManager.cs
- HotSpot.cs
- IsolatedStorageFilePermission.cs
- AssociationSet.cs
- PluralizationService.cs
- EmptyStringExpandableObjectConverter.cs
- LicenseException.cs
- XmlNode.cs
- AndMessageFilterTable.cs
- Point3DCollection.cs
- DrawTreeNodeEventArgs.cs
- DBPropSet.cs
- TypedRowHandler.cs
- HealthMonitoringSectionHelper.cs
- UriExt.cs
- CurrentChangedEventManager.cs
- SimpleType.cs
- CustomTypeDescriptor.cs
- MimeTypePropertyAttribute.cs
- Timer.cs
- CoreSwitches.cs
- DocumentXmlWriter.cs
- EmulateRecognizeCompletedEventArgs.cs
- ColumnBinding.cs
- QueueAccessMode.cs
- TextEditorTables.cs
- Win32MouseDevice.cs
- EastAsianLunisolarCalendar.cs
- PeerCollaborationPermission.cs
- EntitySetRetriever.cs
- CultureSpecificCharacterBufferRange.cs
- CommandSet.cs
- DataControlPagerLinkButton.cs
- SqlFlattener.cs
- AutomationPatternInfo.cs
- StateRuntime.cs
- ObservableDictionary.cs
- DataGrid.cs
- CounterCreationDataConverter.cs
- mda.cs
- ContainerVisual.cs
- Activity.cs
- DragEventArgs.cs
- ClientTargetCollection.cs
- LicenseManager.cs
- PageWrapper.cs
- SQLGuid.cs
- _BasicClient.cs
- XPathCompileException.cs
- ECDiffieHellmanCngPublicKey.cs
- dsa.cs
- DataViewManager.cs
- DataGridViewIntLinkedList.cs
- StackBuilderSink.cs
- UnmanagedHandle.cs
- GorillaCodec.cs
- HashCodeCombiner.cs
- CompositeCollectionView.cs
- DataRowView.cs
- DataReaderContainer.cs
- FeatureSupport.cs
- Region.cs
- SettingsPropertyNotFoundException.cs
- SatelliteContractVersionAttribute.cs
- GridErrorDlg.cs
- EditingMode.cs
- ReadWriteObjectLock.cs
- DataRelationPropertyDescriptor.cs
- Decoder.cs
- metadatamappinghashervisitor.hashsourcebuilder.cs
- TypedTableBaseExtensions.cs
- ApplicationActivator.cs
- GradientBrush.cs
- ScriptingAuthenticationServiceSection.cs
- WebPartManagerDesigner.cs
- DPTypeDescriptorContext.cs
- TablePattern.cs
- ClipboardProcessor.cs
- ScrollChrome.cs
- HyperLinkField.cs
- WindowsBrush.cs
- Random.cs
- AppDomainProtocolHandler.cs
- AssertHelper.cs
- EventSinkHelperWriter.cs
- SendMessageChannelCache.cs
- WebConfigurationManager.cs
- SelectionItemProviderWrapper.cs
- GenericTypeParameterBuilder.cs
- BaseAppDomainProtocolHandler.cs
- CacheMemory.cs
- MetadataArtifactLoader.cs
- ColorMatrix.cs
- DataRowChangeEvent.cs
- _UriSyntax.cs
- ContentOperations.cs
- EmptyStringExpandableObjectConverter.cs
- ExceptQueryOperator.cs