使用内联对象创建减少.Net代码

Pio*_*ula 0 .net vb.net visual-studio-2010

我已经成功地将几行代码压缩了

For Each gal In galleries
   With New HtmlGenericControl("div")
                .ID = gal.Header
                .Controls.Add(New HtmlImage() With {.Src = "http://p.com/pic.jpg"})

                galleryContent.Controls.Add(**Me**)
   End With
Next
Run Code Online (Sandbox Code Playgroud)

我找不到任何地方如何引用回到我正在使用的对象将控件添加回'galleryContent' - 使用普通me崩溃整个Web服务器... whooops.

使用不提供刚刚使用的较短手. - 但它使用唯一的方法来做到这一点?我特意期待某种类似的.Me 东西this

有任何想法吗?

Eri*_*sch 5

你不能.至少不那样.

试试这个:

For Each gal In galleries 
   Dim obj as New HtmlGenericControl("div") 
   With obj
        .ID = gal.Header 
        .Controls.Add(New HtmlImage() With {.Src = "http://p.com/pic.jpg"}) 

        galleryContent.Controls.Add(ojb) 
   End With 
Next 
Run Code Online (Sandbox Code Playgroud)