@@ -3163,8 +3163,12 @@ private IEnumerable<Expression> BuildFromJSToCollectionInterfaceExpressions(
31633163 * (key) => (JSValue)key,
31643164 * (value) => (JSValue)value);
31653165 */
3166- MethodInfo asDictionaryMethod = typeof ( JSCollectionExtensions) . GetStaticMethod(
3167- nameof( JSCollectionExtensions. AsDictionary) ) ! . MakeGenericMethod( keyType, valueType) ;
3166+ MethodInfo asDictionaryMethod = typeof ( JSCollectionExtensions)
3167+ . GetMethods( BindingFlags. Public | BindingFlags. Static)
3168+ . Where( ( m) => m . Name == nameof ( JSCollectionExtensions . AsDictionary ) &&
3169+ m . GetParameters ( ) [ 0 ] . ParameterType == typeof ( JSMap ) )
3170+ . Single ( )
3171+ . MakeGenericMethod ( keyType , valueType ) ;
31683172 MethodInfo asJSMapMethod = typeof ( JSMap ) . GetExplicitConversion (
31693173 typeof ( JSValue ) , typeof ( JSMap ) ) ;
31703174 yield return Expression. Coalesce (
@@ -3189,9 +3193,12 @@ private IEnumerable<Expression> BuildFromJSToCollectionInterfaceExpressions(
31893193 * (value) => (TValue)value,
31903194 * (key) => (JSValue)key);
31913195 */
3192- MethodInfo asDictionaryMethod = typeof ( JSCollectionExtensions) . GetStaticMethod(
3193- nameof( JSCollectionExtensions. AsReadOnlyDictionary) )
3194- ! . MakeGenericMethod( keyType, valueType) ;
3196+ MethodInfo asDictionaryMethod = typeof ( JSCollectionExtensions )
3197+ . GetMethods ( BindingFlags . Public | BindingFlags . Static )
3198+ . Where ( ( m ) => m . Name == nameof ( JSCollectionExtensions . AsReadOnlyDictionary ) &&
3199+ m . GetParameters ( ) [ 0 ] . ParameterType == typeof ( JSMap ) )
3200+ . Single ( )
3201+ . MakeGenericMethod ( keyType , valueType ) ;
31953202 MethodInfo asJSMapMethod = typeof ( JSMap ) . GetExplicitConversion (
31963203 typeof ( JSValue ) , typeof ( JSMap ) ) ;
31973204 yield return Expression. Coalesce (
@@ -3248,71 +3255,6 @@ private IEnumerable<Expression> BuildFromJSToCollectionClassExpressions(
32483255 Expression . Convert ( valueExpression , jsIterableType , asJSIterableMethod ) ,
32493256 GetFromJSValueExpression ( elementType ) ) ) ) ;
32503257 }
3251- else if ( typeDefinition == typeof ( Dictionary< , > ) )
3252- {
3253- Type keyType = elementType;
3254- Type valueType = toType. GenericTypeArguments[ 1 ] ;
3255-
3256- /*
3257- * value.TryUnwrap() as Dictionary<TKey, TValue> ??
3258- * new Dictionary<TKey, TValue>(((JSMap)value).AsDictionary<TKey, TValue>(
3259- * (key) => (TKey)key,
3260- * (value) => (TValue)value,
3261- * (key) => (JSValue)key,
3262- * (value) => (JSValue)value);
3263- */
3264- MethodInfo asDictionaryMethod = typeof ( JSCollectionExtensions) . GetStaticMethod(
3265- nameof( JSCollectionExtensions. AsDictionary) ) ! . MakeGenericMethod(
3266- keyType, valueType) ;
3267- MethodInfo asJSMapMethod = typeof ( JSMap) . GetExplicitConversion(
3268- typeof ( JSValue) , typeof ( JSMap) ) ;
3269- ConstructorInfo dictionaryConstructor = toType. GetConstructor(
3270- new [ ] { typeof ( IDictionary< , > ) . MakeGenericType( keyType, valueType) } ) ! ;
3271- yield return Expression. Coalesce(
3272- Expression. TypeAs( Expression. Call( valueExpression, s_tryUnwrap) , toType) ,
3273- Expression. New(
3274- dictionaryConstructor,
3275- Expression. Call(
3276- asDictionaryMethod,
3277- Expression. Convert( valueExpression, typeof ( JSMap) , asJSMapMethod) ,
3278- GetFromJSValueExpression( keyType) ,
3279- GetFromJSValueExpression( valueType) ,
3280- GetToJSValueExpression( keyType) ,
3281- GetToJSValueExpression( valueType) ) ) ) ;
3282- }
3283- else if ( typeDefinition == typeof ( SortedDictionary< , > ) )
3284- {
3285- Type keyType = elementType;
3286- Type valueType = toType. GenericTypeArguments[ 1 ] ;
3287-
3288- /*
3289- * value.TryUnwrap() as SortedDictionary<TKey, TValue> ??
3290- * new SortedDictionary<TKey, TValue>(((JSMap)value).AsDictionary<TKey, TValue>(
3291- * (key) => (TKey)key,
3292- * (value) => (TValue)value,
3293- * (key) => (JSValue)key,
3294- * (value) => (JSValue)value));
3295- */
3296- MethodInfo asDictionaryMethod = typeof ( JSCollectionExtensions) . GetStaticMethod(
3297- nameof( JSCollectionExtensions. AsDictionary) ) ! . MakeGenericMethod(
3298- keyType, valueType) ;
3299- MethodInfo asJSMapMethod = typeof ( JSMap) . GetExplicitConversion(
3300- typeof ( JSValue) , typeof ( JSMap) ) ;
3301- // SortedDictionary doesn't have a constructor that takes IEnumerable<KeyValuePair<>>.
3302- ConstructorInfo dictionaryConstructor = toType. GetConstructor(
3303- new [ ] { typeof ( IDictionary< , > ) . MakeGenericType( keyType, valueType) } ) ! ;
3304- yield return Expression. Coalesce(
3305- Expression. TypeAs( Expression. Call( valueExpression, s_tryUnwrap) , toType) ,
3306- Expression. New(
3307- dictionaryConstructor,
3308- Expression. Call(
3309- asDictionaryMethod,
3310- Expression. Convert( valueExpression, typeof ( JSMap) , asJSMapMethod) ,
3311- GetFromJSValueExpression( keyType) ,
3312- GetFromJSValueExpression( valueType) ,
3313- GetToJSValueExpression( keyType) ,
3314- GetToJSValueExpression( valueType) ) ) ) ;
3315- }
33163258 else if ( typeDefinition == typeof ( Collection < > ) ||
33173259 typeDefinition == typeof ( ReadOnlyCollection < > ) )
33183260 {
@@ -3342,21 +3284,27 @@ private IEnumerable<Expression> BuildFromJSToCollectionClassExpressions(
33423284 GetToJSValueExpression ( elementType ) ) ) ) ;
33433285
33443286 }
3345- else if ( typeDefinition == typeof ( ReadOnlyDictionary< , > ) )
3287+ else if ( typeDefinition == typeof ( Dictionary < , > ) ||
3288+ typeDefinition == typeof ( SortedDictionary < , > ) ||
3289+ typeDefinition == typeof ( ReadOnlyDictionary < , > ) )
33463290 {
33473291 Type keyType = elementType;
33483292 Type valueType = toType. GenericTypeArguments [ 1 ] ;
33493293
33503294 /*
3351- * value.TryUnwrap() as ReadOnlyDictionary <TKey, TValue> ??
3295+ * value.TryUnwrap() as Dictionary <TKey, TValue> ??
33523296 * new Dictionary<TKey, TValue>(((JSMap)value).AsDictionary<TKey, TValue>(
33533297 * (key) => (TKey)key,
33543298 * (value) => (TValue)value,
33553299 * (key) => (JSValue)key,
33563300 * (value) => (JSValue)value));
33573301 */
3358- MethodInfo asDictionaryMethod = typeof ( JSCollectionExtensions) . GetStaticMethod(
3359- nameof( JSCollectionExtensions. AsDictionary) ) ! . MakeGenericMethod( keyType, valueType) ;
3302+ MethodInfo asDictionaryMethod = typeof ( JSCollectionExtensions )
3303+ . GetMethods ( BindingFlags . Public | BindingFlags . Static )
3304+ . Where ( ( m ) => m . Name == nameof ( JSCollectionExtensions . AsDictionary ) &&
3305+ m . GetParameters ( ) [ 0 ] . ParameterType == typeof ( JSMap ) )
3306+ . Single ( )
3307+ . MakeGenericMethod ( keyType , valueType ) ;
33603308 MethodInfo asJSMapMethod = typeof ( JSMap ) . GetExplicitConversion (
33613309 typeof ( JSValue ) , typeof ( JSMap ) ) ;
33623310 ConstructorInfo dictionaryConstructor = toType . GetConstructor (
0 commit comments