Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / TypedReference.cs / 1305376 / TypedReference.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== namespace System { // TypedReference is basically only ever seen on the call stack, and in param arrays. // These are blob that must be dealt with by the compiler. using System; using System.Reflection; using System.Runtime.CompilerServices; using CultureInfo = System.Globalization.CultureInfo; using FieldInfo = System.Reflection.FieldInfo; using System.Security.Permissions; using System.Runtime.Versioning; using System.Diagnostics.Contracts; [CLSCompliant(false)] [System.Runtime.InteropServices.ComVisible(true)] public struct TypedReference { private IntPtr Value; private IntPtr Type; [System.Security.SecurityCritical] // auto-generated_required [CLSCompliant(false)] public static TypedReference MakeTypedReference(Object target, FieldInfo[] flds) { if (target == null) throw new ArgumentNullException("target"); if (flds == null) throw new ArgumentNullException("flds"); Contract.EndContractBlock(); if (flds.Length == 0) throw new ArgumentException(Environment.GetResourceString("Arg_ArrayZeroError")); else { IntPtr[] fields = new IntPtr[flds.Length]; // For proper handling of Nullabledon't change GetType() to something like 'IsAssignableFrom' // Currently we can't make a TypedReference to fields of Nullable , which is fine. Type targetType = target.GetType(); for (int i = 0; i < flds.Length; i++) { FieldInfo field = flds[i]; if (!(field is RuntimeFieldInfo)) throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeFieldInfo")); else if (field.IsInitOnly || field.IsStatic) throw new ArgumentException(Environment.GetResourceString("Argument_TypedReferenceInvalidField")); if (targetType != field.DeclaringType && !targetType.IsSubclassOf(field.DeclaringType)) throw new MissingMemberException(Environment.GetResourceString("MissingMemberTypeRef")); Type fieldType = field.FieldType; if (fieldType.IsPrimitive) throw new ArgumentException(Environment.GetResourceString("Arg_TypeRefPrimitve")); if (i < flds.Length - 1) if (!fieldType.IsValueType) throw new MissingMemberException(Environment.GetResourceString("MissingMemberNestErr")); fields[i] = field.FieldHandle.Value; targetType = fieldType; } TypedReference result = new TypedReference (); // reference to TypedReference is banned, so have to pass result as pointer unsafe { InternalMakeTypedReference(&result, target, fields, targetType.TypeHandle.GetRuntimeType()); } return result; } } [System.Security.SecurityCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [MethodImplAttribute(MethodImplOptions.InternalCall)] // reference to TypedReference is banned, so have to pass result as pointer private unsafe static extern void InternalMakeTypedReference(void* result, Object target, IntPtr[] flds, RuntimeType lastFieldType); public override int GetHashCode() { if (Type == IntPtr.Zero) return 0; else return __reftype(this).GetHashCode(); } public override bool Equals(Object o) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_NYI")); } [System.Security.SecuritySafeCritical] // auto-generated public unsafe static Object ToObject(TypedReference value) { return InternalToObject(&value); } [System.Security.SecurityCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [MethodImplAttribute(MethodImplOptions.InternalCall)] internal unsafe extern static Object InternalToObject(void * value); internal bool IsNull { get { return Value.IsNull() && Type.IsNull(); } } public static Type GetTargetType (TypedReference value) { return __reftype(value); } public static RuntimeTypeHandle TargetTypeToken (TypedReference value) { return __reftype(value).TypeHandle; } // This may cause the type to be changed. [System.Security.SecuritySafeCritical] // auto-generated [CLSCompliant(false)] public unsafe static void SetTypedReference(TypedReference target, Object value) { InternalSetTypedReference(&target, value); } [System.Security.SecurityCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [MethodImplAttribute(MethodImplOptions.InternalCall)] internal unsafe extern static void InternalSetTypedReference(void * target, Object value); // Internal method for getting a raw pointer for handles in JitHelpers. // The reference has to point into a local stack variable in order so it can not be moved by the GC. [System.Security.SecurityCritical] // auto-generated internal IntPtr GetPointerOnStack() { #if _DEBUG Contract.Assert(IsAddressInStack(Value), "Pointer not in the stack!"); #endif return Value; } #if _DEBUG [System.Security.SecurityCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [MethodImplAttribute(MethodImplOptions.InternalCall)] extern static bool IsAddressInStack(IntPtr ptr); #endif } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== namespace System { // TypedReference is basically only ever seen on the call stack, and in param arrays. // These are blob that must be dealt with by the compiler. using System; using System.Reflection; using System.Runtime.CompilerServices; using CultureInfo = System.Globalization.CultureInfo; using FieldInfo = System.Reflection.FieldInfo; using System.Security.Permissions; using System.Runtime.Versioning; using System.Diagnostics.Contracts; [CLSCompliant(false)] [System.Runtime.InteropServices.ComVisible(true)] public struct TypedReference { private IntPtr Value; private IntPtr Type; [System.Security.SecurityCritical] // auto-generated_required [CLSCompliant(false)] public static TypedReference MakeTypedReference(Object target, FieldInfo[] flds) { if (target == null) throw new ArgumentNullException("target"); if (flds == null) throw new ArgumentNullException("flds"); Contract.EndContractBlock(); if (flds.Length == 0) throw new ArgumentException(Environment.GetResourceString("Arg_ArrayZeroError")); else { IntPtr[] fields = new IntPtr[flds.Length]; // For proper handling of Nullable don't change GetType() to something like 'IsAssignableFrom' // Currently we can't make a TypedReference to fields of Nullable , which is fine. Type targetType = target.GetType(); for (int i = 0; i < flds.Length; i++) { FieldInfo field = flds[i]; if (!(field is RuntimeFieldInfo)) throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeFieldInfo")); else if (field.IsInitOnly || field.IsStatic) throw new ArgumentException(Environment.GetResourceString("Argument_TypedReferenceInvalidField")); if (targetType != field.DeclaringType && !targetType.IsSubclassOf(field.DeclaringType)) throw new MissingMemberException(Environment.GetResourceString("MissingMemberTypeRef")); Type fieldType = field.FieldType; if (fieldType.IsPrimitive) throw new ArgumentException(Environment.GetResourceString("Arg_TypeRefPrimitve")); if (i < flds.Length - 1) if (!fieldType.IsValueType) throw new MissingMemberException(Environment.GetResourceString("MissingMemberNestErr")); fields[i] = field.FieldHandle.Value; targetType = fieldType; } TypedReference result = new TypedReference (); // reference to TypedReference is banned, so have to pass result as pointer unsafe { InternalMakeTypedReference(&result, target, fields, targetType.TypeHandle.GetRuntimeType()); } return result; } } [System.Security.SecurityCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [MethodImplAttribute(MethodImplOptions.InternalCall)] // reference to TypedReference is banned, so have to pass result as pointer private unsafe static extern void InternalMakeTypedReference(void* result, Object target, IntPtr[] flds, RuntimeType lastFieldType); public override int GetHashCode() { if (Type == IntPtr.Zero) return 0; else return __reftype(this).GetHashCode(); } public override bool Equals(Object o) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_NYI")); } [System.Security.SecuritySafeCritical] // auto-generated public unsafe static Object ToObject(TypedReference value) { return InternalToObject(&value); } [System.Security.SecurityCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [MethodImplAttribute(MethodImplOptions.InternalCall)] internal unsafe extern static Object InternalToObject(void * value); internal bool IsNull { get { return Value.IsNull() && Type.IsNull(); } } public static Type GetTargetType (TypedReference value) { return __reftype(value); } public static RuntimeTypeHandle TargetTypeToken (TypedReference value) { return __reftype(value).TypeHandle; } // This may cause the type to be changed. [System.Security.SecuritySafeCritical] // auto-generated [CLSCompliant(false)] public unsafe static void SetTypedReference(TypedReference target, Object value) { InternalSetTypedReference(&target, value); } [System.Security.SecurityCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [MethodImplAttribute(MethodImplOptions.InternalCall)] internal unsafe extern static void InternalSetTypedReference(void * target, Object value); // Internal method for getting a raw pointer for handles in JitHelpers. // The reference has to point into a local stack variable in order so it can not be moved by the GC. [System.Security.SecurityCritical] // auto-generated internal IntPtr GetPointerOnStack() { #if _DEBUG Contract.Assert(IsAddressInStack(Value), "Pointer not in the stack!"); #endif return Value; } #if _DEBUG [System.Security.SecurityCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [MethodImplAttribute(MethodImplOptions.InternalCall)] extern static bool IsAddressInStack(IntPtr ptr); #endif } } // 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
- XmlSchemas.cs
- Utils.cs
- MethodMessage.cs
- KoreanCalendar.cs
- WebColorConverter.cs
- SharedPersonalizationStateInfo.cs
- UpdateRecord.cs
- IntSecurity.cs
- StaticDataManager.cs
- CodeIndexerExpression.cs
- CurrentChangingEventArgs.cs
- securestring.cs
- RemotingHelper.cs
- HttpGetServerProtocol.cs
- DocumentGrid.cs
- SafeThreadHandle.cs
- SchemaMapping.cs
- AssemblyBuilder.cs
- ObjRef.cs
- HttpDictionary.cs
- StyleHelper.cs
- FixedSchema.cs
- COM2IProvidePropertyBuilderHandler.cs
- WmlObjectListAdapter.cs
- OdbcConnection.cs
- TreePrinter.cs
- TypedTableBaseExtensions.cs
- BindingCollection.cs
- wmiprovider.cs
- LicenseManager.cs
- Baml2006KnownTypes.cs
- LocatorBase.cs
- _DisconnectOverlappedAsyncResult.cs
- BaseProcessProtocolHandler.cs
- LocalizedNameDescriptionPair.cs
- Token.cs
- AsymmetricKeyExchangeDeformatter.cs
- DataGridViewCellStyleChangedEventArgs.cs
- DbProviderSpecificTypePropertyAttribute.cs
- ProviderConnectionPointCollection.cs
- DiscoveryClientDuplexChannel.cs
- DataGridViewImageCell.cs
- NativeMethods.cs
- SoapMessage.cs
- HtmlInputButton.cs
- XPathAncestorIterator.cs
- EdmRelationshipRoleAttribute.cs
- StyleCollection.cs
- GenerateTemporaryTargetAssembly.cs
- ObjectAnimationUsingKeyFrames.cs
- ComponentManagerBroker.cs
- NotImplementedException.cs
- XmlSchemaValidator.cs
- XmlWellformedWriter.cs
- OutputCacheSettingsSection.cs
- DispatchChannelSink.cs
- CommentEmitter.cs
- RSAPKCS1KeyExchangeFormatter.cs
- PointLightBase.cs
- ProcessThreadDesigner.cs
- RuntimeHelpers.cs
- DataServiceQuery.cs
- MemoryMappedFile.cs
- TargetPerspective.cs
- translator.cs
- XmlChildNodes.cs
- WaitForChangedResult.cs
- WebPartDisplayModeCollection.cs
- ContentFileHelper.cs
- basevalidator.cs
- ComponentConverter.cs
- XhtmlBasicListAdapter.cs
- SelectionUIHandler.cs
- ClientUtils.cs
- OdbcCommandBuilder.cs
- RecordsAffectedEventArgs.cs
- CodeParameterDeclarationExpression.cs
- FixedDocumentSequencePaginator.cs
- DataMemberConverter.cs
- X509ChainPolicy.cs
- RuleSettingsCollection.cs
- ADRoleFactoryConfiguration.cs
- QilTargetType.cs
- Rule.cs
- PathFigure.cs
- RuleSettingsCollection.cs
- TraceHandler.cs
- SystemIPInterfaceStatistics.cs
- DataSourceConverter.cs
- TaskFormBase.cs
- ConfigErrorGlyph.cs
- WebPageTraceListener.cs
- EntityDataSourceEntitySetNameItem.cs
- ExceptionUtil.cs
- DataTableExtensions.cs
- SessionStateSection.cs
- GenerateScriptTypeAttribute.cs
- Schema.cs
- securestring.cs
- WebPartTransformer.cs