本文整理汇总了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;
}
}
示例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;
}
}
示例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);
}
}
示例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");
}
示例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");
}
示例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;
}
}
示例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);
}
示例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);
}
示例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
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}