PC Review


Reply
Thread Tools Rate Thread

Catching "set" operations for exposed reference types (enlist for processing in transaction)

 
 
Anders Borum
Guest
Posts: n/a
 
      7th Feb 2006
Hello!

I was looking at marking objects with a changed state, once properties have
been changed. The reason behind this is, that I would like to enlist such
objects for processing in a transaction.

The example below illustrates a sample pattern, which is fine when exposing
simple value types.

However, when exposing reference types, it becomes really hard (if not
impossible) to determine if changes to the state of the original object are
made. I have been looking at the implementation details of .NET framework
classes such DataColumn etc., but those only expose value types.

My fealing is that, unless the exposed reference exposes "change" events,
you are blind to any calls (hence potential changes) made to that reference.

I see several answers of catching "set" operations/marking state:

1. Custom Attributes (means calling messages through sinks; slows
performance significantly; inherit from MarshalByRefObject)

2. If using reference types, only use types with "change" events such as
XmlDocument (or your own custom reference types).

3. Don't use reference types - provide developers with parser classes and
ask them to "set" the parsed value as value type back to the original
object.

4. An explicit call to a CmsObject.Enlist() method, that asks the developer
to manually enlist the object for processing. This might look like a good
design, but it asks the developer to remember calling the method (and adds
to the number of code lines - I could provide both: AutoEnlist and manual
using .Enlist())..

5. Your suggestion?

class CmsObject
{
private string _name;
private NodeState _state = NodeState.Unchanged;

public string Name
{
get { return this._name; }
set
{
this._name = value;
this.OnChange();
}
}

private void OnChange()
{
this._state = NodeState.Changed;
}
}

This exercise is mostly for fun; I've been thinking about this for quite
some time and we've had some great discussions on how to implement this with
the current options in .NET (also compared it to other programming
environments).

I am looking for comments on patterns and suggestions, as some of you
hopefully have been doing things like this lots of times :-)

--
Venlig hilsen
Anders Borum / SphereWorks
Microsoft Certified Professional (.NET MCP)



 
Reply With Quote
 
 
 
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      7th Feb 2006

"Anders Borum" <(E-Mail Removed)> wrote in message
news:%23%23Ow0y%(E-Mail Removed)...
> Hello!
>
> I was looking at marking objects with a changed state, once properties
> have been changed. The reason behind this is, that I would like to enlist
> such objects for processing in a transaction.


I would suggest a IChanged interface , it should be easier later to treat
different types in the same way.


> However, when exposing reference types, it becomes really hard (if not
> impossible) to determine if changes to the state of the original object
> are made. I have been looking at the implementation details of .NET
> framework classes such DataColumn etc., but those only expose value types.



You are right it's not possible, not without the colaboration of the
referenced type (if it does implement IChanged is easier )


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


 
Reply With Quote
 
Anders Borum
Guest
Posts: n/a
 
      7th Feb 2006
Hello!

> I would suggest a IChanged interface , it should be easier later to treat
> different types in the same way.


I am already providing the relevant "change" members in a shared baseclass
that all "changeable" classes implement.

> You are right it's not possible, not without the colaboration of the
> referenced type (if it does implement IChanged is easier )


I am also doing this already, but was wondering if I had missed something.

Thanks for the suggestions Ignacio!

--
Venlig hilsen
Anders Borum / SphereWorks
Microsoft Certified Professional (.NET MCP)


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass by Reference as "essential" to swap method exposed as a lie raylopez99 Microsoft C# .NET 21 16th Oct 2008 05:24 PM
Transaction Processing Combing Record Types banker123 Microsoft Access Queries 2 25th May 2007 07:35 PM
What is the best practice to execute multiple "nonQuery" SQL operations in a transaction ? TheSteph Microsoft C# .NET 1 16th Jun 2006 04:59 PM
"Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction." Ollie Riches Microsoft C# .NET 3 11th Mar 2005 05:23 PM
"Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction." Ollie Riches Microsoft ADO .NET 3 11th Mar 2005 05:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:04 PM.