使用 Entity Framework ,在以代码优先的方式使用迁移文件时,它会生成 .resx
文件 (xml),其中包含名为 Target
的数据字段:
<data name="Target" xml:space="preserve">
<value>H4sIAAAAAAAEAO ... ICAA==</value>
</data>
该字段是哪种格式?
==
在数据的末尾使认为它是base64,但是当解码时,它看起来像是二进制数据。有人知道数据的结构/格式吗?
最佳答案
它是一个 edmx/xml 文件,已经被 gzipped 然后 base64 编码。以下应用程序将打印给定 .resx 文件的 xml。
using System;
using System.Collections;
using System.IO;
using System.IO.Compression;
using System.Resources;
using System.Xml.Linq;
namespace ResxReader
{
class Program
{
private const string ResxFilename = @"full path to your .resx file";
public static void Main()
{
var reader = new ResXResourceReader(ResxFilename);
IDictionaryEnumerator resources = reader.GetEnumerator();
while (resources.MoveNext())
{
if ("Target".Equals(resources.Key))
{
XDocument target = Decompress(Convert.FromBase64String(resources.Value.ToString()));
Console.Write(target);
}
}
}
public static XDocument Decompress(byte[] bytes)
{
using (var memoryStream = new MemoryStream(bytes))
{
using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
{
return XDocument.Load(gzipStream);
}
}
}
}
}
关于.net - EF 迁移 resx 文件中的目标字段采用哪种格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47768143/