當前位置: 首頁>>代碼示例>>C#>>正文


C# Type.GetField方法代碼示例

本文整理匯總了C#中System.Type.GetField方法的典型用法代碼示例。如果您正苦於以下問題:C# Type.GetField方法的具體用法?C# Type.GetField怎麽用?C# Type.GetField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Type的用法示例。


在下文中一共展示了Type.GetField方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DynamicScopeTokenResolver

        static DynamicScopeTokenResolver()
        {
            BindingFlags s_bfInternal = BindingFlags.NonPublic | BindingFlags.Instance;
            s_indexer = Type.GetType("System.Reflection.Emit.DynamicScope").GetProperty("Item", s_bfInternal);
            s_scopeFi = Type.GetType("System.Reflection.Emit.DynamicILGenerator").GetField("m_scope", s_bfInternal);

            s_varArgMethodType = Type.GetType("System.Reflection.Emit.VarArgMethod");
            s_varargFi1 = s_varArgMethodType.GetField("m_method", s_bfInternal);
            s_varargFi2 = s_varArgMethodType.GetField("m_signature", s_bfInternal);

            s_genMethodInfoType = Type.GetType("System.Reflection.Emit.GenericMethodInfo");
            s_genmethFi1 = s_genMethodInfoType.GetField("m_methodHandle", s_bfInternal);
            s_genmethFi2 = s_genMethodInfoType.GetField("m_context", s_bfInternal);

            s_genFieldInfoType = Type.GetType("System.Reflection.Emit.GenericFieldInfo", false);
            if (s_genFieldInfoType != null)
            {
                s_genfieldFi1 = s_genFieldInfoType.GetField("m_fieldHandle", s_bfInternal);
                s_genfieldFi2 = s_genFieldInfoType.GetField("m_context", s_bfInternal);
            }
            else
            {
                s_genfieldFi1 = s_genfieldFi2 = null;
            }
        }
開發者ID:taolin123,項目名稱:ExpressionFutures,代碼行數:25,代碼來源:DynamicScopeTokenResolver.cs

示例2: DynamicScopeTokenResolver

        static DynamicScopeTokenResolver()
        {
            BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance;
            dynamicScopePropertyItem = Type.GetType("System.Reflection.Emit.DynamicScope").GetProperty("Item", flags);
            dynamicILGeneratorFieldScope = Type.GetType("System.Reflection.Emit.DynamicILGenerator").GetField("m_scope", flags);

            varArgMethodType = Type.GetType("System.Reflection.Emit.VarArgMethod");
            varArgMethodFieldMethod = varArgMethodType.GetField("m_method", flags);
            varArgMethodFieldSignature = varArgMethodType.GetField("m_signature", flags);

            genericMethodInfoType = Type.GetType("System.Reflection.Emit.GenericMethodInfo");
            genericMethodInfoFieldMethodHandle = genericMethodInfoType.GetField("m_method", flags); //use m_methodHandle in .Net 4.0
            if (genericMethodInfoFieldMethodHandle == null)
                genericMethodInfoFieldMethodHandle = genericMethodInfoType.GetField("m_methodHandle", flags);
            genericMethodInfoFieldContext = genericMethodInfoType.GetField("m_context", flags);

            genericFieldInfoType = Type.GetType("System.Reflection.Emit.GenericFieldInfo", false);
            if (genericFieldInfoType != null)
            {
                genericFieldInfoFieldFieldHandle = genericFieldInfoType.GetField("m_field", flags); //use m_fieldHandle in .Net 4.0
                if (genericFieldInfoFieldFieldHandle == null)
                    genericFieldInfoFieldFieldHandle = genericFieldInfoType.GetField("m_fieldHandle", flags);
                genericFieldInfoFieldContext = genericFieldInfoType.GetField("m_context", flags);
            }
            else
            {
                genericFieldInfoFieldFieldHandle = genericFieldInfoFieldContext = null;
            }
        }        
開發者ID:adisik,項目名稱:simple-assembly-explorer,代碼行數:29,代碼來源:DynamicScopeTokenResolver.cs

