本文整理汇总了C#中System.Reflection.PropertyInfo.GetIndexParameters方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyInfo.GetIndexParameters方法的具体用法?C# PropertyInfo.GetIndexParameters怎么用?C# PropertyInfo.GetIndexParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.PropertyInfo
的用法示例。
在下文中一共展示了PropertyInfo.GetIndexParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMemberID
/// <summary>
///
/// </summary>
/// <param name="property"></param>
/// <returns></returns>
public static string GetMemberID(PropertyInfo property)
{
string memberName;
memberName = "P:" + GetFullNamespaceName(property) +
"." + property.Name.Replace('.', '#').Replace('+', '#');
try
{
if (property.GetIndexParameters().Length > 0)
{
memberName += "(";
int i = 0;
foreach (ParameterInfo parameter in property.GetIndexParameters())
{
if (i > 0)
{
memberName += ",";
}
Type type = parameter.ParameterType;
#if NET_2_0
if (type.ContainsGenericParameters && type.IsGenericParameter)
{
memberName += "`" + type.GenericParameterPosition.ToString();
}
else if (type.FullName != null)
{
memberName += type.FullName;
}
else
{
memberName += type.Name;
}
#else
memberName += type.FullName;
#endif
++i;
}
memberName += ")";
}
}
catch (System.Security.SecurityException) { }
return memberName;
}
示例2: PropertyHasValue
/// <summary>
/// Check if the property is not null and can be read and is no indexed.
/// This is done to know if it can be read safely.
/// </summary>
/// <param name="obj">Obj.</param>
/// <param name="prop">Prop.</param>
/// <returns></returns>
private static bool PropertyHasValue(object obj, PropertyInfo prop)
{
if (obj == null || prop == null || !prop.CanRead || prop.GetIndexParameters().Length > 0)
return false;
else
return true;
}
示例3: IsAValidProperty
private static bool IsAValidProperty(PropertyInfo propertyInfo)
{
if (!propertyInfo.CanRead) return false;
if (!propertyInfo.CanWrite) return false;
if (propertyInfo.GetIndexParameters().Length > 0) return false;
return true;
}
示例4: GetPropertySetter
internal static MethodInfo GetPropertySetter(PropertyInfo propertyInfo, Type type)
{
if (propertyInfo.DeclaringType == type) return propertyInfo.GetSetMethod(true);
#if NETSTANDARD1_3
return propertyInfo.DeclaringType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Single(x => x.Name == propertyInfo.Name
&& x.PropertyType == propertyInfo.PropertyType
&& IsParameterMatch(x.GetIndexParameters(), propertyInfo.GetIndexParameters())
).GetSetMethod(true);
#else
return propertyInfo.DeclaringType.GetProperty(
propertyInfo.Name,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
Type.DefaultBinder,
propertyInfo.PropertyType,
propertyInfo.GetIndexParameters().Select(p => p.ParameterType).ToArray(),
null).GetSetMethod(true);
#endif
}
示例5: CanRead
public bool CanRead(ReflectedInstance value, Type type, PropertyInfo property)
{
// verify if property is "this[int i]", in real use is: "myList[0]', exclude array objects
// because if array is multidimensional will happen a error when call
// "property.GetValue(obj, new object[] { 0, 0 });" the class "PropertyReaderIndexerInArray" fix it.
var parameters = property.GetIndexParameters();
//
return (parameters.Length == 1)
&& (parameters[0].ParameterType == typeof(int));
}
示例6: HasGetter
private static bool HasGetter(PropertyInfo prop)
{
if (!prop.CanRead)
return false;
if (!ArrayUtil.IsNullOrEmpty(prop.GetIndexParameters()))
return false;
return true;
}
示例7: GetValues
public IEnumerable<MethodValue> GetValues(ReflectedInstance value, Type type, PropertyInfo property)
{
var dictionary = value.Object as IDictionary;
var parameters = property.GetIndexParameters();
foreach (var key in dictionary.Keys)
{
var parameter = new MethodValueParam(parameters[0].Name, parameters[0], key);
yield return new MethodValue(dictionary[key], parameter);
}
}
示例8: GetAssetId
public static string GetAssetId(PropertyInfo propertyInfo)
{
ParameterInfo[] p = propertyInfo.GetIndexParameters();
if (p.Length == 0)
return string.Format("P:{0}.{1}", GetTypeName(propertyInfo.ReflectedType), propertyInfo.Name);
return string.Format("P:{0}.{1}{2}",
GetTypeName(propertyInfo.ReflectedType),
propertyInfo.Name,
CreateParameterSignature(propertyInfo, p.Select(pr => pr.ParameterType).ToArray()));
}
示例9: GetId
public static string GetId(PropertyInfo property)
{
var parameters = string.Join(",", property.GetIndexParameters().Select(x => GetTypeName(x.ParameterType)));
if (!string.IsNullOrEmpty(parameters))
{
parameters = "(" + parameters + ")";
}
return string.Format(CultureInfo.InvariantCulture, "P:{0}.{1}{2}", GetTypeName(property.ReflectedType), HashEncode(property.Name), parameters);
}
示例10: ToSignature
internal static string ToSignature (PropertyInfo pi)
{
StringBuilder sb = new StringBuilder ();
sb.Append (ToSignature (pi.PropertyType));
sb.Append (" ");
sb.Append (ToSignature (pi.DeclaringType));
sb.Append (".");
sb.Append (pi.Name);
sb.Append (ToSignature ('[', pi.GetIndexParameters (), ']'));
return sb.ToString ();
}
示例11: IsCandidateProperty
private bool IsCandidateProperty(PropertyInfo property)
{
if (property == null)
{
throw new ArgumentNullException(nameof(property));
}
return property.CanWrite &&
property.GetIndexParameters().Length == 0 &&
IsSupportedPropertyType(property.PropertyType);
}
示例12: UseWhen
public override bool UseWhen()
{
_info = PropertyInfoHelper.GetIndexerPropertyInfo(TargetType, ColumnName);
if (_info == null)
return false;
var parameterType = _info.GetIndexParameters().First().ParameterType;
_lookUp = Convert.ChangeType(ColumnName, parameterType);
return true;
}
示例13: Match
public override Boolean Match(PropertyInfo sourceProperty, PropertyInfo targetProperty)
{
if (sourceProperty.Name == "Item")
{
var pp = sourceProperty.GetIndexParameters();
//source["key1"]
if (pp.Length == 1 && pp[0].ParameterType == typeof(String))
{
return true;
}
}
return false;
}
示例14: GetIndexerTypes
private static Type[] GetIndexerTypes(PropertyInfo property)
{
var indexerParameters = property.GetIndexParameters();
var result = new Type[indexerParameters.Length];
for (var i = 0; i < indexerParameters.Length; i++)
{
result[i] = indexerParameters[i].ParameterType;
}
return result;
}
示例15: Build
public static ExpressionTypeMemberDescriptor Build(PropertyInfo p)
{
ExpressionTypeMemberDescriptor md = new ExpressionTypeMemberDescriptor
{
Kind = "property",
Name = p.Name,
ReturnType = p.PropertyType.Name,
ReturnExpressionType = p.PropertyType.AssemblyQualifiedName
};
md.Parameters = (
from mdp in p.GetIndexParameters()
select Build(mdp)).ToList();
return md;
}