开发者

Creating/compling .net data class within an application

开发者 https://www.devze.com 2022-12-23 23:34 出处:网络
Is there a pattern, Xml structure, architecture technique we can use to create simple data holder class code that we can deserialise to/from and do that at runtime?

Is there a pattern, Xml structure, architecture technique we can use to create simple data holder class code that we can deserialise to/from and do that at runtime?

We're in the early design stage of a .Net project and one of our goals is to make the resulting system extensible through configuration without needing a developer. We need to support new sources of data, typcially delivered as Xml messages. Currently we convert/deserialise the messages into simple classes and then use an already existing language which can manipulate those classes as we need.

That works well when you have a developer to map the Xml to simple class, create the class and then write the deserialisat开发者_JAVA技巧ion, but it's not extensible for for an administrator. Our target user audience is high end DBA and/or network admin - people who can handle Xml but may not know C#.


You don't have to write any classes or deserialization routines. If you have a schema, you can use the XSD.exe tool from Visual Studio to automatically make Classes, and use built in .NET XML Serialization/Deserialization.

Now how to have that happen without a recompile each time...

It's not ideal, but this should work:

Assume your DBA can write a schema for the XML. You could write a tool that takes the schema, runs it through XSD, Add's some wrapper code on top of it, and creates a dll which can be used from within your application.

This could be a manual process (ie the admins email you the schema) or you can distribute the tool as part of your application.

Also, you can infer a schema from an existing XML document.


Perhaps DataTable? Or just use an xml DOM (XmlDocument or XDocument) as data-storage? Neither is ideal, of course - but there is little point creating a type at runtime just for this if your real code will ever see it. What purpose would the extra class type serve? Among other issues you'd have to use lots of reflection just to talk to it.

The other option is a custom property-bag and IXmlSerializable, but that is effort.

0

精彩评论

暂无评论...
验证码 换一张
取 消