| « | October 2026 | » | | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | |
| 公告 |
| 暂无公告... |
| Blog信息 |
|
blog名称: 日志总数:11 评论数量:2 留言数量:0 访问次数:46579 建立时间:2008年8月31日 |

| |
|
浅谈BlogEngine扩展机制的实现 文章收藏, 随笔, 电脑与网络
david_shar 发表于 2008/9/3 0:44:08 |
| 在Blogengine里,每一个扩展的Class都必须有Extension标记ExtensionAttribute是一个密封类,继承自System.Attribute,System.Attribute没有任何实现,只是一个标记而已。ExtensionAttribute类的代码:(完整代码可以从BlogEngine.NET.zip下载)
[AttributeUsage(AttributeTargets.Class)] //指明该Attrubite只能应用于Class上
public sealed class ExtensionAttribute : System.Attribute
{
/// <summary>
/// Creates an instance of the attribute and assigns a description.
/// </summary>
public ExtensionAttribute(string description, string version, string author)
{
_Description = description;
_Version = version;
_Author = author;
}
private string _Description;
/// <summary>
/// Gets the description of the extension.
/// </summary>
public string Description
{
get { return _Description; }
}
private string _Version;
/// <summary>
/// Gets the version number of the extension
/// </summary>
public string Version
{
get { return _Version; }
}
private string _Author;
/// <summary>
/// Gets the author of the extension
/// </summary>
public string Author
{
get { return _Author; }
}
} [AttributeUsage(AttributeTargets.Class)] //指明该Attrubite只能应用于Class上
public sealed class ExtensionAttribute : System.Attribute
{
/// <summary>
/// Creates an instance of the attribute and assigns a description.
/// </summary>
public ExtensionAttribute(string description, string version, string author)
{
_Description = description;
_Version = version;
_Author = author;
}
private string _Description;
/// <summary>
/// Gets the description of the extension.
/// </summary>
public string Description
{
get { return _Description; }
}
private string _Version;
/// <summary>
/// Gets the version number of the extension
/// </summary>
public string Version
{
get { return _Version; }
}
private string _Author;
/// <summary>
/// Gets the author of the extension
/// </summary>
public string Author
{
get { return _Author; }
}
}
到这里很明了了,扩展类决定于它有没有打Extension标记,是否创建实例取决于该扩展有没有被启用.BlogEngine有很多地方是值得我们学习的. |
|
|