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


C# MethodInfo.GetCustomAttribute方法代码示例

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


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

示例1: MethodMetadata

		/// <summary>
		///     Initializes a new instance.
		/// </summary>
		/// <param name="obj">The S# object the method belongs to.</param>
		/// <param name="method">The CLR method the metadata should be provided for.</param>
		/// <param name="name">The name of the method; if <c>null</c>, the method's CLR name is used.</param>
		/// <param name="baseMethod">The overridden base method, if any.</param>
		internal MethodMetadata(IMetadataObject obj, MethodInfo method, string name = null, MethodMetadata baseMethod = null)
		{
			Requires.NotNull(obj, () => obj);
			Requires.NotNull(method, () => method);
			Requires.That(name == null || !String.IsNullOrWhiteSpace(name), () => name, "The name must be null or non-whitespace only.");
			Requires.That(baseMethod == null || method != baseMethod.MethodInfo, "A method cannot override itself.");
			Requires.That(baseMethod == null || obj == baseMethod._object, "The base method must belong to the same object.");
			Requires.That(baseMethod == null || baseMethod.OverridingMethod == null, "The base method has already been overridden.");

			_object = obj;

			Name = EscapeName(name ?? method.Name);
			MethodInfo = method;
			BaseMethod = baseMethod;

			if (baseMethod != null)
				baseMethod.OverridingMethod = this;

			var backingFieldAttribute = MethodInfo.GetCustomAttribute<BackingFieldAttribute>();
			if (backingFieldAttribute != null)
				BackingField = backingFieldAttribute.GetFieldInfo(MethodInfo.DeclaringType);

			var behaviorAttribute = MethodInfo.GetCustomAttribute<IntendedBehaviorAttribute>();
			if (behaviorAttribute != null)
				IntendedBehavior = behaviorAttribute.GetMethodInfo(MethodInfo.DeclaringType);

			if (backingFieldAttribute == null && behaviorAttribute == null)
				IntendedBehavior = MethodInfo;

			Behaviors = new MethodBehaviorCollection(obj, this);
			ImplementedMethods = DetermineImplementedInterfaceMethods().ToArray();

			_methodBody = new Lazy<MethodBodyMetadata>(InitializeMethodBody);
		}
开发者ID:cubeme,项目名称:safety-sharp,代码行数:41,代码来源:MethodMetadata.cs

示例2: GetRpcMethodName

 public static string GetRpcMethodName(MethodInfo mi)
 {
     string rpcMethod;
     string MethodName = mi.Name;
     Attribute attr = mi.GetCustomAttribute<XmlRpcBeginAttribute>();
     if (attr != null)
     {
         rpcMethod = ((XmlRpcBeginAttribute)attr).Method;
         if (rpcMethod == "")
         {
             if (!MethodName.StartsWith("Begin") || MethodName.Length <= 5)
                 throw new Exception(String.Format(
                   "method {0} has invalid signature for begin method",
                   MethodName));
             rpcMethod = MethodName.Substring(5);
         }
         return rpcMethod;
     }
     // if no XmlRpcBegin attribute, must have XmlRpcMethod attribute
     attr = mi.GetCustomAttribute<XmlRpcMethodAttribute>();
     if (attr == null)
     {
         throw new Exception("missing method attribute");
     }
     XmlRpcMethodAttribute xrmAttr = attr as XmlRpcMethodAttribute;
     rpcMethod = xrmAttr.Method;
     if (rpcMethod == "")
     {
         rpcMethod = mi.Name;
     }
     return rpcMethod;
 }
开发者ID:danielgary,项目名称:xmlrpc-universal,代码行数:32,代码来源:XmlRpcTypeInfo.cs

示例3: CreateMethod

        private static TestMethod CreateMethod(TypeInfo type, object instance, MethodInfo method)
        {
            TestMethod test = new TestMethod();
            test.Name = method.Name;

            if (method.GetCustomAttribute<AsyncTestMethodAttribute>(true) != null)
            {
                test.Test = new AsyncTestMethodAsyncAction(instance, method);                
            }
            else
            {
                test.Test = new TestMethodAsyncAction(instance, method);
            }

            ExcludeTestAttribute excluded = method.GetCustomAttribute<ExcludeTestAttribute>(true);
            if (excluded != null)
            {
                test.Exclude(excluded.Reason);
            }

            if (method.GetCustomAttribute<FunctionalTestAttribute>(true) != null)
            {
                test.Tags.Add("Functional");
            }

            test.Tags.Add(type.FullName + "." + method.Name);
            test.Tags.Add(type.Name + "." + method.Name);
            foreach (TagAttribute attr in method.GetCustomAttributes<TagAttribute>(true))
            {
                test.Tags.Add(attr.Tag);
            }

            return test;
        }
