Home > Posts > Suggestion: Define once and reuse result type of method inside its body

Suggestion: Define once and reuse result type of method inside its body

It would be nice if one could rewrite this C# snippet:

public SortedDictionary<string, UObject> GetObjects()
{
SortedDictionary<string, UObject> result = new SortedDictionary<string, UObject>();
using (ReadTransaction xact = namingSchema.ReadTransaction())
foreach (ObjectName.RowType row in ObjectName.object_name_(xact))
result.Add(row.name_, row.object_);
return result;
}

 

in a more concise form like:

 

public T GetObjects() where T=SortedDictionary<string, UObject>
{
T result = new T();
using (ReadTransaction xact = namingSchema.ReadTransaction())
foreach (ObjectName.RowType row in ObjectName.object_name_(xact))
result.Add(row.name_, row.object_);
return result;
}

 

In case you wonder what this code is doing, it is getting Ubisense objects and their names, for the whole sample see http://UbisensePositioning.codeplex.com

You can vote on this suggestion at:

http://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/10724304-define-once-and-reuse-result-type-of-method-inside

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: