public static string ResolveName(this Item item, ClilocLNG lng = ClilocLNG.ENU, bool setIfNull = false) { if (item == null) { return(String.Empty); } if (item.Name != null) { return(item.Name); } string label = item.DefaultName; if (String.IsNullOrWhiteSpace(label) && item.LabelNumber > 0) { label = lng.GetString(item.LabelNumber); } if (String.IsNullOrWhiteSpace(label) && TileData.ItemTable.InBounds(item.ItemID)) { label = TileData.ItemTable[item.ItemID].Name; } if (String.IsNullOrWhiteSpace(label)) { label = item.GetType().Name.SpaceWords(); } return(setIfNull ? (item.Name = label) : label); }
public static string GetString(this TextDefinition text, ClilocLNG lng) { if (lng == ClilocLNG.NULL) { lng = DefaultLanguage; } return(text.Number > 0 ? lng.GetString(text.Number) : (text.String ?? String.Empty)); }
public static string GetString(this TextDefinition text, ClilocLNG lng) { if (lng == ClilocLNG.NULL) { lng = DefaultLanguage; } return text.Number > 0 ? lng.GetString(text.Number) : (text.String ?? String.Empty); }
public static string ResolveName(this Item item, ClilocLNG lng = ClilocLNG.ENU, bool setIfNull = false) { if (item == null) { return(String.Empty); } var opl = item.PropertyList; if (opl == null) { opl = new ObjectPropertyList(item); item.GetProperties(opl); } var label = opl.GetHeader(); if (!String.IsNullOrEmpty(label)) { label = label.Replace("\t", " ").Replace("\u0009", " ").Replace("<br>", "\n").Replace("<BR>", "\n"); } if (!String.IsNullOrEmpty(label)) { var idx = label.IndexOf('\n'); if (idx >= 0) { label = label.Substring(0, label.Length - idx); } label = label.StripHtml(false); label = label.Trim(); idx = 0; while (idx < label.Length) { if (Char.IsNumber(label, idx)) { ++idx; } else if (Char.IsPunctuation(label, idx) && idx + 1 < label.Length && Char.IsNumber(label, idx + 1)) { ++idx; } else { break; } } if (idx > 0) { label = label.Substring(idx); label = label.Trim(); } } if (String.IsNullOrWhiteSpace(label) && item.Name != null) { label = item.Name; } if (String.IsNullOrWhiteSpace(label) && item.DefaultName != null) { label = item.DefaultName; } if (String.IsNullOrWhiteSpace(label) && item.LabelNumber > 0) { label = lng.GetString(item.LabelNumber); } if (String.IsNullOrWhiteSpace(label) && TileData.ItemTable.InBounds(item.ItemID)) { label = TileData.ItemTable[item.ItemID].Name; } if (String.IsNullOrWhiteSpace(label)) { label = item.GetType().Name.SpaceWords(); } if (!String.IsNullOrEmpty(label)) { label = label.StripExcessWhiteSpace().Trim(); } return(setIfNull ? (item.Name = label) : label); }
public static string ResolveName(this Item item, ClilocLNG lng) { if (item == null) { return(String.Empty); } var label = item.GetOPLHeader(lng); if (!String.IsNullOrEmpty(label)) { label = label.Replace("\t", " ").Replace("\u0009", " ").Replace("<br>", "\n").Replace("<BR>", "\n").Trim(); } if (!String.IsNullOrEmpty(label)) { label = label.StripHtml(false); label = label.Trim(); int idx; if ((idx = label.IndexOf('\n')) >= 0) { if (idx > 0) { label = label.Substring(0, idx); } else { label = label.TrimStart('\n'); } } label = label.Trim(); if ((idx = label.IndexOf(' ')) >= 0) { if (idx > 0) { int amount; if (Int32.TryParse(label.Substring(0, idx), NumberStyles.Number, CultureInfo.InvariantCulture, out amount)) { label = label.Substring(idx + 1); } } else { label = label.TrimStart(' '); } } label = label.Trim(); } if (String.IsNullOrWhiteSpace(label) && item.Name != null) { label = item.Name; } if (String.IsNullOrWhiteSpace(label) && item.DefaultName != null) { label = item.DefaultName; } if (String.IsNullOrWhiteSpace(label) && item.LabelNumber > 0) { label = lng.GetString(item.LabelNumber); } if (String.IsNullOrWhiteSpace(label) && TileData.ItemTable.InBounds(item.ItemID)) { label = TileData.ItemTable[item.ItemID].Name; } if (String.IsNullOrWhiteSpace(label)) { label = item.GetType().Name.SpaceWords(); } if (!String.IsNullOrEmpty(label)) { label = label.StripExcessWhiteSpace().Trim(); } return(label); }
public static string ResolveName(this Item item, ClilocLNG lng = ClilocLNG.ENU, bool setIfNull = false) { if (item == null) { return(String.Empty); } var label = item.PropertyList.DecodePropertyListHeader(lng) .Replace("\t", " ") .Replace("\u0009", " ") .Replace("<br>", "\n") .Replace("<BR>", "\n"); if (!String.IsNullOrWhiteSpace(label)) { var idx = label.IndexOf('\n'); if (idx >= 0) { label = label.Substring(0, label.Length - idx); } label = Regex.Replace(label, @"<[^>]*>", String.Empty); idx = label.IndexOf(' '); if (idx >= 0) { var words = label.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (words.Length > 0) { var amount = words[0].Replace(",", String.Empty).Replace(".", String.Empty).Trim(); label = String.Join(" ", (Int32.TryParse(amount, out idx) ? words.Skip(1) : words).Select(w => w.Trim())); } } label = label.Trim(); } if (String.IsNullOrWhiteSpace(label) && item.Name != null) { label = item.Name; } if (String.IsNullOrWhiteSpace(label) && item.DefaultName != null) { label = item.DefaultName; } if (String.IsNullOrWhiteSpace(label) && item.LabelNumber > 0) { label = lng.GetString(item.LabelNumber); } if (String.IsNullOrWhiteSpace(label) && TileData.ItemTable.InBounds(item.ItemID)) { label = TileData.ItemTable[item.ItemID].Name; } if (String.IsNullOrWhiteSpace(label)) { label = item.GetType().Name.SpaceWords(); } return(setIfNull ? (item.Name = label) : label); }