本文整理汇总了C#中ClientType.GetProperty方法的典型用法代码示例。如果您正苦于以下问题:C# ClientType.GetProperty方法的具体用法?C# ClientType.GetProperty怎么用?C# ClientType.GetProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClientType
的用法示例。
在下文中一共展示了ClientType.GetProperty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadPropertyValue
/// <summary>
/// Given a source property path in segmented form, reads the property value from the resource type instance
/// </summary>
/// <param name="element">Client type instance.</param>
/// <param name="resourceType">Client type whose property is to be read</param>
/// <param name="srcPathSegments">Segmented source property path.</param>
/// <param name="currentSegment">Index of current property name in <paramref name="srcPathSegments"/></param>
/// <returns>Property value read from the client type instance. Possibly null.</returns>
private static object ReadPropertyValue(object element, ClientType resourceType, string[] srcPathSegments, int currentSegment)
{
if (element == null || currentSegment == srcPathSegments.Length)
{
return element;
}
else
{
String srcPathPart = srcPathSegments[currentSegment];
ClientType.ClientProperty resourceProperty = resourceType.GetProperty(srcPathPart, true);
if (resourceProperty == null)
{
throw Error.InvalidOperation(Strings.EpmSourceTree_InaccessiblePropertyOnType(srcPathPart, resourceType.ElementTypeName));
}
// If this is the last part of the path, then it has to be a primitive type otherwise should be a complex type
if (resourceProperty.IsKnownType ^ (currentSegment == srcPathSegments.Length - 1))
{
throw Error.InvalidOperation(!resourceProperty.IsKnownType ? Strings.EpmClientType_PropertyIsComplex(resourceProperty.PropertyName) :
Strings.EpmClientType_PropertyIsPrimitive(resourceProperty.PropertyName));
}
// o.Prop
PropertyInfo pi = element.GetType().GetProperty(srcPathPart, BindingFlags.Instance | BindingFlags.Public);
Debug.Assert(pi != null, "Cannot find property " + srcPathPart + "on type " + element.GetType().Name);
return ReadPropertyValue(
pi.GetValue(element, null),
resourceProperty.IsKnownType ? null : ClientType.Create(resourceProperty.PropertyType),
srcPathSegments,
++currentSegment);
}
}