Archive

Posts Tagged ‘Suggestion’

Suggestion: add optional “where” clause to “foreach” statement in C#

Wouldn’t it be nice if I could use in C# the following syntax?

for (SomeType repeaterVariable

      in SomeEnumerable

      where someBooleanExpressionOfRepeaterVariable)

  doSomethingUsingRepeaterVariable;

e.g. use this one:

image

instead of this one:

image

BTW, if you wonder what FixTime does, it prepends 0: to time strings to make sure they are of format h:m:s.f

Have added this as a comment to another person’s suggestion that I see has similar format, so please vote for that one:

https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/7474789-add-condition-to-foreach-in-statement

Categories: Posts Tags: , , , , ,

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

Suggestion: If and while etc. clauses should accept bool? in C#

At TrackingCam app (http://TrackingCam.codeplex.com) I have the following WPF code, where cbTrackingPresenter is a CheckBox control defined in my MainWindow’s XAML:

private void cbTrackingPresenter_Checked(object sender, RoutedEventArgs e)
{
      if (cbTrackingPresenter.IsChecked == true)
          StartTrackingPresenter();
      else
          StopTrackingPresenter();
}

Note the (redundant in my opinion) == true pattern used there. If the == true is omitted, you get the compile-time error "CS0266", with message "Cannot implicitly convert type ‘bool?’ to ‘bool’. An explicit conversion exists (are you missing a cast?)"

Why not make the "if" clause (and "while" and any clause accepts a boolean/condition) more clever and have it accept bool? too? It would only fire the condition if the value is "true" (not if it is false or null) in that case.

You can vote for this suggestion at:

http://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/11038227-if-should-accept-bool

Suggestion: Add Fullscreen and Pin buttons on Titlebar of Windows

Here are some suggestions I’ve sent via Windows Insider feedback app for Windows 10:

1) Add the Fullscreen button to titlebar of ALL windows, not just the ones of Windows 8.1 Store apps. UWP (Universal Windows Platform) apps don’t seem to show zoom button on their titlebar (to make it and any borders autodisappear and take up the whole screenspace) – this is very inconsistent and limiting compared to Win8.1 Store apps.

2) Add a Pin button next to zoom/minimize/restore/close buttons on titlebar of a window to make the window stay on top. User should be able to click a pinned window to bring it to front if there are several ones pinned to top. Currently some tools apps (e.g. task manager) have such functionality, but it is in their menus. It would be handy if all apps had this.
 
Take care though that any windows that are children (modal or not) of a pinned window also appear on top (pinned) and not behind the app. So a user should be able to pin a child window independently, but when a window is pinned, all its child windows should become pinned with the pin button disabled on them till the parent window is unpinned, or instead better make the pin of the child window be linked to the pin of the parent so that the user can pin/unpin the parent and all child windows from the titlebar pin of anyone of them.

An issue may occur with some programs like TeamViewer that add an extra button on the titlebar of Windows, but they could easily fix their code to see what other buttons there are on the titlebar to not overlap with them (or some compatibility code of Windows could move such buttons a bit more to not overlap in the case of legacy software that has an issue when more buttons than they expect are on the titlebar)

Categories: Posts Tags: , , , ,

Suggestion: C# static extension methods invokable on class type too

it would be nice if C# supported syntax like:

public static DependencyProperty Register(static DependencyProperty x, string name, Type propertyType, Type ownerType, FrameworkPropertyMetadata typeMetadata)

that is static extension methods for classes, that can be invoked without a class instance (just with the class type), apart from normal extension methods that can be invoked on a class instance.

