devExpress 示例分析

我们来看这个例子:


Components\WinForms\XtraTreeList\CS\TreeListMainDemo


这个例子很有意思的一点是,启动就显示了,我想拿来给自己用。

看了看代码,让我奇怪得很,


我的第一个反应就是找找字符串,比如"Data Sources"
代码里没有找到,扩大范围之后发现,在一个xml文件里。


  E:\work\AutoPack\Client\DX2011.2.5_src\Sources\DevExpress.DemoData.Win\DevExpress.DemoData.Win\Products\XtraTreeList\MainDemo.xml


    <WinDemoModule Path="TreeListRegViewer" Group="Data Sources" Type="local:TreeListRegViewer">
      <Title>Reg Viewer</Title>
      <Description>This demo shows how to work with the XtraTreeList in unbound mode.</Description>
    </WinDemoModule>


这里有这样一个文件,装着里面的内容

Components\Data\XtraTreeList.xml


这里我还是没有完全搞清楚。


直到把代码全都加进来,进行了跟踪:


namespace DevExpress.DXperience.Demos

		protected virtual void OnLoad(object sender, System.EventArgs e) {
			
			Assembly entryAssembly = Assembly.GetEntryAssembly();
			if(entryAssembly == null) return;
			object[] attributes = entryAssembly.GetCustomAttributes(typeof(ProductIdAttribute), false);
			if(attributes.Length == 0)
				throw new Exception("Every demo application must have the ProductId assembly attribute");
			ProductIdAttribute productIdAttribute = (ProductIdAttribute)attributes[0];
			MainFormRegisterDemoHelper.RegisterDemos(productIdAttribute.ProductId);
			FillNavBar();


注意这句:


            Assembly entryAssembly = Assembly.GetEntryAssembly();
            object[] attributes = entryAssembly.GetCustomAttributes(typeof(ProductIdAttribute), false);
          ProductIdAttribute productIdAttribute = (ProductIdAttribute)attributes[0];
            MainFormRegisterDemoHelper.RegisterDemos(productIdAttribute.ProductId);

原来是这样,是根据反射,得到了模块的一个二进制属性,

我们去找找:


TreeListMainDemo 工程 的AssemblyInfo.cs

最后一行:

[assembly: ProductId("XtraTreeList")]

原来如此。

后面就不多说了,只要你能把代码引入,跟踪,就能稿清楚了。
看到rgtister,就知道,要注册一个module




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值