Skip to content

Commit ceac638

Browse files
committed
Micro-optimization.
1 parent 609240c commit ceac638

File tree

5 files changed

+370
-149
lines changed

5 files changed

+370
-149
lines changed
Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
using System;
22

33

4-
namespace CSharpToJavaScript.Utils
4+
namespace CSharpToJavaScript.Utils;
5+
6+
[AttributeUsage(AttributeTargets.Class)]
7+
internal class IgnoreAttribute : Attribute
8+
{
9+
public IgnoreAttribute() { }
10+
}
11+
[AttributeUsage(AttributeTargets.All)]
12+
public class ValueAttribute : Attribute
513
{
6-
[AttributeUsage(AttributeTargets.Class)]
7-
internal class IgnoreAttribute : Attribute
14+
public string Value { get; init; }
15+
public ValueAttribute(string value)
816
{
9-
public IgnoreAttribute() { }
17+
Value = value;
1018
}
11-
[AttributeUsage(AttributeTargets.All)]
12-
public class ValueAttribute : Attribute
19+
}
20+
[AttributeUsage(AttributeTargets.All)]
21+
public class EnumValueAttribute : Attribute
22+
{
23+
public string Value { get; init; }
24+
public EnumValueAttribute(string value)
1325
{
14-
public string Value { get; init; }
15-
public ValueAttribute(string value)
16-
{
17-
Value = value;
18-
}
26+
Value = value;
1927
}
20-
[AttributeUsage(AttributeTargets.All)]
21-
public class EnumValueAttribute : Attribute
28+
}
29+
30+
[AttributeUsage(AttributeTargets.All)]
31+
public class ToAttribute : Attribute
32+
{
33+
public const string None = "None";
34+
public const string Default = "Default";
35+
public const string ToLower = "ToLower";
36+
public const string FirstCharToLowerCase = "FirstCharToLowerCase";
37+
38+
public string To { get; set; } = string.Empty;
39+
public ToAttribute(string to)
2240
{
23-
public string Value { get; init; }
24-
public EnumValueAttribute(string value)
25-
{
26-
Value = value;
27-
}
41+
To = to;
2842
}
2943

30-
[AttributeUsage(AttributeTargets.All)]
31-
public class ToAttribute : Attribute
44+
public string Convert(string str)
3245
{
33-
public const string None = "None";
34-
public const string Default = "Default";
35-
public const string ToLower = "ToLower";
36-
public const string FirstCharToLowerCase = "FirstCharToLowerCase";
37-
38-
public string To { get; set; } = string.Empty;
39-
public ToAttribute(string to)
46+
switch (To)
4047
{
41-
To = to;
42-
}
43-
44-
public string Convert(string str)
45-
{
46-
switch (To)
47-
{
48-
case ToLower:
49-
return str.ToLower();
50-
case FirstCharToLowerCase:
51-
return str.FirstCharToLowerCase();
52-
case None:
53-
return "";
54-
case Default:
55-
default:
56-
return str;
57-
}
48+
case ToLower:
49+
return str.ToLower();
50+
case FirstCharToLowerCase:
51+
return str.FirstCharToLowerCase();
52+
case None:
53+
return "";
54+
case Default:
55+
default:
56+
return str;
5857
}
5958
}
6059
}
60+
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
using System;
22

