本文整理汇总了C#中DTypeDesc.GetProperty方法的典型用法代码示例。如果您正苦于以下问题:C# DTypeDesc.GetProperty方法的具体用法?C# DTypeDesc.GetProperty怎么用?C# DTypeDesc.GetProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DTypeDesc
的用法示例。
在下文中一共展示了DTypeDesc.GetProperty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetStaticPropertyDesc
/// <summary>
/// Gets the <see cref="DPropertyDesc"/> of a static property of a class.
/// </summary>
/// <param name="type">The class to get the property of.</param>
/// <param name="propertyName">The property name.</param>
/// <param name="caller"><see cref="DTypeDesc"/> of the object that request the retrieval.</param>
/// <param name="context">Current <see cref="ScriptContext"/>.</param>
/// <param name="quiet">If <B>true</B>, the "property not found" exception should not be thrown.</param>
/// <returns>The <see cref="DPropertyDesc"/> representing the static property or <B>null</B> if an error occurs.</returns>
/// <exception cref="PhpException">The property denoted by <paramref name="propertyName"/> was not found. (Error)</exception>
/// <exception cref="PhpException">The property is inaccessible due to its protected or private visibility level (Error).
/// </exception>
internal static DPropertyDesc GetStaticPropertyDesc(DTypeDesc type, object propertyName, DTypeDesc caller,
ScriptContext context, bool quiet)
{
if (type == null) return null;
// convert propertyName to string
string name = (propertyName == null ? String.Empty : Convert.ObjectToString(propertyName));
// find the property
DPropertyDesc property;
switch (type.GetProperty(new VariableName(name), caller, out property))
{
case GetMemberResult.NotFound:
{
if (!quiet) PhpException.UndeclaredStaticProperty(type.MakeFullName(), name);
return null;
}
case GetMemberResult.BadVisibility:
{
if (!quiet)
{
PhpException.PropertyNotAccessible(
property.DeclaringType.MakeFullName(),
name,
(caller == null ? String.Empty : caller.MakeFullName()),
property.IsProtected);
}
return null;
}
case GetMemberResult.OK:
{
if (!property.IsStatic) goto case GetMemberResult.NotFound;
break;
}
}
// make sure that the property has been initialized for this request
property.EnsureInitialized(context);
return property;
}