本文整理汇总了C#中System.Reflection.MethodInfo.GetCustomAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.GetCustomAttributes方法的具体用法?C# MethodInfo.GetCustomAttributes怎么用?C# MethodInfo.GetCustomAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodInfo
的用法示例。
在下文中一共展示了MethodInfo.GetCustomAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtendsType
public static bool ExtendsType(MethodInfo method, Type type)
{
var ext = method.GetCustomAttributes(typeof(ExtendsAttribute), true);
if (ext.Length != 0 && ((ExtendsAttribute)ext[0]).Type == type)
{
return true;
}
if (method.GetCustomAttributes(typeof(ExtensionAttribute), true).Length == 0)
{
return false;
}
var pars = method.GetParameters();
if (pars.Length == 0)
{
return false;
}
if (type != pars[0].ParameterType)
{
// maybe test for subclass
return false;
}
return true;
}
示例2: Scan
public IEnumerable<ExecutionStep> Scan(object testObject, MethodInfo candidateMethod)
{
var executableAttribute = (ExecutableAttribute)candidateMethod.GetCustomAttributes(typeof(ExecutableAttribute), false).FirstOrDefault();
if(executableAttribute == null)
yield break;
string stepTitle = executableAttribute.StepTitle;
if(string.IsNullOrEmpty(stepTitle))
stepTitle = NetToString.Convert(candidateMethod.Name);
var stepAsserts = IsAssertingByAttribute(candidateMethod);
var runStepWithArgsAttributes = (RunStepWithArgsAttribute[])candidateMethod.GetCustomAttributes(typeof(RunStepWithArgsAttribute), false);
if (runStepWithArgsAttributes.Length == 0)
{
yield return new ExecutionStep(GetStepAction(candidateMethod), stepTitle, stepAsserts, executableAttribute.ExecutionOrder, true);
}
foreach (var runStepWithArgsAttribute in runStepWithArgsAttributes)
{
var inputArguments = runStepWithArgsAttribute.InputArguments;
var flatInput = inputArguments.FlattenArrays();
var stringFlatInputs = flatInput.Select(i => i.ToString()).ToArray();
var methodName = stepTitle + " " + string.Join(", ", stringFlatInputs);
if (!string.IsNullOrEmpty(runStepWithArgsAttribute.StepTextTemplate))
methodName = string.Format(runStepWithArgsAttribute.StepTextTemplate, flatInput);
else if (!string.IsNullOrEmpty(executableAttribute.StepTitle))
methodName = string.Format(executableAttribute.StepTitle, flatInput);
yield return new ExecutionStep(GetStepAction(candidateMethod, inputArguments), methodName, stepAsserts, executableAttribute.ExecutionOrder, true);
}
}
示例3: FromMethodInfo
/// <summary>
/// Returns a ClientMethod instance to get the name of the class and method name on the client-side JavaScript.
/// </summary>
/// <param name="method">The MethodInfo.</param>
/// <returns>
/// Returns the ClientMethod info, if it is not a AjaxMethod it will return null.
/// </returns>
public static ClientMethod FromMethodInfo(MethodInfo method)
{
if(method.GetCustomAttributes(typeof(AjaxPro.AjaxMethodAttribute), true).Length == 0)
return null;
AjaxPro.AjaxNamespaceAttribute[] classns = (AjaxPro.AjaxNamespaceAttribute[])method.ReflectedType.GetCustomAttributes(typeof(AjaxPro.AjaxNamespaceAttribute), true);
AjaxPro.AjaxNamespaceAttribute[] methodns = (AjaxPro.AjaxNamespaceAttribute[])method.GetCustomAttributes(typeof(AjaxPro.AjaxNamespaceAttribute), true);
ClientMethod cm = new ClientMethod();
if (classns.Length > 0)
cm.ClassName = classns[0].ClientNamespace;
else
{
if (Utility.Settings.UseSimpleObjectNaming)
cm.ClassName = method.ReflectedType.Name;
else
cm.ClassName = method.ReflectedType.FullName;
}
if(methodns.Length > 0)
cm.MethodName += methodns[0].ClientNamespace;
else
cm.MethodName += method.Name;
return cm;
}
示例4: PublicMethod_ThatReturnsReferenceType_MustBeTaggedWithNotNullOrCanBeNullAttributes
public void PublicMethod_ThatReturnsReferenceType_MustBeTaggedWithNotNullOrCanBeNullAttributes(MethodInfo method)
{
bool hasNotNullAttribute = method.GetCustomAttributes(typeof(NotNullAttribute), true).Any();
bool hasCanBeNullAttribute = method.GetCustomAttributes(typeof(CanBeNullAttribute), true).Any();
Assume.That(method.DeclaringType != null);
Assert.That(hasNotNullAttribute || hasCanBeNullAttribute, "Method " + method.Name + " of type " + method.DeclaringType.Name + " must be tagged with [NotNull] or [CanBeNull]");
}
示例5: GetMethods
private static string[] GetMethods(MethodInfo methodInfo)
{
var list = new List<string>();
list.AddRange(from customAttribute in methodInfo.GetCustomAttributes<HttpGetAttribute>() from httpMethod in customAttribute.HttpMethods select httpMethod.Method);
list.AddRange(from customAttribute in methodInfo.GetCustomAttributes<HttpPostAttribute>() from httpMethod in customAttribute.HttpMethods select httpMethod.Method);
list.AddRange(from customAttribute in methodInfo.GetCustomAttributes<HttpPutAttribute>() from httpMethod in customAttribute.HttpMethods select httpMethod.Method);
list.AddRange(from customAttribute in methodInfo.GetCustomAttributes<HttpDeleteAttribute>() from httpMethod in customAttribute.HttpMethods select httpMethod.Method);
return list.Distinct().ToArray();
}
示例6: ParameterizedTestMethod
public ParameterizedTestMethod(TestFixture testFixture, MethodInfo methodInfo)
: base(testFixture, methodInfo) {
foreach(DataRow dataRow in methodInfo.GetCustomAttributes(typeof(DataRow), true)) {
_dataSource.Add(dataRow);
}
if(_dataSource.Count == 0) {
object[] attrs = methodInfo.GetCustomAttributes(typeof(DataSourceAttribute), true);
if( attrs.Length > 0 ) {
_dataSource.Add(attrs[0] as DataSourceAttribute);
}
}
_expectedParameterNum = MethodInfo.GetParameters().Length;
}
示例7: ActionMethod
public ActionMethod(MethodInfo methodInfo)
{
_methodInfo = methodInfo;
_filterAttributes = (ActionFilterAttribute[]) methodInfo.GetCustomAttributes(typeof(ActionFilterAttribute), false);
OrderedAttribute.Sort(_filterAttributes);
if (_methodInfo.IsDefined(typeof(LayoutAttribute), false))
_defaultLayoutName = ((LayoutAttribute)_methodInfo.GetCustomAttributes(typeof(LayoutAttribute), false)[0]).LayoutName ?? "";
if (_methodInfo.IsDefined(typeof(ViewAttribute), false))
_defaultViewName = ((ViewAttribute)_methodInfo.GetCustomAttributes(typeof(ViewAttribute), false)[0]).ViewName ?? "";
}
示例8: IsWebMethod
public static bool IsWebMethod(MethodInfo method)
{
object[] customAttributes = method.GetCustomAttributes(typeof(SoapRpcMethodAttribute), true);
if ((customAttributes != null) && (customAttributes.Length > 0))
{
return true;
}
customAttributes = method.GetCustomAttributes(typeof(SoapDocumentMethodAttribute), true);
if ((customAttributes != null) && (customAttributes.Length > 0))
{
return true;
}
customAttributes = method.GetCustomAttributes(typeof(HttpMethodAttribute), true);
return ((customAttributes != null) && (customAttributes.Length > 0));
}
示例9: RegisterMethod
private static void RegisterMethod(MethodInfo method)
{
foreach (ScriptableAttribute attribute in method.GetCustomAttributes(typeof(ScriptableAttribute),false))
{
globalmethods[attribute.Name ?? method.Name] = method;
}
}
示例10: GetAttributes
private List<MethodBoundaryAttribute> GetAttributes(MethodInfo methodInfo)
{
List<MethodBoundaryAttribute> attributes = new List<MethodBoundaryAttribute>();
//Method level attributes
MethodBoundaryAttribute[] methodAttributes = (MethodBoundaryAttribute[])methodInfo.GetCustomAttributes(typeof(MethodBoundaryAttribute), false);
//Class level attributes
MethodBoundaryAttribute[] classAttributes = (MethodBoundaryAttribute[])methodInfo.ReflectedType.GetCustomAttributes(typeof(MethodBoundaryAttribute), false);
//add method level
attributes.AddRange(methodAttributes);
//add class attribute if not exist in method
foreach (MethodBoundaryAttribute classAttr in classAttributes)
{
bool exist = false;
foreach (MethodBoundaryAttribute methodAttr in methodAttributes)
{
if (classAttr.TypeId == methodAttr.TypeId)
exist = true;
}
if (!exist)
attributes.Add(classAttr);
}
return attributes;
}
示例11: CollectFilters
/// <summary>
/// Implementors should collect the transformfilter information
/// and return descriptors instances, or an empty array if none
/// was found.
/// </summary>
/// <param name="methodInfo">The action (MethodInfo)</param>
/// <returns>
/// An array of <see cref="TransformFilterDescriptor"/>
/// </returns>
public TransformFilterDescriptor[] CollectFilters(MethodInfo methodInfo)
{
if (logger.IsDebugEnabled)
{
logger.DebugFormat("Collecting transform filters for {0}", methodInfo.Name);
}
var attributes = methodInfo.GetCustomAttributes(typeof(ITransformFilterDescriptorBuilder), true);
var filters = new List<TransformFilterDescriptor>();
foreach(ITransformFilterDescriptorBuilder builder in attributes)
{
var descs = builder.BuildTransformFilterDescriptors();
if (logger.IsDebugEnabled)
{
foreach(var desc in descs)
{
logger.DebugFormat("Collected transform filter {0} to execute in order {1}", desc.TransformFilterType, desc.ExecutionOrder);
}
}
filters.AddRange(descs);
}
return filters.ToArray();
}
示例12: runMethodTest
TestResultBitmap runMethodTest(object instance, MethodInfo method)
{
if (method.IsGenericMethod)
throw new Exception("{0}: is not allowed to be generic".format(method));
var parameters = method.GetParameters();
if (parameters.Length != 1)
throw new Exception("{0}: expect one parameter".format(method));
var firstParameter = parameters[0];
if (firstParameter.ParameterType != typeof(IDrawingContext))
throw new Exception("{0}: expect IDrawingContext as first and only parameter");
var attribute = (BitmapDrawingTestAttribute)method.GetCustomAttributes(typeof (BitmapDrawingTestAttribute), false)[0];
using (var context = new BitmapDrawingContext(attribute.Width, attribute.Height))
{
IDrawingContext drawingContext;
using (context.beginDraw(out drawingContext))
{
method.Invoke(instance, new object[] { drawingContext });
}
return new TestResultBitmap(attribute.Width, attribute.Height, context.extractRawBitmap());
}
}
示例13: GetMethodGenerator
public IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method)
{
IHqlGeneratorForMethod methodGenerator;
if (method.IsGenericMethod)
{
method = method.GetGenericMethodDefinition();
}
if (_registeredMethods.TryGetValue(method, out methodGenerator))
{
return methodGenerator;
}
// No method generator registered. Look to see if it's a standard LinqExtensionMethod
var attr = method.GetCustomAttributes(typeof (LinqExtensionMethodAttribute), false);
if (attr.Length == 1)
{
// It is
// TODO - cache this? Is it worth it?
return new HqlGeneratorForExtensionMethod((LinqExtensionMethodAttribute) attr[0], method);
}
// Not that either. Let's query each type generator to see if it can handle it
foreach (var typeGenerator in _typeGenerators)
{
if (typeGenerator.SupportsMethod(method))
{
return typeGenerator.GetMethodGenerator(method);
}
}
throw new NotSupportedException(method.ToString());
}
示例14: MustAuthenticate
public bool MustAuthenticate(Type type, MethodInfo method)
{
type.ThrowIfNull("type");
method.ThrowIfNull("method");
return method.GetCustomAttributes(typeof(AuthenticateAttribute), false).Any();
}
示例15: GetCombinations
private static IEnumerable<VariantAttribute> GetCombinations(MethodInfo method)
{
var methodVariants
= method
.GetCustomAttributes(typeof(VariantAttribute), true)
.Cast<VariantAttribute>()
.ToList();
if (methodVariants.Any())
{
return methodVariants;
}
var typeVariants
= method.DeclaringType
.GetCustomAttributes(typeof(VariantAttribute), true)
.Cast<VariantAttribute>()
.ToList();
if (typeVariants.Any())
{
return typeVariants;
}
return new[] { new VariantAttribute(DatabaseProvider.SqlClient, ProgrammingLanguage.CSharp) };
}