コード例 #1
0
        protected override Expression VisitChildren(ExpressionVisitor visitor)
        {
            var outerTable = visitor.VisitAndConvert(OuterTable, nameof(VisitChildren));
            var innerTable = visitor.VisitAndConvert(InnerTable, nameof(VisitChildren));
            var predicate  = visitor.Visit(Predicate);

            if (outerTable != OuterTable || innerTable != InnerTable || predicate != Predicate)
            {
                if (outerTable != OuterTable)
                {
                    var oldTables = OuterTable.Flatten().ToArray();
                    var newTables = outerTable.Flatten().ToArray();

                    var updater = new TableUpdatingExpressionVisitor(oldTables, newTables);

                    innerTable = updater.VisitAndConvert(innerTable, nameof(VisitChildren));
                    predicate  = updater.Visit(predicate);
                }

                if (innerTable != InnerTable)
                {
                    var oldTables = InnerTable.Flatten().ToArray();
                    var newTables = innerTable.Flatten().ToArray();

                    var updater = new TableUpdatingExpressionVisitor(oldTables, newTables);

                    predicate = updater.Visit(predicate);
                }

                return(Recreate(outerTable, innerTable, predicate, Type));
            }

            return(this);
        }
コード例 #2
0
    private InnerTable <T> SerializeAndParse <T>(FlatBufferDeserializationOption option, T item)
    {
        FlatBufferSerializer serializer = new FlatBufferSerializer(new FlatBufferSerializerOptions(option));

        InnerTable <T> value = new InnerTable <T>
        {
            First = new FirstStruct {
                First = 1
            },
            Second = new SecondStruct {
                Second = 2,
            },
            String = "Foo bar baz bat",
            Union  = new FlatBufferUnion <FirstStruct, SecondStruct, string>(new SecondStruct {
                Second = 3
            }),
            Vector = item,
        };

        serializer.Serialize(value, InputBuffer);
        InnerTable <T> parsed = serializer.Parse <InnerTable <T> >(InputBuffer);

        Assert.Equal(1, parsed.First.First);
        Assert.Equal(2, parsed.Second.Second);
        Assert.Equal("Foo bar baz bat", parsed.String);
        Assert.Equal(3, parsed.Union.Value.Item2.Second);

        return(parsed);
    }
コード例 #3
0
        /// <summary>
        /// Gets the inner corresponding to a property in the node.
        /// </summary>
        /// <param name="propertyName">Property name.</param>
        public virtual IReadOnlyInner PropertyToInner(string propertyName)
        {
            Debug.Assert(!string.IsNullOrEmpty(propertyName));
            Debug.Assert(InnerTable.ContainsKey(propertyName));

            return((IReadOnlyInner)InnerTable[propertyName]);
        }
コード例 #4
0
        private static void DeepCompareInnerTable(InnerTable a, dynamic p, dynamic c)
        {
            Assert.AreNotSame(p, c);

            Assert.AreNotEqual("CopyConstructorTest.InnerTable", (string)p.GetType().FullName);
            Assert.AreEqual("CopyConstructorTest.InnerTable", (string)c.GetType().FullName);

            Assert.AreEqual(a.Name, p.Name);
            Assert.AreEqual(a.Name, c.Name);

            var pOuter = p.OuterStruct;
            var cOuter = c.OuterStruct;

            Assert.AreNotSame(pOuter, cOuter);
            Assert.AreNotEqual("CopyConstructorTest.OuterStruct", (string)pOuter.GetType().FullName);
            Assert.AreEqual("CopyConstructorTest.OuterStruct", (string)cOuter.GetType().FullName);

            Assert.AreEqual(a.OuterStruct.Value, pOuter.Value);
            Assert.AreEqual(a.OuterStruct.Value, cOuter.Value);

            var pInner = pOuter.InnerStruct;
            var cInner = cOuter.InnerStruct;

            Assert.AreNotSame(pInner, cInner);
            Assert.AreNotEqual("CopyConstructorTest.InnerStruct", (string)pInner.GetType().FullName);
            Assert.AreEqual("CopyConstructorTest.InnerStruct", (string)cInner.GetType().FullName);

            Assert.AreEqual(a.OuterStruct.InnerStruct.LongValue, pInner.LongValue);
            Assert.AreEqual(a.OuterStruct.InnerStruct.LongValue, cInner.LongValue);
        }
