예제 #1
0
        public virtual bool TryGetConstValueWithCast(CppTypeName cast, out object value)
        {
            if (!TryGetConstValue(out value))
            {
                return(false);
            }
            var type = EocDataTypes.GetConstValueType(value);

            if (type == cast)
            {
                return(true);
            }
            if (EocDataTypes.IsArithmeticType(type) && EocDataTypes.IsArithmeticType(cast))
            {
                var NumberConverter = new Dictionary <CppTypeName, Func <object, object> > {
                    { EocDataTypes.Byte, x => Convert.ToByte(x) },
                    { EocDataTypes.Short, x => Convert.ToInt16(x) },
                    { EocDataTypes.Int, x => Convert.ToInt32(x) },
                    { EocDataTypes.Long, x => Convert.ToInt64(x) },
                    { EocDataTypes.Float, x => Convert.ToSingle(x) },
                    { EocDataTypes.Double, x => Convert.ToDouble(x) },
                };
                if (NumberConverter.TryGetValue(cast, out var converter))
                {
                    value = converter(value);
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
 public override CppTypeName GetResultType()
 {
     if (!TryGetConstValue(out var v))
     {
         throw new Exception();
     }
     return(EocDataTypes.GetConstValueType(v));
 }