예제 #1
0
        public override DeserializationResult PushInheritanceFrom(DeserializationResult source)
        {
            var sourceCollection = source.Cast <DeserializedArray>();
            var values           = (Array)Activator.CreateInstance(Value.GetType(), Value.Length) !;
            var results          = new DeserializationResult[sourceCollection.Mappings.Length];

            for (var i = 0; i < sourceCollection.Mappings.Length; i++)
            {
                var oldRes = sourceCollection.Mappings[i];
                var newRes = oldRes.Copy();

                values.SetValue(newRes.RawValue, i);
                results[i] = newRes;
            }

            for (var i = 0; i < Mappings.Length; i++)
            {
                var oldRes = Mappings[i];
                var newRes = oldRes.Copy();

                values.SetValue(newRes.RawValue, i);
                results[i] = newRes;
            }

            return(new DeserializedArray(values, results));
        }
        public override DeserializationResult PushInheritanceFrom(DeserializationResult source)
        {
            var componentFactory = IoCManager.Resolve <IComponentFactory>();
            var sourceRes        = source.Cast <DeserializedComponentRegistry>();
            var mappingDict      = Mappings.ToDictionary(p => p.Key.Copy(), p => p.Value.Copy());

            foreach (var(keyRes, valRes) in sourceRes.Mappings)
            {
                var newKeyRes   = keyRes.Copy();
                var newValueRes = valRes.Copy();

                if (mappingDict.Any(p =>
                {
                    var k1 = (string)newKeyRes.RawValue !;
                    var k2 = (string)p.Key.RawValue !;

                    if (k1 == k2)
                    {
                        return(false);
                    }

                    var registration1 = componentFactory.GetRegistration(k1 !);
                    var registration2 = componentFactory.GetRegistration(k2 !);

                    foreach (var reference in registration1.References)
                    {
                        if (registration2.References.Contains(reference))
                        {
                            return(true);
                        }
                    }

                    return(false);
                }))
                {
                    continue;
                }

                var res      = newKeyRes;
                var oldEntry = mappingDict.FirstOrNull(p => Equals(p.Key.RawValue, res.RawValue));

                if (oldEntry.HasValue)
                {
                    newKeyRes   = oldEntry.Value.Key.PushInheritanceFrom(newKeyRes);
                    newValueRes = oldEntry.Value.Value.PushInheritanceFrom(newValueRes);
                    mappingDict.Remove(oldEntry.Value.Key);
                }

                mappingDict.Add(newKeyRes, newValueRes);
            }

            var valueDict = new ComponentRegistry();

            foreach (var(key, val) in mappingDict)
            {
                valueDict.Add((string)key.RawValue !, (IComponent)val.RawValue !);
            }

            return(new DeserializedComponentRegistry(valueDict, mappingDict));
        }
예제 #3
0
        public override DeserializationResult PushInheritanceFrom(DeserializationResult source)
        {
            var sourceRes   = source.Cast <DeserializedDictionary <TDict, TKey, TValue> >();
            var valueDict   = new Dictionary <TKey, TValue>();
            var mappingDict = new Dictionary <DeserializationResult, DeserializationResult>();

            foreach (var(keyRes, valRes) in sourceRes.Mappings)
            {
                var newKeyRes   = keyRes.Copy();
                var newValueRes = valRes.Copy();

                valueDict.Add((TKey)newKeyRes.RawValue !, (TValue)newValueRes.RawValue !);
                mappingDict.Add(newKeyRes, newValueRes);
            }

            foreach (var(keyRes, valRes) in Mappings)
            {
                var newKeyRes   = keyRes.Copy();
                var newValueRes = valRes.Copy();

                valueDict.Add((TKey)newKeyRes.RawValue !, (TValue)newValueRes.RawValue !);
                mappingDict.Add(newKeyRes, newValueRes);
            }

            return(new DeserializedDictionary <TDict, TKey, TValue>(CreateDelegate(valueDict), mappingDict, CreateDelegate));
        }
        public override DeserializationResult PushInheritanceFrom(DeserializationResult source)
        {
            var sourceCollection = source.Cast <DeserializedArray>();
            var valueList        = (Array)Activator.CreateInstance(Value.GetType(), Value.Length) !;
            var resList          = new List <DeserializationResult>();

            var i = 0;

            foreach (var oldRes in sourceCollection.Mappings)
            {
                var newRes = oldRes.Copy();
                valueList.SetValue(newRes.RawValue, i);
                resList.Add(newRes);
                i++;
            }

            i = 0;
            foreach (var oldRes in Mappings)
            {
                var newRes = oldRes.Copy();
                valueList.SetValue(newRes.RawValue, i);
                resList.Add(newRes);
                i++;
            }

            return(new DeserializedArray(valueList, resList));
        }
예제 #5
0
        public override DeserializationResult Copy()
        {
            var values  = (Array)Activator.CreateInstance(Value.GetType(), Value.Length) !;
            var results = new DeserializationResult[Mappings.Length];

            for (var i = 0; i < Mappings.Length; i++)
            {
                var oldRes = Mappings[i];
                var newRes = oldRes.Copy();

                values.SetValue(newRes.RawValue, i);
                results[i] = newRes;
            }

            return(new DeserializedArray(values, results));
        }
예제 #6
0
        public override DeserializationResult PushInheritanceFrom(DeserializationResult source)
        {
            var dataDef = source.Cast <DeserializedDefinition <T> >();

            if (dataDef.Mapping.Length != Mapping.Length)
            {
                throw new ArgumentException($"Mapping length mismatch in PushInheritanceFrom ({typeof(T)})");
            }

            var newMapping = new DeserializedFieldEntry[Mapping.Length];

            for (var i = 0; i < dataDef.Mapping.Length; i++)
            {
                newMapping[i] = Mapping[i].PushInheritanceFrom(dataDef.Mapping[i]);
            }

            return(IoCManager.Resolve <ISerializationManager>().CreateDataDefinition <T>(newMapping, true));
        }
        public override DeserializationResult PushInheritanceFrom(DeserializationResult source)
        {
            var sourceCollection = source.Cast <DeserializedCollection <TCollection, TElement> >();
            var valueList        = new List <TElement>();
            var resList          = new List <DeserializationResult>();

            foreach (var oldRes in sourceCollection.Mappings)
            {
                var newRes = oldRes.Copy().Cast <DeserializationResult <TElement> >();
                valueList.Add(newRes.Value !);
                resList.Add(newRes);
            }

            foreach (var oldRes in Mappings)
            {
                var newRes = oldRes.Copy().Cast <DeserializationResult <TElement> >();
                valueList.Add(newRes.Value !);
                resList.Add(newRes);
            }

            return(new DeserializedCollection <TCollection, TElement>(CreateDelegate(valueList), resList, CreateDelegate));
        }
예제 #8
0
 public abstract DeserializationResult PushInheritanceFrom(DeserializationResult source);