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]); }
public UserProcessor(AccesserType accesserType) { DataSourceAccesser = DataSourceAccesserFactory.Instance.GetAccesserForSource(accesserType); }
public DataSourceAccesserAttribute(AccesserType accesserType) { AccesserType = accesserType; }