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


C# Encoding.NullCheck方法代码示例

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


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

示例1: FromBase64

 /// <summary>
 /// 将用Base64编码字符串还原
 /// <param name="input">输入字符串</param>
 /// <param name="encodingUsing">默认编码UTF-8</param>
 /// </summary>
 public static string FromBase64(this string input, Encoding encodingUsing = null)
 {
     if (string.IsNullOrEmpty(input))
         return "";
     byte[] tempArray = Convert.FromBase64String(input);
     return encodingUsing.NullCheck(Encoding.UTF8).GetString(tempArray);
 }
开发者ID:yiwayhb,项目名称:UtilityLib,代码行数:12,代码来源:StringExtensions.cs

示例2: ToEncodedString

 /// <summary>
 /// Converts a byte array to a string
 /// </summary>
 public static string ToEncodedString(this byte[] input, Encoding encodingUsing = null, int index = 0, int count = -1)
 {
     if (input == null)
         return "";
     if (count == -1)
         count = input.Length - index;
     return encodingUsing.NullCheck(new UTF8Encoding()).GetString(input, index, count);
 }
开发者ID:yiwayhb,项目名称:UtilityLib,代码行数:11,代码来源:ValueTypeExtensions.cs

示例3: ToEncodedString

 /// <summary>
 /// Converts a byte array to a string
 /// </summary>
 /// <param name="Input">input array</param>
 /// <param name="EncodingUsing">The type of encoding the string is using (defaults to UTF8)</param>
 /// <param name="Count">Number of bytes starting at the index to convert (use -1 for the entire array starting at the index)</param>
 /// <returns>string of the byte array</returns>
 public static string ToEncodedString(this byte[] Input, Encoding EncodingUsing = null, int Index = 0, int Count = -1)
 {
     if (Input.IsNull())
         return "";
     if (Count == -1)
         Count = Input.Length - Index;
     return EncodingUsing.NullCheck(new UTF8Encoding()).GetString(Input, Index, Count);
 }
开发者ID:JKLFA,项目名称:Craig-s-Utility-Library,代码行数:15,代码来源:ValueTypeExtensions.cs

示例4: Encode

 /// <summary>
 /// Converts a string to a string of another encoding
 /// </summary>
 /// <param name="Input">input string</param>
 /// <param name="OriginalEncodingUsing">The type of encoding the string is currently using (defaults to ASCII)</param>
 /// <param name="EncodingUsing">The type of encoding the string is converted into (defaults to UTF8)</param>
 /// <returns>string of the byte array</returns>
 public static string Encode(this string Input, Encoding OriginalEncodingUsing = null, Encoding EncodingUsing = null)
 {
     if (string.IsNullOrEmpty(Input))
         return "";
     OriginalEncodingUsing = OriginalEncodingUsing.NullCheck(new ASCIIEncoding());
     EncodingUsing = EncodingUsing.NullCheck(new UTF8Encoding());
     return Encoding.Convert(OriginalEncodingUsing, EncodingUsing, Input.ToByteArray(OriginalEncodingUsing))
                    .ToEncodedString(EncodingUsing);
 }
开发者ID:gwilkinson,项目名称:Craig-s-Utility-Library,代码行数:16,代码来源:StringExtensions.cs

示例5: ToByteArray

 /// <summary>
 /// Converts a string to a byte array
 /// </summary>
 /// <param name="Input">input string</param>
 /// <param name="EncodingUsing">The type of encoding the string is using (defaults to UTF8)</param>
 /// <returns>the byte array representing the string</returns>
 public static byte[] ToByteArray(this string Input, Encoding EncodingUsing = null)
 {
     return string.IsNullOrEmpty(Input) ? null : EncodingUsing.NullCheck(new UTF8Encoding()).GetBytes(Input);
 }
开发者ID:gwilkinson,项目名称:Craig-s-Utility-Library,代码行数:10,代码来源:StringExtensions.cs

示例6: ToBase64

 /// <summary>
 /// Converts from the specified encoding to a base 64 string
 /// </summary>
 /// <param name="Input">Input string</param>
 /// <param name="OriginalEncodingUsing">The type of encoding the string is using (defaults to UTF8)</param>
 /// <returns>Bas64 string</returns>
 public static string ToBase64(this string Input, Encoding OriginalEncodingUsing = null)
 {
     if (string.IsNullOrEmpty(Input))
         return "";
     byte[] TempArray = OriginalEncodingUsing.NullCheck(new UTF8Encoding()).GetBytes(Input);
     return Convert.ToBase64String(TempArray);
 }
开发者ID:gwilkinson,项目名称:Craig-s-Utility-Library,代码行数:13,代码来源:StringExtensions.cs

示例7: FromBase64

 /// <summary>
 /// Converts base 64 string based on the encoding passed in
 /// </summary>
 /// <param name="Input">Input string</param>
 /// <param name="EncodingUsing">The type of encoding the string is using (defaults to UTF8)</param>
 /// <returns>string in the encoding format</returns>
 public static string FromBase64(this string Input, Encoding EncodingUsing)
 {
     if (string.IsNullOrEmpty(Input))
         return "";
     byte[] TempArray = Convert.FromBase64String(Input);
     return EncodingUsing.NullCheck(new UTF8Encoding()).GetString(TempArray);
 }
开发者ID:gwilkinson,项目名称:Craig-s-Utility-Library,代码行数:13,代码来源:StringExtensions.cs

