Replies: 1 comment 1 reply
-
Interesting. There are a couple of things that I think will make this a bit tricky: The first is that when the source generator runs, public bool ChildValue
{
get
{
var child = this.Child;
// Other stuff
return child.Value;
}
} Partial properties (dotnet/csharplang#3412) would make this a lot better, as the compiler would be able to bind the IL weavers don't have this problem as bad, as they're working on IL (which is fully bound). PostSharp will still need to keep track of where intermediate variables came from as in my example above, though, which isn't simple. Another issue is that I want PropertyChanged.SourceGenerator to be purely a code generator: I don't want the user to have to add references to DLLs. This means that I can't do something like introduce an I'm tempted to let this one stew for a while: if we ever get partial properties that will make this significantly easier. |
Beta Was this translation helpful? Give feedback.
-
Note that I do not know how it would be done or how complex it would be to implement in this source generator.
But the general idea would be to support something like this:
So basically, right now the source generator will only make it so when the
Child
property onParent
changes, then there is a notification thatChildValue
has changed, but if theValue
property on the child gets changed, there is no notification thatChildValue
has changed.There are many ways I have seen to get around this, such as manually hooking into
Child
'sPropertyChanged
event fromParent
(which could be an issue if theChild
property ofParent
changes as assumed above and needing to manually unhook from thePropertyChanged
even later) or wrapping theParent
instance in a class that can catch child property changes (I used the classes from https://gist.github.com/thojaw/705450 and they do seem to work) or possibly using a proxy class of some sort.PostSharp's INPC support seems to use its own
INotifyChildPropertyChanged
interface to facilitate this, but I'm trying to get away from PostSharp for this. I don't know exactly what their implementation does but just trying to look at it via a decompiler such as ILSpy makes it seem rather complex and possibly incurring a run-time overhead in addition to a compile-time overhead.If this seems out of scope for this source generator, I understand. It seems like a rather complex scenario and I don't know enough about source generators to know if this sort of thing is possible with them or not.
Beta Was this translation helpful? Give feedback.
All reactions