XSD To Entity -- Vs2008 Add Ins

本文介绍了一款用于Visual Studio的XSD转Entity Add-Ins插件,通过简单的几步配置,即可实现XSD文件到实体类的转换。该插件通过自定义菜单项的方式集成到Visual Studio中,方便快捷。

最近闲得无事,不过也是为了以后设计的一个环节,做了一个Add-Ins

主要是XSD To Entity的操作。

Step 1:先配置一下

           把相关的AddIn、DLL Copy To 当前用户\文档\Visual Studio 200X\Addins

image

Step 2:Tools\Add-In Manager勾选即可

image

Step 3:现在随便打开一个project,然后在Code Windows中右击,就可以看到XSD To Entity

 

1

界面

image

选择一个XSD File

image

转换完成

image

转换文件

image 

 

代码方面:

image

Connect.cs:


 
 1  public   void  OnConnection( object  application, ext_ConnectMode connectMode,  object  addInInst,  ref  Array custom)
 2  {
 3            _applicationObject  =  (DTE2)application;
 4            _addInInstance  =  (AddIn)addInInst;
 5 
 6             //  Get the CommandBar for the window in which you want to add the menuitem.
 7             // I am going to add it to the code window.
 8            CommandBar oCommandBar  =  ((CommandBars)_applicationObject.CommandBars)[ " Code Window " ];
 9 
10             //  I am going to add a MenuItem and a submenuitem to that.
11             //  So I go ahead and create a PopUp Item.
12            CommandBarPopup oPopup  =  (CommandBarPopup)oCommandBar.Controls.Add(MsoControlType.msoControlPopup,
13                                                                               System.Reflection.Missing.Value,
14                                                                               System.Reflection.Missing.Value,  1 true );
15             //  Set the caption of the menuitem
16            oPopup.Caption  =   " XSD To Entity " ;
17 
18             //  Now I go ahead and add a Submenu item to the added Menuitem.
19            CommandBarControl oControl  =  oPopup.Controls.Add(MsoControlType.msoControlButton,
20                                                             System.Reflection.Missing.Value,
21                                                             System.Reflection.Missing.Value,  1 true );
22             //  Set the caption of the submenuitem
23            oControl.Caption  =   " Execute " ;
24 
25             //  Now that we have added the menu items,
26             //  we will associate the click events for these items.
27             //  I will associate a click event only for the SubMenuitem at present.
28            oSubMenuItemHandler  =  (CommandBarEvents)_applicationObject.Events.get_CommandBarEvents(oControl);
29            oSubMenuItemHandler.Click  +=   new  _dispCommandBarControlEvents_ClickEventHandler(oSubMenuItemHandler_Click);
30  }
31 
32  ///   <summary>
33  ///  Invoked on click of sub menu item.
34  ///   </summary>
35  protected   void  oSubMenuItemHandler_Click( object  CommandaBarControl,  ref   bool  handled,  ref   bool  cancelDefault)
36  {
37            XSDToEntityFrm frm  =   new  XSDToEntityFrm();
38            frm.ShowDialog();
39  }
XSDToEntityFrm.cs
System.Diagnostics.Process p = new System.Diagnostics.Process();
{
      p.StartInfo.FileName = "cmd.exe";
      p.StartInfo.UseShellExecute = false;
      p.StartInfo.RedirectStandardInput = true;
      p.StartInfo.RedirectStandardOutput = true;
      p.StartInfo.RedirectStandardError = true;
      p.StartInfo.CreateNoWindow = true;
      p.Start();
      p.StandardInput.WriteLine( String.Concat( @"%comspec% /k """"" , txtVsPath.Text , @""""" x86" ) );
      p.StandardInput.WriteLine( String.Concat( @"xsd /c /language:CS " , selectFile , @" /out:" , txtOutPath.Text ) );
      p.StandardInput.WriteLine( "Exit" );
      p.Close();
}

完整程序XSDToEntity

 

XML To XSD : xsd test.xml /outputdir:D:\

XSD TO DataSet : xsd /dataset /language:CS Test.xsd (不过,不是每个xsd都是可以转换的)

DLL To XSD : xsd Test.dll  (不过,不是每个DLL都是可以转换的)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值