I am using Automapper and classes with Xml serialization to generate an XML file.
In this method, it returns an IEnumerable to Automapper, which then writes out a series of <GenerationMethod>...</GenerationMethod>
XML elements.
It does work, however, if it returns an empty IEnumerable, because no results were found, I am getting empty XML tags like this:
<GenerationMethod />
Is there a way to return NULL so that empty XML tags are not generated?
Here is the method. Thanks!
public static IEnumerable<GenerationMethod> GetGenerationMethod(this DungeonGrid monster)
{
var customMonster = monster.Stats
.Where(e => e.Stat.Category.IsActive);
if (monster.MonsterType.DestructionMethod.StartsWith("TEST"))
{
yield return new GenerationMethod(monster.MonsterType.DestructionMethod);
}
foreach (Stat in customMonster)
{
if (DungeonLookupByStatId.ContainsKey(customMonster.MonsterType.Id))
yield return DungeonLookupByStatId[customMonster.MonsterType.Id];
}
}