Example #1
0
        public static TypeCollisionList CombineCollisionLists(TypeCollisionList colList1, TypeCollisionList colList2)
        {
            var newCollisionList = new TypeCollisionList();

            foreach (var obj in colList1.Objects)
            {
                newCollisionList.Objects.Add(obj);
            }
            foreach (var obj in colList2.Objects)
            {
                newCollisionList = AddToCollisionList(newCollisionList, obj);
            }
            return(newCollisionList);
        }
Example #2
0
        private static MutableObject UnionIntoClonedSchema(MutableObject newMutable, MutableObject operand1, MutableObject operand2)
        {
            foreach (var kvp in operand2)
            {
                if (operand1.ContainsKey(kvp.Key))
                {
                    var foundObj = operand1[kvp.Key];

                    newMutable[kvp.Key] = TypeCollisionList.CollideValues(foundObj, kvp.Value);
                    continue;
                }

                newMutable[kvp.Key] = kvp.Value;
            }

            return(newMutable);
        }
Example #3
0
        public static TypeCollisionList AddToCollisionList(TypeCollisionList colList, object obj)
        {
            var newCollisionList = new TypeCollisionList();

            bool inserted = false;

            var mut = obj as MutableObject;

            if (mut != null)   // inserting a mutable object.  Union it into existing mutable objects
            {
                var extantMutables = new List <MutableObject>();

                foreach (var entry in colList.Objects)
                {
                    var entryMut = entry as MutableObject;
                    if (entryMut != null)
                    {
                        extantMutables.Add(entryMut);
                    }
                }
                newCollisionList.Objects.Add(MutableObject.UnionSchemas(mut, extantMutables));
                return(newCollisionList);
            }

            var mutList = obj as IEnumerable <MutableObject>;

            if (mutList != null)
            {
                var extantEnums = new List <IEnumerable <MutableObject> >();

                foreach (var entry in colList.Objects)
                {
                    var entryMutList = entry as IEnumerable <MutableObject>;
                    if (entryMutList != null)
                    {
                        extantEnums.Add(entryMutList);
                    }
                }
                newCollisionList.Objects.Add(new List <MutableObject>()
                {
                    MutableObject.UnionSchemas(
                        extantEnums.Count > 0?mutList.Concat(
                            extantEnums.Aggregate((a, b) => a.Concat(b)))
                    : mutList)
                });

                return(newCollisionList);
            }

            foreach (var entry in colList.Objects)
            {
                if (entry.GetType() == obj.GetType())
                {
                    inserted = true;
                }
                newCollisionList.Objects.Add(entry);
            }
            if (!inserted)
            {
                newCollisionList.Objects.Add(obj);
            }

            return(newCollisionList);
        }