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
- TextProperties.cs
- CloudCollection.cs
- DataStreamFromComStream.cs
- GrammarBuilderDictation.cs
- ComponentEvent.cs
- SignedXml.cs
- PartialList.cs
- SqlTransaction.cs
- TextServicesHost.cs
- ListViewCommandEventArgs.cs
- ClientBuildManagerCallback.cs
- DbgUtil.cs
- ClusterSafeNativeMethods.cs
- _TLSstream.cs
- SortKey.cs
- PopupEventArgs.cs
- ContentElement.cs
- UInt16Storage.cs
- ComPersistableTypeElementCollection.cs
- CollectionCodeDomSerializer.cs
- NullableFloatMinMaxAggregationOperator.cs
- Region.cs
- UIElementPropertyUndoUnit.cs
- FamilyTypeface.cs
- LinkGrep.cs
- DataTableNewRowEvent.cs
- ToolBarPanel.cs
- SigningCredentials.cs
- ElapsedEventArgs.cs
- DetailsViewPagerRow.cs
- KoreanCalendar.cs
- OleDbStruct.cs
- SapiAttributeParser.cs
- CompensatableTransactionScopeActivityDesigner.cs
- ErrorsHelper.cs
- SqlReorderer.cs
- EraserBehavior.cs
- GC.cs
- _ConnectStream.cs
- BitmapEffectGroup.cs
- MemoryRecordBuffer.cs
- TypeExtension.cs
- SqlUserDefinedTypeAttribute.cs
- HelpKeywordAttribute.cs
- NativeMethods.cs
- ProcessHostFactoryHelper.cs
- MsdtcWrapper.cs
- OdbcInfoMessageEvent.cs
- WebPartCollection.cs
- PathTooLongException.cs
- PathSegment.cs
- TableLayoutSettingsTypeConverter.cs
- InstancePersistenceCommand.cs
- HttpCacheParams.cs
- ClientSettingsSection.cs
- DataTableClearEvent.cs
- DeclarativeCatalogPart.cs
- ConfigurationLocation.cs
- SafeHandles.cs
- TypeForwardedToAttribute.cs
- DataGridHeaderBorder.cs
- ClientSideQueueItem.cs
- ApplicationManager.cs
- CodeCompiler.cs
- SrgsDocument.cs
- ScrollViewerAutomationPeer.cs
- sqlnorm.cs
- ProcessModelInfo.cs
- TemplateBuilder.cs
- DictionaryContent.cs
- ModuleBuilder.cs
- DataControlReference.cs
- TextParagraphView.cs
- Section.cs
- SystemWebSectionGroup.cs
- OdbcEnvironment.cs
- ImageAutomationPeer.cs
- ServiceControllerDesigner.cs
- CodeLabeledStatement.cs
- TypeValidationEventArgs.cs
- TextRangeEdit.cs
- LongTypeConverter.cs
- DbConnectionPoolGroupProviderInfo.cs
- EtwProvider.cs
- DetailsViewPagerRow.cs
- SqlInfoMessageEvent.cs
- SourceFileBuildProvider.cs
- AccessControlList.cs
- UriSectionReader.cs
- CompositeCollectionView.cs
- MediaSystem.cs
- DrawingContextDrawingContextWalker.cs
- DataGridBeginningEditEventArgs.cs
- SystemColors.cs
- CqlBlock.cs
- WebPartTransformer.cs
- Interlocked.cs
- QilSortKey.cs
- SecurityCookieModeValidator.cs
- ClientBuildManager.cs