Exemple #1
0
        public StructValue ExportCustomValue(Object value)
        {
            Type  clss = value.GetType();
            XType type;

            try
            {
                type = GetCustomStructType(value.GetType());
            }
            catch (KeyNotFoundException)
            {
                type = null;
            }

            if (type == null && clss == typeof(StructValue))
            {
                StructValue struct1 = (StructValue)value;
                type = struct1.GetXType;
            }

            if (type == null)
            {
                //       if (value is Exception)
                if (typeof(Exception).IsAssignableFrom(clss))
                {
                    type = _mt__Etch_RuntimeException;
                }
                else if (typeof(IList).IsAssignableFrom(clss))
                {
                    type = _mt__Etch_List;
                }
                else if (typeof(IDictionary).IsAssignableFrom(clss))
                {
                    type = _mt__Etch_Map;
                }
                // Need to add set, but in 2.0 there is no set so just use keys of IDictionary,
                else
                {
                    return(null);
                }
            }

            ImportExportHelper helper = type.GetImportExportHelper();

            if (helper == null)
            {
                return(null);
            }

            return(helper.ExportValue(this, value));
        }
Exemple #2
0
        private void Test(URL url)
        {
            XType         type       = new XType("url");
            Class2TypeMap class2type = new Class2TypeMap();

            URLSerializer.Init(type, class2type);
            ImportExportHelper helper = type.GetImportExportHelper();

            StructValue sv = helper.ExportValue(vf, url);

            Assert.AreEqual(sv.GetXType, type);

            URL url2 = (URL)helper.ImportValue(sv);

            Assert.AreEqual(url.ToString(), url2.ToString());
        }
Exemple #3
0
        // no tests for null keys as string? isn't allowed

        public void TestMap(StrIntHashMap map)
        {
            XType type = new XType("map");

            Class2TypeMap class2type = new Class2TypeMap();

            StrIntHashMapSerializer.Init(type, class2type);
            ImportExportHelper helper = type.GetImportExportHelper();

            StructValue sv = helper.ExportValue(vf, map);

            Assert.AreEqual(sv.GetXType, type);

            StrIntHashMap map2 = (StrIntHashMap)helper.ImportValue(sv);

            Assert.AreEqual(map, map2);
        }
Exemple #4
0
        private void TestDate(DateTime date)
        {
            XType type = new XType("date");

            Class2TypeMap class2type =
                new Class2TypeMap();

            DateSerializer.Init(type, class2type);

            ImportExportHelper helper = type.GetImportExportHelper();
            StructValue        sv     = helper.ExportValue(vf, date);

            Assert.AreEqual(sv.GetXType, type);

            DateTime date2 = ( DateTime )helper.ImportValue(sv);

            Assert.AreEqual(date, date2);
        }