formatting comma separated parameter in vs2010 - c#

i have a code like this
void method1(param1
,param2
,param3){...}
but when i press ctrl+k , ctrl+d to reformat the class, it will be formatted as flow
void method1(param1
,
param2
,
param3){...}
i know that it will be fix if i put the comma after param Name but i really want it to be before param Name. how can i inform the auto format future of vs2010 to format my method as follow:
void method1(param1
,param2
,param3){...}

Tools > Options > Text Editor > C# > Formatting
if you use resharper loot at here

Have a look at ReSharper you can configure how you want application tidy-ups to be run (along with providing some other useful features).

Related

Is there any way to automatically add many properties on VS2019?

Don't judge me, but I have an object with over 100 properties, most of them string.
Is there anyway to automatically add them to the code, without extensive typing?
I have them all in a text file with correct casing. I looked for plug ins, but couldn't find any (maybe using wrong keywords?)
I am assuming your file looks like:
Property
SomeOtherProperty
Test
The easiest way would be to use a CSV -> C# Model generator
Steps
Change it to be comma separated, you can do this with C#:
var path = #"C:\Path\To\Your\File.txt";
var text = File.ReadAllText(path);
text = text.Replace(Environment.NewLine, ",");
File.WriteAllText(path, text);
Open the file and copy its contents to your clipboard.
Now open the C# Class from CSV tool.
Paste the contents and voila you have a C# model!
Notepad++ can do it quite easily.
Open your text file with notepad++ and press Ctrl+H
Fill in the fields like below:
search for (.*)
replace with public string \1 {get;set;}
tick "regular expression"
press "Replace all"
And voilà:
Note that this should work with any editor that handle regex (as stated by #Klamsi in the comments section)

Named format placeholders in ReSharper annotations?

ReSharper has the fantastic StringFormatMethodAttribute annotation which provides code analysis for format strings and their parameters. It can be added to any custom string format methods like this:
[StringFormatMethod("format")]
void DebugFormat(string format, params object[] args);
This works well when using integer placeholders, e.g.:
x.DebugFormat("ReSharper is {0} for {1} placeholders", "great", "numbered");
However, some libraries (like Serilog and ASP.Net Core / Microsoft.Extensions.Logging) offer named format placeholders which are used for (semantic | structured) logging and this seems to be something that ReSharper does not (yet) offer. For example, a line of code like this:
x.DebugFormat("ReSharper is {Quality} for {Style} placeholders", "poor?", "named");
Results in the ReSharper code analysis warning
Format item index must be a number starting 0 without leading or trailing whitespaces
Searching on ReSharper support, this site, and Google draws a blank. Has anyone found a way to get string format annotations working with named placeholders?
Relevant JetBrains links:
ReSharper help on StringFormatMethodAttribute
ReSharper help on custom string formatting methods
I have implemented an R# extension for this. Download it here from JetBrains.
It is also hosted on GitHub.
This extension highlights structured logging templates and contains some useful analyzers. Here is how the structured logging events look with the plugin installed:

replace a string if it Contains Format in c#

I´m developing a Quality Management software to show Errors of a Provisioning tool.
therefore I read all errors from an XML and group them
but there are errors like: "Forcedtime 1.08.2016 17:51:00 is in the past"
Is It possible to find Date-Values like this in a string and delete them ?
I can't work with a hard coded replace cause there are many different values for the Date Time.
Thanks for helping me
Yet another suggestion is to read the XML as such and discard the nodes you don't like/need. Then process only the nodes left.
In fact, while the Regex will do the trick for replacing something in the text, it might not be a good fit since this is structured data as opposed to bunch of data in a string format.
(0?[1-9]|[12][0-9]|3[01])\.(0?[1-9]|1[0-2])\.(\d{4}) (00|[0-9]|1[0-9]|2[0-3]):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9])
It checks for date time 1.08.2016 17:51:00.
You have to compare this date format in your string if matches then replace it
Try to learn reg exp

C# replace certain string when typing in any application

I want to make an application that will replace a certain string when I type in any textfield of any application (online textboxes, notepad, word, email, etc..)
For example if I'm writing in notepad++ and I type [for] and press space or enter I want my C# application to work in background, access the field and replace that string with a predefined string in my C# code.
The result would for example be:
for($i = 0; $i < X; $i++)
{
// ....
}
For example if I'm writing a word document and I input [FIRSTPAGE] I would want that to be replaced with a random string I setup early.
Later on I will setup an app that will let me change these on the fly.
I tried searching google but I found no information on anything similar.
I just need to find a way to replace a string in any textfield.
Hope this makes sense. Thanks for your help.
Create a global keyboard hook, C# : Keyboard Hook shows how you can do it.
Once hook is created monitor handle the keylog for typed word. Once the typed word is found use SendKeys to send keystrokes virtually.
There's a really cool library called Scintilla.NET - http://scintillanet.codeplex.com/
It's usually used for building your own code editor with syntax highlighting support.
But it has the auto-suggest feature you are after, i.e:

How do I see the hex values of a string in a VS2008 watch window?

I have a string in a watch window in VS2008 and want to see the hex representation of each character. If I right click there's a hexadecimal option but this doesn't appear to do anything. Anybody know how to view the string as a series of hex values?
Add your string as a watch, then edit the watch expression and append ".ToCharArray()" to view it as an array of chars. When you expand your watch you will see char code next to each individual char. Checking "Hexadecimal display" will show you hex codes for each character.
Default visualizer in VS (at least 2005) does not support this. However, apparently it isn't too much trouble to roll one's own visualizer: http://msdn.microsoft.com/en-us/library/ms379596.aspx (That's an old article from 2005 beta times, but I don't think the API changed much.)
Perhaps somebody somewhere even wrote one, but I haven't seen one yet.

Categories

Resources