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


C# FieldInfo.GetType方法代码示例

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


在下文中一共展示了FieldInfo.GetType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetFieldTokenNoLock

        [System.Security.SecurityCritical]  // auto-generated
        private FieldToken GetFieldTokenNoLock(FieldInfo field) 
        {
            if (field == null) {
                throw new ArgumentNullException("con");
            }
            Contract.EndContractBlock();

            int     tr;
            int     mr = 0;

            FieldBuilder fdBuilder = null;
            RuntimeFieldInfo rtField = null;
            FieldOnTypeBuilderInstantiation fOnTB = null;

            if ((fdBuilder = field as FieldBuilder) != null)
            {
                if (field.DeclaringType != null && field.DeclaringType.IsGenericType)
                {
                    int length;
                    byte[] sig = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out length);
                    tr = GetTokenFromTypeSpec(sig, length);
                    mr = GetMemberRef(this, tr, fdBuilder.GetToken().Token);
                }
                else if (fdBuilder.Module.Equals(this))
                {
                    // field is defined in the same module
                    return fdBuilder.GetToken();
                }
                else
                {
                    // field is defined in a different module
                    if (field.DeclaringType == null)
                    {
                        throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
                    }
                    tr = GetTypeTokenInternal(field.DeclaringType).Token;
                    mr = GetMemberRef(field.ReflectedType.Module, tr, fdBuilder.GetToken().Token);
                }
            }
            else if ( (rtField = field as RuntimeFieldInfo) != null)
            {
                // FieldInfo is not an dynamic field
                
                // We need to get the TypeRef tokens
                if (field.DeclaringType == null)
                {
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
                }
                
                if (field.DeclaringType != null && field.DeclaringType.IsGenericType)
                {
                    int length;
                    byte[] sig = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out length);
                    tr = GetTokenFromTypeSpec(sig, length);
                    mr = GetMemberRefOfFieldInfo(tr, field.DeclaringType.GetTypeHandleInternal(), rtField);
                }
                else
                {
                    tr = GetTypeTokenInternal(field.DeclaringType).Token;       
                    mr = GetMemberRefOfFieldInfo(tr, field.DeclaringType.GetTypeHandleInternal(), rtField);
                }
            }
            else if ( (fOnTB = field as FieldOnTypeBuilderInstantiation) != null)
            {
                FieldInfo fb = fOnTB.FieldInfo;
                int length;
                byte[] sig = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out length);
                tr = GetTokenFromTypeSpec(sig, length);
                mr = GetMemberRef(fb.ReflectedType.Module, tr, fOnTB.MetadataTokenInternal);
            }
            else
            {
                // user defined FieldInfo
                tr = GetTypeTokenInternal(field.ReflectedType).Token;

                SignatureHelper sigHelp = SignatureHelper.GetFieldSigHelper(this);

                sigHelp.AddArgument(field.FieldType, field.GetRequiredCustomModifiers(), field.GetOptionalCustomModifiers());

                int length;
                byte[] sigBytes = sigHelp.InternalGetSignature(out length);

                mr = GetMemberRefFromSignature(tr, field.Name, sigBytes, length);
            }
            
            return new FieldToken(mr, field.GetType());
        }
开发者ID:crummel,项目名称:dotnet_coreclr,代码行数:88,代码来源:ModuleBuilder.cs

示例2: ResolveEnum

 /// <summary>
 /// Resolve an enumeration.
 /// </summary>
 /// <param name="field">The field to resolve.</param>
 /// <param name="v">The value to get the enum for.</param>
 /// <returns>The enum that was resolved.</returns>
 public static Object ResolveEnum(FieldInfo field, FieldInfo v)
 {
     Type type = field.GetType();
     Object[] objs = type.GetMembers(BindingFlags.Public | BindingFlags.Static);
     return objs.Cast<MemberInfo>().FirstOrDefault(obj => obj.Name.Equals(v));
 }
开发者ID:neismit,项目名称:emds,代码行数:12,代码来源:ReflectionUtil.cs

示例3: isFieldPersistent

 private bool isFieldPersistent(FieldInfo field)
 {
     // if not marked as transient and not a collection (not yet as least)
     return !AttributeUtils.isAttributePresent<Transient>(field) && !typeof(ICollection<>).IsAssignableFrom(field.GetType());
 }
开发者ID:Edhendil,项目名称:MonoLiteOrm,代码行数:5,代码来源:AttributeConfigLoader.cs

