コード例 #1
0
 public void AddIfNotNull(string key, StringEnum value)
 {
     if (value != null)
     {
         this.Add(key, value.ToString());
     }
 }
コード例 #2
0
ファイル: StringEnumTest.cs プロジェクト: startere/p4api.net
        public void ToStringTest()
        {
            StringEnum <myEnum> target = new StringEnum <myEnum>(myEnum.Alpha);;

            string expected = "Alpha";
            string actual   = target.ToString();

            Assert.AreEqual(expected, actual);

            target = new StringEnum <myEnum>(myEnum.beta);;

            expected = "beta";
            actual   = target.ToString();

            Assert.AreEqual(expected, actual);

            target = new StringEnum <myEnum>(myEnum.GAMMA);;

            expected = "GAMMA";
            actual   = target.ToString();

            Assert.AreEqual(expected, actual);

            target = new StringEnum <myEnum>(myEnum.DeltaEpsilon);

            expected = "DeltaEpsilon";
            actual   = target.ToString();

            Assert.AreEqual(expected, actual);
        }
コード例 #3
0
        object list(string userName, string permission)
        {
            var site = (Site)jc["site"];

            WebQuery q = new WebQuery();

            q.Id = "users.list";
            q.LoadCondidtion();

            if (!string.IsNullOrEmpty(userName))
            {
                q["userName"] = userName;
            }
            if (!string.IsNullOrEmpty(permission))
            {
                q["permission"] = permission;
            }

            q["siteId"] = site.Id;

            q.TotalCount = SiteUsers.Count(q);
            if (q.PageIndex1 > q.PageCount)
            {
                q.PageIndex = Math.Max(q.PageCount - 1, 0);
            }

            var dt   = SiteUsers.GetDataTable(q);
            var data = new ArrayList();

            foreach (DataRow item in dt.Rows)
            {
                data.Add(new
                {
                    id              = item["userId"].ToString(),
                    user_name       = item["userName"] is DBNull ? "用户不存在" : item["userName"].ToString(),
                    display_name    = item["displayName"] is DBNull ? "用户不存在" : item["displayName"].ToString(),
                    mobile          = item["mobile"] is DBNull ? "用户不存在" : item["mobile"].ToString(),
                    email           = item["email"] is DBNull ? "用户不存在" : item["email"].ToString(),
                    post_count      = item["postCount"].ToInt(),
                    permission      = StringEnum <PermissionLevel> .ToString(StringEnum <PermissionLevel> .SafeParse(item["permission"].ToString())),
                    date_created    = item["dateCreated"].ToDateTime(),
                    date_last_visit = item["dateLastVisit"].ToDateTime()
                });
            }

            return(new
            {
                code = 1,
                data = data,
                paging = new
                {
                    total_count = q.TotalCount,
                    page_size = q.PageSize,
                    page_index = q.PageIndex1
                },
                orderbys = q.orderbys
            });
        }
コード例 #4
0
ファイル: PostsController.cs プロジェクト: leixu2txtek/lSites
        object trash(string key)
        {
            var site = (Site)jc["site"];

            WebQuery q = new WebQuery();

            q.Id = "trash.list";
            q.LoadCondidtion();

            if (!string.IsNullOrEmpty(key))
            {
                q["key"] = key;
            }

            q["siteId"] = site.Id;
            q["userId"] = jc.UserName;

            q.TotalCount = Posts.Count(q);
            if (q.PageIndex1 > q.PageCount)
            {
                q.PageIndex = Math.Max(q.PageCount - 1, 0);
            }

            var dt   = Posts.GetDataTable(q);
            var data = new ArrayList();

            foreach (DataRow item in dt.Rows)
            {
                data.Add(new
                {
                    id             = item["id"].ToString(),
                    title          = item["title"].ToString(),
                    category       = item["category"] is DBNull ? string.Empty : item["category"].ToString(),
                    date_created   = item["dateCreated"].ToDateTime(),
                    view_count     = item["viewCount"].ToInt(),
                    sort_order     = item["sortOrder"].ToInt(),
                    status         = StringEnum <Status> .ToString(StringEnum <Status> .SafeParse(item["status"].ToString())),
                    display_name   = item["displayName"] is DBNull ? "未知用户" : item["displayName"].ToString(),
                    date_published = item["datePublished"].ToDateTime()
                });
            }

            return(new
            {
                code = 1,
                data = data,
                paging = new
                {
                    total_count = q.TotalCount,
                    page_size = q.PageSize,
                    page_index = q.PageIndex1
                },
                orderbys = q.orderbys
            });
        }
