说我有以下课程:
[Serializable]
public class foo
{
public bar randomBar;
// required serialization methods would go here
}
并且
public class bar
{
int barInt;
// constructors and such
}
bar
不可序列化,但foo
是。当我序列化一个foo
对象时,它的randomBar
会被序列化,还是会导致错误?
答案 0 :(得分:0)
序列化程序抛出错误。在LinqPad中尝试以下内容:
void Main()
{
var stream = new MemoryStream();
var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
formatter.Serialize(stream, new Foo { bar = new Bar { barInt = 2 } });
}
// Define other methods and classes here
[Serializable]
public class Foo { public Bar bar; }
public class Bar { public int barInt; }
错误是:
Type 'UserQuery+Bar' in Assembly 'query_nsalab, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.