public static Encoding GetEncoding(this Encodes encode) { if (_encodesMap.TryGetValue(encode, out var result)) { return(result); } return(Encoding.UTF8); }
/// <summary> /// Get the name of the encoding. /// </summary> public static string ToName(this Encodes e) { var info = e.GetType().GetRuntimeField(e.ToString()); var attributes = info.GetCustomAttributes(typeof(EncodeAttribute), false); if (attributes == null) { return(e.ToString()); } foreach (var item in attributes) { if (item is EncodeAttribute) { return((item as EncodeAttribute).Name); } } return(e.ToString()); }
private int GetByteCount(char c, Encodes encodes) { return(encodes.GetEncoding().GetByteCount(new[] { c })); }