Skip to content

Commit

Permalink
fix #435: reflecting generic constructors from F# quotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jand42 committed Jun 24, 2015
1 parent 2cdac41 commit 06b8354
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/compiler/WebSharper.Compiler/ReflectionLayer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,11 @@ module QuotationUtils =
for t in ts ->
CR.Type.FromType(t)
]
//
// let generalize (m: MethodInfo) =
// if m.IsGenericMethod && not m.IsGenericMethodDefinition then
// m.GetGenericMethodDefinition()
// else m

let getProperTypeGenerics (t: System.Type) =
if t.IsGenericType || t.IsGenericTypeDefinition then
Expand All @@ -458,7 +463,7 @@ module QuotationUtils =
else []

let getProperMethodGenerics (m: MethodBase) =
if m.IsGenericMethod|| m.IsGenericMethodDefinition then
if m.IsGenericMethod || m.IsGenericMethodDefinition then
m.GetGenericArguments()
|> convertTypes
else []
Expand Down Expand Up @@ -493,9 +498,7 @@ module QuotationUtils =
else p

let ConvertConstructor (c: ConstructorInfo) : Q.Concrete<CR.Constructor> =
let tD = CR.TypeDefinition.FromType c.DeclaringType
makeSignature (c.GetParameters())
|> CR.Constructor.Create tD
CR.Constructor.Parse c
|> makeConcrete c.DeclaringType []

let ConvertMethod (m: MethodInfo) : Q.Concrete<CR.Method> =
Expand Down
6 changes: 6 additions & 0 deletions src/compiler/WebSharper.Core/Reflection.fs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,12 @@ type Constructor =

static member Create dT s = Constructor (dT, s)

static member Parse(m: System.Reflection.ConstructorInfo) =
let m = m.Module.ResolveMethod m.MetadataToken :?> System.Reflection.ConstructorInfo
let s = [for p in m.GetParameters() -> Type.FromType p.ParameterType]
let d = TypeDefinition.FromType m.DeclaringType
Constructor.Create d s

override this.ToString() =
System.String.Format(".ctor(..) [{0}]", this.DeclaringType)

Expand Down
3 changes: 3 additions & 0 deletions src/compiler/WebSharper.Core/Reflection.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ type Constructor =
/// Updates the declaring type.
member WithDeclaringType : TypeDefinition -> Constructor

/// Parses the constructor.
static member Parse : System.Reflection.ConstructorInfo -> Constructor

/// Constructs a new Constructor with an explicit signature.
static member Create : TypeDefinition -> Signature -> Constructor

Expand Down

0 comments on commit 06b8354

Please sign in to comment.