English 中文(简体)
XmlSerializer andtries-created elements
原标题:XmlSerializer and factory-created elements

我试图将工厂成员所属的物体编成序列/代号。 例如,请指出有一类成员:<代码> Foo,使用FooFactory进行即时处理。 Create。

我目前的想法是:

1.create atom XmlReader(例如,来自XmlTextReader),并随工厂随行。

2. 第九编

3. 在RepXml()中,我可以从读者那里 gr磨工厂。

谁也做了类似的尝试?

最佳回答

XmlSerializer only isn t set up for this. 我强烈建议,如果你想要使用<条码>XmlSerializer,那么你最好用的是将数据描绘成一个更简单的DTO模型first,并注明。 在从DTO回到模型时,在固定代码中添加工厂的创建there。 DTO模式应当简单明了;只需XmlSerializer就简单易懂。

是的,实施<代码>IXmlSerializable> 是an 选择,但:APIC是,很难获得100%的权利(处理所有各种方式的xml可以看见)。 我发现,APIC非常困难,我有许多序列化。 我总是认为,编写几条法典,从您的main<>>>/em>模型到DTO模型,比试图执行<代码>IXmlSerializable要强得多(更快捷)。

For example, you could have:

[XmlRoot("foo")]
public class FooDTO {
     [XmlAttribute("bar")]
     public int Bar {get;set;}

     public static implicit operator Foo(FooDTO value)
     {
         return value == null ? null : FooFactory.Create(value.Bar);
     }
     public static implicit operator FooDTO(Foo value)
     {
         return value == null ? null : new FooDTO { Bar = value.Bar; }
     }
}

届时,您可转换为。 缩略语

Foo foo = ...
FooDTO dto = foo;
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...