CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
TypeSystem.cs
Go to the documentation of this file.
1#if !NETFX_CORE
2//-----------------------------------------------------------------------
3// <copyright file="TypeSystem.cs" company="Marimer LLC">
4// Copyright (c) Marimer LLC. All rights reserved.
5// Website: https://cslanet.com
6// </copyright>
7// <summary>no summary</summary>
8//-----------------------------------------------------------------------
9using System;
10using System.Collections.Generic;
11
12namespace Csla.Core
13{
14 internal static class TypeSystem
15 {
16 internal static Type GetElementType(Type seqType)
17 {
18 Type ienum = FindIEnumerable(seqType);
19 if (ienum == null) return seqType;
20 return ienum.GetGenericArguments()[0];
21 }
22
23 private static Type FindIEnumerable(Type seqType)
24 {
25 if (seqType == null || seqType == typeof(string))
26 return null;
27
28 if (seqType.IsArray)
29 return typeof(IEnumerable<>).MakeGenericType(seqType.GetElementType());
30
31 if (seqType.IsGenericType)
32 {
33 foreach (Type arg in seqType.GetGenericArguments())
34 {
35 Type ienum = typeof(IEnumerable<>).MakeGenericType(arg);
36 if (ienum.IsAssignableFrom(seqType))
37 {
38 return ienum;
39 }
40 }
41 }
42
43 Type[] ifaces = seqType.GetInterfaces();
44 if (ifaces != null && ifaces.Length > 0)
45 {
46 foreach (Type iface in ifaces)
47 {
48 Type ienum = FindIEnumerable(iface);
49 if (ienum != null) return ienum;
50 }
51 }
52
53 if (seqType.BaseType != null && seqType.BaseType != typeof(object))
54 {
55 return FindIEnumerable(seqType.BaseType);
56 }
57
58 return null;
59 }
60 }
61}
62#endif