Beispiel #1
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 =>
            {
                ImplementDao impl = field.ReflectedType.GetCustomAttribute(typeof(ImplementDao)) as ImplementDao;
                field.SetValue(obj, FactoryDao.GetInstance().GetDao(impl.ClassName));
            });
        }
        public ResourceAllocationController()
        {
            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;

            Parallel.ForEach(fields, field =>
            {
                ImplementDao impl = field.FieldType.GetCustomAttribute(typeof(ImplementDao)) as ImplementDao;
                field.SetValue(this, FactoryDao.GetInstance().GetDao(impl.ClassName));
            });
        }