SGEN的XMLSerializer - 应.XMLSerializers.dll加为当前项目或向海关总署的参考? [英] SGEN XMLSerializer - should be .XMLSerializers.dll added as a reference to the current project or to the GAC?

查看:299
本文介绍了SGEN的XMLSerializer - 应.XMLSerializers.dll加为当前项目或向海关总署的参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做一些东西与XMLSerializer类。像大多数初学者的我面对的应用程序启动性能问题。我看了很多博客,文章的最后使用SGEN工具。现在的表现看起来是确定,但几件事情还不清楚,我

I do some stuff with XMLSerializer class. Like a most of beginners I face with performance issue on app start. I read a lot of blogs, articles and finally use SGEN tool. Now performance looks to be ok but few things are still not clear for me.

1)我应该使用SGEN语法如下:

1) Should I use SGEN syntax like this:

SGen.exe /assembly:MyAssembly /type:MyRootXmlType

或者是不够的,只是(我使用这个语法目前,我在我的组装只有一个Serializable类):

or it's enough to just (I use this syntax currently, I have only one Serializable class in my assembly):

SGen.exe /assembly:MyAssembly

当/类型参数可以在实践中使用

When /type parameter can be useful in practice?

2)我在MSDN上阅读(的http:// msdn.microsoft.com/en-us/library/ee704594.aspx

2) I read on MSDN ( http://msdn.microsoft.com/en-us/library/ee704594.aspx )

此命令生成的序列化
组装
MyAssembly.XmlSerializers.dll,其中
应该被加入到
当前项目或到GAC的引用。

This command generates the serializer assembly MyAssembly.XmlSerializers.dll, which should be added as a reference to the current project or to the GAC.

但在其他所有的博客和文章(例如在SO),我读了足以只是把MyAssembly.XmlSerializers.dll到哪里MyAssembly程序存在的文件夹。

but on all other blogs and articles (for example on SO) I read that is enough to just put MyAssembly.XmlSerializers.dll into folder where MyAssembly exists.

那么,什么是正确的?

3)这是不够的,只是产生.XmlSerilizers.dll并与一起MyAssembly的部署,或者我应该补充一下我的验证码?

3) It's enough to just generate .XmlSerilizers.dll and deploy it together with MyAssembly or should I add something to my code yet?

我不这么认为,但我想,以确保我不会改变我的代码,并神奇的自动发生。

I don't think so but I would like to be sure that I will not have to change my code and "magic" happens automatically.

推荐答案

如果你不使用sgen.exe的/类型参数那么就会产生德/序列化代码的所有的公共类型的装配。请注意,[Serializable]属性没有在XML序列化使用。我怀疑你会想这一点,使用/类型,以保持生成的程序集小。

If you don't use the /type argument for sgen.exe then it will generate de/serialization code for all public types in the assembly. Note that the [Serializable] attribute is not used in XML serialization. I doubt you'd want this, use /type to keep the generated assembly small.

添加引用是没有必要的,XML序列化总是试图一的Assembly.Load()在.XmlSerializers.dll装配反正。另外,你永远也不会直接在您的代码中引用生成的XmlSerializationWriterXxx和XmlSerializationReaderXxx类。它确实有一个优势,构建系统的装配,当你有一个解决方案,该项目将自动复制。

Adding a reference is not necessary, Xml serialization always tries an Assembly.Load() on the .XmlSerializers.dll assembly anyway. Plus, you'll never reference the generated XmlSerializationWriterXxx and XmlSerializationReaderXxx classes directly in your code. It does have one advantage, the build system will automatically copy the assembly when you include the project in a solution.

在GAC中安装它只是值得考虑,当不同的应用程序序列化和反序列化的XML文件。您可以通过复制手工装配以及提供其他应用程序的.XmlSerializers.dll装配。这是一个有点容易出错,在这里用你自己的判断。检查前一段的方式自动复制。

Installing it in the GAC is only worth considering when different apps serialize and deserialize the XML file. You can provide other apps with the .XmlSerializers.dll assembly by copying the assembly by hand as well. Which is a bit error prone, use your own judgment here. Check the previous paragraph for a way to automate the copy.

这篇关于SGEN的XMLSerializer - 应.XMLSerializers.dll加为当前项目或向海关总署的参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