Validator examples, C# version of INotifyPropertyChanged
9 posts • Page 1 of 1
Validator examples, C# version of INotifyPropertyChanged
Hi I recently found your PostSharp project and I think it is very inspiring!
My name is Peter. I would like to share my code with you.
I have been working on property validators, and a C# implementation of INotifyPropertyChanged.
Examples of my code can be found on my blog at the following two links:
http://www.acceptedeclectic.com/2008/01 ... -dont.html
http://www.acceptedeclectic.com/2008/01 ... pport.html
My INotifyPropertyChanged code originated from the VB examples on your user samples project on google code. I removed the IEditable functionality because it did not integrate with the other enhancers that I have written.
I am very new with PostSharp, and I would like to verify that I am using your library correctly.
Would you like my code in your user samples project?
My name is Peter. I would like to share my code with you.
I have been working on property validators, and a C# implementation of INotifyPropertyChanged.
Examples of my code can be found on my blog at the following two links:
http://www.acceptedeclectic.com/2008/01 ... -dont.html
http://www.acceptedeclectic.com/2008/01 ... pport.html
My INotifyPropertyChanged code originated from the VB examples on your user samples project on google code. I removed the IEditable functionality because it did not integrate with the other enhancers that I have written.
I am very new with PostSharp, and I would like to verify that I am using your library correctly.
Would you like my code in your user samples project?
- PeteWeissbrod
- Posts: 7
- Joined: Sun Jan 20, 2008 8:49 pm
- Full Name: Peter Weissbrod
Re: Validator examples, C# version of INotifyPropertyChanged
Peter,
Of course you are welcome to contribute with your code samples! Just communicate me your Google Account ID and I will make you a member.
I have a question however -- maybe a stupid one. The VB sample you found is basically a translation in VB of a sample that is installed with PostSharp. What is your sample different in? I would like to avoid different samples of basically the same thing.
As for other samples, it's of course not a problem to publish it.
Gael
Of course you are welcome to contribute with your code samples! Just communicate me your Google Account ID and I will make you a member.
I have a question however -- maybe a stupid one. The VB sample you found is basically a translation in VB of a sample that is installed with PostSharp. What is your sample different in? I would like to avoid different samples of basically the same thing.
As for other samples, it's of course not a problem to publish it.
Gael
Gael Fraiteur, project leader
got good support? consider donating to the project.
got good support? consider donating to the project.
- gfraiteur
- Site Admin
- Posts: 608
- Joined: Tue Dec 18, 2007 3:09 pm
- Full Name: Gael Fraiteur
- Company: postsharp.org
Re: Validator examples, C# version of INotifyPropertyChanged
Thanks for the fast reply. I was using your VB example of "SupportDataBinding" from google code. I translated this into C#, then I used it in a business object like:
Your code example of SupportDataBindingAttribute works correctly, when it is alone. When I add my own enhancers such as the "Logger" or "NotNullValidator", I have some problems with the IEditableObject feature. The EditableObjectImplementation.FirePropertyChangedForAll() method can throw a SecurityException when I call CancelEdit().
I believe this is the problem line:
My reflection knowledge is weak, but it seems to me that "InstanceCredentials.Null" are not good enough credentials to access the INotifyPropertyChanged functionality at runtime if I add my own enhancers.
Here is an example of one of my validators:
I would like to try this again with the "installed" version of [SupportDataBinding].
I cannot find it. Tell me, which namespace is this [SupportDataBinding] attribute defined?
Later this evening, I am going to test PostSharp's behavior with the DynamicProxy functionality of NHibernate, this is important to me because all of my business object persistence is managed by NHibernate which relies heavily on reflection. I will be able to give you some feedback on this very soon, if you are interested.
- Code: Select all
[SupportDataBinding]
public class SomeBusinessObject
{
#region members
private string m_Name;
#endregion
#region properties
[NotNullValidator]
[Logger( LogOnEntry = true, LogOnException = true, LogOnSuccess = true)]
[StringLengthValidator(MinLength = 1,MaxLength = 10)]
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}
#endregion
#region methods
public SomeBusinessObject(string name)
{
m_Name = name;
}
#endregion
}
Your code example of SupportDataBindingAttribute works correctly, when it is alone. When I add my own enhancers such as the "Logger" or "NotNullValidator", I have some problems with the IEditableObject feature. The EditableObjectImplementation.FirePropertyChangedForAll() method can throw a SecurityException when I call CancelEdit().
I believe this is the problem line:
- Code: Select all
myINotifyPropChangedImpl = DirectCast(mixIns.GetImplementation(Nothing), NotifyPropertyChangedImplementation)
My reflection knowledge is weak, but it seems to me that "InstanceCredentials.Null" are not good enough credentials to access the INotifyPropertyChanged functionality at runtime if I add my own enhancers.
Here is an example of one of my validators:
- Code: Select all
[Serializable]
public class NotNullValidator : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionEventArgs eventArgs)
{
//ignore calls that have no arguments, they come from reflection
if (eventArgs.GetArguments() == null)
return;
//ignore anything that isnt a setter
if (!eventArgs.Method.Name.StartsWith("set_"))
return;
if (eventArgs.GetArguments()[0] == null)
throw new ArgumentNullException(eventArgs.Method.Name);
base.OnEntry(eventArgs);
}
}
I would like to try this again with the "installed" version of [SupportDataBinding].
I cannot find it. Tell me, which namespace is this [SupportDataBinding] attribute defined?
Later this evening, I am going to test PostSharp's behavior with the DynamicProxy functionality of NHibernate, this is important to me because all of my business object persistence is managed by NHibernate which relies heavily on reflection. I will be able to give you some feedback on this very soon, if you are interested.
- PeteWeissbrod
- Posts: 7
- Joined: Sun Jan 20, 2008 8:49 pm
- Full Name: Peter Weissbrod
Re: Validator examples, C# version of INotifyPropertyChanged
I have some compile-time validator attributes written. This is .NET 3.5, but the code should run fine in earlier versions.
There general usage is attributes for setters of various properties.
I am uncertain of one thing in my code:
Am I using Compile-Time validation correctly?
I dont know. This is why my test cases fail for the SqlDateTimeValidator. Hopefully, with a bit of your help we can add it to the user samples project.
My apologies about the broken references, the forum only allows upload files of size 256K
There general usage is attributes for setters of various properties.
I am uncertain of one thing in my code:
Am I using Compile-Time validation correctly?
I dont know. This is why my test cases fail for the SqlDateTimeValidator. Hopefully, with a bit of your help we can add it to the user samples project.
My apologies about the broken references, the forum only allows upload files of size 256K
You do not have the required permissions to view the files attached to this post.
- PeteWeissbrod
- Posts: 7
- Joined: Sun Jan 20, 2008 8:49 pm
- Full Name: Peter Weissbrod
Re: Validator examples, C# version of INotifyPropertyChanged
Hi Peter,
It is not my code! I don't even verify it completely.
The best way to share and modify code is to use the project http://code.google.com/p/postsharp-user-samples/. If you tell me your google account id (gmail), I could make you a member and you could upload your samples!
Cheers,
Gael
I was using your VB example of "SupportDataBinding" from google code.
It is not my code! I don't even verify it completely.
The best way to share and modify code is to use the project http://code.google.com/p/postsharp-user-samples/. If you tell me your google account id (gmail), I could make you a member and you could upload your samples!
Cheers,
Gael
Gael Fraiteur, project leader
got good support? consider donating to the project.
got good support? consider donating to the project.
- gfraiteur
- Site Admin
- Posts: 608
- Joined: Tue Dec 18, 2007 3:09 pm
- Full Name: Gael Fraiteur
- Company: postsharp.org
Re: Validator examples, C# version of INotifyPropertyChanged
Understood. my google account is talktopete.
- PeteWeissbrod
- Posts: 7
- Joined: Sun Jan 20, 2008 8:49 pm
- Full Name: Peter Weissbrod
Re: Validator examples, C# version of INotifyPropertyChanged
You are a project member
.
Gael Fraiteur, project leader
got good support? consider donating to the project.
got good support? consider donating to the project.
- gfraiteur
- Site Admin
- Posts: 608
- Joined: Tue Dec 18, 2007 3:09 pm
- Full Name: Gael Fraiteur
- Company: postsharp.org
Re: Validator examples, C# version of INotifyPropertyChanged
Thanks, everything is committed for now. Do let me know if theres anything else I can do to help.
Otherwise, I am working on a Authorization security-based Attribute in the near future, so I will see you again.
Otherwise, I am working on a Authorization security-based Attribute in the near future, so I will see you again.
- PeteWeissbrod
- Posts: 7
- Joined: Sun Jan 20, 2008 8:49 pm
- Full Name: Peter Weissbrod
Re: Validator examples, C# version of INotifyPropertyChanged
Ok, thank you!
Gael Fraiteur, project leader
got good support? consider donating to the project.
got good support? consider donating to the project.
- gfraiteur
- Site Admin
- Posts: 608
- Joined: Tue Dec 18, 2007 3:09 pm
- Full Name: Gael Fraiteur
- Company: postsharp.org
9 posts • Page 1 of 1