本文整理汇总了C#中System.Reflection.MethodBase.GetCustomAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBase.GetCustomAttribute方法的具体用法?C# MethodBase.GetCustomAttribute怎么用?C# MethodBase.GetCustomAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodBase
的用法示例。
在下文中一共展示了MethodBase.GetCustomAttribute方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromMethod
/// <summary>
/// Creates a REST call from a given method.
/// If the method has no marker, a null is returned
/// </summary>
/// <param name="methodBase">The method base.</param>
/// <returns></returns>
public static RestCall FromMethod(MethodBase methodBase)
{
var httpGet = methodBase.GetCustomAttribute<HttpGetAttribute>();
if (httpGet != null)
return new RestCall("GET", httpGet.UriTemplate);
return null;
}
示例2: EmitFunction
private static Function EmitFunction(Module module, MethodBase method)
{
var methodInfo = method as MethodInfo;
var methodConstructor = method as ConstructorInfo;
var declaringType = method.DeclaringType;
if (methodInfo == null && methodConstructor == null)
throw new CudaSharpException("Unknown MethodBase type " + method.GetType().FullName);
if (declaringType == null)
throw new CudaSharpException("Could not find the declaring type of " + method.Name.StripNameToValidPtx());
var parameters = method.GetParameters().Select(p => p.ParameterType);
if (methodConstructor != null)
parameters = new[] { declaringType.MakeByRefType() }.Concat(parameters);
if (methodInfo != null && methodInfo.IsStatic == false)
{
if (declaringType.IsValueType == false)
throw new CudaSharpException("Cannot compile object instance methods (did you forget to mark the method as static?)");
parameters = new[] { declaringType.MakeByRefType() }.Concat(parameters);
}
var llvmParameters =
parameters.Select(t => ConvertType(module, t)).ToArray();
var funcType = new FunctionType(ConvertType(module, methodInfo == null ? typeof(void) : methodInfo.ReturnType), llvmParameters);
var intrinsic = method.GetCustomAttribute<Gpu.BuiltinAttribute>();
if (intrinsic != null)
{
var name = intrinsic.Intrinsic;
var preExisting = module.GetFunction(name);
if (preExisting != null)
return preExisting;
return module.CreateFunction(name, funcType);
}
var function = module.CreateFunction(methodConstructor == null ? method.Name.StripNameToValidPtx() : declaringType.Name.StripNameToValidPtx() + "_ctor", funcType);
var block = new Block("entry", module.Context, function);
var writer = new InstructionBuilder(module.Context, block);
var opcodes = method.Disassemble().ToList();
FindBranchTargets(opcodes, module.Context, function);
var body = method.GetMethodBody();
var efo = new EmitFuncObj(module, function, body, writer, null, new Stack<Value>(),
body == null ? null : new Value[body.LocalVariables.Count], new Value[llvmParameters.Length]);
PrintHeader(efo);
foreach (var opcode in opcodes)
{
if (EmitFunctions.ContainsKey(opcode.Opcode) == false)
throw new CudaSharpException("Unsupported CIL instruction " + opcode.Opcode);
var func = EmitFunctions[opcode.Opcode];
efo.Argument = opcode.Parameter;
func(efo);
}
return function;
}
示例3: FromMethodInfo
public static MethodTranslationInfo FromMethodInfo(MethodBase methodInfo, ClassTranslationInfo classTranslationInfo)
{
var result = new MethodTranslationInfo
{
_scriptName = methodInfo.Name,
_classTi = classTranslationInfo
};
var scriptNameAttribute = methodInfo.GetCustomAttribute<ScriptNameAttribute>();
if (scriptNameAttribute != null)
result._scriptName = scriptNameAttribute.Name.Trim();
if (string.IsNullOrEmpty(result._scriptName))
throw new Exception("Method name is empty");
return result;
}
示例4: TryGetReflectedCode
internal static bool TryGetReflectedCode(MethodBase b, out string code)
{
var att = b.GetCustomAttribute<CompiledReflectedDefinitionAttribute>(false);
if (att != null)
{
var c = att.Code;
c = c.Replace("\\r", "\r").Replace("\\n", "\n");
code = c;
return true;
}
else
{
code = null;
return false;
}
}
示例5: ScanMethod
//.........这里部分代码省略.........
// care of new additions.
if (xVirtMethod != null)
{
Queue(xVirtMethod, aMethod, "Virtual Base");
mVirtuals.Add(xVirtMethod);
// List changes as we go, cant be foreach
for (int i = 0; i < mItemsList.Count; i++)
{
if (mItemsList[i] is Type)
{
var xType = (Type) mItemsList[i];
if (xType.IsSubclassOf(xVirtMethod.DeclaringType) || (xVirtMethod.DeclaringType.IsInterface && xVirtMethod.DeclaringType.IsAssignableFrom(xType)))
{
var xNewMethod = xType.GetMethod(aMethod.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, xParamTypes, null);
if (xNewMethod != null)
{
// We need to check IsVirtual, a non virtual could
// "replace" a virtual above it?
if (xNewMethod.IsVirtual)
{
Queue(xNewMethod, aMethod, "Virtual Downscan");
}
}
}
}
}
}
}
#endregion
MethodBase xPlug = null;
// Plugs may use plugs, but plugs won't be plugged over themself
var inl = aMethod.GetCustomAttribute<InlineAttribute>();
if (!aIsPlug && !xIsDynamicMethod)
{
// Check to see if method is plugged, if it is we don't scan body
xPlug = mPlugManager.ResolvePlug(aMethod, xParamTypes);
if (xPlug != null)
{
//ScanMethod(xPlug, true, "Plug method");
if (inl == null)
{
Queue(xPlug, aMethod, "Plug method");
}
}
}
if (xPlug == null)
{
bool xNeedsPlug = false;
if ((aMethod.Attributes & MethodAttributes.PinvokeImpl) != 0)
{
// pinvoke methods dont have an embedded implementation
xNeedsPlug = true;
}
else
{
var xImplFlags = aMethod.GetMethodImplementationFlags();
// todo: prob even more
if (((xImplFlags & MethodImplAttributes.Native) != 0) ||
((xImplFlags & MethodImplAttributes.InternalCall) != 0))
{
// native implementations cannot be compiled
xNeedsPlug = true;
示例6: GetCallerCommand
private static string GetCallerCommand(MethodBase caller)
{
if (caller == null) return "nullCallerMethod!?";
string name = string.Empty;
var atrCom = (CommandMethodAttribute)caller.GetCustomAttribute(typeof(CommandMethodAttribute));
if (atrCom != null)
{
name = atrCom.GlobalName;
}
else
{
name = caller.Name;
}
return name;
}
示例7: Resolve
public void Resolve(IDictionary<Identifier, IReferencable> referencables)
{
if (referencables.ContainsKey(identifier))
{
IsResolved = true;
IReferencable referencable = referencables[identifier];
var method = referencable as Method;
if (method == null)
{
throw new InvalidOperationException("Cannot resolve to '" + referencable.GetType().FullName + "'");
}
ReturnType = method.ReturnType;
if (ReturnType != null && !ReturnType.IsResolved)
{
ReturnType.Resolve(referencables);
}
declaration = method.declaration;
if (declaration != null && declaration.IsDefined(typeof (ObsoleteAttribute)))
{
ObsoleteReason = declaration.GetCustomAttribute<ObsoleteAttribute>().Message;
}
if (!Summary.IsResolved)
{
Summary.Resolve(referencables);
}
if (!Remarks.IsResolved)
{
Remarks.Resolve(referencables);
}
foreach (MethodParameter para in Parameters)
{
if ((para.Reference != null) && (!para.Reference.IsResolved))
{
para.Reference.Resolve(referencables);
}
}
}
else
{
ConvertToExternalReference();
}
}
示例8: GetCacheRegion
static string GetCacheRegion(MethodBase method)
{
var cachingAttribute = method.GetCustomAttribute<CacheRegionAttribute>(false);
if (cachingAttribute == null) {
cachingAttribute = method.DeclaringType.GetCustomAttribute<CacheRegionAttribute>(false);
}
if (cachingAttribute == null) {
return "ThinkCache";
}
return cachingAttribute.CacheRegion;
}
示例9: TraceMethod
private void TraceMethod( MethodBase method )
{
Contract.Assert( method != null );
#if !WINDOWS_PHONE
bool isMethodBuilder = method is MethodBuilder || method is ConstructorBuilder;
#endif
if ( !isMethodBuilder )
{
try
{
method.GetParameters();
}
catch ( NotSupportedException )
{
// For internal MethodBuilderInstantiationType
isMethodBuilder = true;
}
}
/*
* <instr_method> <callConv> <type> [ <typeSpec> :: ] <methodName> ( <parameters> )
*/
// <callConv>
if ( !method.IsStatic )
{
this._trace.Write( "instance " );
}
var unamanagedCallingConvention = default( CallingConvention? );
// TODO: Back to NLiblet
#if !WINDOWS_PHONE
if ( !isMethodBuilder )
#endif
{
// TODO: C++/CLI etc...
var dllImport = method.GetCustomAttribute<DllImportAttribute>();
if ( dllImport != null )
{
unamanagedCallingConvention = dllImport.CallingConvention;
}
}
WriteCallingConventions( this._trace, method.CallingConvention, unamanagedCallingConvention );
var asMethodInfo = method as MethodInfo;
if ( asMethodInfo != null )
{
WriteType( this._trace, asMethodInfo.ReturnType );
this._trace.Write( " " );
}
if ( method.DeclaringType == null )
{
// '[' '.module' name1 ']'
this._trace.Write( "[.module" );
this._trace.Write( asMethodInfo.Module.Name );
this._trace.Write( "]::" );
}
#if !WINDOWS_PHONE
else if ( this._isInDynamicMethod || !isMethodBuilder ) // declaring type of the method should be omitted for same type.
#else
else
#endif
{
WriteType( this._trace, method.DeclaringType );
this._trace.Write( "::" );
}
this._trace.Write( method.Name );
this._trace.Write( "(" );
#if !WINDOWS_PHONE
if ( !isMethodBuilder )
#endif
{
var parameters = method.GetParameters();
for ( int i = 0; i < parameters.Length; i++ )
{
if ( i == 0 )
{
this._trace.Write( " " );
}
else
{
this._trace.Write( ", " );
}
if ( parameters[ i ].IsOut )
{
this._trace.Write( "out " );
}
else if ( parameters[ i ].ParameterType.IsByRef )
{
this._trace.Write( "ref " );
}
WriteType( this._trace, parameters[ i ].ParameterType.IsByRef ? parameters[ i ].ParameterType.GetElementType() : parameters[ i ].ParameterType );
this._trace.Write( " " );
this._trace.Write( parameters[ i ].Name );
//.........这里部分代码省略.........
示例10: ProcessPluggedMethod
/// <summary>
/// Process a plugged method.
/// </summary>
/// <param name="aMethod">The method to process.</param>
/// <returns>A new ILChunk marked as plugged with common attribites loaded. Null if any errors occur.</returns>
public ILChunk ProcessPluggedMethod(MethodBase aMethod)
{
ILChunk result = null;
PluggedMethodAttribute plugAttr = (PluggedMethodAttribute)aMethod.GetCustomAttribute(typeof(PluggedMethodAttribute));
//Resolve the ASMPlugPath to be relative to the assembly file that the method came from
string ASMPlugPath = plugAttr.ASMFilePath;
//Null path will result in no load attempt
//Allows multiple methods to be plugged by the same ASM file
if (ASMPlugPath == null)
{
result = new ILChunk()
{
Plugged = true,
PlugASMFilePath = null,
Method = aMethod
};
ProcessCommonMethodAttributes(aMethod, result);
return result;
}
string assemblyPath = aMethod.DeclaringType.Assembly.Location;
assemblyPath = Path.GetDirectoryName(assemblyPath);
ASMPlugPath = Path.Combine(assemblyPath, ASMPlugPath);
if (ASMPlugPath.EndsWith("\\"))
{
ASMPlugPath = ASMPlugPath.Substring(0, ASMPlugPath.Length - 1);
}
result = new ILChunk()
{
Plugged = true,
PlugASMFilePath = ASMPlugPath,
Method = aMethod
};
ProcessCommonMethodAttributes(aMethod, result);
return result;
}
示例11: ProcessCommonMethodAttributes
/// <summary>
/// Processes attributes that are common to both plugged and unplugged methods.
/// </summary>
/// <param name="aMethod">The method to process attributes of.</param>
/// <param name="aChunk">The ILChunk to load attributes' info into.</param>
private void ProcessCommonMethodAttributes(MethodBase aMethod, ILChunk aChunk)
{
SequencePriorityAttribute seqPriorityAttr = (SequencePriorityAttribute)aMethod.GetCustomAttribute(typeof(SequencePriorityAttribute));
if (seqPriorityAttr != null)
{
aChunk.SequencePriority = seqPriorityAttr.Priority;
}
else
{
aChunk.SequencePriority = 0;
}
NoGCAttribute noGCAttr = (NoGCAttribute)aMethod.GetCustomAttribute(typeof(NoGCAttribute));
if (noGCAttr != null)
{
aChunk.ApplyGC = false;
}
NoDebugAttribute noDebugAttr = (NoDebugAttribute)aMethod.GetCustomAttribute(typeof(NoDebugAttribute));
if (noDebugAttr != null)
{
aChunk.NoDebugOps = true;
}
KernelMainMethodAttribute kernelMainMethodAttr = (KernelMainMethodAttribute)aMethod.GetCustomAttribute(typeof(KernelMainMethodAttribute));
if (kernelMainMethodAttr != null)
{
aChunk.IsMainMethod = true;
}
CallStaticConstructorsMethodAttribute callStaticConstructorsMethodAttr = (CallStaticConstructorsMethodAttribute)aMethod.GetCustomAttribute(typeof(CallStaticConstructorsMethodAttribute));
if (callStaticConstructorsMethodAttr != null)
{
aChunk.IsCallStaticConstructorsMethod = true;
}
AddExceptionHandlerInfoMethodAttribute addExceptionHandlerInfoMethodAttr = (AddExceptionHandlerInfoMethodAttribute)aMethod.GetCustomAttribute(typeof(AddExceptionHandlerInfoMethodAttribute));
if (addExceptionHandlerInfoMethodAttr != null)
{
aChunk.IsAddExceptionHandlerInfoMethod = true;
}
ExceptionsHandleLeaveMethodAttribute exceptionsHandleLeaveMethodAttr = (ExceptionsHandleLeaveMethodAttribute)aMethod.GetCustomAttribute(typeof(ExceptionsHandleLeaveMethodAttribute));
if (exceptionsHandleLeaveMethodAttr != null)
{
aChunk.IsExceptionsHandleLeaveMethod = true;
}
ExceptionsHandleEndFinallyMethodAttribute exceptionsHandleEndFinallyMethodAttr = (ExceptionsHandleEndFinallyMethodAttribute)aMethod.GetCustomAttribute(typeof(ExceptionsHandleEndFinallyMethodAttribute));
if (exceptionsHandleEndFinallyMethodAttr != null)
{
aChunk.IsExceptionsHandleEndFinallyMethod = true;
}
ThrowExceptionMethodAttribute throwExceptionMethodAttr = (ThrowExceptionMethodAttribute)aMethod.GetCustomAttribute(typeof(ThrowExceptionMethodAttribute));
if (throwExceptionMethodAttr != null)
{
aChunk.IsExceptionsThrowMethod = true;
}
ThrowNullReferenceExceptionMethodAttribute throwNullReferenceExceptionMethodAttr = (ThrowNullReferenceExceptionMethodAttribute)aMethod.GetCustomAttribute(typeof(ThrowNullReferenceExceptionMethodAttribute));
if (throwNullReferenceExceptionMethodAttr != null)
{
aChunk.IsExceptionsThrowNullReferenceMethod = true;
}
ThrowArrayTypeMismatchExceptionMethodAttribute throwArrayTypeMismatchExceptionMethodAttr = (ThrowArrayTypeMismatchExceptionMethodAttribute)aMethod.GetCustomAttribute(typeof(ThrowArrayTypeMismatchExceptionMethodAttribute));
if (throwArrayTypeMismatchExceptionMethodAttr != null)
{
aChunk.IsExceptionsThrowArrayTypeMismatchMethod = true;
}
ThrowIndexOutOfRangeExceptionMethodAttribute throwIndexOutOfRangeExceptionMethodAttr = (ThrowIndexOutOfRangeExceptionMethodAttribute)aMethod.GetCustomAttribute(typeof(ThrowIndexOutOfRangeExceptionMethodAttribute));
if (throwIndexOutOfRangeExceptionMethodAttr != null)
{
aChunk.IsExceptionsThrowIndexOutOfRangeMethod = true;
}
HandleExceptionMethodAttribute handleExceptionMethodAttr = (HandleExceptionMethodAttribute)aMethod.GetCustomAttribute(typeof(HandleExceptionMethodAttribute));
if (handleExceptionMethodAttr != null)
{
aChunk.IsExceptionsHandleExceptionMethod = true;
}
NewObjMethodAttribute newObjMethodAttr = (NewObjMethodAttribute)aMethod.GetCustomAttribute(typeof(NewObjMethodAttribute));
if (newObjMethodAttr != null)
{
aChunk.IsNewObjMethod = true;
}
NewArrMethodAttribute newArrMethodAttr = (NewArrMethodAttribute)aMethod.GetCustomAttribute(typeof(NewArrMethodAttribute));
if (newArrMethodAttr != null)
{
aChunk.IsNewArrMethod = true;
}
IncrementRefCountMethodAttribute incrementRefCountMethodAttr = (IncrementRefCountMethodAttribute)aMethod.GetCustomAttribute(typeof(IncrementRefCountMethodAttribute));
if (incrementRefCountMethodAttr != null)
{
aChunk.IsIncrementRefCountMethod = true;
}
DecrementRefCountMethodAttribute decrementRefCountMethodAttr = (DecrementRefCountMethodAttribute)aMethod.GetCustomAttribute(typeof(DecrementRefCountMethodAttribute));
if (decrementRefCountMethodAttr != null)
{
aChunk.IsDecrementRefCountMethod = true;
}
HaltMethodAttribute haltMethodAttr = (HaltMethodAttribute)aMethod.GetCustomAttribute(typeof(HaltMethodAttribute));
if (haltMethodAttr != null)
//.........这里部分代码省略.........