views:

112

answers:

2

I'm generating dto classes with a template engine and would like to exclude some properties in an asmx webservice, what, if possible, is the best way to do this?

Ex:

[WebMethod]
public ProductPackages GetPackages()
{
   ProductPackages packages = new ProductPackages();
   packages.Packages.add(new PackageDTO());
   return packages;
}

The PackageDTO contains some properties that's not relevant for this service. But as the class can be regenerated any time i can't apply [XmlIgnore] to the fields.

So I'm looking for a way to apply a "exclude list" without touching the actual class. Above is just an example, the template engine generates dto's for all tables in a given project, and I would like to be able to use them in services without needing to maintain a big bunch of nearly identical classes.

A: 

Just hit the same problem. You can exclude fields by marking them as internal.

public class Order
{
    public double OrderPrice;
    internal double ProfitMargin;
    internal string TheTruthAboutThisCustomer;
}
Andomar
-1: he says: "But as the class can be regenerated any time i can't apply [XmlIgnore] to the fields". I bet he can't change fields to `internal`, either.
John Saunders
A: 

If you don't want to return a field or property, then don't have it in the object you return! It's as simple as that.

John Saunders
-1 he says: "But as the class can be regenerated any time i can't apply [XmlIgnore] to the fields". I bet he can't remove it from the object he returns, either
Andomar
Duh - he should return a wrapper object, exposing only the fields he wants returned.
John Saunders