当前位置: 首页>>代码示例>>C#>>正文


C# System.RuntimeFieldHandle类代码示例

本文整理汇总了C#中System.RuntimeFieldHandle的典型用法代码示例。如果您正苦于以下问题:C# RuntimeFieldHandle类的具体用法?C# RuntimeFieldHandle怎么用?C# RuntimeFieldHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RuntimeFieldHandle类属于System命名空间,在下文中一共展示了RuntimeFieldHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetFieldFromHandle

        public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle)
        {
            if (handle.IsNullHandle())
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));

#if !FEATURE_CORECLR
            if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage))
            {
                FrameworkEventSource.Log.BeginGetFieldFromHandle();
            }
#endif
            
            FieldInfo f = RuntimeType.GetFieldInfo(handle.GetRuntimeFieldInfo());

            Type declaringType = f.DeclaringType;

#if !FEATURE_CORECLR
            if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage) && declaringType != null && f != null)
            {
                FrameworkEventSource.Log.EndGetFieldFromHandle(declaringType.GetFullNameForEtw(), f.GetFullNameForEtw());
            }
#endif
            
            if (declaringType != null && declaringType.IsGenericType)
                throw new ArgumentException(String.Format(
                    CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_FieldDeclaringTypeGeneric"), 
                    f.Name, declaringType.GetGenericTypeDefinition()));

            return f;            
        }           
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:30,代码来源:fieldinfo.cs

示例2: TestUseCase

        public static void TestUseCase(Assert assert)
        {
            assert.Expect(7);

            var t1 = new Type();
            assert.Ok(t1 != null, "#565 t1");

            var t2 = new ValueType();
            assert.Ok(t2 != null, "#565 t2");

            var t3 = new IntPtr();
            assert.Ok(t3.GetType() == typeof(IntPtr) , "#565 t3");

            var t4 = new UIntPtr();
            assert.Ok(t4.GetType() == typeof(UIntPtr), "#565 t4");

            var t5 = new ParamArrayAttribute();
            assert.Ok(t5 != null, "#565 t5");

            var t6 = new RuntimeTypeHandle();
            assert.Ok(t6.GetType() == typeof(RuntimeTypeHandle), "#565 t6");

            var t7 = new RuntimeFieldHandle();
            assert.Ok(t7.GetType() == typeof(RuntimeFieldHandle), "#565 t7");
        }
开发者ID:Cestbienmoi,项目名称:Bridge,代码行数:25,代码来源:N565.cs

示例3: InitializeArray

		public static void InitializeArray(Array array, RuntimeFieldHandle fldHandle) {
			// Arguments:
			//    Array aArray, RuntimeFieldHandle aFieldHandle
            new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0xC }; // array
            new CPUx86.Mov { DestinationReg = CPUx86.Registers.ESI, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 8 };// aFieldHandle
            new CPUx86.Add { DestinationReg = CPUx86.Registers.EDI, SourceValue = 8 };
			new CPUx86.Push{DestinationReg=CPUx86.Registers.EDI, DestinationIsIndirect=true};
            new CPUx86.Add { DestinationReg = CPUx86.Registers.EDI, SourceValue = 4 };
            new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.EDI, SourceIsIndirect = true };
			new CPUx86.Multiply{DestinationReg=CPUx86.Registers.ESP, DestinationIsIndirect=true, Size=32};
            new CPUx86.Pop { DestinationReg = CPUx86.Registers.ECX };
            new CPUx86.Mov { DestinationReg = CPUx86.Registers.ECX, SourceReg = CPUx86.Registers.EAX };
            new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceValue = 0 };
            new CPUx86.Add { DestinationReg = CPUx86.Registers.EDI, SourceValue = 4 };

			new Label(".StartLoop");
			new CPUx86.Mov { DestinationReg = CPUx86.Registers.DL, SourceReg = CPUx86.Registers.ESI, SourceIsIndirect = true };
            new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, DestinationIsIndirect = true, SourceReg = CPUx86.Registers.DL };
			new CPUx86.Add{DestinationReg = CPUx86.Registers.EAX, SourceValue=1};
            new CPUx86.Add { DestinationReg = CPUx86.Registers.ESI, SourceValue = 1 };
            new CPUx86.Add { DestinationReg = CPUx86.Registers.EDI, SourceValue = 1 };
			new CPUx86.Compare { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.ECX };
            new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.Equal, DestinationLabel = ".EndLoop" };
            new CPUx86.Jump { DestinationLabel = ".StartLoop" };

			new Label(".EndLoop");
		}
开发者ID:iSalva,项目名称:Cosmos,代码行数:27,代码来源:RuntimeHelpersImpl.cs

