Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
InstanceDescriptor.cs
Go to the documentation of this file.
3
5
6public sealed class InstanceDescriptor
7{
8 public ICollection Arguments { get; }
9
10 public bool IsComplete { get; }
11
12 public MemberInfo? MemberInfo { get; }
13
14 public InstanceDescriptor(MemberInfo? member, ICollection? arguments)
15 : this(member, arguments, isComplete: true)
16 {
17 }
18
19 public InstanceDescriptor(MemberInfo? member, ICollection? arguments, bool isComplete)
20 {
21 MemberInfo = member;
22 IsComplete = isComplete;
23 if (arguments == null)
24 {
25 Arguments = Array.Empty<object>();
26 }
27 else
28 {
29 object[] array = new object[arguments.Count];
30 arguments.CopyTo(array, 0);
32 }
33 if (member is FieldInfo fieldInfo)
34 {
35 if (!fieldInfo.IsStatic)
36 {
38 }
39 if (Arguments.Count != 0)
40 {
42 }
43 }
44 else if (member is ConstructorInfo constructorInfo)
45 {
46 if (constructorInfo.IsStatic)
47 {
49 }
50 if (Arguments.Count != constructorInfo.GetParameters().Length)
51 {
53 }
54 }
55 else if (member is MethodInfo methodInfo)
56 {
57 if (!methodInfo.IsStatic)
58 {
60 }
61 if (Arguments.Count != methodInfo.GetParameters().Length)
62 {
64 }
65 }
66 else if (member is PropertyInfo propertyInfo)
67 {
68 if (!propertyInfo.CanRead)
69 {
71 }
72 MethodInfo getMethod = propertyInfo.GetGetMethod();
73 if (getMethod != null && !getMethod.IsStatic)
74 {
76 }
77 }
78 }
79
80 public object? Invoke()
81 {
82 object[] array = new object[Arguments.Count];
84 for (int i = 0; i < array.Length; i++)
85 {
86 if (array[i] is InstanceDescriptor instanceDescriptor)
87 {
88 array[i] = instanceDescriptor.Invoke();
89 }
90 }
92 {
93 return ((ConstructorInfo)MemberInfo).Invoke(array);
94 }
96 {
97 return ((MethodInfo)MemberInfo).Invoke(null, array);
98 }
100 {
101 return ((PropertyInfo)MemberInfo).GetValue(null, array);
102 }
103 if (MemberInfo is FieldInfo)
104 {
105 return ((FieldInfo)MemberInfo).GetValue(null);
106 }
107 return null;
108 }
109}
InstanceDescriptor(MemberInfo? member, ICollection? arguments, bool isComplete)
InstanceDescriptor(MemberInfo? member, ICollection? arguments)
static string InstanceDescriptorMustBeReadable
Definition SR.cs:102
static string InstanceDescriptorLengthMismatch
Definition SR.cs:104
static string InstanceDescriptorMustBeStatic
Definition SR.cs:100
static string InstanceDescriptorCannotBeStatic
Definition SR.cs:98
Definition SR.cs:7
void CopyTo(Array array, int index)