全部项目在.Net 2.0版本和4.0版本下编译通过,win10+vs2017需要在系统功能安装.Net2.0/3.5
大石头 authored at 2018-05-06 23:06:42
2.12 KiB
X
using System;
using NewLife.Model;
using NewLife.Reflection;
using XCode.Model;

namespace XCode.Accessors
{
    /// <summary>实体访问器工厂</summary>
    public static class EntityAccessorFactory
    {
        internal static void Reg(IObjectContainer container)
        {
            Func<Object, Object> callback = e =>
            {
                var ea = e as EntityAccessorBase;
                if (ea != null) return ea.Kind;

                return null;
            };
            // 注册内置访问器
            container
                .AutoRegister<IEntityAccessor, HttpEntityAccessor>(callback, EntityAccessorTypes.Http)
                .AutoRegister<IEntityAccessor, WebFormEntityAccessor>(callback, EntityAccessorTypes.WebForm)
                .AutoRegister<IEntityAccessor, WinFormEntityAccessor>(callback, EntityAccessorTypes.WinForm);
                //.AutoRegister<IEntityAccessor, BinaryEntityAccessor>(callback, EntityAccessorTypes.Binary)
                //.AutoRegister<IEntityAccessor, XmlEntityAccessor>(callback, EntityAccessorTypes.Xml)
                //.AutoRegister<IEntityAccessor, JsonEntityAccessor>(callback, EntityAccessorTypes.Json);
        }

        /// <summary>创建指定类型的实体访问器</summary>
        /// <param name="name">名称</param>
        /// <returns></returns>
        public static IEntityAccessor Create(String name)
        {
            return XCodeService.Container.Resolve<IEntityAccessor>(Enum.Parse(typeof(EntityAccessorTypes), name));
        }

        /// <summary>创建指定类型的实体访问器</summary>
        /// <param name="kind"></param>
        /// <returns></returns>
        public static IEntityAccessor Create(EntityAccessorTypes kind)
        {
            //return Create(kind);
            return XCodeService.Container.Resolve<IEntityAccessor>(kind);
        }

        internal static Boolean EqualIgnoreCase(this String str, EntityAccessorOptions option)
        {
            //if (String.IsNullOrEmpty(str)) return false;

            return str.EqualIgnoreCase(option.ToString());
        }
    }
}