Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TypedTableBase.cs « Data « System « System.Data.DataSetExtensions « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2d8289f89557317c58b995f562bbf1d478b15cfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//------------------------------------------------------------------------------
// <copyright file="TypedTableBase.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="false">spather</owner>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.Serialization;

namespace System.Data {

    /// <summary>
    /// This is the generic base class for TypedDataSet
    /// </summary>
    [Serializable]
    public abstract class TypedTableBase<T> : DataTable, IEnumerable<T> where T : DataRow {

        /// <summary>
        ///   Default constructor for generic TypedTableBase.
        ///   Will be called by generated Typed DataSet classes and is not for public use.
        /// </summary>
        protected TypedTableBase() : base() {}

        /// <summary>
        ///   Constructor for the generic TypedTableBase with takes SerializationInfo and StreamingContext.
        ///   Will be called by generated Typed DataSet classes and
        ///   is not for public use.
        /// </summary>
        /// <param name="info">
        ///   SerializationInfo containing data to construct the object.
        /// </param>
        /// <param name="context">
        ///   The streaming context for the object being deserializad.
        /// </param>
        protected TypedTableBase(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
            : base(info, context) {}

        /// <summary>
        ///   This property returns a enumerator of T for the TypedTable.  Note, this could
        ///   execute the underlying Linq expression.
        /// </summary>
        /// <returns>
        ///   IEnumerable of T.
        /// </returns>
        public IEnumerator<T> GetEnumerator() {
            return this.Rows.Cast<T>().GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator() {
            return GetEnumerator();
        }


        /// <summary>
        /// Casts an EnumerableDataTable_TSource into EnumerableDataTable_TResult
        /// </summary>
        public EnumerableRowCollection<TResult> Cast<TResult>()
        {
            EnumerableRowCollection<T> erc = new EnumerableRowCollection<T>((DataTable)this);
            return erc.Cast<TResult>();
        }

    }
}