开发者

What is the equivalent for VB's CreateObject in c# 3.0?

I have the below code in VB

Private Sub RefreshCharts()
On Error GoTo err_getICHELPER_REFRESH
    Application.Cursor = xlWait
    Dim objOperationRefresh
    Set objOperationRefresh = CreateObject("Char开发者_如何学Cting.AutomationProxy")
    Dim a As Variant
    Set a = Application
    objOperationRefresh.RefreshApplication a
    Application.StatusBar = "Refreshing .. "
    Do While Len(objOperationRefresh.RefreshStatus) = 0
        DoEvents
    Loop
    Application.StatusBar = "Refreshing Complete."
    Set objOperationRefresh = Nothing
    Application.StatusBar = ""
    Exit Sub
err_getICHELPER_REFRESH:

I have done the conversion in C# except for CreateObject("Charting.AutomationProxy"). What will be the equivalent of that in c# 3.0?

Thanks


You could use reflection:

Type type = Type.GetTypeFromProgID("Charting.AutomationProxy");
object instance = Activator.CreateInstance(type);

Contrary to VB and VB.NET, C# doesn't support dynamic types until C# 4.0. As this is a COM object another possibility is to generate a strongly typed wrapper which will greatly simplify the usage: in the Add Reference dialog select the component from COM components tab or use the tlbimp.exe utility.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