In Visual Studio 2013, is there a way to change the syntax colouring of C# method parameters?
e.g. Can I have AAA and BBB colored, but not someInt, Foo, ToString
private int MyMethod(int AAA, int BBB)
{
int someInt = new int();
someInt = AAA + BBB;
string Foo = AAA.ToString();
}
I tried going to Tools -> Options -> Environment -> Fonts and Colours -> Text Editor and changing Identifier, but this changed the coloring of just about everything (variables, methods, parameters).
ReSharper can do this.
First, check this in ReSharper options:
Then choose the color in the VS options:
End result:
I recently found this extention while looking for the same thing for TypeScript, apparently it supports C# and VisualBasic, so it may be helpful for you and anybody else looking:
Visual studio SemanticColorizer
For VS 2017 you can use.
Enhanced Syntax Highlighting by Stanislav Kuzmich
https://marketplace.visualstudio.com/items?itemName=StanislavKuzmichArtStea1th.EnhancedSyntaxHighlighting
Now you can do this in Visual Studio without any extension.
Here is VS 2022
Unfortunately, you will not find a way to colorize parameter variables with the C# language. You do have the option, however, of writing an extension to do just that. Or, you could rewrite everything in C++, where you can get your parameters colorized.
Related
The coding style that my employer uses states that the brace { should go on the same line, not the next one. Example:
class bar {
private void foo() {
if (1) {
Console.WriteLine("great");
} else {
Console.WriteLine("also great");
}
}
}
Visual Studio's default is to place braces on their own line.
How can I get Visual Studio to respect this coding style?
(I don't have 2017, but this is what I see in 2015, so it may be similar.)
Under Tools -> Options -> Text Editor -> C# -> Formatting -> New Lines, there are several options for "Place open brace on new line for <X>" (where X may be "types" or "methods", etc), as well as "Place <X> on new line", where X is "else" or "catch" or "members in anonymous types".
You can check and uncheck these boxes as required to match the style your company sets up.
In VS 2017 you can use the following Option; TextEditor -> C# -> Code Style -> Formating -> New Lines:
I believe it is called K&R style. I use JetBrains ReSharper, but it is not free.
Recently I convert some of my old codes from vb.net to C#.
I need to change all my existing codes using visual studio regular expression (find & replace dialog inside Visual studio 2010 IDE)
Find
Rows(0).Item(0).ToString()
Replace with
Rows[0][0].ToString()
that means Rows(--any--).Item(--any--).ToString()
to
Rows[--any--][--any--].ToString()
I searched a lot but I am still not able to do this.
Tip: I am using visual studio 2010
My old vb.net code is
Dim firstColumnValue As String = dataTable.Rows(0).Item("firstColumn")
Dim secondColumnValue As String = dataTable.Rows(0).Item("secondColumn")
When i am converting VB.net to C#, i got the following using this plugin, i got this.
var firstColumnValue= dataTable.Rows(0).Item("firstColumn").ToString();
var secondColumnValue = dataTable.Rows(0).Item("SecondColumn").ToString();
But i actually wants like below.
var firstColumnValue= dataTable.Rows[0]["firstColumn"].ToString();
var secondColumnValue = dataTable.Rows[0]["SecondColumn"].ToString();
That vb.net to C# conversion tool converts almost all are fine but i need the above change in almost all files.
Regex:
Rows\(([^)]*)\)\.Item\(([^)]*)\)(\.ToString\(\))
Replacement string:
Rows[\1][\2]\3
DEMO
Example:
string str = "foo bar Rows(0).Item(0).ToString() barfoo";
string result = Regex.Replace(str, #"Rows\(([^)]*)\)\.Item\(([^)]*)\)(\.ToString\(\))", "Rows[$1][$2]$3");
Console.WriteLine(result);
Console.ReadLine();
IDEONE
Find:
Rows\({([^)]*)}\)\.Item\({([^)]*)}\)(\.ToString\(\))
Replace:
Rows[\1][\2]\3
Use:
find : Rows({\d*}).Item({\d*}).ToString()
replace with : Rows[\1][\2].ToString()
and check Use Regular Expression in the search/replace window
You can use Microsoft Visual Studio to convert code from VB to C#.
You can use a free plug-ins like this one This simple plug-in for Visual Studio 2010/2012 allows you to convert VB.net code to C#
Also this regex solutions below are not so perfect. For example: a function call inside parentheses, like "foo bar Rows(0).Item(myfunc(n)).ToString() barfoo";
I'm working in a C# project and using Visual Studio 2012. When Visual Studio tries to format my code, it breaks lines and make my code look difficult to read. The original code (what looks pretty nice to read for me and my team):
if (list.Any(x => x.Type == (int) EnumType.Customer))
{
}
And when Visual Studio tries to format:
if (
list.Any(
x => x.Type ==
(int) EnumType.Customer))
{
// Other break codes
}
There are a lot of other parts where it is breaking my code. I like auto formatting for some parts, but my question is: Is there a way to disable this break lines from auto formatting in Visual Studio?*
PS: I also have ReSharper installed.
Solution for long lines:
ReSharper, menu Options → Code Editing → C# → Formatting Style → Line Breaks And Wrapping.
And disable Wrap long lines:
And it really makes me crazy!
In ReSharper's settings, in the Languages section, you can change the formatting style of your C# code. The option you're looking to disable is something along the lines of "Indent anonymous method body." You can also look through the options to further customize the formatting style to your preference.
I'm new to visual studio, so perhaps this is something easy... but I've had no luck finding how to solve this formatting issue.
I would like for VS to auto format this
int x =
5;
like this
int x = 5;
When I type this in and select 'Format Document' nothing changes.
It will also not remove unnecessary newlines such as
MyClass someClass =
new MyClass();
Any help for this would be great!
Visual studio can't fix that. You can do it with the Replace All dialog + regex if you are careful.
jgauffin is right. However you can format other items to speed up the process.
Tip for key combinations for general reformatting
Tip for using a macro to modify all files in your solution
When editing a C# source file, I type
new {
Visual Studio auto-corrects it to
new object{
Is there a way to stop this behavior?
You can configure which characters being typed commit the current intellisense selection. In Tools | Options | Text Editor | C# | IntelliSense.
Remove "{" and ensure committed by the space bar is not checked.
NB. This option is no longer present as of Visual Studio 2015.
I ran into this issue, and the answers above didn't work for me. In my case, it was caused by Resharper, and I addressed it by navigating to Resharper -> Options -> Environment -> Intellisense -> Completing Characters and adding the opening curly brace character "{" to the "Do not complete on" list for C#.
What are you typing before the new {?
I've just tried it and it auto-completes with the object type, so if I type:
Button test = new {
it becomes:
Button test = new Button{
But if I type:
var test = new {
it leaves it alone.
I haven't configured my VS2008 install in any way.
Have you checked your auto-complete options for ReSharper? I just tried this in a new (empty) class with the default ReSharper settings and couldn't duplicate it. What version of studio/ReSharper are you using?
Try typing the left brace first, then going back and typing new. VS2008 does this for me (without ReSharper) and, if I remember, this is what I do. It's less typing than deleting the inserted "object".