Пример #1
0
        internal InMemoryTableValue(IRContext irContext, IEnumerable <DValue <RecordValue> > records) : base(irContext)
        {
            Contract.Assert(IRContext.ResultType is TableType);
            var tableType  = (TableType)IRContext.ResultType;
            var recordType = tableType.ToRecord();

            _records = records.Select(r =>
            {
                if (r.IsValue)
                {
                    return(DValue <RecordValue> .Of(new InMemoryRecordValue(IRContext.NotInSource(recordType), r.Value.Fields)));
                }
                else
                {
                    return(r);
                }
            });
        }
Пример #2
0
        // More type safe than base class's ParseJson
        // Parse json.
        // [1,2,3]  is a single column table, actually equivalent to:
        // [{Value : 1, Value: 2, Value :3 }]
        internal static TableValue TableFromJsonArray(JsonElement array)
        {
            Contract.Assert(array.ValueKind == JsonValueKind.Array);

            List <RecordValue> records = new List <RecordValue>();

            for (var i = 0; i < array.GetArrayLength(); ++i)
            {
                var element = array[i];
                var val     = GuaranteeRecord(FormulaValue.FromJson(element));

                records.Add(val);
            }

            // Constructor will handle both single-column table
            TableType type;

            if (records.Count == 0)
            {
                type = new TableType();
            }
            else
            {
                type = TableType.FromRecord((RecordType)GuaranteeRecord(records[0]).IRContext.ResultType);
            }
            return(new InMemoryTableValue(IRContext.NotInSource(type), records.Select(r => DValue <RecordValue> .Of(r))));
        }
Пример #3
0
        public static TableValue TableFromRecords <T>(IEnumerable <T> values, TableType type)
        {
            var values2 = values.Select(v => GuaranteeRecord(FormulaValue.New(v, typeof(T))));

            return(new InMemoryTableValue(IRContext.NotInSource(type), values2.Select(r => DValue <RecordValue> .Of(r))));
        }
Пример #4
0
 public static TableValue TableFromRecords(IEnumerable <RecordValue> values, TableType type)
 {
     return(new InMemoryTableValue(IRContext.NotInSource(type), values.Select(r => DValue <RecordValue> .Of(r))));
 }