表达式表示一个“方法组”,其中需要一个“变量”、“值”或“类型”
Expression denotes a `method group', where a `variable', `value' or `type' was expected
我有一个存储 Unity 项目文件的项目。我想要的是找到这些文件并压缩它们。我想使用 ZipFile Class。我的代码很简单如下:
string dataSource = @"D:\dt\2015-11-09-11\";
string zipFile = @"D:\dt\2015-11-09-11\file.zip";
ZipFile.CreateFromDirectory(dataSource, zipFile, CompressionLevel.Fastest, true);
但是我从统一中得到错误:
Assets/file.cs(54,25): error CS0119: Expression denotes a method group', where a
variable', value' or
type' was expected
我做错了什么?
编辑:问题是 ZipFile class 适用于 .NET 4.5 及更高版本,而 unity 适用于 .NET 3.5。我按照以下 lib commnets 中的建议更改了我使用的库。我现在的代码如下:
string dataSource = @"D:\data\2015-11-09-11-11-37-3286";
FileStream fsOut = File.Create(dataSource);
ZipOutputStream zipStream = new ZipOutputStream(fsOut);
zipStream.SetLevel(3);
int folderOffset = dataSource.Length + (dataSource.EndsWith("\") ? 0 : 1);
CompressFolder(dataSource, zipStream, folderOffset);
zipStream.IsStreamOwner = true; // Makes the Close also Close the underlying stream
zipStream.Close();
可以找到 CompressFolder 方法 here。我收到以下消息(目录是现有路径):
DirectoryNotFoundException: Could not find a part of the path "D:\data15-11-09-11-11-37-3286".
System.IO.FileStream..ctor
问题出在建议代码的第二行FileStream out = File.Create(dataSource);
别急,我建议你也调用了一个方法ZipFile
。
将其重命名为与 class 名称不冲突的名称或使用 Using alias = ...
声明。
我想我明白了。 Unity 在浏览未知目录时出现问题。当我将目录更改为 Unity 可以访问的文件夹时,一切正常。
我有一个存储 Unity 项目文件的项目。我想要的是找到这些文件并压缩它们。我想使用 ZipFile Class。我的代码很简单如下:
string dataSource = @"D:\dt\2015-11-09-11\";
string zipFile = @"D:\dt\2015-11-09-11\file.zip";
ZipFile.CreateFromDirectory(dataSource, zipFile, CompressionLevel.Fastest, true);
但是我从统一中得到错误:
Assets/file.cs(54,25): error CS0119: Expression denotes a
method group', where a
variable',value' or
type' was expected
我做错了什么?
编辑:问题是 ZipFile class 适用于 .NET 4.5 及更高版本,而 unity 适用于 .NET 3.5。我按照以下 lib commnets 中的建议更改了我使用的库。我现在的代码如下:
string dataSource = @"D:\data\2015-11-09-11-11-37-3286";
FileStream fsOut = File.Create(dataSource);
ZipOutputStream zipStream = new ZipOutputStream(fsOut);
zipStream.SetLevel(3);
int folderOffset = dataSource.Length + (dataSource.EndsWith("\") ? 0 : 1);
CompressFolder(dataSource, zipStream, folderOffset);
zipStream.IsStreamOwner = true; // Makes the Close also Close the underlying stream
zipStream.Close();
可以找到 CompressFolder 方法 here。我收到以下消息(目录是现有路径):
DirectoryNotFoundException: Could not find a part of the path "D:\data15-11-09-11-11-37-3286". System.IO.FileStream..ctor
问题出在建议代码的第二行FileStream out = File.Create(dataSource);
别急,我建议你也调用了一个方法ZipFile
。
将其重命名为与 class 名称不冲突的名称或使用 Using alias = ...
声明。
我想我明白了。 Unity 在浏览未知目录时出现问题。当我将目录更改为 Unity 可以访问的文件夹时,一切正常。