示例3: FGConsole

 static FGConsole()
 {
     consoleWindowType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ConsoleWindow");
     if (consoleWindowType != null)
     {
         consoleWindowField = consoleWindowType.GetField("ms_ConsoleWindow", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
         consoleListViewField = consoleWindowType.GetField("m_ListView", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
         consoleActiveTextField = consoleWindowType.GetField("m_ActiveText", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
         consoleOnGUIMethod = consoleWindowType.GetMethod("OnGUI", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
     }
     listViewStateType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ListViewState");
     if (listViewStateType != null)
     {
         listViewStateRowField = listViewStateType.GetField("row", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
     }
     editorWindowPosField = typeof(EditorWindow).GetField("m_Pos", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
     logEntriesType = typeof(EditorWindow).Assembly.GetType("UnityEditorInternal.LogEntries");
     if (logEntriesType != null)
     {
         getEntryMethod = logEntriesType.GetMethod("GetEntryInternal", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
         startGettingEntriesMethod = logEntriesType.GetMethod("StartGettingEntries", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
         endGettingEntriesMethod = logEntriesType.GetMethod("EndGettingEntries", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
     }
     logEntryType = typeof(EditorWindow).Assembly.GetType("UnityEditorInternal.LogEntry");
     if (logEntryType != null)
     {
         logEntry = System.Activator.CreateInstance(logEntryType);
         logEntryFileField = logEntryType.GetField("file", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
         logEntryLineField = logEntryType.GetField("line", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
         logEntryInstanceIDField = logEntryType.GetField("instanceID", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
     }
 }
開發者ID:hnguyen091188,項目名稱:BurstLine,代碼行數:32,代碼來源:FGConsole.cs

示例4: SandboxGameAssemblyWrapper

        protected SandboxGameAssemblyWrapper()
        {
            m_instance = this;
            m_isDebugging = false;
            m_isUsingCommonProgramData = false;
            m_isInSafeMode = false;

            m_assembly = Assembly.UnsafeLoadFrom("Sandbox.Game.dll");

            m_mainGameType = m_assembly.GetType(MainGameNamespace + "." + MainGameClass);
            m_serverCoreType = m_assembly.GetType(ServerCoreClass);

            m_mainGameInstanceField = m_mainGameType.GetField(MainGameInstanceField, BindingFlags.Static | BindingFlags.Public);
            m_configContainerField = m_mainGameType.GetField(MainGameConfigContainerField, BindingFlags.Static | BindingFlags.Public);
            m_configContainerType = m_configContainerField.FieldType;
            m_serverCoreNullRender = m_serverCoreType.GetField(ServerCoreNullRenderField, BindingFlags.Public | BindingFlags.Static);

            m_configContainerDedicatedDataField = m_configContainerType.GetField(ConfigContainerDedicatedDataField, BindingFlags.NonPublic | BindingFlags.Instance);
            m_setConfigWorldName = m_configContainerType.GetMethod(ConfigContainerSetWorldName, BindingFlags.Public | BindingFlags.Instance);

            m_lastProfilingOutput = DateTime.Now;
            m_countQueuedActions = 0;
            m_averageQueuedActions = 0;

            Console.WriteLine("Finished loading SandboxGameAssemblyWrapper");
        }
開發者ID:noxer,項目名稱:SE-Community-Mod-API,代碼行數:26,代碼來源:SandboxGameAssemblyWrapper.cs

示例5: Initialize

			internal static void Initialize (Assembly KISasm)
			{
				ResourceInfo_class = KISasm.GetTypes().Where (t => t.Name.Equals ("ResourceInfo")).FirstOrDefault ();
				kis_resourceName = ResourceInfo_class.GetField ("resourceName");
				kis_maxAmount = ResourceInfo_class.GetField ("maxAmount");
				kis_amount = ResourceInfo_class.GetField ("amount");
			}
開發者ID:tfischer4765,項目名稱:Extraplanetary-Launchpads,代碼行數:7,代碼來源:KISWrapper.cs

示例6: HasField

 public static bool HasField( Type objectType, string fieldName )
 {
     try
     {
         if ( String.IsNullOrEmpty( fieldName ) )
             return false;
         FieldInfo field = objectType.GetField( fieldName );
         if ( field == null )
             field = objectType.GetField( fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy );
         if ( field == null )
             field = objectType.BaseType.GetField( fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy );
         if ( field == null )
         {
             if ( ExtenderOptions.IsDebugging )
                 Log.Error( "Failed to find field '" + fieldName + "' in type '" + objectType.FullName + "'" );
             return false;
         }
         return true;
     }
     catch ( Exception ex )
     {
         if ( ExtenderOptions.IsDebugging )
             Log.Error( "Failed to find field '" + fieldName + "' in type '" + objectType.FullName + "': " + ex.Message );
         Log.Error( ex );
         return false;
     }
 }
開發者ID:LoganRickert,項目名稱:SEServerExtender,代碼行數:27,代碼來源:Reflection.cs

示例7: InitializeField

			void InitializeField(Type type) {
				if (fieldInfo != null)
					return;

				var flags = SR.BindingFlags.Instance | SR.BindingFlags.Public | SR.BindingFlags.NonPublic;
				fieldInfo = type.GetField(fieldName1, flags);
				if (fieldInfo == null && fieldName2 != null)
					fieldInfo = type.GetField(fieldName2, flags);
			}
開發者ID:EmilZhou,項目名稱:dnlib,代碼行數:9,代碼來源:DynamicMethodBodyReader.cs

示例8: output_verification

        public void output_verification(Type output)
        {
            var expectedOutput = output.GetField("Output").GetValue(output) as string;
            var expectedExitCode = output.GetField("ExitCode").GetValue(output);

            var tag = output.Name.Replace("_output", "");
            var actualOutput = Run(tag);

            actualOutput.Item1.Is(expectedOutput.Replace("\r\n", "\n"));
            actualOutput.Item2.Is(expectedExitCode);
        }
開發者ID:kramuenke,項目名稱:NSpec,代碼行數:11,代碼來源:describe_output.cs

示例9: VisualControlInfo

		public VisualControlInfo(string name, Type t)
		{
			Name = name;
			
			_GUID = Guid.Parse((string)t.GetField("GUID", BindingFlags.Static | BindingFlags.Public).GetValue(null));
			FieldInfo fi = t.GetField("ALLOW_MULTI", BindingFlags.Static | BindingFlags.Public);
			_allowMulti = fi != null ? (bool)fi.GetValue(false) : false;
			_version = (string)t.GetField("VERSION", BindingFlags.Static | BindingFlags.Public).GetValue(null);
			_dockStyle = (ControlDockStyle)t.GetField("DOCK_STYLE", BindingFlags.Static | BindingFlags.Public).GetValue(null);
			_classType = t;
			_instance_GUID = _GUID; // this is template info
		}
開發者ID:xwcs,項目名稱:xwcs.core,代碼行數:12,代碼來源:VisualControlInfo.cs

示例10: GetField

        public static FieldInfo GetField(Type t, string name)
        {
            var type = t;
            BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
            FieldInfo finfo = null;
            while(t != null)
            {
                finfo = t.GetField(name, flags) ?? t.GetField(UnTitleCase(name), flags);
                if (finfo != null)
                    return finfo;

                t = t.BaseType;
            }
            return finfo;
        }
開發者ID:akumetsuv,項目名稱:flood,代碼行數:15,代碼來源:GeneratorTests.cs

示例11: DocumentedEnum

 public DocumentedEnum(Identifier name, XmlNode xml, MemberInfo mi, Type targetType)
 {
     Name = name;
     Xml = xml;
     Member = mi;
     TargetType = targetType;
     try
     {
         Value = (int)targetType.GetField(mi.Name).GetValue(null);
     }
     catch (Exception e)
     {
         Value = (uint)targetType.GetField(mi.Name).GetValue(null);
     }
 }
開發者ID:J4S0Nc,項目名稱:docu,代碼行數:15,代碼來源:DocumentedEnum.cs

示例12: FindFieldThroughoutHierarchy

 public static FieldInfo FindFieldThroughoutHierarchy(Type type, string name)
 {
     FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
     if (field == null && type.GetCustomAttributes(_includeBaseAttributeType, false).Length > 0)
         field = FindFieldThroughoutHierarchy(type.BaseType, name);
     return field;
 }
開發者ID:grimlor,項目名稱:GGJ_SpyHeart,代碼行數:7,代碼來源:ReflectionHelper.cs

示例13: Enable

        public static void Enable(Type resourcesType)
        {
            if (null == resourcesType)
            {
                throw new ArgumentNullException("resourcesType");
            }

            // Get the ResourceManager property
            var resourceManagerProperty = resourcesType.GetProperty("ResourceManager", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
            if (null == resourceManagerProperty)
            {
                throw new NotSupportedException("RESX managed wrapper class does not contain the expected internal/public static ResourceManager property.");
            }

            // Get the ResourceManager value (ensures the resourceMan field gets initialized)
            var resourceManagerValue = resourceManagerProperty.GetValue(null, null) as ResourceManager;
            if (null == resourceManagerValue)
            {
                throw new NotSupportedException("RESX managed wrapper class returned null for the ResourceManager property getter.");
            }

            // Get the resourceMan field
            var resourceManField = resourcesType.GetField("resourceMan", BindingFlags.Static | BindingFlags.NonPublic);
            if (null == resourceManField)
            {
                throw new NotSupportedException("RESX managed wrapper class does not contain the expected private static resourceMan field.");
            }

            // Create a substitute ResourceManager to do the pseudo-localization
            var resourceManSubstitute = new PseudoLocalizerResourceManager(resourceManagerValue.BaseName, resourcesType.Assembly);

            // Replace the resourceMan field value
            resourceManField.SetValue(null, resourceManSubstitute);
        }
開發者ID:richardszalay,項目名稱:build-scout,代碼行數:34,代碼來源:PseudoLocalizer.cs

示例14: GetEnumDescription

 /// <summary>
 /// Gets the description for certaing named value in an Enumeration
 /// </summary>
 /// <param name="value">The type of the Enumeration</param>
 /// <param name="name">The name of the Enumeration value</param>
 /// <returns>The description, if any, else the passed name</returns>
 public static string GetEnumDescription(Type value, string name) {
     FieldInfo fi = value.GetField(name);
     var attributes =
         (DescriptionAttribute[])fi.GetCustomAttributes(
                                      typeof(DescriptionAttribute), false);
     return (attributes.Length > 0) ? attributes[0].Description : name;
 }
開發者ID:aries544,項目名稱:eXpand,代碼行數:13,代碼來源:EnumDescConverter.cs

示例15: GetEnumDescription

 public static string GetEnumDescription(Type type, Object value)
 {
     FieldInfo fi = type.GetField(Enum.GetName(type, value));
     DescriptionAttribute dna = (DescriptionAttribute)Attribute.GetCustomAttribute(fi, typeof(DescriptionAttribute));
     if (dna != null) return dna.Description;
     else return value.ToString();
 }
開發者ID:cnark,項目名稱:Seal-Report,代碼行數:7,代碼來源:Helper.cs


注:本文中的System.Type.GetField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。