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


C# MethodInfo.IsSetter方法代码示例

本文整理汇总了C#中System.Reflection.MethodInfo.IsSetter方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.IsSetter方法的具体用法?C# MethodInfo.IsSetter怎么用?C# MethodInfo.IsSetter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.MethodInfo的用法示例。


在下文中一共展示了MethodInfo.IsSetter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SelectInterceptors

        /// <summary>Select interceptors which must be applied to the method.</summary>
        /// <param name="type">The type.</param>
        /// <param name="method">The method.</param>
        /// <param name="interceptors">The interceptors.</param>
        /// <returns>The interceptors after filtering.</returns>
        public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors)
        {
            if (method.IsGetter())
            {
                var propertyInfo = type.GetProperty(method);
                if (propertyInfo.IsPropertyWithSelectorAttribute())
                {
                    return typeof(BaseHtmlElement).IsAssignableFrom(method.ReturnType) 
                        ? interceptors.Where(x => x is PropertyInterceptor).ToArray() 
                        : interceptors.Where(x => x is CollectionPropertyInterceptor).ToArray();
                }
            }

            if (method.IsSetter())
            {
                var propertyInfo = type.GetProperty(method);
                if (propertyInfo.IsPropertyWithSelectorAttribute())
                {
                    return interceptors.Where(x => x is InvalidWriteOperationInterceptor).ToArray();
                }
            }

            return interceptors.Where(x => !(x is PropertyInterceptor) 
                && !(x is CollectionPropertyInterceptor)
                && !(x is InvalidWriteOperationInterceptor)).ToArray();
        }
开发者ID:pbakshy,项目名称:Selenol,代码行数:31,代码来源:InterceptorSelector.cs

示例2: ShouldInterceptMethod

        /// <summary>Invoked by the generation process to know if
        /// the specified member should be intercepted.</summary>
        /// <param name="type">The type.</param>
        /// <param name="methodInfo">The method Info.</param>
        /// <returns>The true if should otherwise false.</returns>
        public bool ShouldInterceptMethod(Type type, MethodInfo methodInfo) 
        {
            this.SetProxiedTypeIfNeed(type);
            if (!methodInfo.IsGetter() && !methodInfo.IsSetter())
            {
                return false;
            }

            var propertyInfo = type.GetProperty(methodInfo);
            this.AppedProcessedProperty(propertyInfo);
            if (!propertyInfo.IsPropertyWithSelectorAttribute())
            {
                return false;
            }

            if (!propertyInfo.IsAutoProperty())
            {
                this.AppendError("'{0}' is not an auto property. Selector attributes can be used only for auto properties.".F(propertyInfo.Name));

                return false;
            }

            var propertyType = propertyInfo.PropertyType;
            var isValidCollectionType = IsValidCollectionType(propertyType);
            if (isValidCollectionType && propertyType.GetGenericArguments().Single().IsAbstract)
            {
                var errorMessage = "'{0}' property has invalid type. Generic type argument can not be abstract. For Elements use ReadOnlyCollection<ButtonElement> instead of ReadOnlyCollection<BaseHtmlElement>. For Controls use non abstract Control type as generic argument for collection."
                    .F(propertyInfo.Name);
                this.AppendError(errorMessage);
                return false;
            }

            if (!isValidCollectionType && !typeof(BaseHtmlElement).IsAssignableFrom(propertyType))
            {
                var errorMessage = "'{0}' property has invalid type. Selector attributes can be used only for properties: \r\n - with type derived from BaseHtmlElement or Contro<T>\r\n - assignable from ReadOnlyCollection<T> where T : BaseHtmlElement or Control<T>"
                    .F(propertyInfo.Name);
                this.AppendError(errorMessage);
                return false;
            }

            if (!isValidCollectionType && propertyType.IsAbstract)
            {
                this.AppendError("'{0}' property has invalid type. Selector attributes can not be used for abstract types.".F(propertyInfo.Name));
                return false;
            }

            return true;
        }
开发者ID:pbakshy,项目名称:Selenol,代码行数:53,代码来源:PageProxyGenerationHook.cs


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