当前位置: 首页>>代码示例>>C#>>正文


C# PropertyInfo.GetAnnotation方法代码示例

本文整理汇总了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);
        }
开发者ID:VladimirLevchuk,项目名称:EPiProperties,代码行数:8,代码来源:PagePredicatePropertyGetter.cs

示例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;
        }
开发者ID:VladimirLevchuk,项目名称:EPiProperties,代码行数:9,代码来源:PublishedStatusPropertyGetter.cs

示例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
            }
        }
开发者ID:VladimirLevchuk,项目名称:EPiProperties,代码行数:76,代码来源:ReferencePropertyGetter.cs


注:本文中的System.Reflection.PropertyInfo.GetAnnotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。