Esempio n. 1
0
    public void SetModel(CollectionMeta collection)
    {
        this.collection = collection;

        title.text  = collection.title;
        slogan.text = collection.slogan;

        LoadCover();
    }
Esempio n. 2
0
 private IList FromClass(CollectionMeta meta)
 {
     if (meta.Type.IsArray)
     {
         return(Array.CreateInstance(meta.Type.GetElementType(), Count));
     }
     if (meta.Is <IEnumerable>())
     {
         return((IList)meta.NewUp());
     }
     throw new Tantrum(string.Format("Don't know how to create a new {0} as collection", meta));
 }
Esempio n. 3
0
        public IEnumerable As(Type type)
        {
            var meta = new CollectionMeta(type);

            if (!meta.IsCollection)
            {
                throw new ArgumentException(string.Format("{0} is not a collection type", type));
            }
            var list = ConvertTo(meta);

            return(Populate(list));
        }
Esempio n. 4
0
 private static IList FromInterface(CollectionMeta meta)
 {
     if (meta.Is <IEnumerable>())
     {
         if (meta.Type.IsGenericType)
         {
             var list = typeof(List <>);
             var type = list.MakeGenericType(meta.Type.GetGenericArguments());
             return((IList)Activator.CreateInstance(type));
         }
         return(new ArrayList());
     }
     throw new Tantrum(string.Format("Don't know how to create a new {0} as collection", meta));
 }
        public override object Map(object source)
        {
            if (source == null)
            {
                return(null);
            }
            var list = new ChameleonList();

            var collectionMeta = new CollectionMeta(TargetType.Type);
            var targetType     = collectionMeta.GetItemType();

            foreach (var value in (IEnumerable)source)
            {
                list.Add(MapValue(value, targetType));
            }
            return(list.As(TargetType.Type));
        }
Esempio n. 6
0
 private IList ConvertTo(CollectionMeta meta)
 {
     return(meta.Type.IsInterface ? FromInterface(meta) : FromClass(meta));
 }