Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 8aa2eea

Browse files
committed
Rename GetGenericType API's which traverse heirachy to FirstGenericType()
1 parent 2a8b9e3 commit 8aa2eea

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/ServiceStack.Text/CollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static ICollection<T> CreateAndPopulate<T>(Type ofCollectionType, T[] wit
99
{
1010
if (ofCollectionType == null) return new List<T>(withItems);
1111

12-
var genericType = ofCollectionType.GetGenericType();
12+
var genericType = ofCollectionType.FirstGenericType();
1313
var genericTypeDefinition = genericType != null
1414
? genericType.GetGenericTypeDefinition()
1515
: null;

src/ServiceStack.Text/ReflectionExtensions.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public static bool HasGenericType(this Type type)
130130
return false;
131131
}
132132

133-
public static Type GetGenericType(this Type type)
133+
public static Type FirstGenericType(this Type type)
134134
{
135135
while (type != null)
136136
{
@@ -174,7 +174,7 @@ public static Type GetTypeWithGenericTypeDefinitionOf(this Type type, Type gener
174174
}
175175
}
176176

177-
var genericType = type.GetGenericType();
177+
var genericType = type.FirstGenericType();
178178
if (genericType != null && genericType.GetGenericTypeDefinition() == genericTypeDefinition)
179179
{
180180
return genericType;
@@ -321,7 +321,7 @@ public static Type GetTypeWithGenericInterfaceOf(this Type type, Type genericInt
321321

322322
if (!type.IsGeneric()) return null;
323323

324-
var genericType = type.GetGenericType();
324+
var genericType = type.FirstGenericType();
325325
return genericType.GetGenericTypeDefinition() == genericInterfaceType
326326
? genericType
327327
: null;
@@ -1325,12 +1325,11 @@ public static Type FirstGenericTypeDefinition(this Type type)
13251325
{
13261326
while (type != null)
13271327
{
1328-
if (type.HasGenericType())
1328+
if (type.IsGenericTypeDefinition())
13291329
return type.GenericTypeDefinition();
13301330

13311331
type = type.BaseType();
13321332
}
1333-
13341333
return null;
13351334
}
13361335

src/ServiceStack.Text/TranslateListWithElements.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static object TranslateToConvertibleGenericICollectionCache(
5858
ConvertInstanceDelegate translateToFn;
5959
if (TranslateConvertibleICollectionCache.TryGetValue(typeKey, out translateToFn)) return translateToFn(from, toInstanceOfType);
6060

61-
var toElementType = toInstanceOfType.GetGenericType().GenericTypeArguments()[0];
61+
var toElementType = toInstanceOfType.FirstGenericType().GenericTypeArguments()[0];
6262
var genericType = typeof(TranslateListWithConvertibleElements<,>).MakeGenericType(fromElementType, toElementType);
6363
var mi = genericType.GetStaticMethod("LateBoundTranslateToGenericICollection");
6464
translateToFn = (ConvertInstanceDelegate)mi.MakeDelegate(typeof(ConvertInstanceDelegate));

0 commit comments

Comments
 (0)