| 
 | 1 | +using System.Collections.Generic;  | 
 | 2 | +using System.Linq;  | 
 | 3 | +using System.Reflection;  | 
 | 4 | + | 
 | 5 | +namespace FineCodeCoverage.Engine.ReportGenerator  | 
 | 6 | +{  | 
 | 7 | +	internal static class ReportColoursExtensions  | 
 | 8 | +	{  | 
 | 9 | +		private class ColourReflection  | 
 | 10 | +		{  | 
 | 11 | +			public PropertyInfo ReportColoursPropertyInfo { get; set; }  | 
 | 12 | +			public FieldInfo JsThemeStylingFieldInfo { get; set; }  | 
 | 13 | +		}  | 
 | 14 | +		private static List<ColourReflection> colourReflections;  | 
 | 15 | +		private static List<ColourReflection> ColourReflections  | 
 | 16 | +		{  | 
 | 17 | +			get  | 
 | 18 | +			{  | 
 | 19 | +				if (colourReflections == null)  | 
 | 20 | +				{  | 
 | 21 | +					var reportColourPropertyInfos = typeof(IReportColours).GetProperties();  | 
 | 22 | +					var jsThemeStylingFieldInfos = typeof(JsThemeStyling).GetFields();  | 
 | 23 | +					colourReflections = reportColourPropertyInfos.Select(prop =>  | 
 | 24 | +					{  | 
 | 25 | +						var field = jsThemeStylingFieldInfos.FirstOrDefault(f => f.Name == prop.Name);  | 
 | 26 | +						if (field == null)  | 
 | 27 | +						{  | 
 | 28 | +							return null;  | 
 | 29 | +						}  | 
 | 30 | +						else  | 
 | 31 | +						{  | 
 | 32 | +							return new ColourReflection { ReportColoursPropertyInfo = prop, JsThemeStylingFieldInfo = field };  | 
 | 33 | +						}  | 
 | 34 | +					}).Where(cr => cr != null).ToList();  | 
 | 35 | +				}  | 
 | 36 | +				return colourReflections;  | 
 | 37 | +			}  | 
 | 38 | +		}  | 
 | 39 | +		public static JsThemeStyling Convert(this IReportColours reportColours)  | 
 | 40 | +		{  | 
 | 41 | +			var jsThemeStyling = new JsThemeStyling();  | 
 | 42 | +			ColourReflections.ForEach(cr =>  | 
 | 43 | +			{  | 
 | 44 | +				cr.JsThemeStylingFieldInfo.SetValue(jsThemeStyling, ((System.Drawing.Color)cr.ReportColoursPropertyInfo.GetValue(reportColours)).ToJsColour());  | 
 | 45 | +			});  | 
 | 46 | +			return jsThemeStyling;  | 
 | 47 | +		}  | 
 | 48 | + | 
 | 49 | +		public static string ToJsColour(this System.Drawing.Color colour)  | 
 | 50 | +		{  | 
 | 51 | +			return $"rgba({colour.R},{colour.G},{colour.B},{colour.A})";  | 
 | 52 | +		}  | 
 | 53 | +	}  | 
 | 54 | +}  | 
0 commit comments