Code:
/ FX-1434 / FX-1434 / 1.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
- SchemaLookupTable.cs
- RequestResizeEvent.cs
- TextBoxBase.cs
- RegexReplacement.cs
- EntityContainer.cs
- OracleConnection.cs
- ExpressionBuilder.cs
- CapacityStreamGeometryContext.cs
- LinearGradientBrush.cs
- ProcessModuleCollection.cs
- StringFreezingAttribute.cs
- ExtractedStateEntry.cs
- CompressedStack.cs
- StateChangeEvent.cs
- HttpListenerRequest.cs
- SqlDataSourceView.cs
- SqlGatherProducedAliases.cs
- Pen.cs
- Comparer.cs
- ColumnTypeConverter.cs
- MediaElement.cs
- SqlDataSourceView.cs
- UmAlQuraCalendar.cs
- SchemaImporter.cs
- XmlValidatingReaderImpl.cs
- UTF8Encoding.cs
- MetadataArtifactLoaderComposite.cs
- WebConfigurationHost.cs
- WebPartConnectionsConnectVerb.cs
- _LoggingObject.cs
- _DomainName.cs
- LocalizabilityAttribute.cs
- AliasExpr.cs
- HttpListenerTimeoutManager.cs
- ModelFactory.cs
- OdbcReferenceCollection.cs
- IndexedString.cs
- ListViewCommandEventArgs.cs
- SplitterEvent.cs
- CounterSetInstance.cs
- ActivityBindForm.cs
- GroupQuery.cs
- FontInfo.cs
- CalendarButton.cs
- InputProviderSite.cs
- Helper.cs
- PathGradientBrush.cs
- SqlCaseSimplifier.cs
- DefaultProfileManager.cs
- DataTableClearEvent.cs
- Rotation3D.cs
- BitmapDownload.cs
- AsyncPostBackErrorEventArgs.cs
- ListViewGroup.cs
- DragAssistanceManager.cs
- WpfWebRequestHelper.cs
- ResourceDictionaryCollection.cs
- CorrelationExtension.cs
- HttpDictionary.cs
- DataGridCommandEventArgs.cs
- EventLevel.cs
- ElementHost.cs
- RadialGradientBrush.cs
- MergeFilterQuery.cs
- RuntimeHelpers.cs
- MetadataSource.cs
- TraceUtility.cs
- ProvidePropertyAttribute.cs
- TextTreePropertyUndoUnit.cs
- MsmqException.cs
- ContextMenuAutomationPeer.cs
- BlockUIContainer.cs
- DbTypeMap.cs
- ListViewItemSelectionChangedEvent.cs
- Vector3DAnimation.cs
- HttpAsyncResult.cs
- FieldTemplateUserControl.cs
- OutputCacheSettings.cs
- OrderedDictionary.cs
- PropertyGridCommands.cs
- TraceData.cs
- OdbcReferenceCollection.cs
- ObjectStateFormatter.cs
- RenamedEventArgs.cs
- IsolatedStorageException.cs
- Encoder.cs
- LocationFactory.cs
- DoubleAnimationUsingPath.cs
- ObjectSet.cs
- Collection.cs
- DbConnectionOptions.cs
- StrongNameIdentityPermission.cs
- DataControlFieldCollection.cs
- XmlTextAttribute.cs
- AppSecurityManager.cs
- SplineKeyFrames.cs
- SettingsBindableAttribute.cs
- XmlSchemaObjectTable.cs
- securitycriticaldataClass.cs
- FileLevelControlBuilderAttribute.cs