本文整理汇总了C#中System.Reflection.TypeInfo.GetDeclaredField方法的典型用法代码示例。如果您正苦于以下问题:C# TypeInfo.GetDeclaredField方法的具体用法?C# TypeInfo.GetDeclaredField怎么用?C# TypeInfo.GetDeclaredField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.TypeInfo
的用法示例。
在下文中一共展示了TypeInfo.GetDeclaredField方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetFieldInHierarchy
public static FieldInfo TryGetFieldInHierarchy(TypeInfo ti, string name)
{
while (true)
{
var fi = ti.GetDeclaredField(name);
if (fi != null)
{
return fi;
}
var baseType = ti.BaseType;
if (baseType == null)
{
return null;
}
ti = baseType.GetTypeInfo();
}
}
示例2: GetField
public static FieldInfo GetField(TypeInfo ti, string name)
{
var r = ti.GetDeclaredField(name);
if (r != null) return r;
throw new ArgumentException("Cannot get field: " + name);
}
示例3: GetAuthorization
private static IAuthorize GetAuthorization(TypeInfo typeInfo)
{
return (IAuthorize)typeInfo.GetDeclaredField("Instance").GetValue(null);
}
示例4: actuallyGetField
FieldInfo actuallyGetField(TypeInfo typeInfo, string propertyName)
{
var current = typeInfo;
while (current != null) {
var ret = typeInfo.GetDeclaredField(propertyName);
if (ret != null && ret.IsStatic) return ret;
current = current.BaseType.GetTypeInfo();
}
return null;
}
示例5: SetupPart
void SetupPart(TypeInfo sourceType, BindingExpressionPart part)
{
part.Arguments = null;
part.LastGetter = null;
part.LastSetter = null;
PropertyInfo property = null;
if (part.IsIndexer)
{
if (sourceType.IsArray)
{
int index;
if (!int.TryParse(part.Content, out index))
Log.Warning("Binding", "{0} could not be parsed as an index for a {1}", part.Content, sourceType);
else
part.Arguments = new object[] { index };
part.LastGetter = sourceType.GetDeclaredMethod("Get");
part.LastSetter = sourceType.GetDeclaredMethod("Set");
part.SetterType = sourceType.GetElementType();
}
DefaultMemberAttribute defaultMember = sourceType.GetCustomAttributes(typeof(DefaultMemberAttribute), true).OfType<DefaultMemberAttribute>().FirstOrDefault();
string indexerName = defaultMember != null ? defaultMember.MemberName : "Item";
part.IndexerName = indexerName;
property = sourceType.GetDeclaredProperty(indexerName);
if (property == null)
property = sourceType.BaseType.GetProperty(indexerName);
if (property != null)
{
ParameterInfo parameter = property.GetIndexParameters().FirstOrDefault();
if (parameter != null)
{
try
{
object arg = Convert.ChangeType(part.Content, parameter.ParameterType, CultureInfo.InvariantCulture);
part.Arguments = new[] { arg };
}
catch (FormatException)
{
}
catch (InvalidCastException)
{
}
catch (OverflowException)
{
}
}
}
}
else
{
property = sourceType.GetDeclaredProperty(part.Content);
if (property == null)
property = sourceType.BaseType.GetProperty(part.Content);
}
if (property != null)
{
if (property.CanRead && property.GetMethod.IsPublic && !property.GetMethod.IsStatic)
part.LastGetter = property.GetMethod;
if (property.CanWrite && property.SetMethod.IsPublic && !property.SetMethod.IsStatic)
{
part.LastSetter = property.SetMethod;
part.SetterType = part.LastSetter.GetParameters().Last().ParameterType;
if (Binding.AllowChaining)
{
FieldInfo bindablePropertyField = sourceType.GetDeclaredField(part.Content + "Property");
if (bindablePropertyField != null && bindablePropertyField.FieldType == typeof(BindableProperty) && sourceType.ImplementedInterfaces.Contains(typeof(IElementController)))
{
MethodInfo setValueMethod = null;
foreach (MethodInfo m in sourceType.AsType().GetRuntimeMethods())
{
if (m.Name.EndsWith("IElementController.SetValueFromRenderer"))
{
ParameterInfo[] parameters = m.GetParameters();
if (parameters.Length == 2 && parameters[0].ParameterType == typeof(BindableProperty))
{
setValueMethod = m;
break;
}
}
}
if (setValueMethod != null)
{
part.LastSetter = setValueMethod;
part.IsBindablePropertySetter = true;
part.BindablePropertyField = bindablePropertyField.GetValue(null);
}
}
}
}
}
}