public static CiladorConfigType ReadCiladorConfig(XElement config)
{
Contract.Requires(config != null);
Contract.Ensures(Contract.Result<CiladorConfigType>() != null);
var childElements = config.Elements();
var children = childElements as XElement[] ?? childElements.ToArray();
if (children.Count() != 1)
{
throw new WeavingException("Cilador config in FodyWeavers.xml should have exactly one child");
}
var firstChild = children.First();
if (firstChild.Name.NamespaceName != "urn:Cilador:Fody:Config" ||
firstChild.Name.LocalName != "CiladorConfig")
{
throw new WeavingException("Child of Cilador config in FodyWeavers.xml should be CiladorConfig in namespace urn:Cilador:Fody:Config");
}
CiladorConfigType deserializedConfig;
try
{
deserializedConfig = firstChild.FromXElement<CiladorConfigType>();
}
catch (Exception e)
{
throw new WeavingException(
"Element urn:Cilador:Fody:Config:CiladorConfig in FodyWeavers.xml could not be deserialized into type of CiladorConfigType",
e);
}
return deserializedConfig;
}