コード例 #1
0
        /// <summary>
        /// 从配置文件获取 检测项目、该检测项目所用的检测命令类 键值对
        /// </summary>
        /// <returns></returns>
        private void InitializeCommandDictionary()  //项目名称,该检测项目所用的检测命令类
        {
            ResourceManager manager     = new ResourceManager("Microstar.Production.PCBTest.Properties.Resources", typeof(Resources).Assembly);
            var             commandList = SerializeHelper.DeserializeXML <CommandDescriptions>(Settings.Default.ProfilePath);

            if (!commandDictionary.IsValueCreated)
            {
                foreach (CommandDescription commandDescription in commandList.Command)
                {
                    object instance = Reflections.CreateInstance("Microstar.Production.PCBTest.Command." + commandDescription.CommandType);

                    commandDictionary.Value.Add(
                        manager.GetString(commandDescription.ResoureId),
                        (ICommand)instance);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 检测项目、误差控件键值对
        /// </summary>
        /// <returns></returns>
        private void InitializeErrorControlDictionary()  //项目名称,误差控件名称
        {
            ResourceManager manager = new ResourceManager("Microstar.Production.PCBTest.Properties.Resources", typeof(Resources).Assembly);

            var commandList = SerializeHelper.DeserializeXML <CommandDescriptions>(Settings.Default.ProfilePath);

            if (!errorControlDictionary.IsValueCreated)
            {
                foreach (CommandDescription commandDescription in commandList.Command)
                {
                    object instance = Reflections.CreateInstance("Microstar.Production.PCBTest.Controls." + commandDescription.ErrorControlType);

                    errorControlDictionary.Value.Add(
                        manager.GetString(commandDescription.ResoureId),
                        (IParameterControl)instance);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// 注册AutoMapper对象映射操作
        /// </summary>
        /// <param name="services">服务集合</param>
        public static void AddAutoMapper(this IServiceCollection services)
        {
            var mapperProfileTypeFinder = services.GetOrAddTypeFinder <IMapperProfileTypeFinder>(assemblyFinder => new MapperProfileTypeFinder(assemblyFinder));
            var instances = mapperProfileTypeFinder
                            .FindAll()
                            .Select(type => Reflections.CreateInstance <IObjectMapperProfile>(type))
                            .ToList();
            var configuration = new MapperConfiguration(cfg =>
            {
                foreach (var instance in instances)
                {
                    Debug.WriteLine($"初始化AutoMapper配置:{instance.GetType().FullName}");
                    instance.CreateMap();
                    // ReSharper disable once SuspiciousTypeConversion.Global
                    cfg.AddProfile(instance as Profile);
                }
            });
            var mapper = new AutoMapperObjectMapper(configuration);

            ObjectMapperExtensions.SetMapper(mapper);
            services.TryAddSingleton <IObjectMapper>(mapper);
        }
コード例 #4
0
        public MapTest()
        {
            var allAssemblyFinder       = new AppDomainAllAssemblyFinder();
            var mapperProfileTypeFinder = new MapperProfileTypeFinder(allAssemblyFinder);
            var instances = mapperProfileTypeFinder
                            .FindAll()
                            .Select(type => Reflections.CreateInstance <IObjectMapperProfile>(type))
                            .ToList();
            var configuration = new MapperConfiguration(cfg =>
            {
                foreach (var instance in instances)
                {
                    Debug.WriteLine($"初始化AutoMapper配置:{instance.GetType().FullName}");
                    instance.CreateMap();
                    // ReSharper disable once SuspiciousTypeConversion.Global
                    cfg.AddProfile(instance as Profile);
                }
            });
            var mapper = new AutoMapperObjectMapper(configuration, instances);

            ObjectMapperExtensions.SetMapper(mapper);
        }