Home > Posts > Suggestion: Add instance modifiers to C# (and other languages)

Suggestion: Add instance modifiers to C# (and other languages)

I’d like to be able to do

someFunctionReturningY(x){ somePropertyOfY=4; … }.DoSomething();

It should also support casting without needing parentheses in the following type of statement:

Z zzz = (Z)functionReturningY{somePropertyOfZ=…; … };

 

The same pattern should work for enums too apart from object instances. It is inspired by initializers in C#, e.g. var x = new Test(){someProperty=…}. It’s just a generalization of the same pattern.

E.g. at the following scenario I want to modify an object that GetMetadataFromUI function returns

C#SuggestionObjectModifiers1

 

and currently I’m forced to write this which is way more verbose:

C#SuggestionObjectModifiers2 

 

If you like this suggestion please vote for it at:

https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/13804794-suggestion-add-instance-modifiers-to-c-and-othe

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: