⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class1.cs

📁 C#开发教程 由浅入深 配有实例 是初学者的好帮手
💻 CS
字号:
using System;
using System.Reflection;

namespace MethodAttribs
{
	public class TransactionableAttribute : Attribute
	{
		public TransactionableAttribute()
		{
		}
	}

	class SomeClass
	{
		[Transactionable]
		public void Foo()
		{}

		public void Bar()
		{}

		[Transactionable]
		public void Goo()
		{}
	}

	class Test
	{
		[STAThread]
		static void Main(string[] args)
		{
			Type type = Type.GetType("MethodAttribs.SomeClass");
			foreach (MethodInfo method in type.GetMethods())
			{
				foreach (Attribute attr in
					method.GetCustomAttributes(true))
				{
					if (attr is TransactionableAttribute)
					{
						Console.WriteLine(
							"{0} is transactionable.", 
							method.Name);
					}
				}
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -