Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TypeLimiter.cs
Go to the documentation of this file.
4using System.Linq;
7
8namespace System.Data;
9
10internal sealed class TypeLimiter
11{
12 private sealed class Scope : IDisposable
13 {
14 private static readonly HashSet<Type> s_allowedTypes = new HashSet<Type>
15 {
16 typeof(bool),
17 typeof(char),
18 typeof(sbyte),
19 typeof(byte),
20 typeof(short),
21 typeof(ushort),
22 typeof(int),
23 typeof(uint),
24 typeof(long),
25 typeof(ulong),
26 typeof(float),
27 typeof(double),
28 typeof(decimal),
32 typeof(string),
33 typeof(Guid),
49 typeof(object),
50 typeof(Type),
52 typeof(Uri),
58 typeof(Size),
60 };
61
63
64 private readonly Scope m_previousScope;
65
67
74
75 public void Dispose()
76 {
77 if (this != s_activeScope)
78 {
79 throw new ObjectDisposedException(GetType().FullName);
80 }
83 }
84
85 public bool IsAllowedType(Type type)
86 {
88 {
89 return true;
90 }
91 for (Scope scope = this; scope != null; scope = scope.m_previousScope)
92 {
93 if (scope.m_allowedTypes.Contains(type))
94 {
95 return true;
96 }
97 }
98 Type[] array = (Type[])AppDomain.CurrentDomain.GetData("System.Data.DataSetDefaultAllowedTypes");
99 if (array != null)
100 {
101 for (int i = 0; i < array.Length; i++)
102 {
103 if (type == array[i])
104 {
105 return true;
106 }
107 }
108 }
109 return false;
110 }
111
113 {
114 while (true)
115 {
116 if (s_allowedTypes.Contains(type))
117 {
118 return true;
119 }
120 if (type.IsEnum)
121 {
122 return true;
123 }
124 if (type.IsSZArray)
125 {
126 type = type.GetElementType();
127 continue;
128 }
129 if (!type.IsGenericType || type.IsGenericTypeDefinition || !(type.GetGenericTypeDefinition() == typeof(List<>)))
130 {
131 break;
132 }
133 type = type.GetGenericArguments()[0];
134 }
135 return false;
136 }
137 }
138
140 private static Scope s_activeScope;
141
143
145
146 private TypeLimiter(Scope scope)
147 {
148 m_instanceScope = scope;
149 }
150
151 public static TypeLimiter Capture()
152 {
153 Scope scope = s_activeScope;
154 if (scope == null)
155 {
156 return null;
157 }
158 return new TypeLimiter(scope);
159 }
160
162 {
163 if ((object)type != null)
164 {
165 Scope scope = capturedLimiter?.m_instanceScope ?? s_activeScope;
166 if (scope != null && !scope.IsAllowedType(type))
167 {
169 }
170 }
171 }
172
174 {
176 {
177 return null;
178 }
180 }
181
183 {
185 {
186 return null;
187 }
189 }
190
192 {
193 if (dataTable == null)
194 {
195 return Enumerable.Empty<Type>();
196 }
198 select column.DataType;
199 }
200
202 {
203 if (dataSet == null)
204 {
205 return Enumerable.Empty<Type>();
206 }
207 return dataSet.Tables.Cast<DataTable>().SelectMany((DataTable table) => GetPreviouslyDeclaredDataTypes(table));
208 }
209}
static AppDomain CurrentDomain
Definition AppDomain.cs:28
static Exception TypeNotAllowed(Type type)
HashSet< Type > m_allowedTypes
bool IsAllowedType(Type type)
static readonly HashSet< Type > s_allowedTypes
Scope(Scope previousScope, IEnumerable< Type > allowedTypes)
readonly DeserializationToken m_deserializationToken
static bool IsTypeUnconditionallyAllowed(Type type)
static IDisposable EnterRestrictedScope(DataSet dataSet)
static TypeLimiter Capture()
static void EnsureTypeIsAllowed(Type type, TypeLimiter capturedLimiter=null)
static Scope s_activeScope
static IEnumerable< Type > GetPreviouslyDeclaredDataTypes(DataSet dataSet)
static IDisposable EnterRestrictedScope(DataTable dataTable)
static IEnumerable< Type > GetPreviouslyDeclaredDataTypes(DataTable dataTable)
static bool IsTypeLimitingDisabled
static DeserializationToken StartDeserialization()