示例4: GetFieldToken

        // Return a token for the FieldInfo relative to the Module. 
        // 
        /// <include file='doc\ModuleBuilder.uex' path='docs/doc[@for="ModuleBuilder.GetFieldToken"]/*' />
        public FieldToken GetFieldToken(FieldInfo field) 
        {
            try
            {
                Enter();

                int     tr;
                int     mr = 0;
                
                if (field == null) {
                    throw new ArgumentNullException("con");
                }
                if (field is FieldBuilder)
                {
                    FieldBuilder fdBuilder = (FieldBuilder) field;
                    if (fdBuilder.GetTypeBuilder().Module.Equals(this))
                    {
                        // field is defined in the same module
                        return fdBuilder.GetToken();
                    }
                    else
                    {
                        // field is defined in a different module
                        if (field.DeclaringType == null)
                        {
                            throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
                        }
                        tr = GetTypeToken(field.DeclaringType).Token;
                        mr = InternalGetMemberRef(field.ReflectedType.Module, tr, fdBuilder.GetToken().Token);
                    }
                }
                else if (field is RuntimeFieldInfo)
                {
                    // FieldInfo is not an dynamic field
                    
                    // We need to get the TypeRef tokens
                    if (field.DeclaringType == null)
                    {
                        throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
                    }
                    tr = GetTypeToken(field.DeclaringType).Token;       
                    mr = InternalGetMemberRefOfFieldInfo(tr, (RuntimeFieldInfo)field);
                }
                else
                {
                    // user defined FieldInfo
                    tr = GetTypeToken(field.ReflectedType).Token;
                    SignatureHelper sigHelp = SignatureHelper.GetFieldSigHelper(this);
                    sigHelp.AddArgument(field.FieldType);
                    int length;                                           
                    byte[] sigBytes = sigHelp.InternalGetSignature(out length);
                    mr = InternalGetMemberRefFromSignature(tr, field.Name, sigBytes, length);                 
                }
                
                return new FieldToken(mr, field.GetType());
            }
            finally
            {
                Exit();
            }
        }
开发者ID:ArildF,项目名称:masters,代码行数:64,代码来源:modulebuilder.cs

示例5: ResolveEnum

 /// <summary>
 /// Resolve an enumeration.
 /// </summary>
 /// <param name="field">The field to resolve.</param>
 /// <param name="value">The value to get the enum for.</param>
 /// <returns>The enum that was resolved.</returns>
 public static Object ResolveEnum(FieldInfo field, FieldInfo value)
 {
     Type type = field.GetType();
     Object[] objs = type.GetMembers(BindingFlags.Public | BindingFlags.Static);
     foreach (MemberInfo obj in objs)
     {
         if (obj.Name.Equals(value))
             return obj;
     }
     return null;
 }
开发者ID:OperatorOverload,项目名称:encog-cs,代码行数:17,代码来源:ReflectionUtil.cs

示例6: FindMostSpecificField

    	private static int FindMostSpecificField(FieldInfo cur1,FieldInfo cur2,Type type)
    	{
    		Type c1 = cur1.GetType();
    		Type c2 = cur2.GetType();
    	
    		if (c1 == c2)
            {
                // Check to see if the fields have the same name.
                if (c1.Name == c2.Name)
                {
                    int hierarchyDepth1 = GetHierarchyDepth(cur1.DeclaringType);
                    int hierarchyDepth2 = GetHierarchyDepth(cur2.DeclaringType);

                    if (hierarchyDepth1 == hierarchyDepth2) {
                        BCLDebug.Assert(cur1.IsStatic != cur2.IsStatic, "hierarchyDepth1 == hierarchyDepth2");
                        return 0; 
                    }
                    else if (hierarchyDepth1 < hierarchyDepth2) 
                        return 2;
                    else
                        return 1;
                }

                // The match is ambigous.
                return 0;
            }
    		
    		// If the c1 is a primitive 
    		if (c1.IsPrimitive) {
    			// C2 is object we can widden p1 is less however...
    			if (c2 == typeof(Object)) 
    				return 1;
    			
    			// Unfortunitly, an UInt16 and char can be converted
    			//	both ways...
    			if (c2 == typeof(char) || c2 == typeof(UInt16)) {
    				if (type == c1)
    					return 1;
    				else
    					return 2;
    			}
    			
    			// Check for primitive conversions...
    			if (c2.UnderlyingSystemType is RuntimeType && CanConvertPrimitive((RuntimeType)c1.UnderlyingSystemType,(RuntimeType)c2.UnderlyingSystemType))
    				return 1;
    		}
    		// Else c1 is an object
    		else {
    			// C2 can be an object, p1 is less
    			if (c2 == typeof(Object))
    				return 1;
    			// Check for assignment compatibility...
    			if (!c1.IsAssignableFrom(c2))
    				return 1;
    		}
    		
    		// If we got here it means that p2 is less in this situation.
    		// We will set the flag indicating this....
    		return 2;
    	}
