/// <summary> /// 获取以制表符分开的行,按照表对应的列进行填充。 /// </summary> /// <param name="valDic"></param> /// <returns></returns> public string GetTabValues(Dictionary <string, T> valDic) { StringBuilder sb = new StringBuilder(); int i = -1; foreach (var item in WholeColTitles) { i++; //非关键标题则跳过 if (KeyNames != null && !KeyNames.Contains(item)) { continue; } if (i != 0) { sb.Append("\t"); } if (valDic.ContainsKey(item)) { sb.Append(String.Format(new NumeralFormatProvider(), "{0}", valDic[item])); } else { sb.Append(String.Format(new NumeralFormatProvider(), "{0}", Placeholder)); }; //占位 } return(sb.ToString()); }
protected override bool IsValue(string name) { if (ColumnsDef.Any(c => c.Name == name && c.Role != ColumnRole.Value)) { return(false); } if (ColumnsDef.Any(c => c.Name == name && c.Role == ColumnRole.Value)) { return(true); } if (KeyNames.Contains(name)) { return(false); } if (ValueNames.Contains(name)) { return(true); } if (ValueNames.Count > 0) { return(false); } return(false); }
protected override bool IsKey(string name) { if (ColumnsDef.Any(c => (c.Identifier as ColumnNameIdentifier)?.Name == name && c.Role != ColumnRole.Key)) { return(false); } if (ColumnsDef.Any(c => (c.Identifier as ColumnNameIdentifier)?.Name == name && c.Role == ColumnRole.Key)) { return(true); } if (KeyNames.Contains(name)) { return(true); } if (ValueNames.Contains(name)) { return(false); } if (ValueNames.Count > 0 && KeyNames.Count == 0) { return(true); } return(false); }
/// <summary> /// Removes a key from this keyring. /// </summary> /// <param name="name">Name of key to remove</param> public void Remove(string name) { if (ReadOnly) { throw new Exception("Keyring is read-only."); } if (KeyNames.Contains(name)) { throw new Exception("Key not found."); } Keys.RemoveAll(k => k.Name == name); KeyNames.Remove(name); KeyringChanged?.Invoke(); }
/// <summary> /// Adds a key to this keyring. /// </summary> /// <param name="name">Name of the key</param> /// <param name="key">Key encryption data</param> /// <param name="preLocked">If the key should be locked immediately</param> public void Add(string name, EncryptionKey key, bool preLocked = false) { if (ReadOnly) { throw new Exception("Keyring is read-only."); } if (KeyNames.Contains(name)) { throw new Exception("Key already exists. If replacing, use Remove() first."); } var newKey = new KeyDescriptor(name, key, preLocked); newKey.KeyLockChanged += locked => { KeyringChanged?.Invoke(); }; Keys.Add(newKey); KeyNames.Add(newKey.Name); KeyringChanged?.Invoke(); }
/// <summary> /// Checks if the keyring has a definition for the given key name. /// </summary> /// <param name="name">Name of key to check</param> /// <returns></returns> public bool HasKey(string name) { return(KeyNames.Contains(name)); }