Esempio n. 1
0
        /// <summary>
        ///     创建ResourceTemplate
        /// </summary>
        /// <param name="resourceTemplateType"></param>
        /// <param name="resourceName"></param>
        /// <returns></returns>
        /// added by sunjian 2019-12-24
        private static IResourceTemplate CreateTemplateResource(string resourceTemplateType, string resourceName)
        {
            try
            {
                var resourcePath = ResourceClassRegister.GetResourceTemplateFullName(resourceTemplateType);

                var packageName = ResourceClassRegister.GetPackageName(resourceTemplateType);

                var findingPath  = resourcePath + "," + packageName;
                var resourceType = Type.GetType(findingPath, true);

                var obj = Activator.CreateInstance(resourceType, resourceName);

                return((IResourceTemplate)obj);
            }
            catch (Exception ex)
            {
                Log.Error($"创建资源模板:{resourceTemplateType},名称:{resourceName}失败:{ex}");
                return(null);
            }
        }
Esempio n. 2
0
        private static IResource CreateResource(string strResourceType, string resourceName, string genericType)
        {
            // 根据类型加载资源 -- Dongmin 20171226
            try
            {
                var resourcePath = ResourceClassRegister.GetResourceFullName(strResourceType);

                var packageName = ResourceClassRegister.GetPackageName(strResourceType);

                var findingPath = resourcePath + "," + packageName;

                var resourceType = Type.GetType(findingPath, true);

                object obj;

                if (string.IsNullOrEmpty(genericType))
                {
                    obj = Activator.CreateInstance(resourceType, resourceName);
                }
                //sunjian 2020-08 增加泛型资源的创建,GenericType必须是实现了ICustomType接口的类
                else
                {
                    var genericObj = Parameter.CreateValue(genericType);

                    var makeGenericType = resourceType.MakeGenericType(genericObj.GetType());

                    obj = Activator.CreateInstance(makeGenericType, resourceName);
                }

                return((IResource)obj);
            }
            catch (Exception ex)
            {
                Log.Error($"创建资源类型:{strResourceType},名称:{resourceName}失败:{ex}");
                return(null);
            }
        }