Ejemplo n.º 1
0
        public static object GetStaticValue(FieldInfo info)
        {
            TkDebug.AssertArgumentNull(info, "info", null);

            try
            {
                return(info.GetValue(null));
            }
            catch (MemberAccessException ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "调用方没有访问类型{0}中字段{1}的权限",
                                                            info.DeclaringType, info.Name), ex, null);
            }
            catch (ArgumentException ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "类型{0}中既不声明字段{1}也不继承字段{1}",
                                                            info.DeclaringType, info.Name), ex, null);
            }
            catch (NotSupportedException ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "类型{0}中字段{1}被标记为文本,但是该字段没有一个可接受的文本类型",
                                                            info.DeclaringType, info.Name), ex, null);
            }
            catch (Exception ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "对象{0}中字段{1}可能不是静态的,请检查",
                                                            info.DeclaringType, info.Name), ex, null);
            }
            TkDebug.ThrowImpossibleCode(null);
            return(null);
        }
Ejemplo n.º 2
0
        public string GetTemplateUrl(IPageStyle style, IPageData pageData)
        {
            if (style == null || pageData == null)
            {
                return(string.Empty);
            }

            var       info        = pageData.SourceInfo;
            string    source      = info.Source;
            PageStyle pageStyle   = style.Style;
            string    styleString = pageStyle.ToString().ToLower(ObjectUtil.SysCulture);

            switch (pageStyle)
            {
            case PageStyle.Custom:
                return($"c/{info.ModuleCreator}/{style}/{source}");

            case PageStyle.Insert:
            case PageStyle.List:
            case PageStyle.Update:
            case PageStyle.Delete:
            case PageStyle.Detail:
                return($"c/{info.ModuleCreator}/{styleString}/{source}");

            default:
                TkDebug.ThrowImpossibleCode(this);
                return(null);
            }
        }
Ejemplo n.º 3
0
        public static string GetName(NamingRule rule, string fieldName)
        {
            if (string.IsNullOrEmpty(fieldName))
            {
                return(fieldName);
            }

            switch (rule)
            {
            case NamingRule.Pascal:
                if (char.IsUpper(fieldName[0]))
                {
                    return(fieldName);
                }
                return(char.ToUpper(fieldName[0], ObjectUtil.SysCulture)
                       + fieldName.Substring(1));

            case NamingRule.Camel:
                if (char.IsLower(fieldName[0]))
                {
                    return(fieldName);
                }
                return(char.ToLower(fieldName[0], ObjectUtil.SysCulture)
                       + fieldName.Substring(1));

            case NamingRule.Upper:
                return(fieldName.ToUpper());

            case NamingRule.Lower:
                return(fieldName.ToLower());

            case NamingRule.UnderLineLower:
                return(GetUnderlineLowerName(fieldName));

            default:
                TkDebug.ThrowImpossibleCode(null);
                return(string.Empty);
            }
        }
Ejemplo n.º 4
0
        public static object GetValue(PropertyInfo info, object receiver)
        {
            TkDebug.AssertArgumentNull(info, "info", null);
            TkDebug.AssertArgumentNull(receiver, "receiver", null);

            try
            {
                return(info.GetValue(receiver, null));
            }
            catch (MemberAccessException ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "无法从对象{0}中获取属性{1}的值,请检查get的访问权限",
                                                            receiver.GetType(), info.Name), ex, null);
            }
            catch (Exception ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "对象{0}中可能不存在属性{1},请检查",
                                                            receiver.GetType(), info.Name), ex, null);
            }
            TkDebug.ThrowImpossibleCode(null);
            return(null);
        }