本文整理汇总了C#中System.Reflection.MethodBase.GetCustomAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBase.GetCustomAttributes方法的具体用法?C# MethodBase.GetCustomAttributes怎么用?C# MethodBase.GetCustomAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodBase
的用法示例。
在下文中一共展示了MethodBase.GetCustomAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldWarn
public static bool ShouldWarn(PythonBinder/*!*/ binder, MethodBase/*!*/ method, out WarningInfo info) {
Assert.NotNull(method);
ObsoleteAttribute[] os = (ObsoleteAttribute[])method.GetCustomAttributes(typeof(ObsoleteAttribute), true);
if (os.Length > 0) {
info = new WarningInfo(
PythonExceptions.DeprecationWarning,
String.Format("{0}.{1} has been obsoleted. {2}",
NameConverter.GetTypeName(method.DeclaringType),
method.Name,
os[0].Message
)
);
return true;
}
if (binder.WarnOnPython3000) {
Python3WarningAttribute[] py3kwarnings = (Python3WarningAttribute[])method.GetCustomAttributes(typeof(Python3WarningAttribute), true);
if (py3kwarnings.Length > 0) {
info = new WarningInfo(
PythonExceptions.DeprecationWarning,
py3kwarnings[0].Message
);
return true;
}
}
#if !SILVERLIGHT
// no apartment states on Silverlight
if (method.DeclaringType == typeof(Thread)) {
if (method.Name == "Sleep") {
info = new WarningInfo(
PythonExceptions.RuntimeWarning,
"Calling Thread.Sleep on an STA thread doesn't pump messages. Use Thread.CurrentThread.Join instead.",
Expression.Equal(
Expression.Call(
Expression.Property(
null,
typeof(Thread).GetProperty("CurrentThread")
),
typeof(Thread).GetMethod("GetApartmentState")
),
AstUtils.Constant(ApartmentState.STA)
),
() => Thread.CurrentThread.GetApartmentState() == ApartmentState.STA
);
return true;
}
}
#endif
info = null;
return false;
}
示例2: GetBaseName
public string GetBaseName(MethodBase method, Func<DisplayAsAttribute, string> selectName)
{
var nameAttribute = method.GetCustomAttributes(typeof(DisplayAsAttribute), true);
if(nameAttribute.Length != 0)
return selectName(((DisplayAsAttribute)nameAttribute[0]));
return NormalizeNamePattern.Replace(method.Name, " ");
}
示例3: MethodShouldBeProxied
public bool MethodShouldBeProxied(MethodBase method, IList aspects, Type baseType)
{
foreach (IAspect aspect in aspects)
{
IGenericAspect tmpAspect;
if (aspect is IGenericAspect)
tmpAspect = (IGenericAspect) aspect;
else
tmpAspect = TypedToGenericConverter.Convert((ITypedAspect) aspect);
foreach (IPointcut pointcut in tmpAspect.Pointcuts)
{
if (pointcut.IsMatch(method, baseType))
return true;
}
}
foreach (FixedInterceptorAttribute fixedInterceptorAttribute in method.GetCustomAttributes(typeof(FixedInterceptorAttribute), true))
return true;
if (baseType != null)
{
foreach (FixedInterceptorAttribute fixedInterceptorAttribute in baseType.GetCustomAttributes(typeof(FixedInterceptorAttribute), true))
return true;
}
return false;
}
示例4: GetMongoSessionAttribute
private MongoSessionAttribute GetMongoSessionAttribute(MethodBase methodBase)
{
// ���忡 Ư���� �����Ǿ� �ִ��� Ȯ���Ѵ�.
object[] attrs
= methodBase.GetCustomAttributes(typeof(MongoSessionAttribute), true);
MongoSessionAttribute sessionAttribute = null;
if (attrs != null && attrs.Length > 0)
{
sessionAttribute = (MongoSessionAttribute)attrs[0];
}
else
{
// Ŭ������ Ư���� �����Ǿ� �ִ��� Ȯ���Ѵ�.
attrs = methodBase.ReflectedType.GetCustomAttributes(
typeof(MongoSessionAttribute), true);
if (attrs != null && attrs.Length > 0)
{
sessionAttribute = (MongoSessionAttribute)attrs[0];
}
}
return sessionAttribute;
}
示例5: WebAttributesOCEExtender
static bool WebAttributesOCEExtender (MethodBase method, object[] customAttributes, ref OperationContractAttribute oca)
{
int caLength = customAttributes == null ? 0 : customAttributes.Length;
if (method == null && caLength == 0)
return false;
if (caLength == 0) {
customAttributes = method.GetCustomAttributes (false);
if (customAttributes.Length == 0)
return false;
}
bool foundWebAttribute = false;
foreach (object o in customAttributes) {
if (o is WebInvokeAttribute || o is WebGetAttribute) {
foundWebAttribute = true;
break;
}
}
if (!foundWebAttribute)
return false;
// LAMESPEC: .NET allows for contract methods decorated only with
// Web{Get,Invoke}Attribute and _without_ the OperationContractAttribute.
if (oca == null)
oca = new OperationContractAttribute ();
return true;
}
示例6: IsUnitTestMethod
private static bool IsUnitTestMethod(MethodBase method)
{
// Look for NUnit [Test] attribute on method
var testAttributes = method.GetCustomAttributes(typeof(TestAttribute), true);
return testAttributes.Any();
}
示例7: GetOperationContractAttribute
GetOperationContractAttribute (MethodBase method)
{
object [] matts = method.GetCustomAttributes (
typeof (OperationContractAttribute), false);
if (matts.Length == 0)
return null;
return (OperationContractAttribute) matts [0];
}
示例8: CompileTimeValidate
public override bool CompileTimeValidate(MethodBase method)
{
return
(method.GetCustomAttributes(typeof(CompilerGeneratedAttribute), true).Length == 0 &&
!method.Name.StartsWith("get_") &&
!method.Name.StartsWith("set_") &&
!method.IsConstructor);
}
示例9: Matches
public bool Matches(MethodBase member)
{
Guard.ArgumentNotNull(member, "member");
object[] attribues = member.GetCustomAttributes(attributeType, inherited);
return (attribues != null && attribues.Length > 0);
}
示例10: AddSnippet
protected void AddSnippet(ServiceOutput output, MethodBase methodBase)
{
if (output == null)
{
throw new ArgumentNullException("output");
}
if (methodBase == null)
{
throw new ArgumentNullException("methodBase");
}
// get the action associated with the call
SnippetAction action = SnippetManager.Instance.Parse(HttpContext.Current.Request.Params);
if (action.IsEnabled)
{
bool snippetMatch = false;
//get the name of the snippet that needs to be loaded
string snippetName = action.Name;
// make sure the method can support this snippet.
object[] attributes = methodBase.GetCustomAttributes(typeof(SupportedSnippetAttribute), false);
foreach (object a in attributes)
{
SupportedSnippetAttribute attribute = a as SupportedSnippetAttribute;
if (attribute != null &&
attribute.Name.Equals(attribute.Name, StringComparison.OrdinalIgnoreCase) )
{
snippetMatch = true;
break;
}
}
logger.Log(LogLevel.Debug, "SnippetName - [{0}] , Match - {1}", snippetName, snippetMatch);
// asked snippet can be supported by the service.
if (snippetMatch &&
SnippetManager.Instance.IsRegistered(snippetName))
{
// load the snippet control from the location
Control control = FormlessPage.GetControl(SnippetManager.Instance.GetControlPath(snippetName));
SnippetControl snippet = control as SnippetControl;
if (snippet != null)
{
logger.Log(LogLevel.Debug, "Got snippet [{0}], invoking to get output.", snippetName);
//set the control values
snippet.SetProperties(action.Properties);
output.AddOutput(Constants.Json.Html, snippet.GetJsonHtml());
}
}
}
}
示例11: MethodMemberDescriptor
/// <summary>
/// Initializes a new instance of the <see cref="MethodMemberDescriptor"/> class.
/// </summary>
/// <param name="methodBase">The MethodBase (MethodInfo or ConstructorInfo) got through reflection.</param>
/// <param name="accessMode">The interop access mode.</param>
/// <exception cref="System.ArgumentException">Invalid accessMode</exception>
public MethodMemberDescriptor(MethodBase methodBase, InteropAccessMode accessMode = InteropAccessMode.Default)
{
CheckMethodIsCompatible(methodBase, true);
IsConstructor = (methodBase is ConstructorInfo);
this.MethodInfo = methodBase;
bool isStatic = methodBase.IsStatic || IsConstructor;
if (IsConstructor)
m_IsAction = false;
else
m_IsAction = ((MethodInfo)methodBase).ReturnType == typeof(void);
ParameterInfo[] reflectionParams = methodBase.GetParameters();
ParameterDescriptor[] parameters;
if (this.MethodInfo.DeclaringType.IsArray)
{
m_IsArrayCtor = true;
int rank = this.MethodInfo.DeclaringType.GetArrayRank();
parameters = new ParameterDescriptor[rank];
for (int i = 0; i < rank; i++)
parameters[i] = new ParameterDescriptor("idx" + i.ToString(), typeof(int));
}
else
{
parameters = reflectionParams.Select(pi => new ParameterDescriptor(pi)).ToArray();
}
bool isExtensionMethod = (methodBase.IsStatic && parameters.Length > 0 && methodBase.GetCustomAttributes(typeof(ExtensionAttribute), false).Any());
base.Initialize(methodBase.Name, isStatic, parameters, isExtensionMethod);
// adjust access mode
if (Script.GlobalOptions.Platform.IsRunningOnAOT())
accessMode = InteropAccessMode.Reflection;
if (accessMode == InteropAccessMode.Default)
accessMode = UserData.DefaultAccessMode;
if (accessMode == InteropAccessMode.HideMembers)
throw new ArgumentException("Invalid accessMode");
if (parameters.Any(p => p.Type.IsByRef))
accessMode = InteropAccessMode.Reflection;
this.AccessMode = accessMode;
if (AccessMode == InteropAccessMode.Preoptimized)
((IOptimizableDescriptor)this).Optimize();
}
示例12: Matches
public bool Matches(MethodBase member)
{
Guard.ArgumentNotNull(member, "member");
bool hasNoPoliciesAttribute =
(member.GetCustomAttributes(typeof(ApplyNoPoliciesAttribute), false).Length != 0);
hasNoPoliciesAttribute |=
(member.DeclaringType.GetCustomAttributes(typeof(ApplyNoPoliciesAttribute), false).
Length != 0);
return !hasNoPoliciesAttribute;
}
示例13: IsBoxedMath
public static bool IsBoxedMath(MethodBase m)
{
Type t = m.DeclaringType;
if ( t == typeof(Numbers))
{
object[] boxedMaths = m.GetCustomAttributes(typeof(WarnBoxedMathAttribute), true);
if (boxedMaths.Length > 0)
return ((WarnBoxedMathAttribute)boxedMaths[0]).Value;
ParameterInfo[] pis = ((MethodBase)m).GetParameters();
foreach (ParameterInfo param in pis)
if (param.ParameterType.Equals(typeof(object)) )
return true;
}
return false;
}
示例14: GetOperationContractAttribute
public static OperationContractAttribute GetOperationContractAttribute (MethodBase method)
{
object [] matts = method.GetCustomAttributes (typeof (OperationContractAttribute), false);
OperationContractAttribute oca;
if (matts.Length == 0)
oca = null;
else
oca = matts [0] as OperationContractAttribute;
if (getOperationContractAttributeExtenders != null && getOperationContractAttributeExtenders.Count > 0) {
foreach (var extender in getOperationContractAttributeExtenders)
if (extender (method, matts, ref oca))
break;
}
return oca;
}
示例15: MethodMemberDescriptor
/// <summary>
/// Initializes a new instance of the <see cref="MethodMemberDescriptor" /> class.
/// </summary>
/// <param name="methodBase">The MethodBase (MethodInfo or ConstructorInfo) got through reflection.</param>
/// <param name="accessMode">The interop access mode.</param>
/// <exception cref="System.ArgumentException">Invalid accessMode</exception>
public MethodMemberDescriptor(MethodBase methodBase, InteropAccessMode accessMode = InteropAccessMode.Default)
{
CheckMethodIsCompatible(methodBase, true);
IsConstructor = (methodBase is ConstructorInfo);
MethodInfo = methodBase;
var isStatic = methodBase.IsStatic || IsConstructor;
if (IsConstructor)
m_IsAction = false;
else
m_IsAction = ((MethodInfo) methodBase).ReturnType == typeof (void);
var reflectionParams = methodBase.GetParameters();
var parameters = reflectionParams.Select(pi => new ParameterDescriptor(pi)).ToArray();
var isExtensionMethod = (methodBase.IsStatic && parameters.Length > 0 &&
methodBase.GetCustomAttributes(typeof (ExtensionAttribute), false).Any());
Initialize(methodBase.Name, isStatic, parameters, isExtensionMethod);
// adjust access mode
if (Script.GlobalOptions.Platform.IsRunningOnAOT())
accessMode = InteropAccessMode.Reflection;
if (accessMode == InteropAccessMode.Default)
accessMode = UserData.DefaultAccessMode;
if (accessMode == InteropAccessMode.HideMembers)
throw new ArgumentException("Invalid accessMode");
if (parameters.Any(p => p.Type.IsByRef))
accessMode = InteropAccessMode.Reflection;
AccessMode = accessMode;
if (AccessMode == InteropAccessMode.Preoptimized)
((IOptimizableDescriptor) this).Optimize();
}