当前位置: 首页>>代码示例>>C#>>正文


C# MethodBase.IsDefined方法代码示例

本文整理汇总了C#中System.Reflection.MethodBase.IsDefined方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBase.IsDefined方法的具体用法?C# MethodBase.IsDefined怎么用?C# MethodBase.IsDefined使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.MethodBase的用法示例。


在下文中一共展示了MethodBase.IsDefined方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Rate

        /// <summary>
        /// Scores the given constructor based on the number of dependencies we can fill.
        /// </summary>
        static int Rate(MethodBase constructor, TypeTracker typeTracker)
        {
            // Preserve the default behaviour of preferring explicitly marked constructors.
            if (constructor.IsDefined(typeof(InjectionConstructorAttribute), false))
                return int.MaxValue;

            var score = 0;

            foreach (var parameter in constructor.GetParameters())
            {
                if(parameter.IsOut || parameter.IsRetval)
                    return -1;

                if (typeTracker.HasDependency(parameter.ParameterType))
                {
                    score++;
                }
                else
                {
                    // We don't know how to fill this parameter so try a different constructor
                    return -1;
                }
            }

            return score;
        }
开发者ID:rokite,项目名称:openrasta-stable,代码行数:29,代码来源:ConstructorSelectorPolicy.cs

示例2: HasTestEntryPointAttribute

 private static bool HasTestEntryPointAttribute(MethodBase method)
 {
     return method.IsDefined(typeof(UserCodeEntryPointAttribute), true);
 }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:4,代码来源:StackTraceFilter.cs

示例3: HasHiddenOrNonUserCodeOrInternalAttribute

 private static bool HasHiddenOrNonUserCodeOrInternalAttribute(MethodBase method)
 {
     return method.IsDefined(typeof(DebuggerHiddenAttribute), true)
         || method.IsDefined(typeof(DebuggerNonUserCodeAttribute), true)
         || method.IsDefined(typeof(SystemInternalAttribute), true);
 }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:6,代码来源:StackTraceFilter.cs

示例4: IsOneWay

		public static bool IsOneWay(MethodBase method)
		{
			return method.IsDefined (typeof (OneWayAttribute), false);
		}
开发者ID:gustavo-melo,项目名称:mono,代码行数:4,代码来源:RemotingServices.cs

