ToolPart类与System.Reflection
如果你仍然工作在SharePoint基类部分,你可能与ToolPart类熟悉。 该ToolPart类允许你随意暴露一个整洁的小件您自定义的范围内就在WebPart ToolPane本身扩展菜单中Web部件决定一堆。 这是一种不错的时候做这样显示的版权或任何东西你Web部件。 如需ToolPart类的基本代码如下所示:
C#中:
- . WebPartPages ; 使用Microsoft。SharePoint 实现。WebPartPages;
- ; 使用 系统 ;
- . Web . UI ; 使用 系统 。 网络 。 用户界面 ;
- 空间 buenz。WebParts的
- (
-
BasicToolpart : ToolPart 公共 类 BasicToolpart:ToolPart
- (
- 公共 BasicToolpartMS()
- (
- = "My Name" ; 基地 。 标题 =“我的名字”;
- )
- 公众覆盖无效 ApplyChanges()
- (
- )
- 公众覆盖无效 CancelChanges()
- (
- )
- HtmlTextWriter output ) 保护覆盖无效 RenderToolPart(HtmlTextWriter输出)
- (
- "Adam Buenz" ) ;输出。 写 (“亚当Buenz”);
- )
- 公众覆盖无效 SyncChanges()
- (
- )
- )
- )
但是,当你像WebParts的显示等,往往有点eaiser使用任何版本。NET的反射而不是不得不通过字符串值在一堆去WebPart类文件显示的Web部件的版本。 相反,你可以只撤出在大会上所作信息文件使用System.Reflection命名它的任务。 要利用这一优势,目前只有一两件事情,你必须做的。 首先是要对System.Reflection引用,然后初始化三个字符串来保存正在从数据执行的程序集拉在这种情况下,在WebPart版本,公司名称,建立了网页组件,当然,在WebPart产品名称。 另一种是得到从WebPart集文件资料使用GetExecutingAssembly()来获得在WebPart位置二进制,然后获取相关信息。
C#中:
- . WebPartPages ; 使用Microsoft。SharePoint 实现。WebPartPages;
- ; 使用 系统 ;
- . Web . UI ; 使用 系统 。 网络 。 用户界面 ;
- . Reflection ; 使用 系统 。 反射 ;
- 空间 buenz。WebParts的
- (
- ReflectingToolPart : ToolPart 公共 类 ReflectingToolPart:ToolPart
- (
- labelVersion; 私人 串 labelVersion;
- labelCompanyName; 私人 串 labelCompanyName;
- labelProductName; 私人 串 labelProductName;
- 公共 ReflectingToolPart()
- (
- = AssemblyProduct; 这一点 。labelProductName = AssemblyProduct;
- = AssemblyCompany; 这一点 。labelCompanyName = AssemblyCompany;
- = String . Format ( "Version {0}" , AssemblyVersion ) ; 这一点 。labelVersion = 字符串 。 格式 (“版本(0)”,AssemblyVersion);
- = "My WebPart" ; 基地 。 标题 =“我的Web部件”;
- )
- 公众覆盖无效 ApplyChanges()
- (
- )
- AssemblyVersion 公共 串 AssemblyVersion
- (
- 获得
- (
- ( ) . GetName ( ) . Version . ToString ( ) ; 返回大会。GetExecutingAssembly()。GetName()。版本 。 的toString();
- )
- )
- AssemblyProduct 公共 串 AssemblyProduct
- (
- 获得
- (
- / /获取所有产品特性在此集会
- attributes = Assembly. GetExecutingAssembly ( ) . GetCustomAttributes ( typeof ( AssemblyProductAttribute ) , false ) ; 对象 []属性=大会。GetExecutingAssembly()。GetCustomAttributes的 (typeof(AssemblyProductAttribute), 假 );
- / /如果没有任何产品属性,返回一个空字符串
- attributes. Length == 0 ) 如果 (attributes. 长度 == 0)
- ; 返回 “”;
- / /如果有一个产品的属性,返回其值
- AssemblyProductAttribute ) attributes [ 0 ] ) . Product ; 返回 ((AssemblyProductAttribute)属性[0])。 产品 ;
- )
- )
- AssemblyCompany 公共 串 AssemblyCompany
- (
- 获得
- (
- / /获取所有属性的公司在此集会
- attributes = Assembly. GetExecutingAssembly ( ) . GetCustomAttributes ( typeof ( AssemblyCompanyAttribute ) , false ) ; 对象 []属性=大会。GetExecutingAssembly()。GetCustomAttributes的 (typeof(AssemblyCompanyAttribute), 假 );
- / /如果没有任何公司的属性,返回一个空字符串
- attributes. Length == 0 ) 如果 (attributes. 长度 == 0)
- ; 返回 “”;
- / /如果有一个公司的属性,返回其值
- AssemblyCompanyAttribute ) attributes [ 0 ] ) . Company ; 返回 ((AssemblyCompanyAttribute)属性[0])。 公司 ;
- )
- )
- 公众覆盖无效 CancelChanges()
- (
- )
- HtmlTextWriter output ) 保护覆盖无效 RenderToolPart(HtmlTextWriter输出)
- (
- "输出。 写 (“
- ; <center>“);
- "输出。 写 (“
- ; “);
- labelProductName ) ;输出。 写 (labelProductName);
- "" ) ;输出。 写 (“”);
- labelVersion ) ;输出。 写 (labelVersion);
- "" ) ;输出。 写 (“”);
- labelCompanyName ) ;输出。 写 (labelCompanyName);
- SyncChanges ( ) ) 公共覆盖无效 SyncChanges()
- (
- )
- )
- )
只要确保您的属性从WebPart拉不包含空值。
没有评论»
还没有评论。






























