المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : ToString() method on objects returned from a webservice (Compact framework) [modified]



C# Programming
06-30-2009, 07:00 PM
Hi.
I'm having a problem and cannot find the solution. trust me, i've read lots on msdn and google'd, in the wrong places obviously but i hope someone here can help me.

I'm porting an application to compact framework 3 and to reduce client side load i created a webservice for the BL (also, else i would have to copy all code and compile to CF since i cant use "regular" dll's in CF)
this webservice exposes some custom classes and a couple of methods. a simple example would be

(in webservice)
public enum ToStringType {
FirstName,
LastName
}

public class person
{
public string firstname {get;set;}
public string lastname {get;set;}
public ToStringType stringtype {get;set;}
public person(){
stringtype = ToStringType.FirstName ;
}

public override ToString(){

public override string ToString()
{
string tostr = string.Empty;
switch (stringtype )
{
case ToStringType.FirstName :
tostr = FirstName;
break;
case ToStringType.LastName:
tostr = LastName;
break;

}
return tostr;
}

and the ws has a method returning person[]

on the client. when i run the method and get a list of persons
first of all:
myperson.ToString() returns the object class name. not first/last-name

so i add a method:
tostr (){
...
}
with the logic in tostring(),

this works. returns firstname. but
if i (on the client) myperson.stringtype =ToStringType.LastName;
and debug the application, i see that myperson.stringtype IS ToStringType.LastName
but the method returns firstname.
i would really get the tostring to work since i'm adding the person[] to a combobox and i prefer not to use datasource/bindings. (tried those to. same problem, Displaymember has no effect)

how come this split personality disorder in my classes, and why does ToString return the class name instead of my overloaded ToString method?

I hope someone can help me
regards Tomas

There is no spoon

modified on Tuesday, June 30, 2009 10:54 AM