PC Review


Reply
Thread Tools Rate Thread

Context Bound Class, IMessage, Custom Attribute and Field problem

 
 
Mark
Guest
Posts: n/a
 
      21st Mar 2005
Hi,

Am trying to write custom validation attributes for public fields,
properties, methods etc. using context-bound programming.

It works fine for properties, methods, parameters etc.

But, when intercepting a Set of a public field, there appears to be an
underlying method set up; a FieldSetter, which take parameters type,
fieldname and fieldvalue.

The problem is that my Field's Custom Attributes don't seem to be
copied to the FieldSetter, so I can't determine what validation to
perform.

Can someone shed some light on this one? I'd really be most grateful


Mark.
 
Reply With Quote
 
 
 
 
Alexander Shirshov
Guest
Posts: n/a
 
      22nd Mar 2005
Mark,

In a class which implements IContextProperty you should have a method:

public IMessageSink GetObjectSink(MarshalByRefObject o, IMessageSink next)

That's probably where you create an instance of IMessageSink implementor.
You could pass o (this is your actual context-bound object) to the
constructor and save it in a field:

public IMessageSink GetObjectSink (MarshalByRefObject o, IMessageSink next)
{
return new MySink(o, next);
}

class MySink
{
MyBusinessObject obj;

public MySink (MarshalByRefObject o, IMessageSink next)
{
obj = (MyBusinessObject)o;
}
}

Now it's a piece of cake to get the attributes:

public IMessage SyncProcessMessage (IMessage msg)
{
IMethodMessage call = msg as IMethodMessage;

if(call.MethodName == "FieldGetter"){
//Get the name of the field being accessed
string fldName = (string)call.GetArg(1);

FieldInfo fld = obj.GetType().GetField(fldName);
Attribute[] attrs = fld.GetAttributes();

...

The sample is a mess, but you should get the idea.

I also tried to implement the call interception framework...


HTH,
Alexander

"Mark" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> Am trying to write custom validation attributes for public fields,
> properties, methods etc. using context-bound programming.
>
> It works fine for properties, methods, parameters etc.
>
> But, when intercepting a Set of a public field, there appears to be an
> underlying method set up; a FieldSetter, which take parameters type,
> fieldname and fieldvalue.
>
> The problem is that my Field's Custom Attributes don't seem to be
> copied to the FieldSetter, so I can't determine what validation to
> perform.
>
> Can someone shed some light on this one? I'd really be most grateful
>
>
> Mark.



 
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
Sort Datagrid bound to custom class array Ben Microsoft C# .NET 5 10th Jul 2008 11:18 PM
Apply custom attribute to page class without CodeBehind... Nathan Baulch Microsoft ASP .NET 0 25th Oct 2007 03:57 AM
Decorating a partial class with a custom attribute hardieca@hotmail.com Microsoft ASP .NET 1 17th Jul 2007 04:04 PM
FormView bound to Custom Class with Object DataSource Stuart Ferguson Microsoft ASP .NET 1 3rd Apr 2006 10:59 PM
Possible to hide a custom user class attribute from LDAP queries ? ZigZag Master Microsoft Windows 2000 Active Directory 1 18th Sep 2003 12:41 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:26 PM.