✅ XmlReader generic Mapper
Hello 👋 . I am trying to create generic mapper for my project, that is using XmlReader.
All my XML files have same structure, i.e.:
For model:
So, I want to use Mapper this way:
13 Replies
let me a sec to upload full code
https://paste.mod.gg/ajnmxvtzfudh/0
So, the questions I have:
1) How can I improve performance?
2) How can I implement
.Map(..., ao => ao.FullName); // ! it should map to $"{TYPENAME} {NAME}"
P.S. by it should map to $"{TYPENAME} {NAME}"
I mean that my mapper should find 2 XML attributes, i.e. TYPENAME="street"
and NAME="Abaya"
and for property FullName
of provided generic class it will make "street Abaya"
(final property should be created by lambda)
Also, It will great to have functionality to map more than 2 attributes for propertyBlazeBin - ajnmxvtzfudh
A tool for sharing your source code with the world!
Before we start conversation, is it a good way to parse large files (few gbs) with this class, or should I create not generic parser for each model?
or should I create not generic parser for each model?how can you have this doubt after having already created
XmlReaderCopyHelper<>
?I mean, I have deals with some reflection which can slower my app, but it is too sensitive for speed, caz it is 43 gb zipped xml files
you don't necessarily have to use reflection if you don't need to automate stuff, depends how many models you have
also you are not caching anything in
SetProperty
Maybe I'm missing the point but... Why not just use
XmlSerializer?
That does a bunch of code generation to give you pretty optimal deserializationIt's slower then XmlReader, that's why
Have you read the generated code?
It's literally generated code directly over XmlReader
It's the same stuff you'd write by hand if you were writing a hand-optimised deserializer for a particular type
whether XmlSerializer is slower than XmlReader doesn't matter. (of course it's slower, it's at least as slow as XmlReader, because that's what it uses to do the reading.) what matters is whether XmlSerializer is slower than your mapper
And unless you're doing code generation, or skipping out fairly basic sanity-checks, you're not going to get faster than XmlSerializer. Heck, hand-written code will struggle to get faster
It makes sense. I thought XmlSerializer does not use XmlReader
I'll try XmlSerializer then, thx!
Make sure you cache the generated XmlSerialiser