【发布时间】:2012-06-04 09:26:32
【问题描述】:
奇怪的是,我有两个枚举集:
public enum ComponentActionTypes {
Add = 0,
Move = 1,
Delete = 2,
Edit = 3,
Enable = 4,
Disable = 5
}
public enum ComponentNames {
Component = 0,
Logo = 1,
Main_menu = 2,
Search_box = 3,
Highlighter = 4,
RSS = 5,
Twitter = 6,
YouTube = 7
}
当我尝试打印以下文本时,
ActionText =
string.Format("{0}ed a {1}", action.ComponentActionType, action.ComponentName);
将生成:
184ed a Logo 而不是Added a Logo
action.ComponentActionType 被转换为数字(ToString 没有帮助),也是一个
奇怪的数字(如184,而不是枚举数本身)
知道如何解决这个问题吗?
更新:
namespace BrandToolbar.Common.ActionLog.Model
{
public class ActionItem
{
public Guid UserId { get; set; }
public Int64 PublicId { get; set; }
public ComponentActionTypes ComponentActionType { get; set; }
public DateTime Date { get; set; }
public ComponentNames ComponentName { get; set; }
public string UiJsonPreview { get; set; }
}
}
public static ActionItemUI ConvertModelToUiObj(ActionItem action)
{
return new ActionItemUI()
{
ActionText = string.Format(
"{0}ed a {1}",
action.ComponentActionType,
action.ComponentName
).Replace("_", " "),
TooltipText = string.Format(
"{0}ed on {1}",
action.ComponentActionType,
action.Date.ToString(StringFormatter.DateFormat)
),
ImageUrl = string.Empty,
ConponentText = string.Empty
};
}
【问题讨论】:
-
你确定
action.ComponentActionType真的是ComponentActionTypes类型吗? -
可能是个蹩脚的问题,但你确定 action.ComponentActionType 是 ComponentActionTypes 类型吗?我认为 .ToString() 至少会给你你需要的东西
-
你能展示创建你的动作对象的代码吗?此外,Action 类可能很有用。