本文整理汇总了C#中System.Reflection.FieldInfo类的典型用法代码示例。如果您正苦于以下问题:C# FieldInfo类的具体用法?C# FieldInfo怎么用?C# FieldInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FieldInfo类属于System.Reflection命名空间,在下文中一共展示了FieldInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSerializableMembers2
private static MemberInfo[] GetSerializableMembers2(Type type)
{
// get the list of all fields
FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
int countProper = 0;
for (int i = 0; i < fields.Length; i++)
{
if ((fields[i].Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized)
continue;
countProper++;
}
if (countProper != fields.Length)
{
FieldInfo[] properFields = new FieldInfo[countProper];
countProper = 0;
for (int i = 0; i < fields.Length; i++)
{
if ((fields[i].Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized)
continue;
properFields[countProper] = fields[i];
countProper++;
}
return properFields;
}
else
return fields;
}
示例2: CreateMessage
public static string CreateMessage(FieldInfo field)
{
return String.Format("Instance could not be created for field '{0}' of type '{1}' in Assembly '{2}'",
field.Name,
field.DeclaringType.FullName,
field.Module);
}
示例3: FindActionWindow
/// <summary>
/// Find the UIPartActionWindow for a part. Usually this is useful just to mark it as dirty.
/// </summary>
public static UIPartActionWindow FindActionWindow(this Part part)
{
if (part == null)
return null;
// We need to do quite a bit of piss-farting about with reflection to
// dig the thing out. We could just use Object.Find, but that requires hitting a heap more objects.
UIPartActionController controller = UIPartActionController.Instance;
if (controller == null)
return null;
if (windowListField == null)
{
Type cntrType = typeof(UIPartActionController);
foreach (FieldInfo info in cntrType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
{
if (info.FieldType == typeof(List<UIPartActionWindow>))
{
windowListField = info;
goto foundField;
}
}
Debug.LogWarning("*PartUtils* Unable to find UIPartActionWindow list");
return null;
}
foundField:
List<UIPartActionWindow> uiPartActionWindows = (List<UIPartActionWindow>)windowListField.GetValue(controller);
if (uiPartActionWindows == null)
return null;
return uiPartActionWindows.FirstOrDefault(window => window != null && window.part == part);
}
示例4: FieldGetter
public FieldGetter(FieldInfo fieldInfo)
{
_fieldInfo = fieldInfo;
_name = fieldInfo.Name;
_memberType = fieldInfo.FieldType;
_lateBoundFieldGet = DelegateFactory.CreateGet(fieldInfo);
}
示例5: 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;
}
}
示例6: ProcessField
/// <summary>
/// Dispatches the call to the extensions.
/// </summary>
/// <param name="fi">The field info reflection object.</param>
/// <param name="model">The model.</param>
public void ProcessField(FieldInfo fi, ActiveRecordModel model)
{
foreach(IModelBuilderExtension extension in extensions)
{
extension.ProcessField(fi, model);
}
}
示例7: GetFieldValueAccess
/// <summary>
/// Creates a <see cref="ValueAccess"/> suitable for accessing the value in <paramref name="fieldInfo"/>.
/// </summary>
/// <param name="fieldInfo">The <see cref="FieldInfo"/></param> representing the field for which a
/// <see cref="ValueAccess"/> is required.
/// <returns>The <see cref="ValueAccess"/> that allows for accessing the value in <paramref name="fieldInfo"/>.</returns>
/// <exception cref="ArgumentNullException">when <paramref name="fieldInfo"/> is <see langword="null"/>.</exception>
public ValueAccess GetFieldValueAccess(FieldInfo fieldInfo)
{
if (null == fieldInfo)
throw new ArgumentNullException("fieldInfo");
return DoGetFieldValueAccess(fieldInfo);
}
示例8: FieldGetter
public FieldGetter(FieldInfo fieldInfo)
{
_fieldInfo = fieldInfo;
Name = fieldInfo.Name;
MemberType = fieldInfo.FieldType;
_lateBoundFieldGet = LazyFactory.Create(() => DelegateFactory.CreateGet(fieldInfo));
}
示例9: checkFields
private List<string> _list; //Store the list of existing languages
//[TestMethod]
//public void TestAllLanguageTranslationsExists()
//{
// Language defaultlang = new Language(); //Load the English version
// defaultlang.General.TranslatedBy = "Translated by ..."; // to avoid assertion
// foreach (String cultureName in _list) //Loop over all language files
// {
// //Load language
// var reader = new System.IO.StreamReader(Path.Combine(Configuration.BaseDirectory, "Languages") + Path.DirectorySeparatorChar + cultureName + ".xml");
// Language lang = Language.Load(reader);
// //Loop over all field in language
// checkFields(cultureName, defaultlang, lang, defaultlang.GetType().GetFields());
// checkProperty(cultureName, defaultlang, lang, defaultlang.GetType().GetProperties());
// //If u want to save a kind of fixed lang file
// //Disabled the assert fail function for it!
// // lang.Save("Languagesnew\\" + cultureName + ".xml");
// reader.Close();
// }
//}
private void checkFields(string cultureName, object completeLang, object cultureLang, FieldInfo[] fields)
{
foreach (FieldInfo fieldInfo in fields)
{
if (fieldInfo.IsPublic && fieldInfo.FieldType.Namespace.Equals("Nikse.SubtitleEdit.Logic")) {
object completeLangatt = fieldInfo.GetValue(completeLang);
object cultureLangatt = fieldInfo.GetValue(cultureLang);
if ((cultureLangatt == null) || (completeLangatt == null))
{
Assert.Fail(fieldInfo.Name + " is mssing");
}
//Console.Out.WriteLine("Field: " + fieldInfo.Name + " checked of type:" + fieldInfo.FieldType.FullName);
if (!fieldInfo.FieldType.FullName.Equals("System.String"))
{
checkFields(cultureName, completeLang, cultureLang, fieldInfo.FieldType.GetFields());
checkProperty(cultureName, completeLangatt, cultureLangatt, fieldInfo.FieldType.GetProperties());
}
else
{
Assert.Fail("no expecting a string here");
}
}
}
}
示例10: ProccessField
/// <summary>
/// 判断字段的过虑条件。
/// </summary>
/// <param name="field"></param>
/// <returns></returns>
public static bool ProccessField(FieldInfo field)
{
if(field.FieldType.IsSubclassOf(typeof(Delegate)))
return false;
return true;
}
示例11: CreateProxiedMethod
public void CreateProxiedMethod(FieldInfo field, MethodInfo method, TypeBuilder typeBuilder)
{
const MethodAttributes methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig |
MethodAttributes.Virtual;
ParameterInfo[] parameters = method.GetParameters();
MethodBuilder methodBuilder = typeBuilder.DefineMethod(method.Name, methodAttributes,
CallingConventions.HasThis, method.ReturnType,
parameters.Select(param => param.ParameterType).ToArray());
System.Type[] typeArgs = method.GetGenericArguments();
if (typeArgs.Length > 0)
{
var typeNames = new List<string>();
for (int index = 0; index < typeArgs.Length; index++)
{
typeNames.Add(string.Format("T{0}", index));
}
methodBuilder.DefineGenericParameters(typeNames.ToArray());
}
ILGenerator IL = methodBuilder.GetILGenerator();
Debug.Assert(MethodBodyEmitter != null);
MethodBodyEmitter.EmitMethodBody(IL, method, field);
}
示例12: Create
private static IGetterAndSetter Create(FieldInfo fieldInfo)
{
var setter = typeof(GetterAndSetter<,>).MakeGenericType(fieldInfo.DeclaringType, fieldInfo.FieldType);
var constructorInfo = setter.GetConstructor(new[] { typeof(FieldInfo) });
//// ReSharper disable once PossibleNullReferenceException nope, not here
return (IGetterAndSetter)constructorInfo.Invoke(new object[] { fieldInfo });
}
示例13: GlideInfo
public GlideInfo(object target, FieldInfo info)
{
Target = target;
field = info;
PropertyName = info.Name;
PropertyType = info.FieldType;
}
示例14: RubyFieldInfo
public RubyFieldInfo(FieldInfo/*!*/ fieldInfo, RubyMemberFlags flags, RubyModule/*!*/ declaringModule, bool isSetter, bool isDetached)
: base(flags, declaringModule) {
Assert.NotNull(fieldInfo, declaringModule);
_fieldInfo = fieldInfo;
_isSetter = isSetter;
_isDetached = isDetached;
}
示例15: Decorate
public virtual object Decorate(FieldInfo field)
{
if (!(typeof(IWebElement).IsAssignableFrom(field.FieldType)
|| IsDecoratableList(field)))
{
return null;
}
IElementLocator locator = factory.CreateLocator(field);
if (locator == null)
{
return null;
}
if (typeof(IWebElement).IsAssignableFrom(field.FieldType))
{
return ProxyForLocator(locator);
}
else if (typeof(IList).IsAssignableFrom(field.FieldType))
{
return ProxyForListLocator(locator);
}
else
{
return null;
}
}