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

%d bloggers like this: