После некоторого откладывания этого на задний план ответ стал очевидным:
Хотя вы не можете легко переопределить метод Read () для изменения значения чтения, вы можете подключить метод доступа к свойствучтобы сделать то же самое:
using System;
using System.Collections.Generic;
using System.Xml;
namespace blah {
class XmlCustomTextReader : XmlTextReader {
private Func<string, List<KeyValuePair<string, string>>, string> _updateFunc;
public XmlCustomTextReader(string fileName, Func<string, List<KeyValuePair<string, string>>, string> updateFunc = null) : base(fileName) {
_updateFunc = updateFunc;
}
//
// intercept and override value access - 'un-mangle' strings that were rewritten by XMLTextReader
public override string Value {
get {
string currentvalue = base.Value;
// only text nodes
if (NodeType != XmlNodeType.Text)
return currentvalue;
string newValue = currentvalue;
// if a conversion function was provided, use it to update the string
if (_updateFunc != null)
newValue = _updateFunc(currentvalue, null);
return newValue;
}
}
}
}
Используйте это:
Func<string, List<KeyValuePair<string, string>>, string> updateFunc = UpdateString;
XmlCustomTextReader reader = new XmlCustomTextReader(fileName, updateFunc);
reader.XmlResolver = new XmlCustomResolver(XmlCustomResolver.ResolverType.useResource);
XDocument targetDoc = XDocument.Load(reader);
Я надеюсь, что это поможет кому-то в будущем ...