-
Notifications
You must be signed in to change notification settings - Fork 0
/
Types.cs
73 lines (70 loc) · 2.29 KB
/
Types.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.CompilerServices;
using Platform.Collections.Lists;
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
#pragma warning disable CA1819 // Properties should not return arrays
namespace Platform.Reflection
{
/// <summary>
/// <para>
/// Represents the types.
/// </para>
/// <para></para>
/// </summary>
public abstract class Types
{
/// <summary>
/// <para>
/// Gets the collection value.
/// </para>
/// <para></para>
/// </summary>
public static ReadOnlyCollection<Type> Collection { get; } = new ReadOnlyCollection<Type>(System.Array.Empty<Type>());
/// <summary>
/// <para>
/// Gets the array value.
/// </para>
/// <para></para>
/// </summary>
public static Type[] Array => Collection.ToArray();
/// <summary>
/// <para>
/// Returns the read only collection.
/// </para>
/// <para></para>
/// </summary>
/// <returns>
/// <para>A read only collection of type</para>
/// <para></para>
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected ReadOnlyCollection<Type> ToReadOnlyCollection()
{
var types = GetType().GetGenericArguments();
var result = new List<Type>();
AppendTypes(result, types);
return new ReadOnlyCollection<Type>(result);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void AppendTypes(List<Type> container, IList<Type> types)
{
for (var i = 0; i < types.Count; i++)
{
var element = types[i];
if (element != typeof(Types))
{
if (element.IsSubclassOf(typeof(Types)))
{
AppendTypes(container, element.GetStaticPropertyValue<ReadOnlyCollection<Type>>(nameof(Types<object>.Collection)));
}
else
{
container.Add(element);
}
}
}
}
}
}