Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- TemplateControl.cs
- ButtonFlatAdapter.cs
- TriggerAction.cs
- RuleRefElement.cs
- DataGridRowAutomationPeer.cs
- EntityAdapter.cs
- Frame.cs
- HttpServerUtilityWrapper.cs
- ReachPageContentSerializerAsync.cs
- MenuItemBindingCollection.cs
- ObjectViewQueryResultData.cs
- SafeNativeMethods.cs
- EncryptedPackageFilter.cs
- LinearGradientBrush.cs
- PropertyToken.cs
- WebDisplayNameAttribute.cs
- IpcChannel.cs
- sqlcontext.cs
- CustomErrorsSection.cs
- ModuleBuilder.cs
- UxThemeWrapper.cs
- FixedPageAutomationPeer.cs
- BlurBitmapEffect.cs
- ResourceReferenceExpressionConverter.cs
- SamlAuthorizationDecisionClaimResource.cs
- XmlWellformedWriter.cs
- OperatingSystem.cs
- fixedPageContentExtractor.cs
- Color.cs
- CombinedHttpChannel.cs
- FileUpload.cs
- BitmapCache.cs
- GeneralTransform3DGroup.cs
- EncodingFallbackAwareXmlTextWriter.cs
- ActionMismatchAddressingException.cs
- ThumbAutomationPeer.cs
- DataSvcMapFileSerializer.cs
- DecoderNLS.cs
- SessionSwitchEventArgs.cs
- HtmlLink.cs
- DataGridViewRowEventArgs.cs
- ProgressBar.cs
- CodeDomDesignerLoader.cs
- PrePrepareMethodAttribute.cs
- ChildTable.cs
- Group.cs
- MetabaseSettingsIis7.cs
- ScriptReferenceBase.cs
- TextChangedEventArgs.cs
- KeyInfo.cs
- JsonByteArrayDataContract.cs
- ReadWriteControlDesigner.cs
- DataSetUtil.cs
- ParentUndoUnit.cs
- XamlValidatingReader.cs
- ThicknessConverter.cs
- DateTimeValueSerializerContext.cs
- WebEncodingValidatorAttribute.cs
- SqlTypesSchemaImporter.cs
- XmlUtil.cs
- ConsumerConnectionPointCollection.cs
- StrongNameIdentityPermission.cs
- PlatformCulture.cs
- DrawListViewColumnHeaderEventArgs.cs
- MonikerUtility.cs
- HttpException.cs
- OptimizedTemplateContentHelper.cs
- TableRow.cs
- PersianCalendar.cs
- ProcessThreadCollection.cs
- AutoCompleteStringCollection.cs
- FirstMatchCodeGroup.cs
- CompiledELinqQueryState.cs
- DataControlFieldHeaderCell.cs
- ZeroOpNode.cs
- BlockCollection.cs
- DecimalStorage.cs
- WebPartUserCapability.cs
- SmiMetaData.cs
- ProgressBarRenderer.cs
- URLMembershipCondition.cs
- _RequestLifetimeSetter.cs
- SmtpNtlmAuthenticationModule.cs
- TreeBuilder.cs
- XmlSiteMapProvider.cs
- SQLConvert.cs
- Rotation3DAnimation.cs
- PolygonHotSpot.cs
- QueryStoreStatusRequest.cs
- IIS7WorkerRequest.cs
- HttpApplicationFactory.cs
- AuthenticationService.cs
- DataControlExtensions.cs
- BufferedStream.cs
- PartBasedPackageProperties.cs
- Attributes.cs
- SiteMap.cs
- Function.cs
- ObjectDataProvider.cs
- DataSourceXmlAttributeAttribute.cs