Is it getting to be time for C# to support compile-time macros?
Posted
by Robert Rossney
on Stack Overflow
See other posts from Stack Overflow
or by Robert Rossney
Published on 2010-04-26T17:27:23Z
Indexed on
2010/04/26
17:33 UTC
Read the original article
Hit count: 216
Thus far, Microsoft's C# team has resisted adding formal compile-time macro capabilities to the language. There are aspects of programming with WPF that seem (to me, at least) to be creating some compelling use cases for macros.
Dependency properties, for instance. It would be so nice to just be able to do something like this:
[DependencyProperty]
public string Foo { get; set; }
and have the body of the Foo
property and the static FooProperty
property be generated automatically at compile time. Or, for another example an attribute like this:
[NotifyPropertyChanged]
public string Foo { get; set; }
that would make the currently-nonexistent preprocessor produce this:
private string _Foo;
public string Foo
{
get { return _Foo; }
set { _Foo = value; OnPropertyChanged("Foo"); }
}
You can implement change notification with PostSharp, and really, maybe PostSharp is a better answer to the question. I really don't know.
Assuming that you've thought about this more than I have, which if you've thought about it at all you probably have, what do you think? (This is clearly a community wiki question and I've marked it accordingly.)
© Stack Overflow or respective owner