Creating instance of all classes that have certain attribut value I have a simple custom attribute MessageDeliveryAttribute that has one string filed. Also I have several classes that mark with this attribute like:

[MessageDeliveryAttribute("MessegaToDb")]


In the app.config are settings like:

  &lt;appSettings&gt;
    &lt;add key="MessageToConsole" value="true"/&gt;
    &lt;add key="MessageToDb" value="true"/&gt;
    &lt;add key="MessageToService" value="false"/&gt;
    &lt;add key="MessageToFile" value="false"/&gt;
  &lt;/appSettings&gt;


I'm trying to implement class that will read all keys with value "true" from app.config, find all classes that marked with attribute 

[MessageDeliveryAttribute("value of key from app.config where value = true")]


and then create a list with instance of these classes.
Here are working code, but I need your suggestions how to improve that?

public static List&lt;IMessageDelivery&gt; GetMessagesDelivery()
{
    var instances = new List&lt;IMessageDelivery&gt;();

    // list of settings from app.config where value is true
    List&lt;string&gt; settingValues = ConfigurationManager.AppSettings.AllKeys
        .Where(key =&gt; ConfigurationManager.AppSettings[key].Equals("true"))
        .Select(value =&gt; value)
        .ToList();


    foreach (var types in GetTypesWithMessageDeliveryAttribute())
    {
        var attributeValue = GetAttributeValue(types);
        if (settingValues.IndexOf(attributeValue) &gt;= 0)
        {
            instances.Add(Activator.CreateInstance(types) as IMessageDelivery); 
        }                 
    }

    return instances;
}
// Get all classes with my custom attribute
public static IEnumerable&lt;Type&gt; GetTypesWithMessageDeliveryAttribute()
{
    var assembly = Assembly.GetExecutingAssembly();
    return from type in assembly.GetTypes()
           where type.IsDefined(typeof(MessageDeliveryAttribute), false)
           select type;
}
// get value of attribute
public static string GetAttributeValue(Type t)
{
    var messageDeliveryAttribute = (MessageDeliveryAttribute)Attribute.GetCustomAttribute(t, typeof(MessageDeliveryAttribute));

    return messageDeliveryAttribute != null ? messageDeliveryAttribute.DeliveryPointName : string.Empty;
}
I'm not sure what feedback specifically you're looking for. There are minor formatting and naming questions, but only two things I would specifically draw attention to.

The first thing is that you're enumerating all the settings in the App.config, but you're only interested in settings that relate directly to message delivery. You should name-space your setting keys, and filter the settings before evaluating them.

&lt;appSettings&gt;
    &lt;add key="MessageDelivery.MessageToConsole" value="true"/&gt;
    &lt;add key="MessageDelivery.MessageToDb" value="true"/&gt;
    &lt;add key="MessageDelivery.MessageToService" value="false"/&gt;
    &lt;add key="MessageDelivery.MessageToFile" value="false"/&gt;
  &lt;/appSettings&gt;


and

List&lt;string&gt; settingValues = ConfigurationManager.AppSettings.AllKeys
        .Where(key =&gt; ConfigurationManager.AppSettings[key].Equals("true"))
        .Where(key =&gt; key.StartsWith("MessageDelivery."))
        .Select(value =&gt; value.Replace("MessageDelivery.",""))
        .ToList();




Secondly, avoid using two different forms of Linq expression building:

List&lt;string&gt; settingValues = ConfigurationManager.AppSettings.AllKeys

        .Where(key =&gt; ConfigurationManager.AppSettings[key].Equals("true"))
        .Select(value =&gt; value)
        .ToList();


and

return from type in assembly.GetTypes()
           where type.IsDefined(typeof(MessageDeliveryAttribute), false)
           select type;