PWMIS.Core/Entity/EntityBuilder.cs

(开头部分) 12KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;
using PWMIS.DataMap.Entity;
using PWMIS.Common;
using Entity.Common;

namespace PWMIS.DataMap.Entity
{
    /// <summary>
    /// PDF.NET实体类构造器,程序内部使用
    /// </summary>
    public class EntityBuilder
    {
        private Type targetType;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="targetType">被实现或者继承的类型</param>
        public EntityBuilder(Type targetType)
        {
            this.targetType = targetType;
        }

        private static Dictionary<Type, Type> dictEntityType = new Dictionary<Type, Type>();
        private static object sync_lock = new object();

        /// <summary>
        /// 根据接口类型,创建实体类的实例
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T CreateEntity<T>() where T:class
        {
            Type targetType = null;
            Type sourceType = typeof(T);
           
            if (sourceType.IsSubclassOf(typeof(EntityBase)) || sourceType.IsSubclassOf(typeof(IReadData)) 
                || !sourceType.IsInterface)
            {
               return Activator.CreateInstance<T>();
            }
            else
            {
                if (!dictEntityType.TryGetValue(sourceType, out targetType))
                {
                    lock (sync_lock)
                    {
                        if (!dictEntityType.TryGetValue(sourceType, out targetType))
                        {
                            EntityBuilder builder = new EntityBuilder(sourceType);
                            targetType = builder.Build();
                            dictEntityType[sourceType] = targetType;
                        }
                    }
                }
            }
后面还有 220 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。