本文整理汇总了C#中System.Reflection.MethodInfo.HasAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.HasAttribute方法的具体用法?C# MethodInfo.HasAttribute怎么用?C# MethodInfo.HasAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodInfo
的用法示例。
在下文中一共展示了MethodInfo.HasAttribute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProviderMethodBinding
public ProviderMethodBinding(MethodInfo method, string providerKey, object target, bool isLibrary)
: base(providerKey, null, method.HasAttribute<SingletonAttribute>(),
method.DeclaringType.FullName + "." + method.Name)
{
this.method = method;
this.target = target;
IsLibrary = isLibrary;
}
示例2: WriteFunction
/// <summary>
/// Writes the type method to function.
/// </summary>
/// <param name="targetType">Type of the target.</param>
/// <param name="methodInfo">The method info.</param>
private void WriteFunction(string targetType, MethodInfo methodInfo)
{
string functionName;
string targetMethod;
if (methodInfo.HasAttribute<ConstructorAttribute>()) {
functionName = "new" + targetType.ToLower().ToPascalCase();
targetMethod = targetType;
ParameterInfo[] ctrParameters = methodInfo.GetParameters();
functionName = AddBySuffix(ctrParameters, functionName);
} else if (methodInfo.HasAttribute<DestructorAttribute>()) {
functionName = "delete" + targetType.ToLower().ToPascalCase();
targetMethod = "~" + targetType;
} else {
functionName = targetType.ToLower().ToPascalCase() + methodInfo.Name;
targetMethod = methodInfo.Name.ToCamelCase();
if (IsOverloaded(methodInfo))
functionName += GetNumberFromSequence(methodInfo);
}
string parameters;
if (methodInfo.HasAttribute<DestructorAttribute>()) {
parameters = "InvHandle self";
} else if (methodInfo.HasAttribute<MethodAttribute>()) {
var attr = methodInfo.GetAttribute<MethodAttribute>(true);
parameters = GetParametersString(methodInfo);
if (!attr.Static)
parameters = "InvHandle self" +
(!string.IsNullOrEmpty(parameters) ? (", " + parameters) : parameters);
} else {
parameters = GetParametersString(methodInfo);
}
_writer.WriteLine("/**");
_writer.WriteLine(" * Method: {0}::{1}", targetType, targetMethod);
_writer.WriteLine(" */");
_writer.WriteLine("INV_EXPORT {0}",
ConfigOptions.ToCppTypename(methodInfo.ReturnParameter, methodInfo.ReturnType));
_writer.WriteLine("INV_CALL {0}({1});", functionName.ToCStyle(), parameters);
_writer.WriteLine();
}
示例3: WriteMethod
/// <summary>
/// Writes the method.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="methodInfo">The method info.</param>
/// <param name="writeContent">if set to <c>true</c> [write content].</param>
protected virtual void WriteMethod(Type type, MethodInfo methodInfo, bool writeContent = false)
{
string functionName;
string targetMethod;
var targetType = ConfigOptions.GetCppTypename(type);
bool isConstructor = false;
bool implemented = false;
string cppTargetType = targetType;
if (methodInfo.HasAttribute<ConstructorAttribute>()) {
functionName = "new" + targetType.ToLower().ToPascalCase();
targetMethod = targetType;
//ParameterInfo[] ctrParameters = methodInfo.GetParameters();
//functionName = AddBySuffix(ctrParameters, functionName);
if (IsOverloaded(methodInfo))
functionName += "_m" + GetNumberFromSequence(methodInfo);
isConstructor = true;
implemented = methodInfo.QueryAttribute<ConstructorAttribute>(x => x.Implemented);
} else if (methodInfo.HasAttribute<DestructorAttribute>()) {
functionName = "delete" + targetType.ToLower().ToPascalCase();
targetMethod = "~" + targetType;
implemented = methodInfo.QueryAttribute<DestructorAttribute>(x => x.Implemented);
} else {
var methodName = methodInfo.Name;
functionName = targetType.ToLower().ToPascalCase() + methodName;
targetMethod = methodInfo.Name.ToCamelCase();
if (IsOverloaded(methodInfo))
functionName += "_m" + GetNumberFromSequence(methodInfo);
implemented = methodInfo.QueryAttribute<MethodAttribute>(x => x.Implemented);
}
string parameters;
if (methodInfo.HasAttribute<DestructorAttribute>()) {
parameters = "InvHandle self";
} else if (methodInfo.HasAttribute<MethodAttribute>()) {
var attr = methodInfo.GetAttribute<MethodAttribute>(true);
parameters = GetParametersString(methodInfo);
if (!attr.Static)
parameters = "InvHandle self" +
(!string.IsNullOrEmpty(parameters) ? (", " + parameters) : parameters);
} else {
parameters = GetParametersString(methodInfo);
}
string returnedType = ConfigOptions.ToCppTypename(methodInfo.ReturnParameter, methodInfo.ReturnType);
if (isConstructor)
returnedType = "InvHandle";
_writer.WriteLine("/**");
_writer.WriteLine(" * Method: {0}::{1} {2}", cppTargetType, targetMethod, implemented ? "(OK)" : "(NOT IMPLEMENTED)");
_writer.WriteLine(" */");
_writer.WriteLine("INV_EXPORT {0}", returnedType);
_writer.WriteLine("INV_CALL {0}({1}){2}", functionName.ToCStyle(), parameters, writeContent ? string.Empty : ";");
if (writeContent) {
_writer.OpenBlock();
WriteMethodContent(type, methodInfo);
_writer.CloseBlock();
}
_writer.WriteLine();
}
示例4: GetExternalMethodName
/// <summary>
/// Gets the name of the external method.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="method">The method.</param>
/// <returns></returns>
public static string GetExternalMethodName(Type type, MethodInfo method)
{
string functionName;
string targetType = ConfigOptions.GetCppTypename(type);
if (method.HasAttribute<ConstructorAttribute>()) {
functionName = "new" + targetType.ToLower().ToPascalCase();
//ParameterInfo[] ctrParameters = method.GetParameters();
//functionName = AddBySuffix(ctrParameters, functionName);
} else if (method.HasAttribute<DestructorAttribute>()) {
functionName = "delete" + targetType.ToLower().ToPascalCase();
} else {
functionName = targetType.ToLower().ToPascalCase() + method.Name;
}
if (IsOverloaded(method))
functionName += "_m" + GetNumberFromSequence(method);
return functionName.ToCStyle();
}
示例5: GetMethodType
private HttpVerbs GetMethodType(MethodInfo method)
{
if (method.HasAttribute<System.Web.Http.HttpGetAttribute>() || method.HasAttribute<System.Web.Mvc.HttpGetAttribute>()) return HttpVerbs.Get;
if (method.HasAttribute<System.Web.Http.HttpPostAttribute>() || method.HasAttribute<System.Web.Mvc.HttpPostAttribute>()) return HttpVerbs.Post;
if (method.HasAttribute<System.Web.Http.HttpDeleteAttribute>() || method.HasAttribute<System.Web.Mvc.HttpDeleteAttribute>()) return HttpVerbs.Delete;
if (method.HasAttribute<System.Web.Http.HttpPutAttribute>() || method.HasAttribute<System.Web.Mvc.HttpPutAttribute>()) return HttpVerbs.Put;
var acceptVerbs = method.GetCustomAttribute<System.Web.Http.AcceptVerbsAttribute>();
if (acceptVerbs != null && acceptVerbs.HttpMethods.Any())
return acceptVerbs.HttpMethods.Select(s => (HttpVerbs)Enum.Parse(typeof(HttpVerbs), s.ToString(), true)).First();
var acceptVerbsMvc = method.GetCustomAttribute<System.Web.Mvc.AcceptVerbsAttribute>();
if (acceptVerbsMvc != null && acceptVerbsMvc.Verbs.Any())
return acceptVerbsMvc.Verbs.Select(s => (HttpVerbs)Enum.Parse(typeof(HttpVerbs), s.ToString(), true)).First();
var name = method.Name.ToLower();
if (name.StartsWith("get")) return HttpVerbs.Get;
if (name.StartsWith("post")) return HttpVerbs.Post;
if (name.StartsWith("delete")) return HttpVerbs.Delete;
if (name.StartsWith("put")) return HttpVerbs.Put;
return HttpVerbs.Get;
}
示例6: WriteMethodSignature
/// <summary>
/// Writes the method signature.
/// </summary>
/// <param name="method">The method.</param>
private void WriteMethodSignature(MethodInfo method)
{
string returnType = ConfigOptions.GetCSharpTypeString(method.ReturnType);
if (method.HasAttribute<ConstructorAttribute>() || method.ReturnType.HasICppInterface())
returnType = typeof(Handle).Name;
Writer.BeginLine();
Writer.Write("public static extern {0} {1}(",
returnType,
method.Name);
ParameterInfo[] parameters = method.GetParameters();
bool firstParam = true;
bool isNonStaticMethod = method.QueryAttribute<MethodAttribute>(attr => !attr.Static);
bool isDestructor = method.HasAttribute<DestructorAttribute>();
bool longParameters = (parameters.Length + (isNonStaticMethod ? 1 : 0)) > 1;
if (longParameters) {
Writer.Write(Writer.NewLine);
Writer.Indent();
Writer.BeginLine();
}
if (isNonStaticMethod || isDestructor) {
firstParam = false;
Writer.Write("Handle self");
}
foreach (ParameterInfo parameter in parameters) {
if (firstParam)
firstParam = false;
else {
Writer.Write(", ");
if (longParameters) {
Writer.Write(Writer.NewLine);
Writer.BeginLine();
}
}
var marshalAsAttribute = parameter.GetAttribute<MarshalAsAttribute>(true);
if (marshalAsAttribute != null) {
Writer.Write(BuildMarshalAsAttribute(marshalAsAttribute, false));
Writer.Write(" ");
}
string paramModification = ConfigOptions.GetCSharpParameterModifier(parameter);
var parameterType = parameter.ParameterType;
if (parameterType.HasICppInterface())
parameterType = typeof(Handle);
Writer.Write("{0}{1} {2}",
string.IsNullOrEmpty(paramModification)
? string.Empty
: string.Format("{0} ", paramModification),
ConfigOptions.GetCSharpTypeString(parameterType),
parameter.Name);
}
Writer.Write(");{0}", Writer.NewLine);
if (longParameters)
Writer.Deindent();
}
示例7: IsEvaluator
private static bool IsEvaluator(MethodInfo info)
{
return info.HasAttribute<FormulaArgumentAttribute>() &&
info.ReturnType == typeof (double);
}
示例8: AppliesTo
public bool AppliesTo(MethodInfo method, Type mixin, Type compositeType, Type fragmentClass)
{
return method.HasAttribute(this.annotationType);
}