当前位置: 首页>>代码示例>>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;未经允许,请勿转载。