简单的代码,google搜索提炼和分析,主要是利用反射技术,测试通过,抛砖引玉,自娱自乐,多多指教。
public
partial
class
_Default : System.Web.UI.Page
{
protected void Page_Load( object sender, EventArgs e)
{
if ( ! IsPostBack)
{
Assembly ass = Assembly.LoadFile( @" D:\com.uuu9.api.dll " );
DebuggableAttribute att = Utils.GetCustomAttribute < DebuggableAttribute > (ass);
Response.Write(att.IsJITTrackingEnabled ? " Debug " : " Release " );
}
}
}
public static class Utils
{
public static T GetCustomAttribute < T > ( this ICustomAttributeProvider provider)
where T : Attribute
{
var attributes = provider.GetCustomAttributes( typeof (T), false );
return attributes.Length > 0 ? attributes[ 0 ] as T : default (T);
}
}
{
protected void Page_Load( object sender, EventArgs e)
{
if ( ! IsPostBack)
{
Assembly ass = Assembly.LoadFile( @" D:\com.uuu9.api.dll " );
DebuggableAttribute att = Utils.GetCustomAttribute < DebuggableAttribute > (ass);
Response.Write(att.IsJITTrackingEnabled ? " Debug " : " Release " );
}
}
}
public static class Utils
{
public static T GetCustomAttribute < T > ( this ICustomAttributeProvider provider)
where T : Attribute
{
var attributes = provider.GetCustomAttributes( typeof (T), false );
return attributes.Length > 0 ? attributes[ 0 ] as T : default (T);
}
}
如果本文对你有所帮助,请打赏——1元就足够感动我:)
联系邮箱:intdb@qq.com
我的GitHub: https://github.com/vipstone
联系邮箱:intdb@qq.com
我的GitHub: https://github.com/vipstone
关注公众号:
作者: 王磊
出处: http://vipstone.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,请标明出处。