开发者ID:TroyBolton,项目名称:azure-mobile-services,代码行数:34,代码来源:TestDiscovery.cs

示例4: GetHttpMethod

        static HttpMethods GetHttpMethod(MethodInfo m)
        {
            var postAttr = m.GetCustomAttribute<HttpPostAttribute>();
            var getAttr = m.GetCustomAttribute<HttpGetAttribute>();
            var putAttr = m.GetCustomAttribute<HttpPutAttribute>();
            var deleteAttr = m.GetCustomAttribute<HttpDeleteAttribute>();
            var patchAttr = m.GetCustomAttribute<HttpPatchAttribute>();

            if (postAttr != null) return HttpMethods.Post;
            else if (getAttr != null) return HttpMethods.Get;
            else if (putAttr != null) return HttpMethods.Put;
            else if (deleteAttr != null) return HttpMethods.Delete;
            else if (patchAttr != null) return HttpMethods.Patch;
            else return HttpMethods.Unknown;
        }
开发者ID:qstream-inactive,项目名称:ENTech-Store,代码行数:15,代码来源:Program.cs

示例5: IsVisible

        /// <summary>
        /// Returns a value indicating whether or not a server-side dispatcher should be generated for the provided <paramref name="method"/>.
        /// </summary>
        /// <param name="containingType">
        /// The containing type.
        /// </param>
        /// <param name="method">
        /// The method.
        /// </param>
        /// <returns>
        /// A value indicating whether or not a server-side dispatcher should be generated for the provided <paramref name="method"/>.
        /// </returns>
        public static bool IsVisible(Type containingType, MethodInfo method)
        {
            var typeLevelAttribute = method.DeclaringType.GetCustomAttribute<VisibleAttribute>()
                                     ?? containingType.GetCustomAttribute<VisibleAttribute>();
            var hasTypeOverride = typeLevelAttribute != null && typeLevelAttribute.Visible.HasValue;
            var typeVisibility = typeLevelAttribute != null && typeLevelAttribute.Visible.HasValue
                                 && typeLevelAttribute.Visible.Value;

            var methodLevelAttribute = method.GetCustomAttribute<VisibleAttribute>();
            var hasMethodOverride = methodLevelAttribute != null && methodLevelAttribute.Visible.HasValue;
            var methodVisibility = methodLevelAttribute != null && methodLevelAttribute.Visible.HasValue
                                   && methodLevelAttribute.Visible.Value;

            if (hasMethodOverride)
            {
                return methodVisibility;
            }

            if (hasTypeOverride)
            {
                return typeVisibility;
            }

            return true;
        }
开发者ID:Bee-Htcpcp,项目名称:OrleansEventJournal,代码行数:37,代码来源:ProxyGenerationUtility.cs

示例6: GetMethodName

 private static string GetMethodName(MethodInfo methodInfo)
 {
     var webMetodAttribute = methodInfo.GetCustomAttribute(typeof(WebMethodAttribute), true)
         as WebMethodAttribute;
     var methodCustomName = webMetodAttribute.MessageName;
     return String.IsNullOrEmpty(methodCustomName) ? methodInfo.Name : methodCustomName;
 }
开发者ID:ondrejmyska,项目名称:Owin.WebServices,代码行数:7,代码来源:WebServicesSelector.cs

示例7: Discover

        public bool Discover(MethodInfo publicMethod, OperationMetadata methodMetadata)
        {
            var notes = publicMethod.GetCustomAttribute<NotesAttribute>() ?? new NotesAttribute("");
            methodMetadata.Notes = notes.Notes;
            methodMetadata.Notes += "Uri template " + methodMetadata.Uri.Uri;

            return true;
        }
开发者ID:avengerine,项目名称:OpenRastaSwagger,代码行数:8,代码来源:DiscoverNotes.cs

示例8: CommandHandlerInfo

        internal CommandHandlerInfo(MethodInfo method)
        {
            Method = method;
            Attribute = method.GetCustomAttribute<CommandHandlerAttribute>();
            Debug.Assert(Attribute != null);

            Parameters = (from e in method.GetParameters() select new CommandParameterInfo(e)).ToArray();
        }
开发者ID:ktj007,项目名称:mmo,代码行数:8,代码来源:CommandHandlerInfo.cs

示例9: Generate

 public IAction Generate(MethodInfo method)
 {
     if (!method.IsPublic) return null;
     //标记了NoAction的方法跳过
     var noAction = method.GetCustomAttribute<NonActionAttribute>();
     if (noAction != null) return null;
     var buildContext = new ActionGenerationContext(method, this.BinderFactory);
     return Generate(buildContext);
 }
开发者ID:yanyitec,项目名称:yitec,代码行数:9,代码来源:ActionGenerator.cs

