Am i abusing CallerMemberName?

Hi guys. I'm wondering if im abusing CallerMemberName in this scenario. Google's material design standards define a brush's naming convention as such:

[$BrushFamily${char}][AOPT ] [$Luminosity${##0}]

Examples:

GreenA200

Green400

Green050

LightBlue900

I want to be able to access information such as the luminosity of the brush, the palatte family, whether or not it is accented (The optional A), etc. Ive written a Material class where i automatically parse this information using the CallerMemberName parameter attribute (Excuse my messy parsing logic. Ill fix it later.)

[TypeConverter(typeof(MaterialConverter))] public class Material { public Color Color { get; } public SolidColorBrush Brush { get; } public Luminosity Luminosity { get; } public string Name { get; } public static implicit operator Color(Material d) { return d.Color; } public static implicit operator SolidColorBrush(Material d) { return d.Brush; } public Material(Color color, [CallerMemberName] string cmn = null) { Color = color; Brush = new SolidColorBrush(color); if (cmn == null) throw new Exception("CallerMemberName not assigned."); var brushName = ""; var intensityStr = ""; var hasEncounteredDigit = false; foreach (var c in cmn.ToCharArray()) { if (!char.IsLetterOrDigit(c)) throw new Exception("Improper naming convension for auto brush"); if (char.IsDigit(c)) { hasEncounteredDigit = true; intensityStr += c; } if (char.IsLetter(c)) { if(hasEncounteredDigit) throw new Exception("Improper naming convension for auto brush ([Letter]*A?[Digit]*"); brushName += c; } } Name = brushName; var luminosity = brushName.EndsWith("A") ? Luminosity.Parse("A" + intensityStr) : Luminosity.Parse("P" + intensityStr); Luminosity = luminosity; } } 

I can define a Material set like this:

 public static readonly Material Indigo050 = new Material(Colors.c_Indigo050); public static readonly Material Indigo100 = new Material(Colors.c_Indigo100); public static readonly Material Indigo200 = new Material(Colors.c_Indigo200); public static readonly Material Indigo300 = new Material(Colors.c_Indigo300); public static readonly Material Indigo400 = new Material(Colors.c_Indigo400); public static readonly Material Indigo500 = new Material(Colors.c_Indigo500); public static readonly Material Indigo600 = new Material(Colors.c_Indigo600); public static readonly Material Indigo700 = new Material(Colors.c_Indigo700); public static readonly Material Indigo800 = new Material(Colors.c_Indigo800); public static readonly Material Indigo900 = new Material(Colors.c_Indigo900); public static readonly Material IndigoA100 = new Material(Colors.c_IndigoA100); public static readonly Material IndigoA200 = new Material(Colors.c_IndigoA200); public static readonly Material IndigoA400 = new Material(Colors.c_IndigoA400); public static readonly Material IndigoA700 = new Material(Colors.c_IndigoA700); 

And it will fill in all the information on intensities and accents it needs based on the static object's name.

My question: Am i abusing CallerMemberName?

Thanks!

by CCRed95 via /r/csharp

Leave a Reply