This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathProgram.cs
More file actions
62 lines (50 loc) · 1.59 KB
/
Copy pathProgram.cs
File metadata and controls
62 lines (50 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
namespace RefactoringEssentials.Demonstration
{
class Program
{
static void Main(string[] args)
{
// CompareFloats() shows some detected comparison issues with floats
CompareFloats();
// Compare exactly the same constant value -> suggestion to convert to 'true'
// Also other Refactorings: Convert to Equals() call, invert and negate condition etc.
bool fiveIsFive = (5 == 5);
// Refactoring: Conversion of operator assignment ("|=") to assignment with or operator and vice versa
bool hasArgs = false;
hasArgs |= (args.Length > 0);
// Refactoring: Use explicit type instead of 'var'
var commandLineSwitchParser = new CommandLineSwitchParser();
commandLineSwitchParser.Parameters = args;
commandLineSwitchParser.Parse();
Console.WriteLine("Selected switches: {0}", commandLineSwitchParser.Switches);
// Warning about unassigned created object
new object();
// 1. Analyzer + CodeFix to replace Nullable<T> by T?
// 2. Refactoring: Replace type by 'var'
Nullable<float> nullableFloat = 5;
}
static void CompareFloats()
{
// Doing some float comparison will be marked as potential issue
float float1 = 1.0f;
float float2 = 1.0f;
if (float1 == float2)
{
// Default equality test might fail on floats
}
if (float1 != 0)
{
// Same for zero comparison
}
if (float1 == float.NaN)
{
// Not a good way to test for NaN
}
if (float1 != float.PositiveInfinity)
{
// Not a good way to test for infinity
}
}
}
}