当前位置: 首页>>代码示例>>C#>>正文


C# Encoding.GetType方法代码示例

本文整理汇总了C#中System.Text.Encoding.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Encoding.GetType方法的具体用法?C# Encoding.GetType怎么用?C# Encoding.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.Encoding的用法示例。


在下文中一共展示了Encoding.GetType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EncodingIsRight

        /// <summary>
        /// Encodings the is right.
        /// </summary>
        /// <param name="encoding">The encoding.</param>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public static bool EncodingIsRight(Encoding encoding, byte[] data)
        {
            string text;
            byte[] bytes;
            //string text= encoding.GetString(data);
            //byte[] bytes = encoding.GetBytes(text);
            if (encoding.GetType().Name == "UnicodeEncoding")
            {
                text = ConversionHelper.GetStringUnicode(data);
                bytes = ConversionHelper.GetBytesUnicode(text);

            }
            else
            {
                text = ConversionHelper.GetString(data);
                bytes = ConversionHelper.GetBytes(text);
            }

            if (Algorithm.ArrayEqual(bytes, data))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
开发者ID:YHTechnology,项目名称:DocumentManager,代码行数:33,代码来源:TextEncoding.cs

示例2: StringToHeap

		private static void StringToHeap (string s, Encoding e, bool mustBeEqual)
		{
			IntPtr p = UnixMarshal.StringToHeap (s, e);
			try {
				string _s = UnixMarshal.PtrToString (p, e);
				if (mustBeEqual)
					Assert.AreEqual (s, _s, "#TSTA (" + e.GetType() + ")");
			}
			finally {
				UnixMarshal.FreeHeap (p);
			}
		}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:12,代码来源:UnixMarshalTest.cs

示例3: GetStringByteLength

        private static int GetStringByteLength(IntPtr p, Encoding encoding)
        {
            Type encodingType = encoding.GetType ();

            int len = -1;

            // Encodings that will always end with a single null byte
            if (typeof(UTF8Encoding).IsAssignableFrom (encodingType) ||
                    typeof(UTF7Encoding).IsAssignableFrom (encodingType) ||
                    typeof(UnixEncoding).IsAssignableFrom (encodingType) ||
                    typeof(ASCIIEncoding).IsAssignableFrom (encodingType)) {
                len = checked ((int) Native.Stdlib.strlen (p));
            }
            // Encodings that will always end with a 0x0000 16-bit word
            else if (typeof(UnicodeEncoding).IsAssignableFrom (encodingType)) {
                len = GetInt16BufferLength (p);
            }
            // Some non-public encoding, such as Latin1 or a DBCS charset.
            // Look for a sequence of encoding.GetMaxByteCount() bytes that are all
            // 0, which should be the terminating null.
            // This is "iffy", since it may fail for variable-width encodings; for
            // example, UTF8Encoding.GetMaxByteCount(1) = 4, so this would read 3
            // bytes past the end of the string, possibly into garbage memory
            // (which is why we special case UTF above).
            else {
                len = GetRandomBufferLength (p, encoding.GetMaxByteCount(1));
            }

            if (len == -1)
                throw new NotSupportedException ("Unable to determine native string buffer length");
            return len;
        }
开发者ID:xxtbg,项目名称:coredroidservice,代码行数:32,代码来源:UnixMarshal.cs

示例4: SafeDecodeString

        /// <summary>
        /// Safes the decode string.
        /// </summary>
        /// <param name="encoding">The encoding.</param>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public static object SafeDecodeString(Encoding encoding, byte[] data)
        {
            //string text = encoding.GetString(data);
            //byte[] bytes = encoding.GetBytes(text);

            //if (Algorithm.ArrayEqual(bytes, data))
            //{
            //    return text;
            //}
            //else
            //{
            //    return data;
            //}

            string text;
            byte[] bytes;
            //string text= encoding.GetString(data);
            //byte[] bytes = encoding.GetBytes(text);
            if (encoding.GetType().Name == "UnicodeEncoding")
            {
                text = ConversionHelper.GetStringUnicode(data);
                bytes = ConversionHelper.GetBytesUnicode(text);

            }
            else
            {
                text = ConversionHelper.GetString(data);
                bytes = ConversionHelper.GetBytes(text);
            }

            if (Algorithm.ArrayEqual(bytes, data))
            {
                return text;
            }
            else
            {
                return data;
            }
        }
开发者ID:YHTechnology,项目名称:DocumentManager,代码行数:45,代码来源:TextEncoding.cs

示例5: MultipleTextWriters

			public MultipleTextWriters (params TextWriter [] writers)
			{
				if (writers == null)
					throw new ArgumentNullException (nameof (writers));
				if (writers.Length == 0)
					throw new ArgumentOutOfRangeException (nameof (writers));

				this.writers = writers;
				encoding = writers [0].Encoding;

				foreach (var writer in writers) {
					if (encoding.GetType () != writer.Encoding.GetType ()) {
						throw new Exception ("Encodings mismatch between writers.");
					}
				}
			}
开发者ID:anhlehoang410,项目名称:monodevelop,代码行数:16,代码来源:MultipleOperationConsoles.cs


注:本文中的System.Text.Encoding.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。