示例4: LoadRemoteFieldNew

		internal object LoadRemoteFieldNew (IntPtr classPtr, IntPtr fieldPtr) {
			Mono.RuntimeClassHandle classHandle = new Mono.RuntimeClassHandle (classPtr);
			RuntimeFieldHandle fieldHandle = new RuntimeFieldHandle (fieldPtr);
			RuntimeTypeHandle typeHandle = classHandle.GetTypeHandle ();

			FieldInfo field = FieldInfo.GetFieldFromHandle (fieldHandle);

			if (InCurrentContext ()) {
				object o = _rp._server;
				return field.GetValue(o);
			}

			string typeName = Type.GetTypeFromHandle(typeHandle).FullName;
			string fieldName = field.Name;
			object[] inArgs = new object[] { typeName,
							  fieldName };
			object[] outArgsMsg = new object[1];
			MethodInfo minfo = typeof(object).GetMethod("FieldGetter", BindingFlags.NonPublic | BindingFlags.Instance);
			if (minfo == null)
				throw new MissingMethodException ("System.Object", "FieldGetter");
			MonoMethodMessage msg = new MonoMethodMessage (minfo, inArgs, outArgsMsg);
			object[] outArgs;
			Exception exc;
			RealProxy.PrivateInvoke (_rp, msg, out exc, out outArgs);
			if (exc != null)
				throw exc;
			return outArgs[0];
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:28,代码来源:RealProxy.cs

示例5: GetFieldFromHandle

        public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle, RuntimeTypeHandle declaringType)
        {
            if (handle.IsNullHandle())
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));

            return RuntimeType.GetFieldInfo(declaringType.GetRuntimeType(), handle.GetRuntimeFieldInfo());
        }           
开发者ID:nietras,项目名称:coreclr,代码行数:7,代码来源:FieldInfo.cs

示例6: InitializeArray

        public static void InitializeArray(Array array, RuntimeFieldHandle fldHandle)
        {
            // Arguments:
            //    Array aArray, RuntimeFieldHandle aFieldHandle
            XS.Set(XSRegisters.EDI, XSRegisters.EBP, sourceDisplacement: 20); // array
            XS.Set(XSRegisters.ESI, XSRegisters.EBP, sourceDisplacement: 12);  // aFieldHandle
            XS.Add(XSRegisters.EDI, 8);
            XS.Push(EDI, isIndirect: true); // element size
            XS.Add(XSRegisters.EDI, 4);
            XS.Set(EAX, EDI, sourceIsIndirect: true);
            XS.Multiply(ESP, isIndirect: true, size: RegisterSize.Int32);
            XS.Pop(XSRegisters.ECX);
            XS.Set(XSRegisters.ECX, XSRegisters.EAX);
            XS.Set(XSRegisters.EAX, 0);
            XS.Add(XSRegisters.EDI, 4);

            XS.Label(".StartLoop");
            XS.Set(DL, ESI, sourceIsIndirect: true);
            XS.Set(EDI, DL, destinationIsIndirect: true);
            XS.Add(XSRegisters.EAX, 1);
            XS.Add(XSRegisters.ESI, 1);
            XS.Add(XSRegisters.EDI, 1);
            XS.Compare(XSRegisters.EAX, XSRegisters.ECX);
            XS.Jump(CPUx86.ConditionalTestEnum.Equal, ".EndLoop");
            XS.Jump(".StartLoop");

            XS.Label(".EndLoop");
        }
开发者ID:fanoI,项目名称:Cosmos,代码行数:28,代码来源:RuntimeHelpersImpl.cs

