本文整理汇总了C#中IReflect.GetProperty方法的典型用法代码示例。如果您正苦于以下问题:C# IReflect.GetProperty方法的具体用法?C# IReflect.GetProperty怎么用?C# IReflect.GetProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IReflect
的用法示例。
在下文中一共展示了IReflect.GetProperty方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPropertyCaseInsensitive
private static PropertyInfo GetPropertyCaseInsensitive(IReflect type, string propertyName)
{
// make the property reflection lookup case insensitive
const BindingFlags bindingFlags = BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance;
return type.GetProperty(propertyName, bindingFlags);
}
示例2: LookupResource
public static string LookupResource(IReflect resourceManagerProvider, string resourceKey)
{
PropertyInfo property = resourceManagerProvider.GetProperty(resourceKey, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
// Fallback with the key name
if (property == null)
return resourceKey;
return (string) property.GetValue(null, null); // returns string directly from res file
}
示例3: GetArray
private string GetArray(IReflect reflect)
{
PropertyInfo piLength = reflect.GetProperty("length", BindingFlags.Default);
int len = (int)piLength.GetValue(reflect, null);
string[] ret = new string[len];
for (int i = 0; i < len; i++) {
PropertyInfo pi = reflect.GetProperty(i.ToString(), BindingFlags.Default);
object item;
if (pi == null) {
item = null;
}
else {
item = pi.GetValue(reflect, null);
}
ret[i] = GetString(item);
}
return string.Format("[ {0} ]", string.Join(", ", ret));
}
示例4: GetMember
private static MemberInfo GetMember(IReflect entityType, string[] memberNames)
{
var publicProperties =
from name in memberNames
select entityType.GetProperty(name, BindingFlags.Instance | BindingFlags.Public) into propertyInfo
where propertyInfo != null && IsPropertyOk(propertyInfo)
select propertyInfo;
var privateProperties =
from name in memberNames
select entityType.GetProperty(name, BindingFlags.Instance | BindingFlags.NonPublic) into propertyInfo
where propertyInfo != null && IsPropertyOk(propertyInfo)
select propertyInfo;
var publicFields =
from name in memberNames
select entityType.GetField(name, BindingFlags.Instance | BindingFlags.Public) into fieldInfo
where fieldInfo != null && IsFildOk(fieldInfo)
select fieldInfo;
return publicProperties.OfType<MemberInfo>().Concat(privateProperties).Concat(publicFields).FirstOrDefault();
}
示例5: GetAndWrapMember
private static MemberInfo[] GetAndWrapMember(IReflect reflect, Object namedItem, String name, BindingFlags bindingAttr){
PropertyInfo property = reflect.GetProperty(name, bindingAttr);
if (property != null){
MethodInfo getMethod = JSProperty.GetGetMethod(property, false);
MethodInfo setMethod = JSProperty.GetSetMethod(property, false);
if ((getMethod != null && !getMethod.IsStatic) || (setMethod != null && !setMethod.IsStatic)){
MethodInfo method = reflect.GetMethod(name, bindingAttr);
if (method != null && !method.IsStatic){
MemberInfo[] propMethods = new MemberInfo[1];
propMethods[0] = new JSWrappedPropertyAndMethod(property, method, namedItem);
return propMethods;
}
}
}
MemberInfo[] members = reflect.GetMember(name, bindingAttr);
if (members != null && members.Length > 0)
return ScriptObject.WrapMembers(members, namedItem);
return null;
}
示例6: GetAndWrapMember
private static MemberInfo[] GetAndWrapMember(IReflect reflect, object namedItem, string name, BindingFlags bindingAttr)
{
PropertyInfo property = reflect.GetProperty(name, bindingAttr);
if (property != null)
{
MethodInfo getMethod = JSProperty.GetGetMethod(property, false);
MethodInfo setMethod = JSProperty.GetSetMethod(property, false);
if (((getMethod != null) && !getMethod.IsStatic) || ((setMethod != null) && !setMethod.IsStatic))
{
MethodInfo method = reflect.GetMethod(name, bindingAttr);
if ((method != null) && !method.IsStatic)
{
return new MemberInfo[] { new JSWrappedPropertyAndMethod(property, method, namedItem) };
}
}
}
MemberInfo[] member = reflect.GetMember(name, bindingAttr);
if ((member != null) && (member.Length > 0))
{
return ScriptObject.WrapMembers(member, namedItem);
}
return null;
}
示例7: SetProperty
/// <summary>
/// Sets the property.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="strMethod">The STR method.</param>
/// <param name="objInstance">The obj instance.</param>
/// <param name="eFlags">The e flags.</param>
/// <param name="setValue">The set value.</param>
/// <param name="index">The index.</param>
/// <returns></returns>
private static object SetProperty(IReflect type, string strMethod, object objInstance, BindingFlags eFlags, object setValue, object[] index)
{
PropertyInfo property;
try
{
if ((eFlags == InstanceBindingFlags) && (objInstance == null))
{
throw new ArgumentException("The reflection non-static object argument was invalid");
}
if ((eFlags == StaticBindingFlags) && (objInstance != null))
{
throw new ArgumentException("The reflection static object argument was invalid");
}
if ((objInstance != null) && (objInstance.GetType() != (Type)type) && (objInstance.GetType().BaseType != (Type)type))
{
throw new ArgumentException("The object instance was of type '" + objInstance.GetType() + "' for type '" + type + "'.");
}
if (string.IsNullOrEmpty(strMethod))
{
throw new ArgumentException("The reflection method argument was invalid");
}
property = type.GetProperty(strMethod, eFlags);
if (property == null)
{
throw new ArgumentException("There is no property '" + strMethod + "' for type '" + type + "'.");
}
if (setValue.GetType() != property.PropertyType)
{
throw new ArgumentException("The value instance was of type '" + setValue.GetType() + "' for field type '" + property.PropertyType + "'.");
}
property.SetValue(objInstance, setValue, index);
var objRet = property.GetValue(objInstance, index);
return objRet;
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
throw;
}
}
示例8: SetAuthId
private bool SetAuthId(IReflect t, dynamic o)
{
var mustAuth = t.GetProperty("MustAuth", BindingFlags.Public | BindingFlags.Instance);
if (mustAuth != null)
{
if (Sorted.ContainsKey("session"))
{
_authorizedId = GetUserId(YunWebUtils.FromBase64StringForUrl(Sorted["session"]));
if (_authorizedId > 0)
{
var authId = t.GetProperty("AuthId", BindingFlags.Public | BindingFlags.Instance);
if (authId != null)
{
o.AuthId = _authorizedId;
//authId.SetValue(o, Convert.ChangeType(_authorizedId, TypeCode.Int32), null);
return true;
}
}
}
//return !(bool)mustAuth.GetValue(o, null);
return !o.MustAuth;
}
return true;
}
示例9: GetSetPropertyInfo
private static PropertyInfo GetSetPropertyInfo(IReflect actionType, string propertyName, string actionId)
{
var propertyInfo = actionType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.IgnoreCase);
if (propertyInfo == null || (propertyInfo.SetMethod.Attributes & MethodAttributes.Public) != MethodAttributes.Public)
{
throw new InvalidDataException(
string.Format(
"Add-on '{0}' doesn't implement public setter for property '{1}' but input property is required for action '{2}'.",
actionType,
propertyName,
actionId));
}
return propertyInfo;
}
示例10: GetAs
private static object GetAs(IReflect type, object obj, string prop)
{
var propInfo = type.GetProperty(prop, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
return propInfo.GetValue(obj, null);
}