コード例 #1
0
        public static NumberType ToNumberType(this EffectScalarType scalarType)
        {
            switch (scalarType)
            {
            case EffectScalarType.Bool:
                return(NumberType.Bool);

            case EffectScalarType.Float:
                return(NumberType.Float);

            case EffectScalarType.Int:
                return(NumberType.Int);

            case EffectScalarType.UInt:
                return(NumberType.UInt);

            default:
                return(NumberType.Unknown);
            }
        }
コード例 #2
0
        public string FormatValue(Number value, EffectScalarType scalarType)
        {
            var type = MemberType.GetAssignmentType();

            if (type == null)
            {
                return(value.UInt.ToString());
            }
            var numberType = scalarType.ToNumberType();

            if (type.IsEnum && scalarType == EffectScalarType.Int)
            {
                var enumValue   = (Enum)Enum.ToObject(type, value.UInt);
                var description = EnumExtensions.GetDescription(enumValue);
                return(string.Format("{0} /* {1} */", description, value.UInt));
            }
            else if (type.IsEnum)
            {
                return(value.ToString(numberType));
            }
            if (type == typeof(float))
            {
                return(value.ToString());
            }
            if (type == typeof(byte))
            {
                if (numberType == Shex.NumberType.UInt || numberType == Shex.NumberType.Int)
                {
                    return(string.Format("0x{0:x2}", value.Byte0));
                }
                else
                {
                    return(value.ToString(numberType));
                }
            }
            if (type == typeof(bool))
            {
                if (scalarType == EffectScalarType.Bool)
                {
                    return(string.Format("{0} /* {1} */",
                                         value.ToString(Shex.NumberType.Bool).ToUpper(), value.ToString(Shex.NumberType.Bool)));
                }
                else if (scalarType == EffectScalarType.Int)
                {
                    return(string.Format("{0} /* {1} */",
                                         value.ToString(Shex.NumberType.Bool).ToUpper(), value.UInt));
                }
                else
                {
                    return(value.ToString(numberType));
                }
            }
            if (type == typeof(uint))
            {
                if (scalarType == EffectScalarType.UInt)
                {
                    if (value.UInt > 10000)
                    {
                        return("0x" + value.UInt.ToString("x8"));
                    }
                    return(value.UInt.ToString());
                }
                else
                {
                    return(value.ToString(numberType));
                }
            }
            return(value.ToString(numberType));
        }