本文整理汇总了C#中System.Text.Encoding.IsNull方法的典型用法代码示例。如果您正苦于以下问题:C# Encoding.IsNull方法的具体用法?C# Encoding.IsNull怎么用?C# Encoding.IsNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.Encoding
的用法示例。
在下文中一共展示了Encoding.IsNull方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetReader
/// <summary>
/// Opens a StreamReader using the specified encoding.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="encoding">The encoding.</param>
/// <returns>The stream reader</returns>
public static StreamReader GetReader(this Stream stream, Encoding encoding)
{
if (!stream.CanRead)
{
throw new InvalidOperationException("Stream does not support reading.");
}
return encoding.IsNull()
? new StreamReader(stream, true)
: new StreamReader(stream, encoding);
}
示例2: Base64Decode
/// <summary>
/// Base64解密
/// </summary>
/// <param name="decryptString">密文</param>
/// <param name="encoding">编码</param>
/// <returns>明文</returns>
public static string Base64Decode(this string decryptString, Encoding encoding = null) {
byte[] decbuff = Convert.FromBase64String(decryptString);
return (encoding.IsNull() ? System.Text.Encoding.UTF8 : encoding).GetString(decbuff);
}
示例3: WriteForFileStream
/// <summary>
/// 写日志 线程安全
/// </summary>
/// <param name="fileName">文件</param>
/// <param name="str">消息</param>
/// <param name="encoding">编码</param>
private static bool WriteForFileStream(string fileName, string str, Encoding encoding = null) {
bool _isTrue = false;
if (encoding.IsNull()) encoding = Encoding.Default;
lock (lockHelper) {
using (FileStream fs = FileDirectory.FileExists(fileName) ? File.OpenWrite(fileName) : File.Create(fileName)) {
byte[] bt = encoding.IfNull(Encoding.UTF8).GetBytes(str + Environment.NewLine);
fs.Seek(0, SeekOrigin.End);
fs.Write(bt, 0, bt.Length);
_isTrue = true;
}
}
return _isTrue;
}
示例4: Base64Encode
public static string Base64Encode(this string encryptString, Encoding encoding = null) {
byte[] encbuff = (encoding.IsNull() ? System.Text.Encoding.UTF8 : encoding).GetBytes(encryptString);
return Convert.ToBase64String(encbuff);
}
示例5: WriteForStreamWriter
/// <summary>
/// 写日志 线程安全
/// </summary>
/// <param name="fileName">文件</param>
/// <param name="str">消息</param>
/// <param name="encoding">编码</param>
private static bool WriteForStreamWriter(string fileName, string str, Encoding encoding = null) {
bool _isTrue = false;
if (encoding.IsNull()) encoding = Encoding.Default;
lock (lockHelper) {
using (System.IO.StreamWriter f2 = new System.IO.StreamWriter(fileName, true, encoding.IfNull(Encoding.UTF8))) { f2.WriteLine(str); _isTrue = true; }
}
return _isTrue;
}