You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let asms = (if toTgt then getTargetAssemblies() else getSourceAssemblies())
8989
8989
let fullName = fixName t.FullName
8990
8990
8991
-
// TODO: this linear search through all available source/target assemblies feels as if it must be too slow in some cases.
8992
-
// However, we store type translations in various tables (typeTableFwd and typeTableBwd) so perhaps it is not a problem
8993
-
let rec loop i =
8994
-
if i < 0 then
8995
-
let msg =
8996
-
if toTgt then sprintf "The design-time type '%O' utilized by a type provider was not found in the target reference assembly set '%A'. You may be referencing a profile which contains fewer types than those needed by the type provider you are using." t (getTargetAssemblies() |> Seq.toList)
8997
-
elif getSourceAssemblies() |> Seq.isEmpty then sprintf "A failure occurred while determining compilation references"
8998
-
else sprintf "The target type '%O' utilized by a type provider was not found in the design-time assembly set '%A'. Please report this problem to the project site for the type provider." t (getSourceAssemblies() |> Seq.toList)
8999
-
failwith msg
9000
-
else
9001
-
match tryGetTypeFromAssembly toTgt t.Assembly.FullName fullName asms[i] with
9002
-
| Some (newT, canSave) ->
9003
-
if canSave then table[t] <- newT
9004
-
newT
9005
-
| None -> loop (i - 1)
9006
-
loop (asms.Count - 1)
8991
+
let bestGuess =
8992
+
asms |> Seq.tryFind(fun a -> a.FullName = t.Assembly.FullName)
8993
+
|> Option.bind(fun a -> tryGetTypeFromAssembly toTgt t.Assembly.FullName fullName a)
8994
+
8995
+
match bestGuess with
8996
+
| Some (newT, canSave) ->
8997
+
if canSave then table.[t] <- newT
8998
+
newT
8999
+
| None ->
9000
+
9001
+
// TODO: this linear search through all available source/target assemblies feels as if it must be too slow in some cases.
9002
+
// However, we store type translations in various tables (typeTableFwd and typeTableBwd) so perhaps it is not a problem
9003
+
let rec loop i =
9004
+
if i < 0 then
9005
+
let msg =
9006
+
if toTgt then sprintf "The design-time type '%O' utilized by a type provider was not found in the target reference assembly set '%A'. You may be referencing a profile which contains fewer types than those needed by the type provider you are using." t (getTargetAssemblies() |> Seq.toList)
9007
+
elif getSourceAssemblies() |> Seq.isEmpty then sprintf "A failure occurred while determining compilation references"
9008
+
else sprintf "The target type '%O' utilized by a type provider was not found in the design-time assembly set '%A'. Please report this problem to the project site for the type provider." t (getSourceAssemblies() |> Seq.toList)
9009
+
failwith msg
9010
+
else
9011
+
match tryGetTypeFromAssembly toTgt t.Assembly.FullName fullName asms[i] with
9012
+
| Some (newT, canSave) ->
9013
+
if canSave then table[t] <- newT
9014
+
newT
9015
+
| None -> loop (i - 1)
9016
+
loop (asms.Count - 1)
9007
9017
9008
9018
and convType toTgt (t:Type) =
9009
9019
let table = (if toTgt then typeTableFwd else typeTableBwd)
9010
9020
match table.TryGetValue(t) with
9011
9021
| true, newT -> newT
9012
9022
| false, _ ->
9013
-
if t :? ProvidedTypeSymbol && (t :?> ProvidedTypeSymbol).IsFSharpTypeAbbreviation then t
9023
+
let isSymbol = t :? ProvidedTypeSymbol
9024
+
if isSymbol && (t :?> ProvidedTypeSymbol).IsFSharpTypeAbbreviation then t
9014
9025
// Types annotated with units-of-measure
9015
-
elif t :? ProvidedTypeSymbol && (t :?> ProvidedTypeSymbol).IsFSharpUnitAnnotated then
9026
+
elif isSymbol && (t :?> ProvidedTypeSymbol).IsFSharpUnitAnnotated then
9016
9027
let genericType = t.GetGenericTypeDefinition()
9017
9028
let newT = convTypeRef toTgt genericType
9018
9029
let typeArguments = t.GetGenericArguments() |> Array.map (convType toTgt) |> Array.toList
0 commit comments