示例7: Initialize

        internal static void Initialize(RuntimeFieldHandle field, byte opKey)
        {
            FieldInfo fieldInfo = FieldInfo.GetFieldFromHandle(field);
            byte[] sig = fieldInfo.Module.ResolveSignature(fieldInfo.MetadataToken);
            int len = sig.Length;
            int key = fieldInfo.GetOptionalCustomModifiers()[0].MetadataToken;

            key += (fieldInfo.Name[Mutation.KeyI0] ^ sig[--len]) << Mutation.KeyI4;
            key += (fieldInfo.Name[Mutation.KeyI1] ^ sig[--len]) << Mutation.KeyI5;
            key += (fieldInfo.Name[Mutation.KeyI2] ^ sig[--len]) << Mutation.KeyI6;
            len--;
            key += (fieldInfo.Name[Mutation.KeyI3] ^ sig[--len]) << Mutation.KeyI7;

            int token = Mutation.Placeholder(key);
            token *= fieldInfo.GetCustomAttributes(false)[0].GetHashCode();

            MethodBase method = fieldInfo.Module.ResolveMethod(token);
            Type delegateType = fieldInfo.FieldType;
            if (method.IsStatic)
                fieldInfo.SetValue(null, Delegate.CreateDelegate(delegateType, (MethodInfo)method));

            else {
                DynamicMethod dm = null;
                Type[] argTypes = null;

                foreach (MethodInfo invoke in fieldInfo.FieldType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance))
                    if (invoke.DeclaringType == delegateType) {
                        ParameterInfo[] paramTypes = invoke.GetParameters();
                        argTypes = new Type[paramTypes.Length];
                        for (int i = 0; i < argTypes.Length; i++)
                            argTypes[i] = paramTypes[i].ParameterType;

                        Type declType = method.DeclaringType;
                        dm = new DynamicMethod("", invoke.ReturnType, argTypes, (declType.IsInterface || declType.IsArray) ? delegateType : declType, true);
                        break;
                    }

                DynamicILInfo info = dm.GetDynamicILInfo();
                info.SetLocalSignature(new byte[] { 0x7, 0x0 });
                var code = new byte[2 * argTypes.Length + 6];
                int index = 0;
                for (int i = 0; i < argTypes.Length; i++) {
                    code[index++] = 0x0e;
                    code[index++] = (byte)i;
                }
                code[index++] = (byte)((byte)fieldInfo.Name[Mutation.KeyI8] ^ opKey);
                int dmToken = info.GetTokenFor(method.MethodHandle);
                code[index++] = (byte)dmToken;
                code[index++] = (byte)(dmToken >> 8);
                code[index++] = (byte)(dmToken >> 16);
                code[index++] = (byte)(dmToken >> 24);
                code[index] = 0x2a;
                info.SetCode(code, argTypes.Length + 1);

                fieldInfo.SetValue(null, dm.CreateDelegate(delegateType));
            }
        }
开发者ID:2sic4you,项目名称:ConfuserEx,代码行数:57,代码来源:RefProxy.Strong.cs

示例8: GetFieldFromHandle

 public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle)
 {
     if (handle.IsNullHandle())
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
     }
     FieldInfo fieldInfo = RuntimeType.GetFieldInfo(handle);
     if ((fieldInfo.DeclaringType != null) && fieldInfo.DeclaringType.IsGenericType)
     {
         throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_FieldDeclaringTypeGeneric"), new object[] { fieldInfo.Name, fieldInfo.DeclaringType.GetGenericTypeDefinition() }));
     }
     return fieldInfo;
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:13,代码来源:FieldInfo.cs

示例9: GetFieldFromHandle

        //
        // This overload of GetFieldForHandle only accepts handles for fields declared on non-generic types. To resolve handles for fields
        // declared on generic types, you must pass the declaring type explicitly using the two-argument overload of GetFieldFromHandle.
        //
        // This is a vestige from desktop generic sharing that got itself enshrined in the code generated by the C# compiler for Linq Expressions.
        //
        public override sealed FieldInfo GetFieldFromHandle(RuntimeFieldHandle runtimeFieldHandle)
        {
            ExecutionEnvironment executionEnvironment = ReflectionCoreExecution.ExecutionEnvironment;
            FieldHandle fieldHandle;
            RuntimeTypeHandle declaringTypeHandle;
            if (!executionEnvironment.TryGetFieldFromHandle(runtimeFieldHandle, out declaringTypeHandle, out fieldHandle))
                throw new ArgumentException(SR.Argument_InvalidHandle);

            FieldInfo fieldInfo = GetFieldInfo(declaringTypeHandle, fieldHandle);
            if (fieldInfo.DeclaringType.IsConstructedGenericType) // For compat with desktop, insist that the caller pass us the declaring type to resolve members of generic types.
                throw new ArgumentException(SR.Format(SR.Argument_FieldDeclaringTypeGeneric, fieldInfo));
            return fieldInfo;
        }
开发者ID:tijoytom,项目名称:corert,代码行数:19,代码来源:ReflectionCoreCallbacksImplementation.cs

示例10: InitializeArray

        public static void InitializeArray(uint* array, RuntimeFieldHandle handle)
        {
            uint* fieldDefinition = ((uint**)&handle)[0];
            byte* arrayElements = (byte*)(array + 3);

            // See FieldDefinition for format of field handle
            byte* fieldData = (byte*)*(fieldDefinition + 4);
            uint dataLength = *(fieldDefinition + 5);
            while (dataLength > 0)
            {
                *arrayElements = *fieldData;
                arrayElements++;
                fieldData++;
                dataLength--;
            }
        }
开发者ID:Boddlnagg,项目名称:MOSA-Project,代码行数:16,代码来源:InternalsForRuntimeHelpers.cs

