forked from Taritsyn/JavaScriptEngineSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemperature.cs
More file actions
105 lines (93 loc) · 1.61 KB
/
Temperature.cs
File metadata and controls
105 lines (93 loc) · 1.61 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
namespace JavaScriptEngineSwitcher.Tests.Interop
{
public struct Temperature
{
double _celsius;
public double Celsius
{
get
{
return _celsius;
}
set
{
_celsius = value;
}
}
public double Kelvin
{
get
{
return _celsius + 273.15;
}
set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException();
}
_celsius = value - 273.15;
}
}
public double Fahrenheit
{
get
{
return 9 * _celsius / 5 + 32;
}
set
{
_celsius = 5 * (value - 32) / 9;
}
}
public Temperature(double degree, TemperatureUnits units)
{
_celsius = 0;
switch (units)
{
case TemperatureUnits.Celsius:
Celsius = degree;
break;
case TemperatureUnits.Kelvin:
Kelvin = degree;
break;
case TemperatureUnits.Fahrenheit:
Fahrenheit = degree;
break;
default:
throw new NotSupportedException();
}
}
public override string ToString()
{
return ToString(TemperatureUnits.Celsius);
}
public string ToString(TemperatureUnits units)
{
string formattedValue;
switch (units)
{
case TemperatureUnits.Celsius:
formattedValue = String.Format("{0}\u00B0 C", Celsius);
break;
case TemperatureUnits.Kelvin:
formattedValue = String.Format("{0}\u00B0 K", Kelvin);
break;
case TemperatureUnits.Fahrenheit:
formattedValue = String.Format("{0}\u00B0 F", Fahrenheit);
break;
default:
formattedValue = string.Empty;
break;
}
return formattedValue;
}
}
public enum TemperatureUnits
{
Celsius,
Kelvin,
Fahrenheit
}
}