/// <summary>
 /// Tries to retrieve an <see cref="IOptionBuilder"/> via attributes for a given
 /// type.
 /// </summary>
 /// <remarks>
 /// This method constructs a builder using the <see cref="OptionBuilderAttribute"/>.
 /// </remarks>
 /// <param name="type">The type to introspect.</param>
 /// <returns>An instance or <see langword="null"/>.</returns>
 public static IOptionBuilder GetOptionBuilderFromAttribute(Type type)
 {
     object[] builderAttributes = type.GetCustomAttributes(typeof(OptionBuilderAttribute), true);
     if (builderAttributes.Length > 0)
     {
         OptionBuilderAttribute mapBuilderAttr = builderAttributes[0] as OptionBuilderAttribute;
         if (mapBuilderAttr != null)
         {
             try {
                 return(Activator.CreateInstance(mapBuilderAttr.OptionBuilderType) as IOptionBuilder);
             } catch (Exception exc) {
                 Trace.WriteLine("Unable to create OptionBuilder for type " + type + ": " + exc.Message);
             }
         }
     }
     return(null);
 }
        private IOptionBuilder GetBuilder(PropertyInfo info, IOptionBuilderContext context, object subject, Type type)
        {
            IOptionBuilder         builder          = null;
            OptionBuilderAttribute builderAttribute =
                (OptionBuilderAttribute)Attribute.GetCustomAttribute(info, typeof(OptionBuilderAttribute));

            if (builderAttribute != null)
            {
                builder = Activator.CreateInstance(builderAttribute.OptionBuilderType) as IOptionBuilder;
            }
            else
            {
                object value = info.GetGetMethod().Invoke(subject, null);
                builder = context.GetOptionBuilder(type, value);
            }
            return(builder);
        }