-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Problem with proxied classes
PostPosted: Fri Sep 02, 2005 5:01 pm 
Newbie

Joined: Sat Jul 09, 2005 1:17 pm
Posts: 17
Hi

I have a weird problem. I've noticed that for some of my proxied objects the underlying private variables of the public virtual properties don't have values, and yet the properties return correct values.
How can this be explained? and the behavior is inconsistent and dependent on a particular sequence of steps that I can explain and provide a log file later upon request.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 03, 2005 9:24 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
This is how proxy objects works, virtual members calls are intercepted to return the right values.
So you should not use private members... (even in virtual members)

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 1:29 pm 
Newbie

Joined: Sat Jul 09, 2005 1:17 pm
Posts: 17
Hi,

Do you mean that instead of using properties in my class I should be using public variables?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 11:42 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Nissim wrote:
Do you mean that instead of using properties in my class I should be using public variables?


You should use virtual members; I am not sure if they have to be public/protected...
By "members" I mean properties; but I think it should also work with fields.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 1:02 pm 
Newbie

Joined: Sat Jul 09, 2005 1:17 pm
Posts: 17
What do you mean? I don't understand. I have public virtual properties. Here is an example:


private string m_comment;


public virtual string comment
{

get {return m_comment;}
set {m_comment = value;}
}

Are you saying that the field m_comment should be public or are you saying that I should just use a public m_comment without tying it to a property?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 1:19 pm 
Contributor
Contributor

Joined: Thu Jun 23, 2005 1:08 pm
Posts: 32
Location: Baltimore, MD
In that example, you should access the public Comment property only, never the private member. This will ensure that the proxy does it's job.

example:

Code:
public void ClearComment()
{
   m_comment = string.Empty;  //Bad, this will not flow through the proxy properly
}

public void ClearComment()
{
   Comment = string.Empty;  //Good
}


By the way, capitalize your public properies:
Code:
public virtual string Comment { get { ... } set { ...} }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.