2

指定したテーブルのモデルを生成できるようにする Visual Studio の拡張機能を作成したいと考えています。

次のコードを使用して、サーバー エクスプローラーのテーブルのコンテキスト メニューに MyCommand 項目を追加しました。

Commands2 commands = (Commands2)_applicationObject.Commands;
CommandBar menuBarCommandBar = ((CommandBars)_applicationObject.CommandBars)["Object Node"];

Command command = commands.AddNamedCommand2(_addInInstance, "MyCommand", "MyCommand", 
    "Executes the command for MyCommand", true, 59, ref contextGUIDS,
    (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
    (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
if ((command != null) && (menuBarCommandBar != null))
{
        command.AddControl(menuBarCommandBar, 1);
}

選択したテーブル項目の名前を取得するには:

string fileName = "Dafault.cs";
var serverExplorer = _applicationObject.ToolWindows.GetToolWindow("Server Explorer") as UIHierarchy;
if (serverExplorer != null)
{
    dynamic item = ((object[])serverExplorer.SelectedItems)[0];
    fileName = string.Format("{0}.cs", item.Name);
}

//...
// Generate model based on table from database 
//...

_applicationObject.ItemOperations.NewFile("General\\Text File", fileName, Constants.vsViewKindCode);

データベース接続に関する情報を取得するにはどうすればよいですか?

4

1 に答える 1

0

ブラッドラーソン、なぜ私の質問が削除されたのですか?

解決策を見つけました。これを使用しました

public static IDbConnection GetConnection(DSRefNavigator navigator、out string type)
        {{
            type = null;
            試す
            {{
                if(ナビゲーター!= null)
                {{
                    IVsDataConnectionsService dataConnectionsService =
                        (IVsDataConnectionsService)Package.GetGlobalService(typeof(IVsDataConnectionsService));
                    string itemName = navigator.GetConnectionName();

if (itemName != null) { int iConn; // = dataConnectionsService.GetConnectionIndex(itemName); DataViewHierarchyAccessor dataViewHierarchy = null; for(iConn = 0; iConn < dataConnectionsService.Count; iConn++) { DataViewHierarchyAccessor hierarchyAccessor = new DataViewHierarchyAccessor((IVsUIHierarchy) dataConnectionsService.GetConnectionHierarchy(iConn)); try { if (hierarchyAccessor.Connection.DisplayConnectionString == itemName) { dataViewHierarchy = hierarchyAccessor; break; } } catch { } } if (dataViewHierarchy != null) { DataConnection connection = dataViewHierarchy.Connection; if (connection != null && connection.ConnectionSupport.ProviderObject != null) { type = connection.ConnectionSupport.ProviderObject.GetType().FullName; return (IDbConnection) connection.ConnectionSupport.ProviderObject; } } } } } catch { } return null; }

于 2012-11-10T20:22:38.187 に答える