Ejemplo n.º 1
0
        /// <summary>
        /// 获取成员信息
        /// </summary>
        /// <param name="binder"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            var propertyInfo = model.GetType().GetProperty(binder.Name);

            if (propertyInfo == null)
            {
                result = null;
                return(false);
            }

            result = propertyInfo.GetValue(model, null);

            if (result == null)
            {
                return(true);
            }

            var type = result.GetType();

            if (result.IsAnonymous())
            {
                result = new AnonymousTypeWrapper(result);
            }

            if (type.IsArray)
            {
                result = ((IEnumerable <object>)result).Select(e => new AnonymousTypeWrapper(e)).ToList();
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 执行编译
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <string> RunAsync(object model = null)
        {
            if (model != null && model.IsAnonymous())
            {
                model = new AnonymousTypeWrapper(model);
            }

            var instance = (IViewEngineTemplate)Activator.CreateInstance(templateType);

            instance.Model = model;

            await instance.ExecuteAsync();

            return(instance.Result());
        }