コード例 #5
0
ファイル: StringManager.cs プロジェクト: nuxleus/ajaxmin
        public static string GetString(StringEnum stringEnum, params object[] args)
        {
            // get the identifier
            string ident = stringEnum.ToString();

            // get the string from resources using the current ui culture
            string format = s_resources.GetString(ident, CultureInfo.CurrentUICulture);
            if (format != null)
            {
                // if we have an array of args
                if (args != null && args.Length > 0)
                {
                    // format the string with the args
                    format = string.Format(CultureInfo.CurrentCulture, format, args);
                }
            }
            else
            {
                // just use the identifier as a last-ditch default
                format = ident;
            }
            return format;
        }
コード例 #6
0
        public static string GetString(StringEnum stringEnum, params object[] args)
        {
            // get the identifier
            string ident = stringEnum.ToString();

            // get the string from resources using the current ui culture
            string format = s_resources.GetString(ident, CultureInfo.CurrentUICulture);

            if (format != null)
            {
                // if we have an array of args
                if (args != null && args.Length > 0)
                {
                    // format the string with the args
                    format = string.Format(CultureInfo.CurrentCulture, format, args);
                }
            }
            else
            {
                // just use the identifier as a last-ditch default
                format = ident;
            }
            return(format);
        }
コード例 #7
0
ファイル: StringEnumTest.cs プロジェクト: startere/p4api.net
        public void ToStringTest2()
        {
            // lower
            StringEnum <myEnum> target = new StringEnum <myEnum>(myEnum.Alpha);;

            string expected = "Alpha".ToLower();
            string actual   = target.ToString(StringEnumCase.Lower);

            Assert.AreEqual(expected, actual);

            target = new StringEnum <myEnum>(myEnum.beta);;

            expected = "beta".ToLower();
            actual   = target.ToString(StringEnumCase.Lower);

            Assert.AreEqual(expected, actual);

            target = new StringEnum <myEnum>(myEnum.GAMMA);;

            expected = "GAMMA".ToLower();
            actual   = target.ToString(StringEnumCase.Lower);

            Assert.AreEqual(expected, actual);

            target = new StringEnum <myEnum>(myEnum.DeltaEpsilon);

            expected = "DeltaEpsilon".ToLower();
            actual   = target.ToString(StringEnumCase.Lower);

            Assert.AreEqual(expected, actual);

            //upper
            target = new StringEnum <myEnum>(myEnum.Alpha);;

            expected = "Alpha".ToUpper();
            actual   = target.ToString(StringEnumCase.Upper);

            Assert.AreEqual(expected, actual);

            target = new StringEnum <myEnum>(myEnum.beta);;

            expected = "beta".ToUpper();
            actual   = target.ToString(StringEnumCase.Upper);

            Assert.AreEqual(expected, actual);

            target = new StringEnum <myEnum>(myEnum.GAMMA);;

            expected = "GAMMA".ToUpper();
            actual   = target.ToString(StringEnumCase.Upper);

            Assert.AreEqual(expected, actual);

            target = new StringEnum <myEnum>(myEnum.DeltaEpsilon);

            expected = "DeltaEpsilon".ToUpper();
            actual   = target.ToString(StringEnumCase.Upper);

            Assert.AreEqual(expected, actual);

            //keep case
            target = new StringEnum <myEnum>(myEnum.Alpha);;

            expected = "Alpha";
            actual   = target.ToString(StringEnumCase.None);

            Assert.AreEqual(expected, actual);

            target = new StringEnum <myEnum>(myEnum.beta);;

            expected = "beta";
            actual   = target.ToString(StringEnumCase.None);

            Assert.AreEqual(expected, actual);

            target = new StringEnum <myEnum>(myEnum.GAMMA);;

            expected = "GAMMA";
            actual   = target.ToString(StringEnumCase.None);

            Assert.AreEqual(expected, actual);

            target = new StringEnum <myEnum>(myEnum.DeltaEpsilon);

            expected = "DeltaEpsilon";
            actual   = target.ToString(StringEnumCase.None);

            Assert.AreEqual(expected, actual);
        }