System.Reflection.Emit
次のMSDN docでタイプを作成しました
このコードを使用して、型とインスタンスを作成します。
//following the tutorial I created a method which returns a dynamic type
Type myDynamicType = CreateNewObject("MyDynamicType", fields);
var instance = Activator.CreateInstance(myDynamicType);
今、私は自分のオブジェクトをシリアライズしたいXmlSerializer
これを試しました:
FileStream fs = new FileStream(@"C:\Test\SerializedDynamic.XML", FileMode.Create);
XmlSerializer xs = new XmlSerializer(typeof(object));
xs.Serialize(fs, instance);
しかし、それは例外をスローします:
"The type MyDynamicType was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."
助けはありますか?