コード例 #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// This baseclass function allows serializers or deserializers to check for external surrogates for the given Type.
        /// This routine will look everywhere that external surrogates could be found- for now, that's the default Framework
        /// stuff and anything found in the Context.
        /// </summary>
        /// <param name="_type">The Type that we're checking for external surrogates</param>
        /// <returns>An IExternalSurrogate for _type, if anything exists.</returns>
        protected IExternalSurrogate GetExternalSurrogate(Type _type)
        {
            if (_type == null)
            {
                return(null);
            }

            var surrogate = m_context.GetExternalSurrogate(_type);

            sm_frameworkSurrogates.TryGetValue(_type, out var predefinedFramework);
            surrogate = CExternalSurrogatePair.Update(surrogate, predefinedFramework);

            if (_type.IsGenericType)
            {
                var genericTypedef = _type.GetGenericTypeDefinition();

                var appDefined = m_context.GetExternalSurrogate(genericTypedef);
                surrogate = CExternalSurrogatePair.Update(surrogate, appDefined);

                sm_frameworkSurrogates.TryGetValue(genericTypedef, out predefinedFramework);
                surrogate = CExternalSurrogatePair.Update(surrogate, predefinedFramework);
            }

            return(surrogate);
        }
コード例 #2
0
        public void TestUpdate()
        {
            IExternalSurrogate s1 = new CGuidSurrogate();
            IExternalSurrogate s2 = new CDateTimeSurrogate();
            IExternalSurrogate s3 = new CUtcDateTimeSurrogate();

            IExternalSurrogate accum = null;

            accum = CExternalSurrogatePair.Update(accum, null);
            Assert.IsNull(accum, "Updating NULL with NULL should result in NULL");

            accum = CExternalSurrogatePair.Update(accum, s1);
            Assert.AreSame(s1, accum, "After UPDATEing null with s1, the accumulator should be s1");

            accum = CExternalSurrogatePair.Update(accum, null);
            Assert.AreSame(s1, accum, "After UPDATEing the s1 accumulator with NULL, the accumulator should not have changed");


            accum = CExternalSurrogatePair.Update(accum, s2);
            Assert.AreEqual(typeof(CExternalSurrogatePair), accum.GetType(), "After UPDATEing accumulator with s2, the accumulator should now be a surrogate Pair.");

            Assert.AreSame(s1, (accum as CExternalSurrogatePair).Surrogate1, "The first surrogate of the Pair should be s1");
            Assert.AreSame(s2, (accum as CExternalSurrogatePair).Surrogate2, "The second surrogate of the Pair should be s2");


            accum = CExternalSurrogatePair.Update(accum, s3);
            Assert.AreEqual(typeof(CExternalSurrogatePair), accum.GetType(), "After UPDATEing accumulator with s3, the accumulator should still be a surrogate Pair.");

            Assert.AreEqual(typeof(CExternalSurrogatePair), (accum as CExternalSurrogatePair).Surrogate1.GetType(), "The Type of the first surrogate of the Pair should be a Pair");
            Assert.AreEqual(typeof(CUtcDateTimeSurrogate), (accum as CExternalSurrogatePair).Surrogate2.GetType(), "The Type of the second surrogate of the Pair should be the UTC Time surrogate");
        }
コード例 #3
0
        public void TestChainSerialize()
        {
            IExternalSurrogate a = new CTest1();

            a = CExternalSurrogatePair.Update(a, new CTest2());
            a = CExternalSurrogatePair.Update(a, new CTest4());

            Assert.AreEqual(0, CTestBase.SER_STATUS, "Initial SER_STATUS should be zero");
            Assert.AreEqual(0, CTestBase.DESER_STATUS, "Initial DESER_STATUS should be zero");


            a.Serialize(null, null, null, null);
            Assert.AreEqual(11, CTestBase.SER_STATUS, "After serializing the first time, the SER_STATUS is wrong");   // 00001011 binary == 11 base 10
            Assert.AreEqual(0, CTestBase.DESER_STATUS, "After serializing the first time, the DESER_STATUS should still be zero");

            a.Deserialize(null, null, null);
            Assert.AreEqual(11, CTestBase.SER_STATUS, "After deserializing the first time, the SER_STATUS should not have changed");   // 00001011 binary == 11 base 10
            Assert.AreEqual(11, CTestBase.DESER_STATUS, "After deserializing the first time, the DESER_STATUS is wrong");



            a = CExternalSurrogatePair.Update(a, new CTest3());
            CTestBase.SER_STATUS   = 0;
            CTestBase.DESER_STATUS = 0;

            a.Serialize(null, null, null, null);
            Assert.AreEqual(15, CTestBase.SER_STATUS, "After serializing the first time, the SER_STATUS is wrong");   // 00001111 binary == 15 base 10
            Assert.AreEqual(0, CTestBase.DESER_STATUS, "After serializing the first time, the DESER_STATUS should still be zero");

            a.Deserialize(null, null, null);
            Assert.AreEqual(15, CTestBase.SER_STATUS, "After deserializing the first time, the SER_STATUS should not have changed");   // 00001111 binary == 15 base 10
            Assert.AreEqual(15, CTestBase.DESER_STATUS, "After deserializing the first time, the DESER_STATUS is wrong");
        }
コード例 #4
0
        public void TestConstructor()
        {
            IExternalSurrogate s1 = new CGuidSurrogate();
            IExternalSurrogate s2 = new CDateTimeSurrogate();

            var pair = new CExternalSurrogatePair(s1, s2);

            Assert.AreSame(s1, pair.Surrogate1, "Surrogate1 does not point to the same object");
            Assert.AreSame(s2, pair.Surrogate2, "Surrogate2 does not point to the same object");
        }
コード例 #5
0
 public void TestNullConstructorParam1()
 {
     IExternalSurrogate s = new CExternalSurrogatePair(null, null);
 }