예제 #1
0
        public void TestArrayArrayAsRef([Values(false, true)] bool compile, [Values(false, true)] bool asRef)
        {
            var tm = TypeModel.Create();

            tm.AutoCompile = compile;

            foreach (var f in tm.Add(typeof(ArrayArrayRef), true).GetFields())
            {
                f.AsReference = asRef;
            }

            var source = ArrayArrayRef.CreateFilled();

            source.Values[0] = source.Values[1];
            try
            {
                var copy = tm.DeepClone(source);
                Assert.That(copy.Values.Length, Is.EqualTo(source.Values.Length));
                for (int i = 0; i < copy.Values.Length; i++)
                {
                    Assert.That(copy.Values[i], Is.EqualTo(source.Values[i]));
                    Assert.That(copy.Values2[i], Is.EqualTo(source.Values2[i]));
                }
                if (asRef)
                {
                    Assert.That(copy.Values2, Is.SameAs(copy.Values));
                    Assert.That(copy.Values[0], Is.SameAs(copy.Values[1]));
                    Assert.That(copy.Self, Is.SameAs(copy));
                }
                else
                {
                    Assert.That(copy.Values2, Is.Not.SameAs(copy.Values));
                    Assert.That(copy.Values[0], Is.Not.SameAs(copy.Values[1]));
                }
            }
            catch (AqlaSerializer.ProtoException e)
            {
                if (asRef || !e.Message.StartsWith("Possible recursion detected"))
                {
                    throw;
                }
            }
            if (compile)
            {
                tm.Compile("arrayarrayref", "arrayarrayref.dll");
                PEVerify.AssertValid("arrayarrayref.dll");
            }
        }
예제 #2
0
        public static ArrayArrayRef CreateFilled()
        {
            var r = new ArrayArrayRef()
            {
                Values = new[]
                {
                    new CustomString[] { "11", "12" },
                    new CustomString[] { "21", "22", "23" },
                    null,
                    new CustomString[0]
                }
            };

            r.Values2 = r.Values;
            r.Self    = r;
            return(r);
        }