Repository navigation
Expand file tree
/
Copy pathTransform.cs
More file actions
55 lines (44 loc) · 1.79 KB
/
Copy pathTransform.cs
File metadata and controls
55 lines (44 loc) · 1.79 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace EinarEgilsson.EventHandlerNaming
{
public class Transform
{
public static readonly Transform NoChange = new Transform(0, "No change", s=>s);
public static readonly Transform LowerCase = new Transform(1, "lowercase", s=>s.ToLower());
public static readonly Transform UpperCase = new Transform(2, "UPPERCASE", s=>s.ToUpper());
public static readonly Transform CamelCase = new Transform(3, "camelCase", s => Char.ToLower(s[0]) + s.Substring(1));
public static readonly Transform PascalCase = new Transform(4, "PascalCase", s => Char.ToUpper(s[0]) + s.Substring(1));
public static readonly List<Transform> Values = new List<Transform>
{
NoChange, LowerCase, UpperCase, CamelCase, PascalCase
};
private Transform(int value, string displayName, Func<string,string> transform)
{
Value = value;
DisplayName = displayName;
_transform = transform;
}
private readonly Func<string, string> _transform;
public override string ToString()
{
return DisplayName;
}
public string Execute(string name)
{
return _transform(Regex.Replace(name, "^_*", ""));
}
public int Value { get; private set; }
public string DisplayName { get; private set; }
public static implicit operator Transform(int value)
{
return Values.FirstOrDefault(transform => transform.Value == value);
}
public static implicit operator int(Transform value)
{
return value.Value;
}
}
}