示例#1
0
        public override string ToSource()
        {
            string targetStr = Target.ToSource();
            string indexStr  = Index.ToSource();

            if (!(Target is GList))
            {
                targetStr += ".ToList()";
            }

            if (!(Index is GNumber))
            {
                indexStr += ".ToNumber()";
            }

            return(string.Format("{0}[{1}]", targetStr, indexStr));
        }
示例#2
0
        public static string CastParameterString(GObject obj, Type type)
        {
            var    compiler   = new CSharpCodeProvider();
            var    castType   = new CodeTypeReference(type);
            string castString = compiler.GetTypeOutput(castType);

            // 변환이 필요없음
            if (type == typeof(object))
            {
                return(obj?.ToSource());
            }

            // 같은 타입임
            if (
                obj is GNumber && type == typeof(double) ||
                obj is GString && type == typeof(string) ||
                obj is GLogic && type == typeof(bool) ||
                obj is GList && type == typeof(List <object>) ||
                obj is ICustom && type == (obj as ICustom).CustomType
                )
            {
                return(obj?.ToSource());
            }

            // To Number
            if (IsNumberType(type))
            {
                if (obj is GNumber)
                {
                    return(string.Format("({0}){1}", castString, obj?.ToSource()));
                }

                if (type == typeof(double))
                {
                    return(string.Format("{0}.ToNumber()", obj?.ToSource()));
                }

                return(string.Format("({0}){1}.ToNumber()", castString, obj?.ToSource()));
            }

            if (type == typeof(string))
            {
                return(string.Format("{0}.ToText()", obj?.ToSource()));
            }

            if (type == typeof(bool))
            {
                return(string.Format("{0}.ToBool()", obj?.ToSource()));
            }

            // is List
            if (IsListType(type))
            {
                Type listType = type.GetGenericArguments()[0];

                if (obj is GList || obj is ICustom && IsListType((obj as ICustom).CustomType))
                {
                    return(string.Format("{0}.Select(e => e.ToCustom<{1}>()).ToList()", obj?.ToSource(), listType.ToString()));
                }

                if (listType == typeof(object))
                {
                    return(string.Format("{0}.ToList()", obj?.ToSource()));
                }

                var    listCastType   = new CodeTypeReference(listType);
                string listCastString = compiler.GetTypeOutput(castType);

                return(string.Format("{0}.ToList().Select(e => e.ToCustom<{1}>()).ToList()", obj?.ToSource(), listCastString));
            }

            if (type == typeof(object))
            {
                return(obj?.ToSource());
            }

            return(string.Format("{0}.ToCustom<{1}>()", obj?.ToSource(), castString));
        }