Saturday, March 24, 2012

this object is read only.

I'm trying to integrate my site with the communityserver forum, and I'm inheriting the forum User class to my user class.
I want to write

AspNetForums.Components.User MyUser = AspNetForums.Users.GetUser(UserID,true);
this = (MyNamespace.User) MyUser;

but it says <this> is read only.
Is there a way to do this without having to write everything out like this?

AspNetForums.Components.User MyUser = AspNetForums.Users.GetUser(UserID,true);
this.YahooIM = MyUser.YahooIM;
this.WebLog = MyUser.WebLog;
this.WebAddress = MyUser.WebAddress;
this.Username = MyUser.Username;

Unless you create a SetProps() method that you pass these properties in, and this function does the assignment. You have to do the property assignment.

Brian
Thanks. Man, this object has like 40 properties.
Yeah, that happens, however, a more dynamic solution (like maybe reflection) could give you performance problems, whereas a little bit of coding will give you less headaches in the long run.

Brian

0 comments:

Post a Comment