开发者ID:ArildF,项目名称:masters,代码行数:60,代码来源:defaultbinder.cs

示例7: AddFieldChildren

		protected override void AddFieldChildren (NodeInfoCollection c, NodeInfo parent, FieldInfo field)
		{
			AddSubnodes (c, parent, field.GetType(), field);
		}
开发者ID:emtees,项目名称:old-code,代码行数:4,代码来源:ReflectionNodeFinder.cs

示例8: GetFieldTokenNoLock

 private FieldToken GetFieldTokenNoLock(FieldInfo field)
 {
     int tokenFromTypeSpec;
     if (field == null)
     {
         throw new ArgumentNullException("con");
     }
     int num2 = 0;
     FieldBuilder builder = null;
     FieldOnTypeBuilderInstantiation instantiation = null;
     builder = field as FieldBuilder;
     if (builder != null)
     {
         if ((field.DeclaringType != null) && field.DeclaringType.IsGenericType)
         {
             int num3;
             byte[] signature = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out num3);
             tokenFromTypeSpec = this.GetTokenFromTypeSpec(signature, num3);
             num2 = this.GetMemberRef(this, tokenFromTypeSpec, builder.GetToken().Token);
         }
         else
         {
             if (builder.Module.Equals(this))
             {
                 return builder.GetToken();
             }
             if (field.DeclaringType == null)
             {
                 throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
             }
             tokenFromTypeSpec = this.GetTypeTokenInternal(field.DeclaringType).Token;
             num2 = this.GetMemberRef(field.ReflectedType.Module, tokenFromTypeSpec, builder.GetToken().Token);
         }
     }
     else if (field is RuntimeFieldInfo)
     {
         if (field.DeclaringType == null)
         {
             throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
         }
         int metadataToken = field.MetadataToken;
         if ((field.DeclaringType != null) && field.DeclaringType.IsGenericType)
         {
             int num5;
             byte[] buffer2 = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out num5);
             tokenFromTypeSpec = this.GetTokenFromTypeSpec(buffer2, num5);
             num2 = this.GetMemberRefOfFieldInfo(tokenFromTypeSpec, field.DeclaringType.GetTypeHandleInternal(), metadataToken);
         }
         else
         {
             tokenFromTypeSpec = this.GetTypeTokenInternal(field.DeclaringType).Token;
             num2 = this.GetMemberRefOfFieldInfo(tokenFromTypeSpec, field.DeclaringType.GetTypeHandleInternal(), metadataToken);
         }
     }
     else
     {
         instantiation = field as FieldOnTypeBuilderInstantiation;
         if (instantiation != null)
         {
             int num6;
             FieldInfo fieldInfo = instantiation.FieldInfo;
             byte[] buffer3 = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out num6);
             tokenFromTypeSpec = this.GetTokenFromTypeSpec(buffer3, num6);
             num2 = this.GetMemberRef(fieldInfo.ReflectedType.Module, tokenFromTypeSpec, instantiation.MetadataTokenInternal);
         }
         else
         {
             int num7;
             tokenFromTypeSpec = this.GetTypeTokenInternal(field.ReflectedType).Token;
             SignatureHelper fieldSigHelper = SignatureHelper.GetFieldSigHelper(this);
             fieldSigHelper.AddArgument(field.FieldType, field.GetRequiredCustomModifiers(), field.GetOptionalCustomModifiers());
             byte[] buffer4 = fieldSigHelper.InternalGetSignature(out num7);
             num2 = this.GetMemberRefFromSignature(tokenFromTypeSpec, field.Name, buffer4, num7);
         }
     }
     return new FieldToken(num2, field.GetType());
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:77,代码来源:ModuleBuilder.cs

示例9: ResolveEnum

 public static object ResolveEnum(FieldInfo field, FieldInfo v)
 {
     return field.GetType().GetMembers(BindingFlags.Public | BindingFlags.Static).Cast<MemberInfo>().FirstOrDefault<MemberInfo>(obj => obj.Name.Equals(v));
 }
开发者ID:neismit,项目名称:emds,代码行数:4,代码来源:ReflectionUtil.cs

示例10: MakeColumnFromFieldInfo

 /// <summary>
 /// Make a column from the given FieldInfo
 /// </summary>
 /// <param name="pinfo"></param>
 /// <returns></returns>
 protected virtual OLVColumn MakeColumnFromFieldInfo(FieldInfo finfo) {
     return MakeColumn(finfo.Name, DisplayNameToColumnTitle(finfo.Name), true, finfo.GetType(), null);
 }
开发者ID:Warpten,项目名称:ADBC2,代码行数:8,代码来源:Generator.cs