示例11: InitializeArray

        public static void InitializeArray(uint* array, RuntimeFieldHandle handle)
        {
            MetadataFieldDefinitionStruct* fieldDefinition = (MetadataFieldDefinitionStruct*)((uint**)&handle)[0];
            byte* arrayElements = (byte*)(array + 3);

            // See FieldDefinition for format of field handle
            byte* fieldData = fieldDefinition->FieldData;
            uint dataLength = fieldDefinition->OffsetOrSize;
            while (dataLength > 0)
            {
                *arrayElements = *fieldData;
                arrayElements++;
                fieldData++;
                dataLength--;
            }
        }
开发者ID:pacificIT,项目名称:MOSA-Project,代码行数:16,代码来源:InternalsForRuntimeHelpers.cs

示例12: MakeTypedReference

 public static unsafe TypedReference MakeTypedReference(object target, FieldInfo[] flds)
 {
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     if (flds == null)
     {
         throw new ArgumentNullException("flds");
     }
     if (flds.Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Arg_ArrayZeroError"));
     }
     RuntimeFieldHandle[] handleArray = new RuntimeFieldHandle[flds.Length];
     System.Type type = target.GetType();
     for (int i = 0; i < flds.Length; i++)
     {
         FieldInfo info = flds[i];
         if (!(info is RuntimeFieldInfo))
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeFieldInfo"));
         }
         if (info.IsInitOnly || info.IsStatic)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_TypedReferenceInvalidField"));
         }
         if ((type != info.DeclaringType) && !type.IsSubclassOf(info.DeclaringType))
         {
             throw new MissingMemberException(Environment.GetResourceString("MissingMemberTypeRef"));
         }
         System.Type fieldType = info.FieldType;
         if (fieldType.IsPrimitive)
         {
             throw new ArgumentException(Environment.GetResourceString("Arg_TypeRefPrimitve"));
         }
         if ((i < (flds.Length - 1)) && !fieldType.IsValueType)
         {
             throw new MissingMemberException(Environment.GetResourceString("MissingMemberNestErr"));
         }
         handleArray[i] = info.FieldHandle;
         type = fieldType;
     }
     TypedReference reference = new TypedReference();
     InternalMakeTypedReference((void*) &reference, target, handleArray, type.TypeHandle);
     return reference;
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:47,代码来源:TypedReference.cs

示例13: TryGetDynamicRuntimeFieldHandleComponents

        private unsafe bool TryGetDynamicRuntimeFieldHandleComponents(RuntimeFieldHandle runtimeFieldHandle, out RuntimeTypeHandle declaringTypeHandle, out string fieldName)
        {
            IntPtr runtimeFieldHandleValue = *(IntPtr*)&runtimeFieldHandle;

            // Special flag in the handle value to indicate it was dynamically allocated
            Debug.Assert((runtimeFieldHandleValue.ToInt64() & 0x1) == 0x1);
            runtimeFieldHandleValue = runtimeFieldHandleValue - 1;

            DynamicFieldHandleInfo* fieldData = (DynamicFieldHandleInfo*)runtimeFieldHandleValue.ToPointer();
            declaringTypeHandle = *(RuntimeTypeHandle*)&(fieldData->DeclaringType);

            // FieldName points to the field name in NativeLayout format, so we parse it using a NativeParser
            IntPtr fieldNamePtr = fieldData->FieldName;
            fieldName = GetStringFromMemoryInNativeFormat(fieldNamePtr);

            return true;
        }
开发者ID:justinvp,项目名称:corert,代码行数:17,代码来源:TypeLoaderEnvironment.LdTokenResultLookup.cs

示例14: MakeTypedReference

        public static TypedReference MakeTypedReference(Object target, FieldInfo[] flds) {
            if (target == null)
                throw new ArgumentNullException("target");
            if (flds == null)
                throw new ArgumentNullException("flds");
            if (flds.Length == 0)
                throw new ArgumentException(Environment.GetResourceString("Arg_ArrayZeroError"));
            else {
                RuntimeFieldHandle[] fields = new RuntimeFieldHandle[flds.Length];
          // For proper handling of Nullable<T> don't change GetType() to something like 'IsAssignableFrom'
          // Currently we can't make a TypedReference to fields of Nullable<T>, 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;
                    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);
                }
                return result;
            }
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:42,代码来源:typedreference.cs

示例15: IsSecuritySafeCritical

 private static extern bool IsSecuritySafeCritical(RuntimeFieldHandle fieldHandle);
开发者ID:jashook,项目名称:coreclr,代码行数:1,代码来源:RuntimeHandles.cs


注:本文中的System.RuntimeFieldHandle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。