static Container DeepClone(Container original, bool notLateToLate)
        {
            var tm1 = TypeModel.Create();
            var tm2 = TypeModel.Create();

            tm1.SkipForcedLateReference = true;
            tm2.SkipForcedLateReference = true;

            ValueMember f = tm2.Add(typeof(Referenced), true)[1];

            f.SetSettings(x => x.V.Format = ValueFormat.Reference);

            if (notLateToLate)
            {
                var tmTemp = tm1;
                tm1 = tm2;
                tm2 = tmTemp;
            }

            Container copy;

            using (var ms = new MemoryStream())
            {
                tm1.Serialize(ms, original);

                ms.Position = 0;

                copy = tm2.Deserialize <Container>(ms);
            }
            return(copy);
        }
Ejemplo n.º 2
0
        static RuntimeTypeModel CreateDefaultRefModel(bool aFirst, bool comp)
        {
            ProtoCompatibilitySettingsValue fullComp = ProtoCompatibilitySettingsValue.FullCompatibility;

            fullComp.SuppressValueEnhancedFormat = false;
            var model = TypeModel.Create(false, comp ? fullComp : ProtoCompatibilitySettingsValue.Incompatible);

            if (comp)
            {
                model.SkipForcedLateReference = true;
            }
            // otherwise will not be compatible
            model.SkipForcedAdvancedVersioning = true;
            if (aFirst)
            {
                model.Add(typeof(A_WithDefaultRef), true);
                model.Add(typeof(B_WithDefaultRef), true);
            }
            else
            {
                model.Add(typeof(B_WithDefaultRef), true);
                model.Add(typeof(A_WithDefaultRef), true);
            }

            ValueMember f = model[typeof(B_WithDefaultRef)][2];
            MemberLevelSettingsValue s = f.GetSettingsCopy(0);

            Assert.That(s.Format, Is.EqualTo(ValueFormat.NotSpecified));
            s.Format = ValueFormat.Compact;
            f.SetSettings(s);

            model.AutoCompile = false;

            return(model);
        }