示例5: IsVisibleFrame

        // TODO: better filtering in DLR
        private static bool IsVisibleFrame(MethodBase/*!*/ method) {
            // filter out the _stub_ methods
            if (method.Name.StartsWith("_stub_")) {
                return false;
            }
                
            Type type = method.DeclaringType;

            if (type != null) {
                string typeName = type.FullName;
                if (typeName.StartsWith("System.Reflection.") ||
                    typeName.StartsWith("System.Runtime") ||
                    typeName.StartsWith("System.Dynamic") ||
                    typeName.StartsWith("Microsoft.Scripting")) {
                    return false;
                }

                // TODO: check loaded assemblies
                if (type.Assembly == typeof(RubyOps).Assembly) {
                    return false;
                }

                if (method.IsDefined(typeof(RubyStackTraceHiddenAttribute), false)) {
                    return false;
                }
                 
                if (type.Assembly.IsDefined(typeof(RubyLibraryAttribute), false)) {
                    return method.IsDefined(typeof(RubyMethodAttribute), false);
                }
            }
                
            return true;
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:34,代码来源:RubyExceptionData.cs

示例6: IsTestMethod

 public static bool IsTestMethod(MethodBase method)
 {
     return method.IsDefined(typeof(TestAttribute), false);
 }
开发者ID:romerod,项目名称:Testeroids,代码行数:4,代码来源:TypeInvestigationService.cs

示例7: Create

		//
		// Imports SRE parameters
		//
		public static AParametersCollection Create (ParameterInfo [] pi, MethodBase method)
		{
			if (pi.Length == 0) {
				if (method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0)
					return new ParametersCollection (new IParameterData [0], Type.EmptyTypes, method, false);

				return Parameters.EmptyReadOnlyParameters;
			}

			Type [] types = new Type [pi.Length];
			IParameterData [] par = new IParameterData [pi.Length];
			bool is_params = false;
			for (int i = 0; i < types.Length; i++) {
				types [i] = TypeManager.TypeToCoreType (pi [i].ParameterType);

				ParameterInfo p = pi [i];
				Parameter.Modifier mod = 0;
				if (types [i].IsByRef) {
					if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out)
						mod = Parameter.Modifier.OUT;
					else
						mod = Parameter.Modifier.REF;

					//
					// Strip reference wrapping
					//
					types [i] = TypeManager.GetElementType (types [i]);
				} else if (i == 0 && TypeManager.extension_attribute_type != null && method != null && method.IsStatic &&
			        (method.DeclaringType.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute &&
			        method.IsDefined (TypeManager.extension_attribute_type, false)) {
					mod = Parameter.Modifier.This;
				} else if (i >= pi.Length - 2 && types [i].IsArray) {
					if (p.IsDefined (TypeManager.param_array_type, false)) {
						mod = Parameter.Modifier.PARAMS;
						is_params = true;
					}
				}

				par [i] = new ParameterData (p.Name, mod);
			}

			return method != null ?
				new ParametersCollection (par, types, method, is_params) :
				new ParametersCollection (par, types);
		}
开发者ID:lewurm,项目名称:benchmarker,代码行数:48,代码来源:parameter.cs

示例8: IsExpectedExceptionTestMethod

 public static bool IsExpectedExceptionTestMethod(MethodBase method)
 {
     return method.IsDefined(typeof(ExpectedExceptionAttribute), false);
 }
开发者ID:romerod,项目名称:Testeroids,代码行数:4,代码来源:TypeInvestigationService.cs

示例9: IsPrerequisiteTestMethod

 public static bool IsPrerequisiteTestMethod(MethodBase method)
 {
     return method.IsDefined(typeof(PrerequisiteAttribute), false);
 }
开发者ID:romerod,项目名称:Testeroids,代码行数:4,代码来源:TypeInvestigationService.cs

示例10: IsSupportedExtensionMethod

        public static bool IsSupportedExtensionMethod(MethodBase method,Type extendedType)
        {
            if (!method.IsDefined(typeof(ExtensionAttribute), false))
                return false;
            var methodParameters = method.GetParameters();
            if (methodParameters.Length < 1)
                return false;

            var hasValidGenericParameter = false;
            for (var i = 0; i < methodParameters.Length; i++)
            {
                var parameterType = methodParameters[i].ParameterType;
                if (i == 0)
                {
                    if (parameterType.IsGenericParameter)
                    {
                        var parameterConstraints = parameterType.GetGenericParameterConstraints();
                        if (parameterConstraints.Length == 0 || !parameterConstraints[0].IsAssignableFrom(extendedType))
                            return false;
                        hasValidGenericParameter = true;
                    }
                    else if (!parameterType.IsAssignableFrom(extendedType))
                        return false;
                }
                else if (parameterType.IsGenericParameter)
                {
                    var parameterConstraints = parameterType.GetGenericParameterConstraints();
                    if (parameterConstraints.Length == 0 || !parameterConstraints[0].IsClass)
                        return false;
                    hasValidGenericParameter = true;
                }
            }
            return hasValidGenericParameter || !method.ContainsGenericParameters;
        }
开发者ID:yb199478,项目名称:CatLib,代码行数:34,代码来源:Utils.cs

示例11: IsExceptionResilientTestMethod

 public static bool IsExceptionResilientTestMethod(MethodBase method)
 {
     return method.IsDefined(typeof(ExceptionResilientAttribute), false);
 }
开发者ID:romerod,项目名称:Testeroids,代码行数:4,代码来源:TypeInvestigationService.cs

示例12: 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();
            }
        }
开发者ID:cdrnet,项目名称:docu,代码行数:49,代码来源:Method.cs

