Skip to content

Commit 4c01e86

Browse files
author
Elad Zelingher
committed
Fixing PCL unit tests
1 parent e912cc1 commit 4c01e86

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/net45/WampSharp/Core/Utilities/TypeExtensions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,14 @@ public static bool IsAssignableFrom(this Type interfaceType, Type type)
136136

137137
public static Type[] GetGenericArguments(this Type type)
138138
{
139-
return type.GenericTypeArguments;
139+
TypeInfo typeInfo = type.GetTypeInfo();
140+
141+
if (typeInfo.IsGenericTypeDefinition)
142+
{
143+
return typeInfo.GenericTypeParameters;
144+
}
145+
146+
return typeInfo.GenericTypeArguments;
140147
}
141148

142149
public static MethodInfo GetMethod(this Type type, string methodName)

src/net45/WampSharp/Core/Utilities/ValueTuple/ValueTupleArrayConverter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ private Func<object[], object> BuildToTuple()
5252
ParameterExpression array =
5353
Expression.Parameter(typeof(object[]), "array");
5454

55+
int tupleLength = mTupleType.GetValueTupleLength();
56+
5557
IEnumerable<BinaryExpression> tupleItemValues =
56-
Enumerable.Range(0, mTupleType.GetValueTupleLength())
58+
Enumerable.Range(0, tupleLength)
5759
.Select(index => Expression.ArrayIndex(array, Expression.Constant(index)));
5860

5961
// new ValueTuple<T1, T2, ..>((T1)array[0],(T2)array[1], ...)

src/net45/WampSharp/Core/Utilities/ValueTuple/ValueTupleTypeExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@ public static int GetValueTupleLength(this Type type)
4040

4141
Type genericTypeDefinition = type.GetGenericTypeDefinition();
4242

43+
Type[] genericArguments = genericTypeDefinition.GetGenericArguments();
44+
45+
int tupleLength = genericArguments.Length;
4346
if (!genericTypeDefinition.IsLongTuple())
4447
{
45-
return genericTypeDefinition.GetGenericArguments().Length;
48+
return tupleLength;
4649
}
4750
else
4851
{
4952
Type last = type.GetGenericArguments().Last();
5053

51-
return (genericTypeDefinition.GetGenericArguments().Length - 1) +
54+
return (tupleLength - 1) +
5255
last.GetValueTupleLength();
5356
}
5457
}

0 commit comments

Comments
 (0)