示例10: Discover

        public bool Discover(MethodInfo publicMethod, OperationMetadata methodMetdata)
        {
            var responseType = publicMethod.GetCustomAttribute<ResponseTypeIsAttribute>() ??
                               new ResponseTypeIsAttribute(publicMethod.ReturnType);
            methodMetdata.ReturnType = responseType.ResponseType;
            methodMetdata.HandlerType = publicMethod.DeclaringType;

            return IsTypeMatch(methodMetdata.DesiredReturnType, methodMetdata.ReturnType);
        }
开发者ID:huoxudong125,项目名称:OpenRastaSwagger,代码行数:9,代码来源:DiscoverReturnType.cs

示例11: GetInvocationName

      public static string GetInvocationName(MethodInfo mi)
      {
        var result = mi.Name;
        var attr = mi.GetCustomAttribute(typeof(ActionAttribute), false) as ActionAttribute;
        if (attr!=null)
          if (attr.Name.IsNotNullOrWhiteSpace()) result = attr.Name;

        return result;
      }
开发者ID:sergey-msu,项目名称:nfx,代码行数:9,代码来源:Reflection.cs

示例12: Add

 /// <summary>
 /// Adds the given test to the session. This test has to be a member of the test class and needs a TestMethod Attribute.
 /// </summary>
 public void Add(MethodInfo test)
 {
     if (test.GetCustomAttribute<JUUTTestMethodAttribute>() == null) {
         throw new ArgumentException("Tests to be added to a TestRunner needs a TestMethod-Attribute.");
     }
     if (test.DeclaringType != TestClass) {
         throw new ArgumentException("The given method isn't a member of the test class.");
     }
     TestsToRun.Add(test);
 }
开发者ID:LennartH,项目名称:JUUT,代码行数:13,代码来源:TestClassSession.cs

示例13: TestMethodInfo

        public TestMethodInfo(MethodInfo info) {
            if (!info.IsPublic) return;
            var attr = info.GetCustomAttribute(typeof(TestAttribute)) as TestAttribute;
            if (attr == null) return;
            var argCount = info.GetParameters().Length;
            if (argCount != 0) return;

            this.IsValid = true;
            this.Description = attr.Description;
            this.MethodInfo = info;
        }
开发者ID:yanyitec,项目名称:Yanyitec,代码行数:11,代码来源:TestMethodInfo.cs

示例14: Discover

        public bool Discover(MethodInfo publicMethod, OperationMetadata methodMetadata)
        {
            var attribute = publicMethod.GetCustomAttribute<NotesAttribute>() ?? new NotesAttribute("");

            if(string.IsNullOrEmpty(attribute.Notes))
                methodMetadata.Notes += "Uri template " + methodMetadata.Uri.Uri;
            else
                methodMetadata.Notes = attribute.Notes;

            return true;
        }
开发者ID:huoxudong125,项目名称:OpenRastaSwagger,代码行数:11,代码来源:DiscoverNotes.cs

示例15: Initialize

		public void Initialize(MethodInfo method, object rawTarget, UnityObject unityTarget, int id, BaseGUI gui, EditorRecord prefs)
		{
            this.prefs = prefs;
			this.gui = gui;
			this.rawTarget = rawTarget;
            this.unityTarget = unityTarget;
			this.id = id;

			if (initialized) return;
			initialized = true;

            isCoroutine = method.ReturnType == typeof(IEnumerator);

            var commentAttr = method.GetCustomAttribute<CommentAttribute>();
            if (commentAttr != null)
                comment = commentAttr.comment;

			niceName = method.GetNiceName();

            if (niceName.IsPrefix("dbg") || niceName.IsPrefix("Dbg"))
                niceName = niceName.Remove(0, 3);

			invoke	     = method.DelegateForCall();
			var argInfos = method.GetParameters();
			int len      = argInfos.Length;
			argValues    = new object[len];
			argKeys      = new int[len];
			argMembers   = new EditorMember[len];

			for (int iLoop = 0; iLoop < len; iLoop++)
			{
				int i = iLoop;
				var argInfo = argInfos[i];

				argKeys[i] = RuntimeHelper.CombineHashCodes(id, argInfo.ParameterType.Name + argInfo.Name);

				argValues[i] = TryLoad(argInfos[i].ParameterType, argKeys[i]);

                argMembers[i] = EditorMember.WrapGetSet(
                        @get         : () =>  argValues[i],
                        @set         : x => argValues[i] = x,
                        @rawTarget   : rawTarget,
                        @unityTarget : unityTarget,
                        @attributes  : argInfo.GetCustomAttributes(true) as Attribute[],
                        @name        : argInfo.Name,
                        @id          : argKeys[i],
                        @dataType    : argInfo.ParameterType
                    );
			}

#if DBG
			Log("Method drawer init");
#endif
		}
开发者ID:flatlineteam,项目名称:relic-rush,代码行数:54,代码来源:MethodDrawer.cs


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