Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTautvydas Žilys <tautvydas.zilys@gmail.com>2020-09-16 01:48:36 +0300
committerGitHub <noreply@github.com>2020-09-16 01:48:36 +0300
commit1e3bbed3ef66b79be7818f6c6ecf2ac639ffeb19 (patch)
treefaa9bd53158a19546066706747c9f3c739251b24 /Test/Mono.Cecil.Tests/TypeDefinitionUtils.cs
parente94d04f9196e3bdec9226bcfb89571249f62b6f3 (diff)
Unity's Windows Runtime changes (#394)
* Implemented Windows Runtime projections for implemented interface overrides. * Don't redirect Windows Runtime projected methods on interfaces. * Add additional test cases for Windows Runtime interface projection. * Fix reading interface impl attributes when using immediate reading mode. * Do not project for windows runtime during read. A type will not be fully initialized during read, so don't attempt to project for Windows runtime until after all of the metadata reading is correct. If a type reading for a module is no completed, a call to BinaryRangeSearch in MetadataSystem can fail, because some of the entries in the types array will still be null. * Fix build warnings. * Remove method that got duplicated during a cherry pick. * Fixed an issue with MethodReferenceComparer where it would incorrectly identify two method references to be the same if they had the same declaring types, the same parameter counts and were both unresolvable. * Sync up latest changes to MethodReferenceComparer and TypeReferenceEquality comparer and also add tests for them. * Fix code formatting. * Remove extra char * Style fix Co-authored-by: Ignas Ziberkas <ignas@unity3d.com> Co-authored-by: Josh Peterson <petersonjm1@gmail.com> Co-authored-by: Jb Evain <jb@evain.net>
Diffstat (limited to 'Test/Mono.Cecil.Tests/TypeDefinitionUtils.cs')
-rw-r--r--Test/Mono.Cecil.Tests/TypeDefinitionUtils.cs41
1 files changed, 41 insertions, 0 deletions
diff --git a/Test/Mono.Cecil.Tests/TypeDefinitionUtils.cs b/Test/Mono.Cecil.Tests/TypeDefinitionUtils.cs
new file mode 100644
index 0000000..7324584
--- /dev/null
+++ b/Test/Mono.Cecil.Tests/TypeDefinitionUtils.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Mono.Cecil {
+
+ public static class TypeDefinitionUtils {
+
+ public static TypeReference TypeDefinitionForGeneric (
+ Type genericType, AssemblyDefinition genericAssemblyDefinition,
+ Type paramterType, AssemblyDefinition parameterAssemblyDefinition)
+ {
+ var paramDefinition = TypeDefinitionUtils.TypeDefinitionFor (paramterType, parameterAssemblyDefinition);
+ var genericDefinition = TypeDefinitionUtils.TypeDefinitionFor (genericType, genericAssemblyDefinition);
+ var genericInstance = new GenericInstanceType (genericDefinition);
+ genericInstance.GenericArguments.Add (paramDefinition);
+ return genericInstance;
+ }
+
+ public static TypeDefinition TypeDefinitionFor (Type type, AssemblyDefinition assemblyDefinition)
+ {
+ var stack = new Stack<string> ();
+ var currentType = type;
+ while (currentType != null) {
+ stack.Push ( (currentType.DeclaringType == null ? currentType.Namespace + "." : "") + currentType.Name);
+ currentType = currentType.DeclaringType;
+ }
+
+ var typeDefinition = assemblyDefinition.MainModule.GetType (stack.Pop ());
+ if (typeDefinition == null)
+ return null;
+
+ while (stack.Count > 0) {
+ var name = stack.Pop ();
+ typeDefinition = typeDefinition.NestedTypes.Single (t => t.Name == name);
+ }
+
+ return typeDefinition;
+ }
+ }
+}