Skip to content

Commit

Permalink
Merge pull request #1158 from karakasa/remove_reflection_hssfcolor
Browse files Browse the repository at this point in the history
Remove reflections in `HSSFColor`
  • Loading branch information
tonyqus authored Aug 12, 2023
2 parents 0e0dda3 + 8c44b08 commit b91b047
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions main/HSSF/Util/HSSFColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ the License. You may obtain a copy of the License at
limitations Under the License.
==================================================================== */

// REMOVE-REFLECITON: Reflection is used to retrieve the 2nd index of a color. Refactored using virtual getter.

namespace NPOI.HSSF.Util
{
using NPOI.SS.UserModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
/**
* Intends to provide support for the very evil index to triplet Issue and
* will likely replace the color constants interface for HSSF 2.0.
Expand Down Expand Up @@ -99,7 +100,7 @@ private static Dictionary<int, HSSFColor> CreateColorsByIndexMap()
for (int i = 0; i < colors.Length; i++)
{
HSSFColor color = colors[i];
int index2 = GetIndex2(color);
int index2 = color.Indexed2;
if (index2 == -1)
{
// most colors don't have a second index
Expand All @@ -120,18 +121,6 @@ private static Dictionary<int, HSSFColor> CreateColorsByIndexMap()
return result;
}

private static int GetIndex2(HSSFColor color)
{
FieldInfo f = color.GetType().GetField("Index2", BindingFlags.Static | BindingFlags.Public);
if (f == null)
{
return -1;
}

short s = (short)f.GetValue(color);
return Convert.ToInt32(s);
}

internal static HSSFColor[] GetAllColors()
{
return new HSSFColor[] {
Expand Down Expand Up @@ -194,6 +183,7 @@ public virtual short Indexed
}
}

public virtual short Indexed2 => -1;
public byte[] RGB
{
get { return this.GetTriplet(); }
Expand Down Expand Up @@ -371,6 +361,7 @@ public class DarkBlue: HSSFColor
public static readonly byte[] Triplet = { 0, 0, 128 };
public const string HexString = "0:0:8080";

public override short Indexed2 => Index2;
public override short Indexed
{
get{return Index;}
Expand Down Expand Up @@ -452,7 +443,7 @@ public class DarkRed: HSSFColor
public const short Index2 = 0x25;
public static readonly byte[] Triplet = { 128, 0, 0 };
public const string HexString = "8080:0:0";

public override short Indexed2 => Index2;
public override short Indexed
{
get{return Index;}
Expand Down Expand Up @@ -561,7 +552,7 @@ public class Teal: HSSFColor
public const short Index2 = 0x26;
public static readonly byte[] Triplet = { 0, 128, 128 };
public const string HexString = "0:8080:8080";

public override short Indexed2 => Index2;
public override short Indexed
{
get{return Index;}
Expand Down Expand Up @@ -589,7 +580,7 @@ public class Blue: HSSFColor
public const short Index2 = 0x27;
public static readonly byte[] Triplet = { 0, 0, 255 };
public const string HexString = "0:0:FFFF";

public override short Indexed2 => Index2;
public override short Indexed
{
get{return Index;}
Expand Down Expand Up @@ -822,7 +813,7 @@ public class Violet: HSSFColor
public const short Index2 = 0x24;
public static readonly byte[] Triplet = { 128, 0, 128 };
public const string HexString = "8080:0:8080";

public override short Indexed2 => Index2;
public override short Indexed
{
get{return Index;}
Expand Down Expand Up @@ -872,7 +863,7 @@ public class Pink: HSSFColor
public const short Index2 = 0x21;
public static readonly byte[] Triplet = { 255, 0, 255 };
public const string HexString = "FFFF:0:FFFF";

public override short Indexed2 => Index2;
public override short Indexed
{
get{return Index;}
Expand Down Expand Up @@ -918,7 +909,7 @@ public class Yellow: HSSFColor
public const short Index2 = 0x22;
public static readonly byte[] Triplet = { 255, 255, 0 };
public const string HexString = "FFFF:FFFF:0";

public override short Indexed2 => Index2;
public override short Indexed
{
get{return Index;}
Expand All @@ -941,7 +932,7 @@ public class BrightGreen: HSSFColor
public const short Index2 = 0x23;
public static readonly byte[] Triplet = { 0, 255, 0 };
public const string HexString = "0:FFFF:0";

public override short Indexed2 => Index2;
public override String GetHexString()
{
return HexString;
Expand Down Expand Up @@ -969,7 +960,7 @@ public class Turquoise: HSSFColor
public const short Index2 = 0x23;
public static readonly byte[] Triplet = { 0, 255, 255 };
public const string HexString = "0:FFFF:FFFF";

public override short Indexed2 => Index2;
public override short Indexed
{
get{return Index;}
Expand Down Expand Up @@ -1024,7 +1015,7 @@ public class Plum: HSSFColor
public const short Index2 = 0x19;
public static readonly byte[] Triplet = { 153, 51, 102 };
public const string HexString = "9999:3333:6666";

public override short Indexed2 => Index2;
public override short Indexed
{
get{return Index;}
Expand Down Expand Up @@ -1187,7 +1178,7 @@ public class LightTurquoise: HSSFColor
public const short Index2 = 0x1b;
public static readonly byte[] Triplet = { 204, 255, 255 };
public const string HexString = "CCCC:FFFF:FFFF";

public override short Indexed2 => Index2;
public override short Indexed
{
get{return Index;}
Expand Down

0 comments on commit b91b047

Please sign in to comment.