Example #1
0
 internal static Creators Merge(BTValue val1, BTValue val2)
 {
     if (val1 == null || val2 == null)
     {
         return(new Creators());
     }
     else if (val1 is PrimitiveBTValue && val2 is PrimitiveBTValue)
     {
         return(PrimitiveBTValue.Merge(val1 as PrimitiveBTValue, val2 as PrimitiveBTValue));
     }
     else if (val1 is ReferenceBTValue && val2 is ReferenceBTValue)
     {
         return(ReferenceBTValue.Merge(val1 as ReferenceBTValue, val2 as ReferenceBTValue));
     }
     else if (val1 is PrimitiveBTValue)
     {
         return((val1 as PrimitiveBTValue).ToReferenceBTValueCreators());
     }
     else if (val2 is PrimitiveBTValue)
     {
         return((val2 as PrimitiveBTValue).ToReferenceBTValueCreators());
     }
     else
     {
         throw new InternalException();
     }
 }
Example #2
0
        internal static Creators Merge(ReferenceBTValue val1, ReferenceBTValue val2)
        {
            val1 = val1.findLeaf();
            val2 = val2.findLeaf();

            if (val1 != val2 && val1.btType == BTType.Static && val2.btType == BTType.Static)
            {
                Creators crtrs = new Creators();

                int count = 0;
                for (int i = 0; i < val1.types.Count; i++)
                {
                    if (val2.types.Contains(val1.types[i]))
                    {
                        count++;
                    }
                }

                if (val1.types.Count > count)
                {
                    crtrs.AddCreators(val2.crtrs);
                }
                if (val2.types.Count > count)
                {
                    crtrs.AddCreators(val1.crtrs);
                }

                val2.setNext(val1);

                foreach (object key in val2.flds.Keys)
                {
                    ReferenceBTValue fld1 = val1.flds[key] as ReferenceBTValue;
                    ReferenceBTValue fld2 = val2.flds[key] as ReferenceBTValue;
                    if (fld1 == null)
                    {
                        val1.flds[key] = fld2;
                    }
                    else
                    {
                        crtrs.AddCreators(ReferenceBTValue.Merge(fld1, fld2));
                    }
                }

                return(crtrs);
            }
            else if (val1.btType == val2.btType)
            {
                return(new Creators());
            }
            else if (val1.btType == BTType.Static)
            {
                val1.setNext(val2);
                return(val1.crtrs);
            }
            else if (val2.btType == BTType.Static)
            {
                val2.setNext(val1);
                return(val2.crtrs);
            }
            else
            {
                throw new InternalException();
            }
        }