测试了下,上传到服务器保存文件名为中文或是下载服务...上传文件,使用 保存为 中文名称 时会报错!非常感谢!正在使用中。刚学C#,今天在这里看到很多不错的学习资料,谢谢!...不错,学习jmail发送邮件核心代码。nb seo...泪求破解啊,不是VIP,怨念啊 命理风水堂敬启 公告:北京易达信动Qpay公司利...你好, 我现在是这样使用的 ss 值为 ...@weiyanlover 已针对该问题做了改进,...我一直在用这个类,觉得不错,因为我在写QQ农场外挂...
C#特性(Attribute)示例
编辑:dnawo 日期:2010-01-23
|
复制内容到剪贴板
程序代码
程序代码[AttributeUsage(AttributeTargets.All,Inherited=false)]
public class TestAttribute : System.Attribute
{
//Fields
private string _description;
//Properties
public string Description
{
get { return _description; }
}
//Constructor
public TestAttribute(string description)
{
this._description = description;
}
}
[Test("user-defined class")]
public class TestClass
{
//Constructor
public TestClass()
{}
//Methods
[Test("user-defined method")]
public int Add(int a, int b)
{
return a + b;
}
}
public class TestAttribute : System.Attribute
{
//Fields
private string _description;
//Properties
public string Description
{
get { return _description; }
}
//Constructor
public TestAttribute(string description)
{
this._description = description;
}
}
[Test("user-defined class")]
public class TestClass
{
//Constructor
public TestClass()
{}
//Methods
[Test("user-defined method")]
public int Add(int a, int b)
{
return a + b;
}
}
调用示例:
复制内容到剪贴板
程序代码
程序代码using System;
using System.Reflection;
namespace Console_Application
{
class Program
{
public static void Main(string[] args)
{
Type t = typeof(TestClass);
MemberInfo memberInfo = t;
TestAttribute attribute = (TestAttribute)Attribute.GetCustomAttribute(memberInfo,typeof(TestAttribute));
Console.WriteLine(attribute.Description);
MethodInfo methodInfo = t.GetMethod("Add");
TestAttribute attribute2 = (TestAttribute)Attribute.GetCustomAttribute(methodInfo,typeof(TestAttribute));
Console.WriteLine(attribute2.Description);
Console.ReadKey(true);
}
}
}
using System.Reflection;
namespace Console_Application
{
class Program
{
public static void Main(string[] args)
{
Type t = typeof(TestClass);
MemberInfo memberInfo = t;
TestAttribute attribute = (TestAttribute)Attribute.GetCustomAttribute(memberInfo,typeof(TestAttribute));
Console.WriteLine(attribute.Description);
MethodInfo methodInfo = t.GetMethod("Add");
TestAttribute attribute2 = (TestAttribute)Attribute.GetCustomAttribute(methodInfo,typeof(TestAttribute));
Console.WriteLine(attribute2.Description);
Console.ReadKey(true);
}
}
}
评论: 0 | 引用: 0 | 查看次数: 233
发表评论
请登录后再发表评论!
上一篇
下一篇


文章来自:
Tags:
相关日志:

