.net: Introducing anonymous types in business layer?

203 views Asked by At

I don't want to create a new class and decided to use anonymous type in order to send data from presentation layer to biz layer.

But my problem is how can I introduce an anonymous type in biz layer? I use Vb.Net 2008 and VS 2008.

EDIT

Actually, I have to work with some data that their nature are really temporary classes and I won't use them again in my own project .

3

There are 3 answers

3
Aliostad On

Don't, don't!

If they are living in acorss server boundaries you end up using dynamic on the client of your function which is no good.

This is because you would probably have to expose the object as object in the method signature and you will loose all the benefits of type safety.

On the other hand, you are not achieving anything, compiler spits out a class for you anyway.

0
Matti Virkkunen On

Anonymous types are scoped so that they can be accessed in a strongly typed way only inside the method in which they were created. If you want to pass them from method to another, you'll have to resort to passing them as object and using reflection (or dynamic) to access their properties, which most certainly isn't what you want.

Use a proper class for your data.

1
gor On

I don't recomment you make such things. Such code won't be maintainable. But you could use dynamic from 4.0, that is no good for this.