forked from hunterzonewu/unity-decompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssemblyValidation.cs
More file actions
159 lines (145 loc) · 6.82 KB
/
AssemblyValidation.cs
File metadata and controls
159 lines (145 loc) · 6.82 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Decompiled with JetBrains decompiler
// Type: AssemblyValidation
// Assembly: UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 01B28312-B6F5-4E06-90F6-BE297B711E41
// Assembly location: C:\Users\Blake\sandbox\unity\test-project\Library\UnityAssemblies\UnityEditor.dll
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using UnityEngine;
internal class AssemblyValidation
{
private static Dictionary<RuntimePlatform, List<System.Type>> _rulesByPlatform;
public static ValidationResult Validate(RuntimePlatform platform, IEnumerable<string> userAssemblies, params object[] options)
{
AssemblyValidation.WarmUpRulesCache();
string[] strArray = userAssemblies as string[] ?? userAssemblies.ToArray<string>();
if (strArray.Length != 0)
{
foreach (IValidationRule validationRule in AssemblyValidation.ValidationRulesFor(platform, options))
{
ValidationResult validationResult = validationRule.Validate((IEnumerable<string>) strArray, options);
if (!validationResult.Success)
return validationResult;
}
}
return new ValidationResult()
{
Success = true
};
}
private static void WarmUpRulesCache()
{
if (AssemblyValidation._rulesByPlatform != null)
return;
AssemblyValidation._rulesByPlatform = new Dictionary<RuntimePlatform, List<System.Type>>();
foreach (System.Type type in ((IEnumerable<System.Type>) typeof (AssemblyValidation).Assembly.GetTypes()).Where<System.Type>(new Func<System.Type, bool>(AssemblyValidation.IsValidationRule)))
AssemblyValidation.RegisterValidationRule(type);
}
private static bool IsValidationRule(System.Type type)
{
return AssemblyValidation.ValidationRuleAttributesFor(type).Any<AssemblyValidationRule>();
}
private static IEnumerable<IValidationRule> ValidationRulesFor(RuntimePlatform platform, params object[] options)
{
// ISSUE: object of a compiler-generated type is created
// ISSUE: reference to a compiler-generated method
return AssemblyValidation.ValidationRuleTypesFor(platform).Select<System.Type, IValidationRule>(new Func<System.Type, IValidationRule>(new AssemblyValidation.\u003CValidationRulesFor\u003Ec__AnonStorey69()
{
options = options
}.\u003C\u003Em__E0)).Where<IValidationRule>((Func<IValidationRule, bool>) (v => v != null));
}
[DebuggerHidden]
private static IEnumerable<System.Type> ValidationRuleTypesFor(RuntimePlatform platform)
{
// ISSUE: object of a compiler-generated type is created
// ISSUE: variable of a compiler-generated type
AssemblyValidation.\u003CValidationRuleTypesFor\u003Ec__Iterator5 typesForCIterator5 = new AssemblyValidation.\u003CValidationRuleTypesFor\u003Ec__Iterator5()
{
platform = platform,
\u003C\u0024\u003Eplatform = platform
};
// ISSUE: reference to a compiler-generated field
typesForCIterator5.\u0024PC = -2;
return (IEnumerable<System.Type>) typesForCIterator5;
}
private static IValidationRule CreateValidationRuleWithOptions(System.Type type, params object[] options)
{
List<object> objectList = new List<object>((IEnumerable<object>) options);
object[] array;
ConstructorInfo constructorInfo;
while (true)
{
array = objectList.ToArray();
constructorInfo = AssemblyValidation.ConstructorFor(type, (IEnumerable<object>) array);
if (constructorInfo == null)
{
if (objectList.Count != 0)
objectList.RemoveAt(objectList.Count - 1);
else
goto label_4;
}
else
break;
}
return (IValidationRule) constructorInfo.Invoke(array);
label_4:
return (IValidationRule) null;
}
private static ConstructorInfo ConstructorFor(System.Type type, IEnumerable<object> options)
{
System.Type[] array = options.Select<object, System.Type>((Func<object, System.Type>) (o => o.GetType())).ToArray<System.Type>();
return type.GetConstructor(array);
}
internal static void RegisterValidationRule(System.Type type)
{
foreach (AssemblyValidationRule assemblyValidationRule in AssemblyValidation.ValidationRuleAttributesFor(type))
AssemblyValidation.RegisterValidationRuleForPlatform(assemblyValidationRule.Platform, type);
}
internal static void RegisterValidationRuleForPlatform(RuntimePlatform platform, System.Type type)
{
// ISSUE: object of a compiler-generated type is created
// ISSUE: variable of a compiler-generated type
AssemblyValidation.\u003CRegisterValidationRuleForPlatform\u003Ec__AnonStorey6A platformCAnonStorey6A = new AssemblyValidation.\u003CRegisterValidationRuleForPlatform\u003Ec__AnonStorey6A();
// ISSUE: reference to a compiler-generated field
platformCAnonStorey6A.platform = platform;
// ISSUE: reference to a compiler-generated field
if (!AssemblyValidation._rulesByPlatform.ContainsKey(platformCAnonStorey6A.platform))
{
// ISSUE: reference to a compiler-generated field
AssemblyValidation._rulesByPlatform[platformCAnonStorey6A.platform] = new List<System.Type>();
}
// ISSUE: reference to a compiler-generated field
if (AssemblyValidation._rulesByPlatform[platformCAnonStorey6A.platform].IndexOf(type) == -1)
{
// ISSUE: reference to a compiler-generated field
AssemblyValidation._rulesByPlatform[platformCAnonStorey6A.platform].Add(type);
}
// ISSUE: reference to a compiler-generated field
// ISSUE: reference to a compiler-generated method
AssemblyValidation._rulesByPlatform[platformCAnonStorey6A.platform].Sort(new Comparison<System.Type>(platformCAnonStorey6A.\u003C\u003Em__E3));
}
internal static int CompareValidationRulesByPriority(System.Type a, System.Type b, RuntimePlatform platform)
{
int num1 = AssemblyValidation.PriorityFor(a, platform);
int num2 = AssemblyValidation.PriorityFor(b, platform);
if (num1 == num2)
return 0;
return num1 < num2 ? -1 : 1;
}
private static int PriorityFor(System.Type type, RuntimePlatform platform)
{
// ISSUE: object of a compiler-generated type is created
// ISSUE: reference to a compiler-generated method
return AssemblyValidation.ValidationRuleAttributesFor(type).Where<AssemblyValidationRule>(new Func<AssemblyValidationRule, bool>(new AssemblyValidation.\u003CPriorityFor\u003Ec__AnonStorey6B()
{
platform = platform
}.\u003C\u003Em__E4)).Select<AssemblyValidationRule, int>((Func<AssemblyValidationRule, int>) (attr => attr.Priority)).FirstOrDefault<int>();
}
private static IEnumerable<AssemblyValidationRule> ValidationRuleAttributesFor(System.Type type)
{
return type.GetCustomAttributes(true).OfType<AssemblyValidationRule>();
}
}