using System; namespace TsSFCDevice.Control.CustomFormatProvider { public class StatusFormatter : IFormatProvider, ICustomFormatter { public object GetFormat(Type formatType) { if (formatType == typeof(ICustomFormatter)) { return this; } return null; } public string Format(string format, object arg, IFormatProvider formatProvider) { string value = string.Empty; switch (format.ToLower()) { case "tag": value = tagFormat(arg); break; case "status": value = StatusFormat(arg); break; case "Enable": value = EnableFormat(arg); break; default: break; } return value; } string tagFormat(object arg) { string value = string.Empty; switch (arg?.ToString() ?? "") { case "N": value = "已提交"; break; case "C": value = "已完成"; break; default: break; } return value; } string EnableFormat(object arg) { bool Enable = false; bool.TryParse(arg + "", out Enable); return Enable ? "启用" : "禁用"; } string StatusFormat(object arg) { string value = string.Empty; switch (arg?.ToString() ?? "") { case "A": value = "启用"; break; case "D": value = "停用"; break; default: break; } return value; } } }