title: Unapply/pattern matching with scala macros and quasiquotes for knownDirectSubclasses
body: <p>I'm trying to create a match statement using macros, that matches all subclasses of a given type.
  But I have trouble with extracting the field values of the case classes.
  For example: </p>
  
  <pre><code>sealed abstract class Foobar
  case class Foo(x:Int,f:Foobar) extends Foobar
  case class Bar(s:String, f:Foobar) extends Foobar
  </code></pre>
  
  <p>Now I want to create code that looks like this, when Foobar is given:</p>
  
  <pre><code> e1 match {
     case Foo(args) =&gt; args.toString
     case Bar(args) =&gt; args.toString
   }
  </code></pre>
  
  <p>Thats what I got so far:</p>
  
  <pre><code>  def eqImpl[A: c.WeakTypeTag](c: Context)(e1: c.Expr[A], e2: c.Expr[A]): c.Expr[Boolean] = {
      import c.universe._
  
      val tpe = c.weakTypeOf[A].typeSymbol.asClass
      tpe.typeSignature // SI-7046
      val subclasses = tpe.knownDirectSubclasses
  
      val cases = 
        subclasses.map{ clazz =&gt;
        cq"x: $clazz =&gt; x " 
      }
      println(cases)
      reify(true)
    }
  </code></pre>
  
  <p>This code would match Foo and Bar, but I can not extract the fields, which I need on the right hand side.</p>