I use Fody.PropertyChanged and Fody.Validar in my C# project to avoid writing boilerplate code. Let's presume I've got some class A:
[AddINotifyPropertyChanged]
[InjectValidation]
public class A { }
I have to use objects of type A in other parts of my code which require type A to implement interfaces like INotifyPropertyChanged or INotifyDataErrorInfo. There are two known ways to do it:
- Implement interfaces manually (a lot of boilerplate):
[AddINotifyPropertyChanged]
[InjectValidation]
public class A: INotifyPropertyChanged, INotifyDataErrorInfo { ... }
- Cast object of type A to required interfaces (more code, ReSharper generates warnings about suspicious casts, generic methods may break):
public static T DoSomething<T>(T arg) where T: INotifyPropertyChanged { ... }
var a = new A();
var b = DoSomething((INotifyPropertyChanged) a) // Returns INotifyPropertyChanged.
Is there any way to "tell" IntelliSense and compiler that the class implements the interface without actually implementing it and let Fody do that work?
[AddINotifyPropertyChanged]
[InjectValidation]
[Implements(typeof(INotifyPropertyChanged))]
public class A { }
var a = new A();
var b = DoSomething(a) // Returns A.