本文整理汇总了C#中System.Reflection.PropertyInfo.GetAnnotation方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyInfo.GetAnnotation方法的具体用法?C# PropertyInfo.GetAnnotation怎么用?C# PropertyInfo.GetAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.PropertyInfo
的用法示例。
在下文中一共展示了PropertyInfo.GetAnnotation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetValue
public virtual object GetValue(IContentData contentData, PropertyInfo property)
{
var annotation = property.GetAnnotation<CmsPagePredicateAttribute>();
var predicate = (IPagePredicate) ServiceLocator.Current.GetService(annotation.Predicate);
return predicate.Test((PageData) contentData);
}
示例2: GetValue
public virtual object GetValue(IContentData contentData, PropertyInfo property)
{
var content = (IContent) contentData;
var annotation = property.GetAnnotation<CmsPublishedStatusAttribute>();
var result = FilterPublished.CheckPublishedStatus(content, annotation.Status);
return result;
}
示例3: GetValue
public object GetValue(IContentData contentData, PropertyInfo property)
{
// define if property is required
var requiredAnnotation = property.GetAttribute<RequiredAttribute>();
// get annotation attribute
var annotation = property.GetAnnotation<CmsReferenceAttribute>();
// get reference property name set by attribute or default
var referencePropertyName = annotation.LinkFieldName ?? property.Name + "Link";
// lookup reference property
var referenceProperty = contentData.Property[referencePropertyName] as PropertyPageReference;
if (referenceProperty != null)
// if reference property found
{
// get link to a referenced page
var link = referenceProperty.ContentLink;
if (!ContentReference.IsNullOrEmpty(link))
// and if it's not empty
{
// load referenced page and cast it to the target property type.
var result = ContentLoader.Get<PageData>(link).Cast(property.PropertyType);
if (result != null)
{
return result;
}
}
}
if (requiredAnnotation == null)
// if property is not marked as required
{
return null;
}
// otherwise get error message
string errorMessageFormat;
if (!string.IsNullOrEmpty(requiredAnnotation.ErrorMessageResourceName))
{
errorMessageFormat = LocalizationService.GetString(requiredAnnotation.ErrorMessageResourceName);
}
else if (!string.IsNullOrEmpty(requiredAnnotation.ErrorMessage))
{
errorMessageFormat = requiredAnnotation.ErrorMessage;
}
else
{
errorMessageFormat = LocalizationService.GetString("EPiProperties/PropertyRequiredFormat", "Required property '{0}' is not properly set on the page #{1} of type '{2}'. ");
}
var content = contentData as IContent;
if (content != null)
{
var contentType = ContentTypeRepository.Load(content.ContentTypeID);
var errorMessage = string.Format(errorMessageFormat,
property.Name,
content.ContentLink.ID,
contentType.DisplayName);
throw new ApplicationException(errorMessage);
}
else
{
throw new ApplicationException(string.Format(errorMessageFormat,
property.Name,
"?",
"?")); // TODO
}
}