示例8: SaveAsync

 /// <summary>
 ///     Saves a string to a file (asynchronously)
 /// </summary>
 /// <param name="file">File to save to</param>
 /// <param name="content">Content to save to the file</param>
 /// <param name="callBack">Call back function</param>
 /// <param name="stateObject">State object</param>
 /// <param name="encodingUsing">Encoding that the content is using (defaults to ASCII)</param>
 /// <param name="mode">Mode for saving the file (defaults to Create)</param>
 /// <returns>The FileInfo object</returns>
 public static FileInfo SaveAsync(this FileInfo file, string content, AsyncCallback callBack,
                                  object stateObject, FileMode mode = FileMode.Create,
                                  Encoding encodingUsing = null)
 {
     Guard.NotNull(file, "file");
     return file.SaveAsync(encodingUsing.NullCheck(new ASCIIEncoding()).GetBytes(content), callBack, stateObject,
                           mode);
 }
开发者ID:OxPatient,项目名称:Rule-Engine,代码行数:18,代码来源:FileInfoExtensions.cs

示例9: Save

 /// <summary>
 ///     Saves a string to a file
 /// </summary>
 /// <param name="file">File to save to</param>
 /// <param name="content">Content to save to the file</param>
 /// <param name="encodingUsing">Encoding that the content is using (defaults to ASCII)</param>
 /// <param name="mode">Mode for saving the file (defaults to Create)</param>
 /// <returns>The FileInfo object</returns>
 public static FileInfo Save(this FileInfo file, string content, FileMode mode = FileMode.Create,
                             Encoding encodingUsing = null)
 {
     Guard.NotNull(file, "file");
     return file.Save(encodingUsing.NullCheck(new ASCIIEncoding()).GetBytes(content), mode);
 }
开发者ID:OxPatient,项目名称:Rule-Engine,代码行数:14,代码来源:FileInfoExtensions.cs

示例10: Encode

 /// <summary>
 ///     Converts a string to a string of another encoding
 /// </summary>
 /// <param name="input">input string</param>
 /// <param name="originalEncodingUsing">The type of encoding the string is currently using (defaults to ASCII)</param>
 /// <param name="encodingUsing">The type of encoding the string is converted into (defaults to UTF8)</param>
 /// <returns>string of the byte array</returns>
 public static string Encode(this string input, Encoding originalEncodingUsing = null,
                             Encoding encodingUsing = null)
 {
     if (string.IsNullOrEmpty(input))
         return "";
     originalEncodingUsing = originalEncodingUsing.NullCheck(new ASCIIEncoding());
     encodingUsing = encodingUsing.NullCheck(new UTF8Encoding());
     return Encoding.Convert(originalEncodingUsing, encodingUsing, input.ToByteArray(originalEncodingUsing))
                    .ToEncodedString(encodingUsing);
 }
开发者ID:OxPatient,项目名称:Rule-Engine,代码行数:17,代码来源:StringExtensions.cs

示例11: SaveAsync

 /// <summary>
 /// Saves a string to a file (asynchronously)
 /// </summary>
 /// <param name="File">File to save to</param>
 /// <param name="Content">Content to save to the file</param>
 /// <param name="CallBack">Call back function</param>
 /// <param name="StateObject">State object</param>
 /// <param name="EncodingUsing">Encoding that the content is using (defaults to ASCII)</param>
 /// <param name="Mode">Mode for saving the file (defaults to Create)</param>
 /// <returns>The FileInfo object</returns>
 public static FileInfo SaveAsync(this FileInfo File, string Content, AsyncCallback CallBack,
     object StateObject, FileMode Mode = FileMode.Create, Encoding EncodingUsing = null)
 {
     File.ThrowIfNull("File");
     return File.SaveAsync(EncodingUsing.NullCheck(new ASCIIEncoding()).GetBytes(Content), CallBack, StateObject, Mode);
 }
开发者ID:jerrymds,项目名称:Concord,代码行数:16,代码来源:FileInfoExtensions.cs

示例12: Save

 /// <summary>
 /// Saves a string to a file
 /// </summary>
 /// <param name="File">File to save to</param>
 /// <param name="Content">Content to save to the file</param>
 /// <param name="EncodingUsing">Encoding that the content is using (defaults to ASCII)</param>
 /// <param name="Mode">Mode for saving the file (defaults to Create)</param>
 /// <returns>The FileInfo object</returns>
 public static FileInfo Save(this FileInfo File, string Content, FileMode Mode = FileMode.Create, Encoding EncodingUsing = null)
 {
     File.ThrowIfNull("File");
     return File.Save(EncodingUsing.NullCheck(new ASCIIEncoding()).GetBytes(Content), Mode);
 }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:13,代码来源:FileInfoExtensions.cs

示例13: ToByteArray

 /// <summary>
 /// 将字符串编码为字节数组(默认编码为UTF8)
 /// </summary>
 public static byte[] ToByteArray(this string input, Encoding encodingUsing = null)
 {
     return string.IsNullOrEmpty(input) ? null : encodingUsing.NullCheck(Encoding.UTF8).GetBytes(input);
 }
开发者ID:yiwayhb,项目名称:UtilityLib,代码行数:7,代码来源:StringExtensions.cs

示例14: ToBase64

 /// <summary>
 /// 将字符串用Base64编码
 /// </summary>
 public static string ToBase64(this string input, Encoding originalEncodingUsing = null)
 {
     if (string.IsNullOrEmpty(input))
         return "";
     byte[] tempArray = originalEncodingUsing.NullCheck(Encoding.UTF8).GetBytes(input);
     return Convert.ToBase64String(tempArray);
 }
开发者ID:yiwayhb,项目名称:UtilityLib,代码行数:10,代码来源:StringExtensions.cs


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