示例13: OnTestMethodEntry

        /// <summary>
        ///   Method executed when entering a test method.
        /// </summary>
        /// <param name="instance"> The instance of the context specification. </param>
        /// <param name="methodInfo"> The test method. </param>
        /// <param name="becauseAction"> The because method. </param>
        private void OnTestMethodEntry(
            IContextSpecification instance, 
            MethodBase methodInfo, 
            Action becauseAction)
        {
            var isRunningInTheContextOfAnotherTest = instance.ArePrerequisiteTestsRunning;

            if (isRunningInTheContextOfAnotherTest)
            {
                return;
            }

            var isRunningPrerequisite = methodInfo.IsDefined(typeof(PrerequisiteAttribute), true);

            becauseAction();

            if (!isRunningPrerequisite)
            {
                this.RunPrerequisiteTestsMethod();
            }
        }
开发者ID:romerod,项目名称:Testeroids,代码行数:27,代码来源:ArrangeActAssertAspectAttribute.cs

示例14: MethodProxy

        public MethodProxy(MethodBase methodBase, object hardTarget)
        {
            this.methodBase = methodBase;
            this.hardTarget = hardTarget;

            parameters = methodBase.GetParameters();

            if (_length == null)
                _length = new Number(0) { attributes = JSObjectAttributesInternal.ReadOnly | JSObjectAttributesInternal.DoNotDelete | JSObjectAttributesInternal.DoNotEnum | JSObjectAttributesInternal.SystemObject };
            var pc = methodBase.GetCustomAttributes(typeof(Modules.ArgumentsLengthAttribute), false).ToArray();
            if (pc.Length != 0)
                _length.iValue = (pc[0] as Modules.ArgumentsLengthAttribute).Count;
            else
                _length.iValue = parameters.Length;

            for (int i = 0; i < parameters.Length; i++)
            {
                var t = parameters[i].GetCustomAttribute(typeof(Modules.ConvertValueAttribute)) as Modules.ConvertValueAttribute;
                if (t != null)
                {
                    if (paramsConverters == null)
                        paramsConverters = new Modules.ConvertValueAttribute[parameters.Length];
                    paramsConverters[i] = t;
                }
            }

            if (methodBase is MethodInfo)
            {
                var methodInfo = methodBase as MethodInfo;
                returnConverter = methodInfo.ReturnParameter.GetCustomAttribute(typeof(Modules.ConvertValueAttribute), false) as Modules.ConvertValueAttribute;

                forceInstance = methodBase.IsDefined(typeof(InstanceMemberAttribute), false);

                if (forceInstance)
                {
                    if (!methodInfo.IsStatic
                        || (parameters.Length == 0)
                        || (parameters.Length > 2)
                        || (parameters[0].ParameterType != typeof(JSObject))
                        || (parameters.Length > 1 && parameters[1].ParameterType != typeof(Arguments)))
                        throw new ArgumentException("Force-instance method \"" + methodBase + "\" have invalid signature");
                    raw = true;
                }

                if (!PartiallyTrusted
                    && !methodInfo.IsStatic
                    && (parameters.Length == 0 || (parameters.Length == 1 && parameters[0].ParameterType == typeof(Arguments)))
#if PORTABLE
 && !methodInfo.ReturnType.GetTypeInfo().IsValueType
 && !methodInfo.DeclaringType.GetTypeInfo().IsValueType)
#else
 && !methodInfo.ReturnType.IsValueType
 && !methodInfo.DeclaringType.IsValueType)
#endif
                {
                    var t = methodBase.GetCustomAttributes(typeof(AllowUnsafeCallAttribute), false).ToArray();
                    alternedTypes = new AllowUnsafeCallAttribute[t.Length];
                    for (var i = 0; i < t.Length; i++)
                        alternedTypes[i] = (AllowUnsafeCallAttribute)t[i];
                }

                #region Magic
                if (alternedTypes != null)
                {
                    if (methodInfo.ReturnType == typeof(void))
                    {
                        if (parameters.Length == 0)
                        {
#if PORTABLE
                            var methodDelegate = methodInfo.CreateDelegate(typeof(Action<>).MakeGenericType(methodBase.DeclaringType));
                            var handle = handleInfo.GetValue(methodDelegate);
                            var forceConverterConstructor = typeof(Action<object>).GetTypeInfo().DeclaredConstructors.First();
#else
                            var forceConverterConstructor = typeof(Action<object>).GetConstructors().First();
                            var handle = methodInfo.MethodHandle.GetFunctionPointer();
#endif
                            action1 = (Action<object>)forceConverterConstructor.Invoke(new object[] { null, (IntPtr)handle });
                            mode = _Mode.A1;
                        }
                        else // 1
                        {
#if PORTABLE
                            var methodDelegate = methodInfo.CreateDelegate(typeof(Action<,>).MakeGenericType(methodBase.DeclaringType, typeof(Arguments)));
                            var handle = handleInfo.GetValue(methodDelegate);
                            var forceConverterConstructor = typeof(Action<object, object>).GetTypeInfo().DeclaredConstructors.First();
#else
                            var forceConverterConstructor = typeof(Action<object, object>).GetConstructors().First();
                            var handle = methodInfo.MethodHandle.GetFunctionPointer();
#endif
                            action2 = (Action<object, object>)forceConverterConstructor.Invoke(new object[] { null, (IntPtr)handle });
                            mode = _Mode.A2;
                        }
                    }
                    else
                    {
                        if (parameters.Length == 0)
                        {
#if PORTABLE
                            var methodDelegate = methodInfo.CreateDelegate(typeof(Func<,>).MakeGenericType(methodBase.DeclaringType, methodInfo.ReturnType));
                            var handle = handleInfo.GetValue(methodDelegate);
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:NiL.JS,代码行数:101,代码来源:MethodProxy.cs

示例15: Create

		//
		// Imports SRE parameters
		//
		public static AParametersCollection Create (ParameterInfo [] pi, MethodBase method)
		{
			int varargs = method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0 ? 1 : 0;

			if (pi.Length == 0 && varargs == 0)
				return ParametersCompiled.EmptyReadOnlyParameters;

			Type [] types = new Type [pi.Length + varargs];
			IParameterData [] par = new IParameterData [pi.Length + varargs];
			bool is_params = false;
			PredefinedAttribute extension_attr = PredefinedAttributes.Get.Extension;
			PredefinedAttribute param_attr = PredefinedAttributes.Get.ParamArray;
			for (int i = 0; i < pi.Length; i++) {
				types [i] = TypeManager.TypeToCoreType (pi [i].ParameterType);

				ParameterInfo p = pi [i];
				Parameter.Modifier mod = 0;
				Expression default_value = null;
				if (types [i].IsByRef) {
					if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out)
						mod = Parameter.Modifier.OUT;
					else
						mod = Parameter.Modifier.REF;

					//
					// Strip reference wrapping
					//
					types [i] = TypeManager.GetElementType (types [i]);
				} else if (i == 0 && extension_attr.IsDefined && method != null && method.IsStatic &&
			        (method.DeclaringType.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute &&
					method.IsDefined (extension_attr.Type, false)) {
					mod = Parameter.Modifier.This;
				} else {
					if (i >= pi.Length - 2 && types[i].IsArray) {
						if (p.IsDefined (param_attr.Type, false)) {
							mod = Parameter.Modifier.PARAMS;
							is_params = true;
						}
					}

					if (!is_params && p.IsOptional) {
						object value = p.DefaultValue;
						if (value == Missing.Value) {
							default_value = EmptyExpression.Null;
						} else if (value == null) {
							default_value = new NullLiteral (Location.Null);
						} else {
							default_value = Constant.CreateConstant (value.GetType (), value, Location.Null);
						}
					}
				}

				par [i] = new ParameterData (p.Name, mod, default_value);
			}

			if (varargs != 0) {
				par [par.Length - 1] = new ArglistParameter (Location.Null);
				types [types.Length - 1] = InternalType.Arglist;
			}

			return method != null ?
				new ParametersImported (par, types, varargs != 0, is_params) :
				new ParametersImported (par, types);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:67,代码来源:parameter.cs


注:本文中的System.Reflection.MethodBase.IsDefined方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。