예제 #1
0
파일: Helpers.cs 프로젝트: Dim0N22/Builder
        public static string TranslateTypeReference(AstType astType, IEmitter emitter)
        {
            var composedType = astType as ComposedType;

            if (composedType != null && composedType.ArraySpecifiers != null && composedType.ArraySpecifiers.Count > 0)
            {
                return("Array");
            }

            var simpleType = astType as SimpleType;

            if (simpleType != null && simpleType.Identifier == "dynamic")
            {
                return("Object");
            }

            string type = emitter.ResolveType(Helpers.GetScriptName(astType, true), astType);

            if (String.IsNullOrEmpty(type))
            {
                throw (Exception)emitter.CreateException(astType, "Cannot resolve type " + astType.ToString());
            }

            var name = type;

            if (emitter.TypeDefinitions.ContainsKey(name))
            {
                name = emitter.ShortenTypeName(type);
            }


            if (simpleType != null && simpleType.TypeArguments.Count > 0 && !Helpers.IsIgnoreGeneric(simpleType, emitter))
            {
                StringBuilder sb        = new StringBuilder(name);
                bool          needComma = false;
                sb.Append("(");
                foreach (var typeArg in simpleType.TypeArguments)
                {
                    if (needComma)
                    {
                        sb.Append(",");
                    }

                    needComma = true;
                    sb.Append(Helpers.TranslateTypeReference(typeArg, emitter));
                }
                sb.Append(")");
                name = sb.ToString();
            }

            return(name);
        }