Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
StructModel.cs
Go to the documentation of this file.
3
5
6internal sealed class StructModel : TypeModel
7{
12
14 {
15 MemberInfo[] members = base.Type.GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
16 MemberInfo[] array = new MemberInfo[members.Length];
17 int num = 0;
18 for (int i = 0; i < members.Length; i++)
19 {
20 if (!(members[i] is PropertyInfo))
21 {
22 array[num++] = members[i];
23 }
24 }
25 for (int j = 0; j < members.Length; j++)
26 {
28 {
29 array[num++] = members[j];
30 }
31 }
32 return array;
33 }
34
35 [RequiresUnreferencedCode("calls GetFieldModel")]
37 {
40 {
42 }
43 else if (memberInfo is PropertyInfo)
44 {
46 }
47 if (fieldModel != null && fieldModel.ReadOnly && fieldModel.FieldTypeDesc.Kind != TypeKind.Collection && fieldModel.FieldTypeDesc.Kind != TypeKind.Enumerable)
48 {
49 return null;
50 }
51 return fieldModel;
52 }
53
55 {
56 if (typeDesc == null)
57 {
58 return;
59 }
60 if (typeDesc.IsUnsupported)
61 {
62 if (typeDesc.Exception == null)
63 {
65 }
67 }
68 CheckSupportedMember(typeDesc.BaseTypeDesc, member, type);
69 CheckSupportedMember(typeDesc.ArrayElementTypeDesc, member, type);
70 }
71
72 [RequiresUnreferencedCode("calls GetTypeDesc")]
74 {
75 if (fieldInfo.IsStatic)
76 {
77 return null;
78 }
79 if (fieldInfo.DeclaringType != base.Type)
80 {
81 return null;
82 }
83 TypeDesc typeDesc = base.ModelScope.TypeScope.GetTypeDesc(fieldInfo.FieldType, fieldInfo, directReference: true, throwOnError: false);
84 if (fieldInfo.IsInitOnly && typeDesc.Kind != TypeKind.Collection && typeDesc.Kind != TypeKind.Enumerable)
85 {
86 return null;
87 }
89 return new FieldModel(fieldInfo, fieldInfo.FieldType, typeDesc);
90 }
91
92 [RequiresUnreferencedCode("calls GetTypeDesc")]
94 {
95 if (propertyInfo.DeclaringType != base.Type)
96 {
97 return null;
98 }
99 if (CheckPropertyRead(propertyInfo))
100 {
101 TypeDesc typeDesc = base.ModelScope.TypeScope.GetTypeDesc(propertyInfo.PropertyType, propertyInfo, directReference: true, throwOnError: false);
102 if (!propertyInfo.CanWrite && typeDesc.Kind != TypeKind.Collection && typeDesc.Kind != TypeKind.Enumerable)
103 {
104 return null;
105 }
106 CheckSupportedMember(typeDesc, propertyInfo, propertyInfo.PropertyType);
107 return new FieldModel(propertyInfo, propertyInfo.PropertyType, typeDesc);
108 }
109 return null;
110 }
111
112 internal static bool CheckPropertyRead(PropertyInfo propertyInfo)
113 {
114 if (!propertyInfo.CanRead)
115 {
116 return false;
117 }
118 MethodInfo getMethod = propertyInfo.GetMethod;
119 if (getMethod.IsStatic)
120 {
121 return false;
122 }
123 ParameterInfo[] parameters = getMethod.GetParameters();
124 if (parameters.Length != 0)
125 {
126 return false;
127 }
128 return true;
129 }
130}
virtual ? MethodInfo GetMethod
static string XmlSerializerUnsupportedType
Definition SR.cs:1394
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string XmlSerializerUnsupportedMember
Definition SR.cs:1396
Definition SR.cs:7
string? FullName
Definition Type.cs:47
static bool CheckPropertyRead(PropertyInfo propertyInfo)
void CheckSupportedMember(TypeDesc typeDesc, MemberInfo member, Type type)
FieldModel GetFieldModel(MemberInfo memberInfo)
FieldModel GetFieldModel(FieldInfo fieldInfo)
StructModel([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, TypeDesc typeDesc, ModelScope scope)
Definition StructModel.cs:8
FieldModel GetPropertyModel(PropertyInfo propertyInfo)