<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Only allowing certain types to set a property</title>
	<atom:link href="http://benreichelt.net/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/feed/" rel="self" type="application/rss+xml" />
	<link>http://benreichelt.net/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/</link>
	<description></description>
	<lastBuildDate>Tue, 18 Aug 2009 22:20:45 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: jdvolz</title>
		<link>http://benreichelt.net/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/comment-page-1/#comment-627</link>
		<dc:creator>jdvolz</dc:creator>
		<pubDate>Fri, 20 Jan 2006 02:36:33 +0000</pubDate>
		<guid isPermaLink="false">http://s194721765.onlinehome.us/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/#comment-627</guid>
		<description>Could you just use the get portion of the property and then write accessor methods for the internal data of the data base object?  Something like:

public class MyDBObject
{
private bool isDirty = false;
public bool IsDirty
{
return this.isDirty;
}

//modifiers
public void SetValue(object someValue)
{
....//set the value within the data structure and then...
this.isDitry = true;
}

}

This method assumes that you are creating a layer of abstraction in the object, and only allowing the object to alter the data that is internal to it (called encapsulation I believe).  I believe this is how DataSets keep track of the state of rows contained within them.</description>
		<content:encoded><![CDATA[<p>Could you just use the get portion of the property and then write accessor methods for the internal data of the data base object?  Something like:</p>
<p>public class MyDBObject<br />
{<br />
private bool isDirty = false;<br />
public bool IsDirty<br />
{<br />
return this.isDirty;<br />
}</p>
<p>//modifiers<br />
public void SetValue(object someValue)<br />
{<br />
&#8230;.//set the value within the data structure and then&#8230;<br />
this.isDitry = true;<br />
}</p>
<p>}</p>
<p>This method assumes that you are creating a layer of abstraction in the object, and only allowing the object to alter the data that is internal to it (called encapsulation I believe).  I believe this is how DataSets keep track of the state of rows contained within them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://benreichelt.net/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/comment-page-1/#comment-626</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Wed, 18 Jan 2006 18:09:28 +0000</pubDate>
		<guid isPermaLink="false">http://s194721765.onlinehome.us/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/#comment-626</guid>
		<description>Of all the comments here, I agree with Jeremy D. Miller. I like the idea of having a seperate object - perhaps the persistor itself - keeping track of the isdirty. The easy way to implement this is to have the DTO raise a MemberChanged event whenever a Set is called, and your listener object sets the isdirty flag on its own. then when your persistor comes along, it reads the isdirty from the listener object to determine whether or not it needs to update that object to the database. Doing this allows you to control which object your persistor pays attention to, to get the isdirty flag.</description>
		<content:encoded><![CDATA[<p>Of all the comments here, I agree with Jeremy D. Miller. I like the idea of having a seperate object &#8211; perhaps the persistor itself &#8211; keeping track of the isdirty. The easy way to implement this is to have the DTO raise a MemberChanged event whenever a Set is called, and your listener object sets the isdirty flag on its own. then when your persistor comes along, it reads the isdirty from the listener object to determine whether or not it needs to update that object to the database. Doing this allows you to control which object your persistor pays attention to, to get the isdirty flag.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://benreichelt.net/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/comment-page-1/#comment-625</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Wed, 18 Jan 2006 16:44:36 +0000</pubDate>
		<guid isPermaLink="false">http://s194721765.onlinehome.us/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/#comment-625</guid>
		<description>perhaps ....

MyDatabaseClass {
   protected bool isDirty
}

MyDirtyDatabaseClass : MyDatabaseClass {
 public bool isDirty {
   get { return isDirty }
   set { isDirty = value}
 }
}

MyDatabaseClass MyDatabaseClassFactory()  {
   return (MyDatabaseClass) new MyDirtyDatabaseClass();
}</description>
		<content:encoded><![CDATA[<p>perhaps &#8230;.</p>
<p>MyDatabaseClass {<br />
   protected bool isDirty<br />
}</p>
<p>MyDirtyDatabaseClass : MyDatabaseClass {<br />
 public bool isDirty {<br />
   get { return isDirty }<br />
   set { isDirty = value}<br />
 }<br />
}</p>
<p>MyDatabaseClass MyDatabaseClassFactory()  {<br />
   return (MyDatabaseClass) new MyDirtyDatabaseClass();<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://benreichelt.net/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/comment-page-1/#comment-624</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Wed, 18 Jan 2006 15:27:17 +0000</pubDate>
		<guid isPermaLink="false">http://s194721765.onlinehome.us/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/#comment-624</guid>
		<description>If you really want to do this with 1.1, have a look at StrongNameIdentityPermission.

http://msmvps.com/blogs/manoj/archive/2004/10/20/16208.aspx</description>
		<content:encoded><![CDATA[<p>If you really want to do this with 1.1, have a look at StrongNameIdentityPermission.</p>
<p><a href="http://msmvps.com/blogs/manoj/archive/2004/10/20/16208.aspx" rel="nofollow">http://msmvps.com/blogs/manoj/archive/2004/10/20/16208.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://benreichelt.net/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/comment-page-1/#comment-623</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Wed, 18 Jan 2006 14:05:21 +0000</pubDate>
		<guid isPermaLink="false">http://s194721765.onlinehome.us/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/#comment-623</guid>
		<description>Sorry, messed that up:

PersistanceClass: IPersistStuff
{
public void PersistMyClass(MyClass class);
}

MyClass
{
private bool isDirty;
public void Persist(IPersistStuff persistStuff)
{
   if (isDirty)
      PersistMyClass(this);
   isDirty = false;
}
}</description>
		<content:encoded><![CDATA[<p>Sorry, messed that up:</p>
<p>PersistanceClass: IPersistStuff<br />
{<br />
public void PersistMyClass(MyClass class);<br />
}</p>
<p>MyClass<br />
{<br />
private bool isDirty;<br />
public void Persist(IPersistStuff persistStuff)<br />
{<br />
   if (isDirty)<br />
      PersistMyClass(this);<br />
   isDirty = false;<br />
}<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://benreichelt.net/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/comment-page-1/#comment-622</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Wed, 18 Jan 2006 14:01:21 +0000</pubDate>
		<guid isPermaLink="false">http://s194721765.onlinehome.us/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/#comment-622</guid>
		<description>It&#039;s hard to know for sure without knowing the code, but maybe something like this?:

PersistanceClass:  IPersistStuff
{
  public void PersistMyClass(MyClass class);
}

MyClass
{
   private bool isDirty;
   public void Persist(IPersistStuff persistStuff)
   {
      if (isDirty)
         persistStuff(this);
      isDirty =false;
   }
}</description>
		<content:encoded><![CDATA[<p>It&#8217;s hard to know for sure without knowing the code, but maybe something like this?:</p>
<p>PersistanceClass:  IPersistStuff<br />
{<br />
  public void PersistMyClass(MyClass class);<br />
}</p>
<p>MyClass<br />
{<br />
   private bool isDirty;<br />
   public void Persist(IPersistStuff persistStuff)<br />
   {<br />
      if (isDirty)<br />
         persistStuff(this);<br />
      isDirty =false;<br />
   }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: johnwood</title>
		<link>http://benreichelt.net/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/comment-page-1/#comment-621</link>
		<dc:creator>johnwood</dc:creator>
		<pubDate>Wed, 18 Jan 2006 13:03:50 +0000</pubDate>
		<guid isPermaLink="false">http://s194721765.onlinehome.us/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/#comment-621</guid>
		<description>Ben,
You can implement Scott&#039;s suggestion in .Net 1.1 simply by having two methods to get and set the field rather than a property. Just make the setter method internal and the getter method public.

John W</description>
		<content:encoded><![CDATA[<p>Ben,<br />
You can implement Scott&#8217;s suggestion in .Net 1.1 simply by having two methods to get and set the field rather than a property. Just make the setter method internal and the getter method public.</p>
<p>John W</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: breichelt</title>
		<link>http://benreichelt.net/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/comment-page-1/#comment-620</link>
		<dc:creator>breichelt</dc:creator>
		<pubDate>Wed, 18 Jan 2006 11:08:16 +0000</pubDate>
		<guid isPermaLink="false">http://s194721765.onlinehome.us/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/#comment-620</guid>
		<description>wow, lots of comments

Scott &amp; John: I didnt know that you could selectively place the internal keyword on getters and setters like that in .net 2.0.  Unfortunately, this is .net 1.1, and, for that matter, the classes are not in the same assembly.  The persistor is part of the common base assembly, and the dto is a business object, in another assembly.  Good tidbit to know though.

Jeremy: thats a good idea, one that I will explore

Craig: I also like your suggestion, it seems pretty easy, I&#039;ll have to see if it would be viable, may have to make a new interface, which is no big deal</description>
		<content:encoded><![CDATA[<p>wow, lots of comments</p>
<p>Scott &#38; John: I didnt know that you could selectively place the internal keyword on getters and setters like that in .net 2.0.  Unfortunately, this is .net 1.1, and, for that matter, the classes are not in the same assembly.  The persistor is part of the common base assembly, and the dto is a business object, in another assembly.  Good tidbit to know though.</p>
<p>Jeremy: thats a good idea, one that I will explore</p>
<p>Craig: I also like your suggestion, it seems pretty easy, I&#8217;ll have to see if it would be viable, may have to make a new interface, which is no big deal</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://benreichelt.net/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/comment-page-1/#comment-619</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Wed, 18 Jan 2006 10:45:49 +0000</pubDate>
		<guid isPermaLink="false">http://s194721765.onlinehome.us/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/#comment-619</guid>
		<description>I second Scott&#039;s suggestion of the internal setter; hopefully they share an assembly...</description>
		<content:encoded><![CDATA[<p>I second Scott&#8217;s suggestion of the internal setter; hopefully they share an assembly&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://benreichelt.net/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/comment-page-1/#comment-618</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Wed, 18 Jan 2006 10:19:18 +0000</pubDate>
		<guid isPermaLink="false">http://s194721765.onlinehome.us/blog/2006/01/18/only-allowing-certain-types-to-set-a-property/#comment-618</guid>
		<description>I&#039;d use:

public bool IsDirty
{
    get { return _isDirty; }
    internal set { _isDirty = value; }
}

(C# 2.0 only). Now I&#039;ve restricted the setter visibility to types inside the same assembly. This may be restrictive enough for you depending on where the Persistor and other types live....</description>
		<content:encoded><![CDATA[<p>I&#8217;d use:</p>
<p>public bool IsDirty<br />
{<br />
    get { return _isDirty; }<br />
    internal set { _isDirty = value; }<br />
}</p>
<p>(C# 2.0 only). Now I&#8217;ve restricted the setter visibility to types inside the same assembly. This may be restrictive enough for you depending on where the Persistor and other types live&#8230;.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
