I need to deserialize an xml string into an internal c# class (.net core 5.0) but it seems like the default XmlSerializer doesn't support that as it can only deserialize xml string into a public class and its public properties. Is there any way around this limitation?
Example: https://dotnetfiddle.net/PkD8no
using System;
using System.IO;
using System.Xml.Serialization;
public class Program
{
public static void Main()
{
var xml = "<?xml version=\"1.0\"?><SampleXml><SampleValue>sample</SampleValue></SampleXml>";
var serializerForInternal = new XmlSerializer(typeof(InternalSampleXml));
using (TextReader reader = new StringReader(xml))
{
var result = (InternalSampleXml)serializerForInternal.Deserialize(reader);
Console.WriteLine(result.SampleValue);
}
}
[System.SerializableAttribute()]
internal class InternalSampleXml
{
internal string SampleValue{ get; set; }
}
}