.net - How can I use VB.Net extension methods in a C# project -
i have legacy vb.net class library includes extension methods, 1 of this:
namespace extensions public module ormextensions <extension()> public function todomainobjectcollection(byref objects ormcollection(of ormobject)) domainobjectcollection return objects.asqueryable().todomainobjectcollection() end function <extension()> public function todomainobjectcollection(byref objects iqueryable(of ormobject)) domainobjectcollection dim doc new domainobjectcollection() each o in objects doc.add(o.todomainobject()) next return doc end function end module end namespace
to use these extensions in vb have import extensions.ormextensions. have project, in c# depends on vb 1 extensions , can't them work. ormextensions isn't available , using namespace vbproject.extensions doesn't make extensions available.
there multiple projects depend on vb project , ideally extensions should available of them.
i've done fair bit of googling haven't been able turn using vb extension methods in c#. assume issue they're required in module, haven't been able confirm that.
i'd rather not duplicate extension methods everywhere they're required(especially in our unit test project, in c#).
you should not using byref
.
vb.net (apparently) supports extension methods on ref
parameters; c# (rightfully) not.
a byref
(ref
in c#) parameter allows method assign new instance variable or field passed caller.
should used.
Comments
Post a Comment