コード例 #5
0
ファイル: JoinDataTable.cs プロジェクト: jirkaceska/C_sharp
        /// <summary>
        /// <para type="description">Process record.</para>
        /// </summary>
        protected override void ProcessRecord()
        {
            Validators.ValidateTableName(OuterTable, "Outer table");
            Validators.ValidateTableName(InnerTable, "Inner table");

            if (JoinedTableName == null)
            {
                JoinedTableName = $"{OuterTable.TableName}_{InnerTable.TableName}";
            }
            Result = new DataTable
            {
                TableName = JoinedTableName
            };
            InsertColumns();

            var joinResult = OuterTable.AsEnumerable().Join(
                InnerTable.AsEnumerable(),
                OuterKeySelector.Execute,
                InnerKeySelector.Execute,
                ResultSelector.Execute,
                new PSScriptResultComparer()
                );

            foreach (var rowItemArray in joinResult)
            {
                var resultRow = Result.NewRow();
                resultRow.ItemArray = rowItemArray.ToArray();
                Result.Rows.Add(resultRow);
            }
        }
コード例 #6
0
    /// <summary>
    /// In lazy deserialization, FlatSharp reads from the underlying buffer each time. No caching is done. This will be
    /// the fastest option if your access patterns are sparse and you touch each element only once.
    /// </summary>
    public static void LazyDeserialization(DemoTable demo)
    {
        var serializer = new FlatBufferSerializer(new FlatBufferSerializerOptions(FlatBufferDeserializationOption.Lazy));

        byte[] buffer = new byte[1024];
        serializer.Serialize(demo, buffer);
        var parsed = serializer.Parse <DemoTable>(buffer);

        // Lazy deserialization reads objects from vectors each time you ask for them.
        InnerTable index0_1 = parsed.ListVector ![0];
コード例 #7
0
        private InnerTable[] CreateInner(params string[] names)
        {
            InnerTable[] table = new InnerTable[names.Length];
            for (int i = 0; i < names.Length; ++i)
            {
                table[i] = new InnerTable
                {
                    Name        = names[i],
                    OuterStruct = new OuterStruct
                    {
                        Value       = 1,
                        InnerStruct = new InnerStruct
                        {
                            LongValue = 2,
                        },
                    }
                };
            }

            return(table);
        }
コード例 #8
0
        /// <summary>
        /// Initializes an item with existing row data, either collection-based on independent mode.
        /// </summary>
        ///
        /// <param name="externalRow">
        ///	The row containing the item's data.
        /// </param>
        ///
        /// <param name="owner">
        /// The collection that is creating the item. If null, the item is created as an independent item.
        /// </param>
        ///
        /// <param name="copyLocal">
        /// If false, data is not copied into the internal table even if there is no owner specified.
        /// </param>
        ///
        /// <remarks>
        /// <para>
        /// If externalRow does not belong to the owner's InnerTable, the data will be imported into
        /// the owner's table as a new row (or imported into the item's independent table if no owner is specified).
        /// </para>
        /// <para>
        /// Fields that exist in the independent version of the item but do not exist in the external row will be
        /// marked as "missing" so that if they are referenced in code their value will be retrieved on-demand.
        /// </para>
        /// </remarks>
        protected internal DataItem(DataRow externalRow, DataItemCollection owner, bool copyLocal) : this()
        {
            // If no external row is specified, use a new empty row from the owner or the inner table
            if (externalRow == null)
            {
                externalRow = owner != null?owner.InnerTable.NewRow() : InnerTable.NewRow();
            }

            // Collect missing column names
            _missingFields = new ArrayList();

            // Row data needs to be imported since we're not attaching to a collection
            if (copyLocal && (owner == null || externalRow.Table != owner.InnerTable))
            {
                ImportIntoOwner(externalRow, owner);
            }
            else
            {
                _row   = externalRow;
                _owner = owner;

                // Look for missing fields
                foreach (DataColumn column in _table.Columns)
                {
                    if (_row.Table.Columns.IndexOf(column.ColumnName) < 0)
                    {
                        _missingFields.Add(column.ColumnName);
                    }
                }
            }

            if (!copyLocal || _owner != null)
            {
                // We don't need the table any more since we have an owner collection
                _table.Dispose();
                _table = null;
            }
        }