Introduction
A while ago I blogged about Clay for VB.Net and found that it didn’t really work for anonymous types in VB.Net. And I even got an explanation why it did not work.
Today I got a comment on my first post saying that impromptu-interface would work in VB.Net and since it is on Nuget I would try it.
Clay
So this code in Clay
Dim c As Object = New ClayFactory
Dim plant = c.Plant(New With {.LatinName = "test"})
Console.WriteLine(plant.LatinName)
Console.ReadLine()```
or this
```vbnet
Dim c As Object = New ClayFactory
Dim plant = c.Plant(LatinName:="test")
Console.WriteLine(plant.LatinName)
Console.ReadLine()```
or this
```vbnet
Dim c As Object = New ClayFactory
Dim plant = c.Plant().LatinName("test")
Console.WriteLine(plant.LatinName)
Console.ReadLine()```
And yes I tried with the newest version of clay and it still doesn’t work.
## impromptu-interface
So I tried this with impromptu-interface and that just worked.
Dim c As Object = Builder.[New]() Dim plant = c.Plant(New With {.LatinName = “test”}) Console.WriteLine(plant.LatinName) Dim d As Object = Builder.[New]() Dim plant2 = d.Plant(LatinName:=“test”) Console.WriteLine(plant2.LatinName) Dim e As Object = Builder.[New]() Dim plant3 = e.Plant().LatinName(“test”) Console.WriteLine(plant3.LatinName) Console.ReadLine()``` So go check it out.
Conclusion
Great work from these guys to make that work.