A strange thing, I have two enum sets:
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
}
when I try to print the following text,
ActionText =
string.Format("{0}ed a {1}", action.ComponentActionType, action.ComponentName);
will generate:
184ed a Logo instead of Added a Logo
action.ComponentActionType is converted to number (ToString didn’t help) and also a
strange number (like 184, not the enum number itself)
Any idea how to solve this?
Update:
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
};
}
Can you check how the ComponentActionType field is filled? Enum values can contain other values than listed. For example: this is perfectly valid:
(If it wasn’t allowed by default, masking with enums would not be possible). The string representation in this case for b is 7, because it cannot be matched to an item in the enumeration.