示例11: MakeColumnFromAttribute

 /// <summary>
 /// Create a column from the given FieldInfo and OLVColumn attribute
 /// </summary>
 /// <param name="pinfo"></param>
 /// <param name="attr"></param>
 /// <returns></returns>
 protected virtual OLVColumn MakeColumnFromAttribute(FieldInfo finfo, OLVColumnAttribute attr) {
     return MakeColumn(finfo.Name, DisplayNameToColumnTitle(finfo.Name), false, finfo.GetType(), attr);
 }
开发者ID:Warpten,项目名称:ADBC2,代码行数:9,代码来源:Generator.cs

示例12: GetConstantValue

 internal static Object GetConstantValue(FieldInfo field) {
   if (field.GetType().Assembly == typeof(TypeReferences).Assembly ||
       !field.DeclaringType.Assembly.ReflectionOnly)
     return field.GetValue(null);
   
   Type type = field.FieldType;
   Object value = field.GetRawConstantValue();
   if (type.IsEnum)
     return MetadataEnumValue.GetEnumValue(type, value);
   return value;
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:11,代码来源:typereferences.cs

示例13: GetField

		internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
		{
			initialize ();

			if (!(fromNoninstanciated is FieldBuilder))
				throw new InvalidOperationException ("Inflating non FieldBuilder objects is not supported: " + fromNoninstanciated.GetType ());

			FieldBuilder fb = (FieldBuilder)fromNoninstanciated;
			if (fields == null)
				fields = new Hashtable ();
			if (!fields.ContainsKey (fb))
				fields [fb] = new FieldOnTypeBuilderInst (this, fb);
			return (FieldInfo)fields [fb];
		}
开发者ID:runefs,项目名称:Marvin,代码行数:14,代码来源:MonoGenericClass.cs

示例14: BuildListWalk

        //────────────────────────────────────────
        /// <summary>
        /// こんなイベントハンドラーを持っていますよ、という情報を作成。
        /// </summary>
        /// <param nFcName="entry"></param>
        /// <param nFcName="delegateFI"></param>
        /// <param nFcName="keyFI"></param>
        /// <param nFcName="nextFI"></param>
        private void BuildListWalk(
            object head,//entry
            FieldInfo fi_Handler,
            FieldInfo fi_Key,
            FieldInfo fi_Next,
            MemoryApplication owner_MemoryApplication,
            Log_Reports log_Reports
            )
        {
            Log_Method pg_Method = new Log_MethodImpl(0, Log_ReportsImpl.BDebugmode_Static);
            pg_Method.BeginMethod(Info_Controls.Name_Library, this, "BuildListWalk",log_Reports);
            //
            //

            Exception err_Excp = null;
            Delegate err_Dele = null;
            object err_Key = null;
            object err_Next = null;
            if (log_Reports.Successful)
            {

                //.Console.WriteLine(this.GetType().NFcName + "#BuildListWalk: 【実行】");

                try
                {
                    if (null != head)
                    {
                        Delegate dele = (Delegate)fi_Handler.GetValue(head);

                        if (null != dele)
                        {

                            object key = fi_Key.GetValue(head);
                            object next = fi_Next.GetValue(head);

                            err_Dele = dele;
                            err_Key = key;
                            err_Next = next;

                            // デリゲーターの呼び出しリスト
                            Delegate[] listeners = dele.GetInvocationList();

                            if (listeners != null && 0 < listeners.Length)
                            {
                                dictionary_EventHandler.Add(key, listeners);
                            }

                            if (null != next)
                            {
                                this.BuildListWalk(
                                    next,
                                    fi_Handler,
                                    fi_Key,
                                    fi_Next,
                                    owner_MemoryApplication,
                                    log_Reports
                                    );
                            }
                        }

                    }
                }
                catch (Exception e)
                {
                    err_Excp = e;
                    goto gt_Error_Exception;
                }
            }

            goto gt_EndMethod;
            //
            //
            #region 異常系
            //────────────────────────────────────────
            gt_Error_Exception:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                tmpl.SetParameter(1, err_Excp.GetType().Name, log_Reports);//例外の型名
                tmpl.SetParameter(2, err_Excp.Message, log_Reports);//例外メッセージ
                //fi_Handlerの型名
                if (null == fi_Handler)
                {
                    tmpl.SetParameter(3, "ヌル", log_Reports);
                }
                else
                {
                    tmpl.SetParameter(3, fi_Handler.GetType().Name, log_Reports);
                }
                //err_Deleの型名
                if (null == err_Dele)
                {
                    tmpl.SetParameter(4, "ヌル", log_Reports);
//.........这里部分代码省略.........
开发者ID:muzudho,项目名称:CSVExE,代码行数:101,代码来源:Remover_AllEventhandlersImpl.cs


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