예제 #1
0
        public static Encoding GetEncoding(this Encodes encode)
        {
            if (_encodesMap.TryGetValue(encode, out var result))
            {
                return(result);
            }

            return(Encoding.UTF8);
        }
예제 #2
0
        /// <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 }));
 }