Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should extension properties be added to C# 4.0? [closed]

Tags:

c#

I've wanted this for fluent interfaces. See, for example this Channel9 discussion. Would probably require also adding indexed properties.

What are your thoughts? Would the advantages outweigh the "language clutter"?

like image 870
lightw8 Avatar asked Sep 26 '08 04:09

lightw8


People also ask

Does C# have extension properties?

C# already supports extension methods which allow for extending existing objects without altering the core contract/shape in any way, which provides a lot of benefit in when trying to add helper, convention, fluent style additions to a given type.

What are extension properties?

Extension properties are values associated with the extension. They are quite similar to regular data properties, wherein you map a key of type string with a value string. The main purpose is to store data configurations for the extension.

Why do we need extension methods in C#?

In C#, the extension method concept allows you to add new methods in the existing class or in the structure without modifying the source code of the original type and you do not require any kind of special permission from the original type and there is no need to re-compile the original type.

Can you add extension methods to an existing static class?

No. Extension methods require an instance of an object.


1 Answers

Since properties are just syntactic sugar for methods, I don't see why C# should have extension methods without extension properties.

like image 186
Ben Hoffstein Avatar answered Sep 18 '22 20:09

Ben Hoffstein