title: Convert custom action filter for Web API use?
body: <p>I found a really nice action filter that converts a comma-separated parameter to a generic type list: <a href="http://stevescodingblog.co.uk/fun-with-action-filters/">http://stevescodingblog.co.uk/fun-with-action-filters/</a></p>
  
  <p>I would like to use it but it will not work for an ApiController, it completely ignore it. Can someone help convert this for Web API use?</p>
  
  <pre><code>[AttributeUsage(AttributeTargets.Method)]
  public class SplitStringAttribute : ActionFilterAttribute
  {
      public string Parameter { get; set; }
  
      public string Delimiter { get; set; }
  
      public SplitStringAttribute()
      {
          Delimiter = ",";
      }
  
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
          if (filterContext.ActionParameters.ContainsKey(this.Parameter))
          {
              string value = null;
              var request = filterContext.RequestContext.HttpContext.Request;
  
              if (filterContext.RouteData.Values.ContainsKey(this.Parameter)
                  &amp;&amp; filterContext.RouteData.Values[this.Parameter] is string)
              {
                  value = (string)filterContext.RouteData.Values[this.Parameter];
              }
              else if (request[this.Parameter] is string)
              {
                  value = request[this.Parameter] as string;
              }
  
              var listArgType = GetParameterEnumerableType(filterContext);
  
              if (listArgType != null &amp;&amp; !string.IsNullOrWhiteSpace(value))
              {
                  string[] values = value.Split(Delimiter.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  
                  var listType = typeof(List&lt;&gt;).MakeGenericType(listArgType);
                  dynamic list = Activator.CreateInstance(listType);
  
                  foreach (var item in values)
                  {
                      try
                      {
                          dynamic convertedValue = TypeDescriptor.GetConverter(listArgType).ConvertFromInvariantString(item);
                          list.Add(convertedValue);
                      }
                      catch (Exception ex)
                      {
                          throw new ApplicationException(string.Format("Could not convert split string value to '{0}'", listArgType.FullName), ex);
                      }
                  }
  
                  filterContext.ActionParameters[this.Parameter] = list;
              }
          }
  
          base.OnActionExecuting(filterContext);
      }
  
      private Type GetParameterEnumerableType(ActionExecutingContext filterContext)
      {
          var param = filterContext.ActionParameters[this.Parameter];
          var paramType = param.GetType();
          var interfaceType = paramType.GetInterface(typeof(IEnumerable&lt;&gt;).FullName);
          Type listArgType = null;
  
          if (interfaceType != null)
          {
              var genericParams = interfaceType.GetGenericArguments();
              if (genericParams.Length == 1)
              {
                  listArgType = genericParams[0];
              }
          }
  
          return listArgType;
      }
  }
  </code></pre>