Exemple #1
0
        public Allocation()
        {
            var fields = from field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                         let attrs = field.GetCustomAttributes()
                                     from attr in attrs
                                     where attr is ResourceDao
                                     select field;

            foreach (var field in fields)
            {
                //ImplementDao impl = field.FieldType.GetCustomAttribute(typeof(ImplementDao)) as ImplementDao;
                //field.SetValue(this, FactoryDao.GetInstance().GetDao(impl.ClassName));
                field.SetValue(this, FactoryDao.GetInstance().GetDao(this.GetType()));
            }
        }
Exemple #2
0
        public void AllocResource(object obj)
        {
            var fields = from field in obj.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                         let attrs = field.GetCustomAttributes()
                                     from attr in attrs
                                     where attr is ResourceDao
                                     select field;

            Parallel.ForEach(fields, field =>
            {
                field.SetValue(obj, FactoryDao.GetInstance().GetDao(obj.GetType()));
                //ImplementDao impl = field.ReflectedType.GetCustomAttribute(typeof(ImplementDao)) as ImplementDao;
                //field.SetValue(obj, FactoryDao.GetInstance().GetDao());
            });
        }