本文整理汇总了C#中ICompressor.ShouldNotBeNull方法的典型用法代码示例。如果您正苦于以下问题:C# ICompressor.ShouldNotBeNull方法的具体用法?C# ICompressor.ShouldNotBeNull怎么用?C# ICompressor.ShouldNotBeNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICompressor
的用法示例。
在下文中一共展示了ICompressor.ShouldNotBeNull方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadFileWithCompress
public static MongoGridFSFileInfo UploadFileWithCompress(this IMongoRepository repository, ICompressor compressor, byte[] data,
string remoteFilename) {
compressor.ShouldNotBeNull("compressor");
var entry = new CompressedFileItem(compressor.GetType(), compressor.Compress(data));
using(var stream = new MemoryStream(FileSerializer.Serialize(entry))) {
return repository.UploadFile(remoteFilename, stream);
}
}
示例2: CreateStateEntity
/// <summary>
/// <paramref name="pageState"/> 정보를 직렬화해서, <see cref="IPageStateEntity"/> 객체로 빌드합니다.
/// </summary>
/// <param name="id"></param>
/// <param name="pageState"></param>
/// <param name="compressor"></param>
/// <param name="compressThreshold"></param>
/// <returns></returns>
public static IPageStateEntity CreateStateEntity(string id, object pageState, ICompressor compressor,
int compressThreshold = 40960) {
compressor.ShouldNotBeNull("compressor");
compressThreshold.ShouldBePositive("compressThreshold");
if(IsDebugEnabled)
log.Debug("상태 정보를 가지는 인스턴스를 생성합니다. pageState=[{0}], compressor=[{1}], compressThreshold=[{2}]",
pageState, compressor, compressThreshold);
if(pageState == null)
return new PageStateEntity(id, null, false);
var serializedValue = Serializer.Serialize(pageState);
if(serializedValue.Length > compressThreshold)
return new PageStateEntity(id, compressor.Compress(serializedValue), true);
return new PageStateEntity(id, serializedValue, false);
}