SharpCrafters Forum – Propagate INotifyPropertyChanged + multi Inheritance

SharpCrafters Support Forum

        


Propagate INotifyPropertyChanged + multi... Expand / Collapse
Author
Message
Posted 8/25/2009 12:14:27 PM


Community Member
Hello,

Thank you for your powerfull product, I begin testing  PostSharp and before integrate it in our project, I have 2 cases where I need some help.

I.
One interface:
public interface IStreamable : INotifyPropertyChanged
{
int A;
int B;
}


in same assembly or in another:

[NotifyPropertyChanged ]
public class StreamObj : IStreamable
{
public int A {get;set;}
public int B {get;set;}
}


Howto doing this or similar with PostSharp?
II. And another question, howto have multi Inheritance without Interface opposit to SimpleCompositionAttribute ?

in assembly 1:
public class AClass
{
public int A {get;set;}
}

public class BClass
{
public int B {get;set;}
}

[Compose(A)]
[Compose(B)]
public class CClass
{
public int B {get;set;}
}

where Compose inherit from CompositionAspect, and get directly Properties from A and B.

and in Assembly 2:
main()
{
var c = new CClass();
c.A = 3;
c.B = 4;
}

to resume II is it possile to create a compositionAspect from 2 class and get there properties public in a second assembly (I think is not possible in Assembly 1)  ?

Thank you for your help,

if this 2 case is possible, We can use postsharp in our real entreprise project.

Best regards,

Alexandre Richonnier
Post #2383
Posted 8/25/2009 12:18:11 PM


Gael Fraiteur

SharpCrafters
I.

I don't understand what you mean there. Are you looking for an aspect implementing INotifyPropertyChanged? There is an example in the sample PostSharp.Samples.Binding.

II.

This is not possible, because the CLR does not support multiple inheritance of classes. It only support multiple inheritance of interfaces.

-gael
Post #2384
Posted 8/25/2009 1:05:30 PM


Community Member
I.

I don't understand what you mean there. Are you looking for an aspect implementing INotifyPropertyChanged? There is an example in the sample PostSharp.Samples.Binding.


No, I have seen it, but in my exemple, my code will not compile, because "StreamObj" does not implement INotifyPropertyChanged. I would like to know if we can fix it.
why to do like that:

if we use sample PostSharp.Samples.Binding, like that

public interface IStreamable
{
int A;
int B;
}

[NotifyPropertyChanged ]
public class StreamObj : IStreamable
{
public int A {get;set;}
public int B {get;set;}
}

[NotifyPropertyChanged ]
public class Stream2Obj : IStreamable
{
public int A {get;set;}
public int B {get;set;}
}

[NotifyPropertyChanged ]
public class Stream3Obj : IStreamable
{
public int A {get;set;}
public int B {get;set;}
}

BindingList<IStreamable> streamlist = new ...;  

list.Add(new StreamObj());
list.Add(new Stream2Obj());
list.Add(new Stream3Obj());
...


StreamObj, Stream2Obj, Stream3Obj implement INotifyPropertyChanged, it's ok, but when you bind streamlist to a datagrid, changed is not apply on PropertyChanged because IStreamable doesn't not implement INotifyPropertyChanged, that is my question. Howto solve this problem.



II.

This is not possible, because the CLR does not support multiple inheritance of classes. It only support multiple inheritance of interfaces.

-gael


I know that the CLR does not support multiple inheritance of classes, that why I want simulate it with AOP to avoid manual composit pattern.
I would like to know if Postsharp Laos can do a composition aspect like "SimpleCompositionAspect" but without interface, directly by taking properties list and  inject them into class with public modifier and at least visible in an other assembly.

Thanks for your quick reply,

Alexandre
Post #2385
Posted 8/25/2009 1:07:55 PM


Gael Fraiteur

SharpCrafters
INotifyPropertyChanged: you can use ComposeAspect, isn't it?

Composing types: PostSharp 2.0 will allow something closer to that.

-g
Post #2386
Posted 8/25/2009 1:57:27 PM


Community Member
INotifyPropertyChanged: you can use ComposeAspect, isn't it?


I have test :

public interface IStreamable : INotifyPropertyChanged
{
int A;
int B;
}

[NotifyPropertyChanged]
   [SimpleComposition(typeof(IStreamable), typeof(StreamObj))]
   public class StreamObj
{
public int A {get;set;}
public int B {get;set;}
}

I have implemented A and B in StreamObj because in real case I make some treatments in properties. The result is
"error -- Duplicate method declaration" --> because SimpleComposition try to implement A and B but it's already implemented.
I have try to add
CompositionAspectOptions GetOptions(){return  CompositionAspectOptions.GenerateImplementationAccessor |
               CompositionAspectOptions.IgnoreIfAlreadyImplemented;}

in SimpleCompositionAttribute, but it change nothing.

then can you give me a track to resolve this use case please ?



Composing types: PostSharp 2.0 will allow something closer to that.
-g

It's a secondary use case, we can wait 2.0.

Thanks,

Alexandre
Post #2387
Posted 8/25/2009 2:01:35 PM


Gael Fraiteur

SharpCrafters
I see, you have a conflict between NotifyPropertyChanged and Compose.
PostSharp 1.5 is not that smart to handle that (actually it does detect the potential problem, but it is not able to solve it). PostSharp 2.0 has a mechanism that let you order aspects (say which has precendence, so which will implement INotifyPropertyChanged).

-gael
Post #2388
Posted 8/25/2009 2:13:06 PM


Community Member
Ok, thank you for all your replies,
To begin, We will probably use PostSharp for small use cases like implementation of INotifyPropertyChanged in <!-- m --><a class="postlink" href="http://codepaste.net/3h4uqp">http://codepaste.net/3h4uqp</a><!-- m --> , log and parameter checking.

We are impatient to see the innovations of version 2.

Best regards,

Alexandre
Post #2389
« Prev Topic | Next Topic »


All times are GMT +1:00, Time now is 1:50am

Powered By InstantForum.NET v4.1.4 © 2010
Execution: 0.035. 11 queries. Compression Disabled.