๊ตฌ๊ธ€๋ง ํ•ด๋ณด๋‹ˆ๊นŒ C#์—์„  Generic Type์„ย Numeric Type์œผ๋กœ ์ œํ•œํ• ์ˆ˜๋Š” ์—†๋‹ค๊ณ  ๋‚˜์˜ค๊ณ 

https://stackoverflow.com/questions/32664/is-there-a-constraint-that-restricts-my-generic-method-to-numeric-types


๋‹ˆ๊ฐ€ ์›ํ•˜๋Š” ๊ธฐ๋Šฅํ•œ๊ฑฐ ์งœ๋ดค์œผ๋‹ˆ๊นŒ ์ด๊ฑธ๋กœ ์“ฐ๋ฉด๋˜์ง€ ์•Š์„๊นŒ์‹ถ๋‹ค

public static bool IsInteger(ValueType value)

{

return (value is SByte || value is Int16 || value is Int32

|| value is Int64 || value is Byte || value is UInt16

|| value is UInt32 || value is UInt64

|| value is BigInteger);

}


public static bool IsFloat(ValueType value)

{

return (value is float | value is double | value is Decimal);

}


public static bool IsNumeric(ValueType value)

{

return (value is Byte ||

ย  value is Int16 ||

ย  value is Int32 ||

ย  value is Int64 ||

ย  value is SByte ||

ย  value is UInt16 ||

ย  value is UInt32 ||

ย  value is UInt64 ||

ย  value is BigInteger ||

ย  value is Decimal ||

ย  value is Double ||

ย  value is Single);

}


public static string EmptyOrNumber(ValueType number)

{

if (number is Enum)

{

return Convert.ToInt32(number).ToString();

}


if (!IsNumeric(number))

return "";


if (IsInteger(number))

{

var i = (int)number;

if (i == 0 || i == 1)

return "";

}

else if (IsFloat(number))

{

float i = Convert.ToSingle(number);

if (i == 0 || i == 1)

{

return "";

}

}


return number.ToString();

}