3-
namespace CSharpToJavaScript.Utils
3+
namespace CSharpToJavaScript.Utils;
4+
5+
internal static class Extensions
46
{
5-
internal static class Extensions
7+
//https://stackoverflow.com/a/21755933
8+
public static string? FirstCharToLowerCase(this string? str)
69
{
7-
//https://stackoverflow.com/a/21755933
8-
public static string? FirstCharToLowerCase(this string? str)
9-
{
10-
if (!string.IsNullOrEmpty(str) && char.IsUpper(str[0]))
11-
return str.Length == 1 ? char.ToLower(str[0]).ToString() : char.ToLower(str[0]) + str[1..];
10+
if (!string.IsNullOrEmpty(str) && char.IsUpper(str[0]))
11+
return str.Length == 1 ? char.ToLower(str[0]).ToString() : char.ToLower(str[0]) + str[1..];
1212

13-
return str;
14-
}
15-
public static string? FirstCharToUpperCase(this string? str)
16-
{
17-
if (!string.IsNullOrEmpty(str) && char.IsLower(str[0]))
18-
return str.Length == 1 ? char.ToUpper(str[0]).ToString() : char.ToUpper(str[0]) + str[1..];
13+
return str;
14+
}
15+
public static string? FirstCharToUpperCase(this string? str)
16+
{
17+
if (!string.IsNullOrEmpty(str) && char.IsLower(str[0]))
18+
return str.Length == 1 ? char.ToUpper(str[0]).ToString() : char.ToUpper(str[0]) + str[1..];
1919

20-
return str;
21-
}
20+
return str;
21+
}
2222

23-
public static bool Contains(this string source, string toCheck, StringComparison comp)
24-
{
25-
return source?.IndexOf(toCheck, comp) >= 0;
26-
}
23+
public static bool Contains(this string source, string toCheck, StringComparison comp)
24+
{
25+
return source?.IndexOf(toCheck, comp) >= 0;
2726
}
2827
}
28+

CSharpToJavaScript/Utils/Log.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static void WriteLine(string message)
4646
if (DisableConsoleOutput == true)
4747
return;
4848

49-
Trace.Write($"{DateTime.UtcNow.ToString("hh:mm:ss.fffffff")}: ");
49+
Trace.Write($"{DateTime.UtcNow.ToString("hh:mm:ss.fff")}: ");
5050
Trace.WriteLine($"{message}");
5151
}
5252

@@ -59,7 +59,7 @@ public static void InfoLine(string message)
5959
if (DisableConsoleOutput == true)
6060
return;
6161

62-
Trace.Write($"{DateTime.UtcNow.ToString("hh:mm:ss.fffffff")}: ");
62+
Trace.Write($"{DateTime.UtcNow.ToString("hh:mm:ss.fff")}: ");
6363

6464
if (_SupportedOS && DisableConsoleColors == false)
6565
Console.ForegroundColor = ConsoleColor.Green;
@@ -82,7 +82,7 @@ public static void WarningLine(string message, [CallerFilePath] string? file = n
8282
if (DisableConsoleOutput == true)
8383
return;
8484

85-
Trace.Write($"{DateTime.UtcNow.ToString("hh:mm:ss.fffffff")}: ");
85+
Trace.Write($"{DateTime.UtcNow.ToString("hh:mm:ss.fff")}: ");
8686

8787
if (_SupportedOS && DisableConsoleColors == false)
8888
Console.ForegroundColor = ConsoleColor.Cyan;
@@ -110,7 +110,7 @@ public static void ErrorLine(string message, [CallerFilePath] string? file = nul
110110
if (DisableConsoleOutput == true)
111111
return;
112112

113-
Trace.Write($"{DateTime.UtcNow.ToString("hh:mm:ss.fffffff")}: ");
113+
Trace.Write($"{DateTime.UtcNow.ToString("hh:mm:ss.fff")}: ");
114114

115115
if (_SupportedOS && DisableConsoleColors == false)
116116
Console.ForegroundColor = ConsoleColor.Cyan;
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
namespace CSharpToJavaScript.Utils
1+
namespace CSharpToJavaScript.Utils;
2+
3+
public class Unsupported
24
{
3-
public class Unsupported
4-
{
5-
public dynamic Value { get; set; }
5+
public dynamic Value { get; set; }
66

7-
public static implicit operator Unsupported(string value) { return new Unsupported { Value = value }; }
8-
public static implicit operator Unsupported(double value) { return new Unsupported { Value = value }; }
9-
public static implicit operator Unsupported(float value) { return new Unsupported { Value = value }; }
10-
public static implicit operator Unsupported(int value) { return new Unsupported { Value = value }; }
11-
}
7+
public static implicit operator Unsupported(string value) { return new Unsupported { Value = value }; }
8+
public static implicit operator Unsupported(double value) { return new Unsupported { Value = value }; }
9+
public static implicit operator Unsupported(float value) { return new Unsupported { Value = value }; }
10+
public static implicit operator Unsupported(int value) { return new Unsupported { Value = value }; }
1211
}
12+

0 commit comments

Comments
 (0)