Ejemplo n.º 1
0
        /// <summary>
        /// 将数据写入器转换为具有键的类型的具体数据写入器。
        /// </summary>
        /// <param name="dataRW">数据写入器</param>
        /// <typeparam name="T">键的类型</typeparam>
        /// <returns>返回具体数据写入器</returns>
        public static IDataRW <T> As <T>(this IDataRW dataRW)
        {
            if (dataRW is IDataRW <T> tRW)
            {
                return(tRW);
            }

            if (dataRW is IAsDataRW asRW)
            {
                return(As <T>(asRW.Original));
            }

            if (dataRW is IDataRW <string> strRW)
            {
                return(new AsDataRW <string, T>(strRW));
            }

            if (dataRW is IDataRW <int> intRW)
            {
                return(new AsDataRW <int, T>(intRW));
            }

            if (AsHelper.GetInstance(dataRW) is AsHelper asHelper)
            {
                return(asHelper.As <T>(dataRW));
            }

            throw new NotSupportedException("Unsupported object.");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 将数据写入器转换为具有键的类型的具体数据写入器。
        /// </summary>
        /// <param name="dataWriter">数据写入器</param>
        /// <typeparam name="T">键的类型</typeparam>
        /// <returns>返回具体数据写入器</returns>
        public static IDataWriter <T> As <T>(this IDataWriter dataWriter)
        {
            if (dataWriter is IDataWriter <T> tWriter)
            {
                return(tWriter);
            }

            if (dataWriter is IAsDataWriter asWriter)
            {
                return(As <T>(asWriter.Original));
            }

            if (dataWriter is IDataWriter <string> strWriter)
            {
                return(new AsDataWriter <string, T>(strWriter));
            }

            if (dataWriter is IDataWriter <int> intWriter)
            {
                return(new AsDataWriter <int, T>(intWriter));
            }

            if (AsHelper.GetInstance(dataWriter) is AsHelper asHelper)
            {
                return(asHelper.As <T>(dataWriter));
            }

            throw new NotSupportedException("Unsupported object.");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建授权代理的数据写入器。
        /// </summary>
        /// <typeparam name="TOutput">授权的字段类型</typeparam>
        /// <typeparam name="TValue">字典的 Value 类型,此功能无需用到该值</typeparam>
        /// <param name="dataWriter">原始数据</param>
        /// <param name="authorizedKeys">一个标识允许访问的字段列表</param>
        /// <returns>返回一个已代理的数据写入器</returns>
        public static IDataWriter CreateAuthorizedKeysWriter <TOutput, TValue>(IDataWriter dataWriter, Dictionary <TOutput, TValue> authorizedKeys)
        {
            var invoker = new CreateAuthorizedKeysRWInvoker <TOutput, TValue>(dataWriter, authorizedKeys);

            AsHelper.GetInstance(dataWriter).Invoke(invoker);

            return((IDataWriter)invoker.AuthorizedKeysRW);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 将数据写入器转换为具有键的类型的具体数据写入器。
        /// </summary>
        /// <param name="dataRW">数据写入器</param>
        /// <typeparam name="T">键的类型</typeparam>
        /// <returns>返回具体数据写入器</returns>
        public static IDataRW <T> As <T>(this IDataRW dataRW)
        {
            if (dataRW is IDataRW <T> t)
            {
                return(t);
            }

            if (dataRW is IAsDataRW a)
            {
                return(As <T>(a.Content));
            }

            if (dataRW is IDataRW <string> s)
            {
                return(new AsDataRW <string, T>(s));
            }

            if (dataRW is IDataRW <int> i)
            {
                return(new AsDataRW <int, T>(i));
            }

            return(AsHelper.GetInstance(dataRW).As <T>(dataRW));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 将数据写入器转换为具有键的类型的具体数据写入器。
        /// </summary>
        /// <param name="dataWriter">数据写入器</param>
        /// <typeparam name="T">键的类型</typeparam>
        /// <returns>返回具体数据写入器</returns>
        public static IDataWriter <T> As <T>(this IDataWriter dataWriter)
        {
            if (dataWriter is IDataWriter <T> t)
            {
                return(t);
            }

            if (dataWriter is IAsDataWriter a)
            {
                return(As <T>(a.Content));
            }

            if (dataWriter is IDataWriter <string> s)
            {
                return(new AsDataWriter <string, T>(s));
            }

            if (dataWriter is IDataWriter <int> i)
            {
                return(new AsDataWriter <int, T>(i));
            }

            return(AsHelper.GetInstance(dataWriter).As <T>(dataWriter));
        }