本文整理汇总了C#中System.Reflection.MethodInfo.IsGetter方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.IsGetter方法的具体用法?C# MethodInfo.IsGetter怎么用?C# MethodInfo.IsGetter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodInfo
的用法示例。
在下文中一共展示了MethodInfo.IsGetter方法的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();
}
示例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;
}