System.Text.SuperEncoding.GetEncoding C# (CSharp) Метод

GetEncoding() публичный статический Метод

获取Encoding(非BIG5、GB2312编码调用原有的Encoding.GetEncoding)
public static GetEncoding ( string name ) : Encoding
name string
Результат Encoding
        public static new Encoding GetEncoding(string name)
        {
            if (!_supportedEncoding.Any(m => m.Equals(name, StringComparison.OrdinalIgnoreCase)))
            {
                return Encoding.GetEncoding(name);
            }

            name = name.ToLower();
            SuperEncoding encoding = new SuperEncoding();
            encoding._webName = name;
            if (_cache.ContainsKey(name))
            {
                var tuple = _cache[name];
                encoding._dbcsToUnicode = tuple.Item1;
                encoding._unicodeToDbcs = tuple.Item2;
                return encoding;
            }
            var dbcsToUnicode = new char[0x10000];
            var unicodeToDbcs = new ushort[0x10000];
            /*
             * According to many feedbacks, add this automatic function for finding resource in revision 1.0.0.1.
             * We suggest that use the old method as below if you understand how to embed the resource.
             * Please make sure the *.bin file was correctly embedded if throw an exception at here.
             */
            using (Stream stream = typeof(SuperEncoding).GetTypeInfo().Assembly
                .GetManifestResourceStream(typeof(SuperEncoding).GetTypeInfo().Assembly.
                GetManifestResourceNames().Single(s => s.EndsWith("." + name + ".bin"))))
            using (BinaryReader reader = new BinaryReader(stream))
            {
                for (int i = 0; i < 0xffff; i++)
                {
                    ushort u = reader.ReadUInt16();
                    unicodeToDbcs[i] = u;
                }
                for (int i = 0; i < 0xffff; i++)
                {
                    ushort u = reader.ReadUInt16();
                    dbcsToUnicode[i] = (char)u;
                }
            }

            _cache[name] = new Tuple<char[], ushort[]>(dbcsToUnicode, unicodeToDbcs);
            encoding._dbcsToUnicode = dbcsToUnicode;
            encoding._unicodeToDbcs = unicodeToDbcs;
            return encoding;
        }