Exemplo n.º 1
0
        /// <summary>
        /// 读取<see cref="IDataReader"/>中的全部内容
        /// </summary>
        /// <param name="Reader">待读取的<see cref="IDataReader"/></param>
        /// <returns>枚举流中内容的枚举器</returns>
        public static IEnumerable <IData> ToDatas(this IDataReader Reader)
        {
            var Schema = Reader.GetSchemaTable().Rows.OfType <DataRow>().ToArray();
            var Titles = Schema.Select(x => x["ColumnName"].ToString()).ToArray();
            var Length = Titles.Length;

            while (Reader.Read())
            {
                var Values = new object?[Length];
                Reader.GetValues(Values);
                yield return(CreateDataObj.Data(Titles.Zip(Values.Select(x => x is DBNull ? null : x)).ToArray()));
            }
            if (Reader.NextResult())
            {
                throw new NotSupportedException("为保证数据架构的一致性,同一个读取器不能返回两个表");
            }
        }
Exemplo n.º 2
0
        /*对IDirect的反序列化遵循以下原则:
         #对于数字类型,反序列化为System.Num
         #对于布尔类型,反序列化为Boolean
         #对于字符串,如果它可以被解释为DateTime,TimeOffset或Guid,
         * 则将其反序列化为对应类型,否则反序列化为String
         #对于集合,一律反序列化为数组
         #对于除此以外的复杂对象,一律反序列化为IDirect,
         * 它的键值对对应对象的属性和值*/
        #endregion
        #region 辅助方法
        #region 反序列化为IDirect
        /// <summary>
        /// 读取<see cref="Utf8JsonReader"/>的对象部分,
        /// 并将其反序列化为<see cref="IDirect"/>
        /// </summary>
        /// <param name="reader">待读取的<see cref="Utf8JsonReader"/></param>
        /// <returns></returns>
        private IDirect ReadDirect(ref Utf8JsonReader reader)
        {
            var link = new LinkedList <(string, object?)>();

            while (reader.Read())
            {
                switch (reader.TokenType)
                {
                case JsonTokenType.None or JsonTokenType.Comment or JsonTokenType.StartObject:
                    break;

                case JsonTokenType.EndObject:
                    return(CreateDataObj.Data(link.ToArray()));

                case JsonTokenType.PropertyName:
                    link.AddLast((reader.GetString() !, ReadObject(ref reader))); break;

                case var type:
                    throw new JsonException($"未识别{type}类型的令牌");
                }
            }
            throw new JsonException($"读取器已到达末尾,但是没有找到{JsonTokenType.EndObject}令牌");
        }
Exemplo n.º 3
0
 /// <summary>
 /// 将<see cref="Microsoft.ML.IDataView"/>转换为<see cref="DataFrancis.IDataView"/>
 /// </summary>
 /// <param name="data">待转换的<see cref="IDataView"/></param>
 /// <param name="maxRows">读取的最大列数,如果这个值过大,可能会对性能产生影响,默认为全部读取</param>
 /// <returns></returns>
 public static IDataViewF ToIData(this IDataViewML data, int maxRows = int.MaxValue)
 => CreateDataObj.DataView(data.Preview(maxRows).RowView.Select(x => CreateDataObj.Data(x.Values, true)).ToArray());