Skip to content

Commit

Permalink
Format codes based on .editorconfig, Part 1 (#2865)
Browse files Browse the repository at this point in the history
  • Loading branch information
nxtn authored May 6, 2020
1 parent 89cda2c commit a4cfd58
Show file tree
Hide file tree
Showing 80 changed files with 556 additions and 551 deletions.
2 changes: 1 addition & 1 deletion core/assembly/MetadataLoadContext/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Collections.Generic;
using System.Reflection;
Expand Down
2 changes: 1 addition & 1 deletion core/console-apps/HelloMsBuild/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ static void Main(string[] args)
Console.WriteLine("Hello World!");
}
}
}
}
2 changes: 1 addition & 1 deletion core/console-apps/fibonacci-msbuild/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ static int FibonacciNumber(int n)
return a;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class DiagScenarioController : ControllerBase
[Route("deadlock/")]
public ActionResult<string> deadlock()
{
(new System.Threading.Thread(() => {
(new System.Threading.Thread(() =>
{
DeadlockFunc();
})).Start();

Expand All @@ -30,7 +31,8 @@ public ActionResult<string> deadlock()
var threads = new Thread[300];
for (int i = 0; i < 300; i++)
{
(threads[i] = new Thread(() => {
(threads[i] = new Thread(() =>
{
lock (o1) { Thread.Sleep(100); }
})).Start();
}
Expand All @@ -47,7 +49,8 @@ private void DeadlockFunc()
{
lock (o1)
{
(new Thread(() => {
(new Thread(() =>
{
lock (o2) { Monitor.Enter(o1); }
})).Start();

Expand Down
2 changes: 1 addition & 1 deletion core/diagnostics/DiagnosticScenarios/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down
2 changes: 1 addition & 1 deletion core/diagnostics/DiagnosticScenarios/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down
150 changes: 75 additions & 75 deletions core/encoding/cyrillic-to-latin/cs/ConsoleModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,90 +4,90 @@

class ConsoleModule
{
static void Main()
{
string[] args = Environment.GetCommandLineArgs();
static void Main()
{
string[] args = Environment.GetCommandLineArgs();

// Get command line arguments.
if (args.Length != 3 || String.IsNullOrWhiteSpace(args[1]) || String.IsNullOrWhiteSpace(args[2]))
{
Console.WriteLine("There must be a source and a destination file.");
ShowSyntax();
return;
}
// Get command line arguments.
if (args.Length != 3 || String.IsNullOrWhiteSpace(args[1]) || String.IsNullOrWhiteSpace(args[2]))
{
Console.WriteLine("There must be a source and a destination file.");
ShowSyntax();
return;
}

string source = args[1];
string destination = args[2];
string source = args[1];
string destination = args[2];

if(!File.Exists(source))
{
Console.WriteLine("The source file does not exist.");
return;
}
if (!File.Exists(source))
{
Console.WriteLine("The source file does not exist.");
return;
}

try
{
using (var sr = new StreamReader(source))
{
// Check whether destination file exists and exit if it should not be overwritten.
if (File.Exists(destination))
try
{
using (var sr = new StreamReader(source))
{
Console.Write("The destination file {1} '{0}'{1}exists. Overwrite it? (Y/N) ",
source, Environment.NewLine);
ConsoleKeyInfo keyPressed = Console.ReadKey(true);
if (Char.ToUpper(keyPressed.KeyChar) == 'Y' | Char.ToUpper(keyPressed.KeyChar) == 'N')
{
Console.WriteLine(keyPressed.KeyChar);
if (Char.ToUpper(keyPressed.KeyChar) == 'N')
return;
}
}
using (var sw = new StreamWriter(destination, false, System.Text.Encoding.UTF8))
{
// Instantiate the encoder
Encoding encoding = Encoding.GetEncoding("us-ascii", new CyrillicToRomanFallback(), new DecoderExceptionFallback());
// This is an encoding operation, so we only need to get the encoder.
Encoder encoder = encoding.GetEncoder();
Decoder decoder = encoding.GetDecoder();
// Check whether destination file exists and exit if it should not be overwritten.
if (File.Exists(destination))
{
Console.Write("The destination file {1} '{0}'{1}exists. Overwrite it? (Y/N) ",
source, Environment.NewLine);
ConsoleKeyInfo keyPressed = Console.ReadKey(true);
if (Char.ToUpper(keyPressed.KeyChar) == 'Y' | Char.ToUpper(keyPressed.KeyChar) == 'N')
{
Console.WriteLine(keyPressed.KeyChar);
if (Char.ToUpper(keyPressed.KeyChar) == 'N')
return;
}
}
using (var sw = new StreamWriter(destination, false, System.Text.Encoding.UTF8))
{
// Instantiate the encoder
Encoding encoding = Encoding.GetEncoding("us-ascii", new CyrillicToRomanFallback(), new DecoderExceptionFallback());
// This is an encoding operation, so we only need to get the encoder.
Encoder encoder = encoding.GetEncoder();
Decoder decoder = encoding.GetDecoder();

// Define buffer to read characters
char[] buffer = new char[100];
int charsRead;
// Define buffer to read characters
char[] buffer = new char[100];
int charsRead;

do
{
// Read next 100 characters from input stream.
charsRead = sr.ReadBlock(buffer, 0, buffer.Length);
do
{
// Read next 100 characters from input stream.
charsRead = sr.ReadBlock(buffer, 0, buffer.Length);

// Encode characters.
int byteCount = encoder.GetByteCount(buffer, 0, charsRead, false);
byte[] bytes = new byte[byteCount];
int bytesWritten = encoder.GetBytes(buffer, 0, charsRead, bytes, 0, false);
// Encode characters.
int byteCount = encoder.GetByteCount(buffer, 0, charsRead, false);
byte[] bytes = new byte[byteCount];
int bytesWritten = encoder.GetBytes(buffer, 0, charsRead, bytes, 0, false);

// Decode characters back to Unicode and write to a UTF-8-encoded file.
char[] charsToWrite = new char[decoder.GetCharCount(bytes, 0, byteCount)];
decoder.GetChars(bytes, 0, bytesWritten, charsToWrite, 0);
sw.Write(charsToWrite);
} while (charsRead == buffer.Length);
// Decode characters back to Unicode and write to a UTF-8-encoded file.
char[] charsToWrite = new char[decoder.GetCharCount(bytes, 0, byteCount)];
decoder.GetChars(bytes, 0, bytesWritten, charsToWrite, 0);
sw.Write(charsToWrite);
} while (charsRead == buffer.Length);
}
}
}
}
catch (DirectoryNotFoundException e)
{
Console.WriteLine($"Invalid directory: {e.Message}");
return;
}
catch (IOException e)
{
Console.WriteLine($"I/O exception: {e.Message}");
return;
}
}
}
catch (DirectoryNotFoundException e)
{
Console.WriteLine($"Invalid directory: {e.Message}");
return;
}
catch (IOException e)
{
Console.WriteLine($"I/O exception: {e.Message}");
return;
}
}

private static void ShowSyntax()
{
Console.WriteLine("\nSyntax: CyrillicToRoman <source> <destination>");
Console.WriteLine(" where <source> = source filename");
Console.WriteLine(" <destination> = destination filename\n");
}
private static void ShowSyntax()
{
Console.WriteLine("\nSyntax: CyrillicToRoman <source> <destination>");
Console.WriteLine(" where <source> = source filename");
Console.WriteLine(" <destination> = destination filename\n");
}
}
Loading

0 comments on commit a4cfd58

Please sign in to comment.