v9.8.2018.0605   由DataReader直接映射实体列表,以支持netstandard的MySql和SQLite,且提升性能
大石头 authored at 2018-06-05 00:45:23
1.65 KiB
X
using System;
using System.Collections.Generic;
using System.Text;

namespace NewLife.Net.Common
{
    /// <summary>
    /// 弱引用
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class WeakReference<T> : WeakReference
    {
        /// <summary>
        /// 实例化
        /// </summary>
        public WeakReference() : base(null) { }

        /// <summary>
        /// 实例化
        /// </summary>
        /// <param name="target"></param>
        public WeakReference(T target) : base(target) { }

        /// <summary>
        /// 实例化
        /// </summary>
        /// <param name="target"></param>
        /// <param name="trackResurrection"></param>
        public WeakReference(T target, bool trackResurrection) : base(target, trackResurrection) { }

        /// <summary>
        /// 目标引用对象
        /// </summary>
        public new T Target
        {
            get { return (T)base.Target; }
            set { base.Target = value; }
        }

        /// <summary>
        /// 类型转换
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static implicit operator T(WeakReference<T> obj)
        {
            if (obj != null && obj.Target != null) return obj.Target;
            return default(T);
        }

        /// <summary>
        /// 类型转换
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public static implicit operator WeakReference<T>(T target)
        {
            return new WeakReference<T>(target);
        }
    }
}