コード例 #1
0
        public IDataSourceAccesser GetAccesserForSource(AccesserType source)
        {
            if (Accessers.Count == 0)
            {
                Type interfaceType = typeof(IDataSourceAccesser);
                Type attributeType = typeof(DataSourceAccesserAttribute);

                var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(assembly => assembly.GetTypes())
                            .Where(t => interfaceType.IsAssignableFrom(t) && !t.IsInterface).ToArray();

                var attributes = types.SelectMany(type =>
                                                  type.GetCustomAttributes(attributeType, false)).ToArray();

                for (int i = 0; i < types.Count(); i++)
                {
                    var attribute = (DataSourceAccesserAttribute)attributes[i];
                    var accesser  = (IDataSourceAccesser)Activator.CreateInstance(types[i]);
                    Accessers.Add(attribute.AccesserType, accesser);
                }
            }

            return(Accessers[source]);
        }
コード例 #2
0
 public UserProcessor(AccesserType accesserType)
 {
     DataSourceAccesser = DataSourceAccesserFactory.Instance.GetAccesserForSource(accesserType);
 }
コード例 #3
0
 public DataSourceAccesserAttribute(AccesserType accesserType)
 {
     AccesserType = accesserType;
 }