當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。