コード例 #1
0
        internal static ICollectionBase ConvertJsonToCollection(string jsonCollection)
        {
            string collectionTypeName = null;

            try
            {
                dynamic collection = JsonConvert.DeserializeObject(jsonCollection);

                // This is not working as expected when it has child members
                //ICollectionBase collection = JsonConvert.DeserializeObject<HomeCollection>(jsonCollection);

                string collectionName = collection.CollectionName;
                collectionTypeName = collection.CollectionType;
                Type            collectionType = CollectableBaseFactory.GetTypeFromFullName(collectionTypeName);
                ICollectionBase newCollection  = new HomeCollection(collectionName, collectionType);

                var collectables = collection.Collectables;
                foreach (var c in collectables)
                {
                    string jsonCollectable = c.ToString();
                    // add custom try/catch??
                    ICollectableBase collectable = GetCollectableFromJson(jsonCollectable, collectionType);

                    newCollection.AddToCollection(collectable);
                }
                return(newCollection);
            }
            catch (Exception ex)
            {
                throw new CollectionParseException($"Unable to parse Json into a collection object.  Type={collectionTypeName}, Json={jsonCollection}", ex);
            }
        }
コード例 #2
0
        public void gettypefromfullname_blank_name_throws_exception()
        {
            string invalidName = "";

            Type collectionType = CollectableBaseFactory.GetTypeFromFullName(invalidName);

            Assert.Fail("Expected GetTypeFromFullName to fail when unable to parse type from name");
        }
コード例 #3
0
        public void gettypefromfullname_returns_collectable_type_successfully()
        {
            foreach (Type collectableType in CollectableBaseFactory.CollectableTypes)
            {
                ICollectionBase collection = new HomeCollection("name", collectableType);
                string          fullName   = collection.CollectionType.FullName;

                Type collectionType = CollectableBaseFactory.GetTypeFromFullName(fullName);

                Assert.AreEqual(collectableType, collectionType);
            }
        }