Creating Custom Attributestạo một Attributes * Lớp tạo Attributes PHP Code: /* * Created by SharpDevelop.. /// [AttributeUsageAttributeTargets.Method|AttributeTargets.Property|Attribu
Trang 1Ví dụ 3!
Creating Custom Attributes(tạo một Attributes)
* Lớp tạo Attributes
PHP Code:
/*
* Created by SharpDevelop
* NetDevelop Co., Ltd
* Author: Tuan Anh Nguyen Ngoc
* Date: 11/24/2006
* Contact Information
* - Email: info.netdevelop@gmail.com
* - Handheld: +84 905 202 088
*/
using System;
namespace AdvancedDotnet
{
/// <summary>
/// Định nghĩa Author Attribute
/// </summary>
[AttributeUsage(AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.S truct,AllowMultiple=false,Inherited=false)]
public class AuthorAttribute : Attribute
{
private string _sName;
public AuthorAttribute(string name)
{
this._sName = name;
}
}
}
Mình không có nhiều thời gian nên các bạn có thể tự tìm hiểu thêm, chú các đến
Enumerator của AttributeTargets
Sử dụng Attribute tự tạo tương tự như sử dụng Attribute
Trang 2* Lớp gọi(sử dụng) Attributes
PHP Code:
/*
* Created by SharpDevelop
* NetDevelop Co., Ltd
* Author: Tuan Anh Nguyen Ngoc
* Date: 11/21/2006
* Contact Information
* - Email: info.netdevelop@gmail.com
* - Handheld: +84 905 202 088
*/
using System;
using System.Resources;
using System.Reflection;
namespace AdvancedDotnet
{
class MainClass
{
[Author("tuan anh nguyen ngoc")]
public static void Main()
{
///do samething
}
}
}
Quote:
[Author("tuan anh nguyen ngoc")]
Author chính là Attributes ta tạo ra
chúc các bạn thành công! có vấn đề gì cần hỏi có thể liên hệ với mình ở thông tin trên,
dauden(UDS)