示例#1
0
        protected override T GetResult(object[] elements)
        {
            Type tupleType = null;

            if (TupleParserUtils.IsTupleType(typeof(T)))
            {
                tupleType = TupleParserUtils.GetTupleType(GetTypes().ToArray());
            }
            else if (TupleParserUtils.IsValueTupleType(typeof(T)))
            {
                tupleType = TupleParserUtils.GetValueTupleType(GetTypes().ToArray());
            }
            return((T)Activator.CreateInstance(tupleType, elements));
        }
示例#2
0
        public override string GetTypeName()
        {
            // Get type name for this tuple.
            // Type name will be different depending on whether this parser is parsing for a ValueTuple<> or a Tuple<>

            if (TupleParserUtils.IsTupleType(typeof(T)))
            {
                // Return "Tuple<...>," filling in the type arguments
                StringBuilder sb = new StringBuilder("Tuple");
                if (Types.Count > 0)
                {
                    sb.Append('<');
                    for (int i = 0; i < Types.Count; i++)
                    {
                        sb.Append(Parser.GetParser(Types[i]).GetTypeName());
                        if (i != Types.Count - 1)
                        {
                            sb.Append(",");
                        }
                    }
                    sb.Append('>');
                }
                return(sb.ToString());
            }
            else
            {
                // Return "(...)," filling in the type arguments
                StringBuilder sb = new StringBuilder("(");

                for (int i = 0; i < Types.Count; i++)
                {
                    sb.Append(Parser.GetParser(Types[i]).GetTypeName());
                    if (i != Types.Count - 1)
                    {
                        sb.Append(",");
                    }
                }

                sb.Append(')');
                return(sb.ToString());
            }
        }