I have a webservice project (old asmx technology) in which I have a class User. This class has a DateTime property that represents the birthdate of this user. Beside this class, I have another file with a partial class User. In this partial class, I add a property 'Age' which returns the age of the user:
public partial class User
{
public DateTime Age
{
get { return DateTime.Now - this.Birthdate; }
}
}
The reason that this is in a partial class is because the User class code is automatically generated from a config file, and I cannot add code to this class without it being removed every time the code is generated.
Now in my webservice I have a webmethod that returns a list of these Users which it gets from a database:
[WebMethod]
public List<User> GetUsers()
{
return Database.LoadUsers();
}
Simple enough... Anyway, in a different project now, I add a Service Reference to this webservice. It generates the service client and a User class for me. The problem is: this User class does not contain the properties defined in the partial class (Age in this example)... It seems the webservice doesn't get this information.
Of course I can create a new partial User class and basically rewrite it in the second project, but I shouldn't have to, should I? Why doesn't the webservice recognize the partial class?