Then for example I could use it in Silverlight to add to its DependencyProperty class some extra WPF syntax that it currently misses, in order to increase code portability. It would wrap Dr.WPF’s implementation of value coercion for Silverlight’s DependencyProperty. I have the related code at my Compatibility library (http://Compatibility.codeplex.com) and respective NuGet package (http://nuget.org/packages/Compatibility), but the syntactic sugar is missing to achieve source code portability (via WPF and Silverlight projects that include common files via file links) without changes.

Note the "static DependencyProperty" parameter instead of the "this DependencyProperty" one that is used in C# extension methods (or else instead of static maybe they could use other keyword like type or typeof there, but I feel static is more appropriate).

Related discussion:

http://stackoverflow.com/questions/866921/static-extension-methods

http://stackoverflow.com/questions/249222/can-i-add-extension-methods-to-an-existing-static-class

Also see https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/2060313-c-support-static-extension-methods-like-f where somebody mentions "static extension properties" apart from "extension properties". Indeed it is natural that if static extension methods are to be allowed in the future, static extension properties should be added too (to extend a type with [attached] static properties)

You can vote for a related suggestion here:

https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/2060313-c-support-static-extension-methods-like-f

Suggestion: Visual Studio should offer to implement callbacks

I type-in new PropertyMetadata(OnCenterXPropertyChanged) but since I haven’t yet implemented On…, I get a suggestion by the IDE to implement it but it suggests to add field, property or read-only field, not to implement the callback for me with the given name. It can find the method signature needed from the delegate that PropertyMetadata (one of its overloaded versions) expects.

It came to me while I was trying to implement Silverlight’s CompositeTransform for WPF:

public static readonly DependencyProperty CenterXProperty = 
DependencyProperty.Register("CenterX", typeof(double),
typeof(CompositeTransform),
new PropertyMetadata(OnCenterXPropertyChanged));

for the Compatibility library I maintain at http://github.com/zoomicon/Compatibility. I have used that library a lot in ClipFlair to maintain a common C# source and XAML between Silverlight and WPF projects (I do code sharing between projects via linked files).

Can vote for this suggestion at:

http://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/10906626-offer-to-implement-callbacks

Suggestion: Initialize multiple fields to same value at constructor call in C#

When using http://github.com/zoomicon/ZUI I would like to write:

FloatingWindow window = new FloatingWindow()
{
  Content = display,
  Title = IconText = title
};

but I have to write:

FloatingWindow window = new FloatingWindow()
{
  Content = display,
  Title = title,
  IconText = title

};

instead. For consistency, I’d prefer that it supported such assignment. Now it thinks IconText is some external field or similar

 

you can vote for this suggestion at:

http://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/10904790-allow-to-initialize-multiple-fields-to-the-same-va

Suggestion: on Duck Typing and C#/.NET

My comment at:

http://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/4272089-support-implicit-interfaces-for-code-reuse

It would be nice indeed if one could define at the client object’s side a static interface that is a subset of the methods of a server (or serving if you prefer) object (it is only the view of the server that the client has gained knowledge of) that has been passed on to the client

Then there could be a service (a facility I mean) that accepts the server object instance and the interface the client has defined (the duck type) and case the server object to that interface by CHECKING that the duck interface is indeed a subset of the methods the server object implements

the check if our duck interface is indeed covered by what the object to be duck-typed offers can be implemented via reflection already

the implementation could be hacked by spitting out a new object (bytecode generation) that wraps each property/method of the object to be duck-typed and calls into the original object, but it would be much better if there was support in the compiler for that (viewing an object via an interface that is compatible to it in functionality, not in strong typing concept)

…when I say support in the compiler, I mean to avoid the proxying layer (of course security should also be considered carefully when implementing such a thing, in case there are pitfalls)

 

A very interesting article on the subject showing how to do DuckTyping in .NET is:

http://www.codeproject.com/Articles/122827/DynamicObjects-Duck-Typing-in-NET

 

Not sure if in the time that has passed (5 years) there have been any DuckTyping-specific additions at C#/.NET

Suggestion: Add support for constants in C# (and VB.net etc.) interfaces

It is rather unfortunate that C# doesn’t support constants in interfaces, whereas Java does.

If IL (intermediate language) that C# usually compiles to (when not using AOT that is like in .NET Native or Xamarin iOS) doesn’t support this, then the compiler could create a special sealed class to carry the constants.

Then, wherever they’re used via the interface it could get them via that class. This would happen internally without the programmer noticing. The programmer should be able to access the constants using:

ISomeInterface.SomeConstant

SomeClass.SomeConstant, where SomeClass implements ISomeInterface

just SomeConstant when the code is inside the body of SomeClass that implements the ISomeInterface

just SomeConstant when there is a “using static” statement (that newer C# has introduced) like “using static ISomeInteface” or “using static ISomeClass”

image

You can vote up this suggestion at:
http://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/10724265-add-support-for-constants-in-c-and-vb-net-etc

Suggestion: Introduce .= operator for C#

It would be nice if one could write in C# (and maybe in other .NET languages too):

s = s.SomeMethodOfS(…)…

as

s .= SomeMethodOfS(…)…

that is to have a .= operator, similar to += and other shorthand experession operators

see screenshot for an example usecase from the opensource project FoscamController

image

Ideally, usage of such operators should lead to compiling – whether is is via JIT (Just in Time) or AOT (Ahead of Time) compilation – into more optimized native code, but I’m not sure if C# compilers are exploting that optimization opportunity.

You can vote up this suggestion at:
http://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/10724280-introduce-operator-for-c

%d bloggers like this: