public static NamespaceList Union(NamespaceList o1, NamespaceList o2, bool v1Compat)
{
NamespaceList nslist = null;
Debug.Assert(o1 != o2);
if (o1.type == ListType.Any) //clause 2 - o1 is Any
{
nslist = new NamespaceList();
}
else if (o2.type == ListType.Any) //clause 2 - o2 is Any
{
nslist = new NamespaceList();
}
else if (o1.type == ListType.Set && o2.type == ListType.Set) //clause 3 , both are sets
{
nslist = o1.Clone();
foreach (string ns in o2.set.Keys)
{
nslist.set[ns] = ns;
}
}
else if (o1.type == ListType.Other && o2.type == ListType.Other) //clause 4, both are negations
{
if (o1.targetNamespace == o2.targetNamespace) //negation of same value
{
nslist = o1.Clone();
}
else //Not a breaking change, going from not expressible to not(absent)
{
nslist = new NamespaceList("##other", string.Empty); //clause 4, negations of different values, result is not(absent)
}
}
else if (o1.type == ListType.Set && o2.type == ListType.Other)
{
if (v1Compat)
{
if (o1.set.Contains(o2.targetNamespace))
{
nslist = new NamespaceList();
}
else //This was not there originally in V1, added for consistency since its not breaking
{
nslist = o2.Clone();
}
}
else
{
if (o2.targetNamespace != string.Empty) //clause 5, o1 is set S, o2 is not(tns)
{
nslist = o1.CompareSetToOther(o2);
}
else if (o1.set.Contains(string.Empty)) //clause 6.1 - set S includes absent, o2 is not(absent)
{
nslist = new NamespaceList();
}
else //clause 6.2 - set S does not include absent, result is not(absent)
{
nslist = new NamespaceList("##other", string.Empty);
}
}
}
else if (o2.type == ListType.Set && o1.type == ListType.Other)
{
if (v1Compat)
{
if (o2.set.Contains(o2.targetNamespace))
{
nslist = new NamespaceList();
}
else
{
nslist = o1.Clone();
}
}
else //New rules
{
if (o1.targetNamespace != string.Empty) //clause 5, o1 is set S, o2 is not(tns)
{
nslist = o2.CompareSetToOther(o1);
}
else if (o2.set.Contains(string.Empty)) //clause 6.1 - set S includes absent, o2 is not(absent)
{
nslist = new NamespaceList();
}
else //clause 6.2 - set S does not include absent, result is not(absent)
{
nslist = new NamespaceList("##other", string.Empty);
}
}
}
return(nslist);
}