Ejemplo n.º 1
0
        public void AddMembers()
        {
            if (NewType.HasGenericParameters)
            {
                var genericInstanceType = new GenericInstanceType(NewType);
                foreach (var newTypeGenericParameter in NewType.GenericParameters)
                {
                    genericInstanceType.GenericArguments.Add(newTypeGenericParameter);
                }
                SelfSubstitutedRef = NewType.Module.ImportReference(genericInstanceType);
                var genericTypeRef = new GenericInstanceType(AssemblyContext.Imports.Il2CppClassPointerStore)
                {
                    GenericArguments = { SelfSubstitutedRef }
                };
                ClassPointerFieldRef = new FieldReference("NativeClassPtr", AssemblyContext.Imports.IntPtr,
                                                          NewType.Module.ImportReference(genericTypeRef));
            }
            else
            {
                SelfSubstitutedRef = NewType;
                var genericTypeRef = new GenericInstanceType(AssemblyContext.Imports.Il2CppClassPointerStore);
                if (OriginalType.IsPrimitive || OriginalType.FullName == "System.String")
                {
                    genericTypeRef.GenericArguments.Add(NewType.Module.ImportReference(TargetTypeSystemHandler.Type.Module.GetType(OriginalType.FullName)));
                }
                else
                {
                    genericTypeRef.GenericArguments.Add(SelfSubstitutedRef);
                }
                ClassPointerFieldRef = new FieldReference("NativeClassPtr", AssemblyContext.Imports.IntPtr,
                                                          NewType.Module.ImportReference(genericTypeRef));
            }

            if (OriginalType.IsEnum)
            {
                return;
            }

            foreach (var originalTypeField in OriginalType.Fields)
            {
                if (originalTypeField.Name.EndsWith(">k__BackingField"))
                {
                    continue;                                                      // covered by properties anyway
                }
                myFieldContexts[originalTypeField] = new FieldRewriteContext(this, originalTypeField);
            }

            foreach (var originalTypeMethod in OriginalType.Methods)
            {
                if (originalTypeMethod.Name == ".cctor")
                {
                    continue;
                }

                var methodRewriteContext = new MethodRewriteContext(this, originalTypeMethod);
                myMethodContexts[originalTypeMethod]            = methodRewriteContext;
                myMethodContextsByName[originalTypeMethod.Name] = methodRewriteContext;
                methodRewriteContext.CtorPhase2();
            }
        }
Ejemplo n.º 2
0
        public void AddMembers()
        {
            if (NewType.HasGenericParameters)
            {
                var genericInstanceType = new GenericInstanceType(NewType);
                foreach (var newTypeGenericParameter in NewType.GenericParameters)
                {
                    genericInstanceType.GenericArguments.Add(newTypeGenericParameter);
                }
                SelfSubstitutedRef = NewType.Module.ImportReference(genericInstanceType);
                var genericTypeRef = new GenericInstanceType(AssemblyContext.Imports.Il2CppClassPointerStore)
                {
                    GenericArguments = { SelfSubstitutedRef }
                };
                ClassPointerFieldRef = new FieldReference("NativeClassPtr", AssemblyContext.Imports.IntPtr,
                                                          NewType.Module.ImportReference(genericTypeRef));
            }
            else
            {
                SelfSubstitutedRef = NewType;
                var genericTypeRef = new GenericInstanceType(AssemblyContext.Imports.Il2CppClassPointerStore);
                if (OriginalType.IsPrimitive || OriginalType.FullName == "System.String")
                {
                    genericTypeRef.GenericArguments.Add(NewType.Module.ImportReference(TargetTypeSystemHandler.Type.Module.GetType(OriginalType.FullName)));
                }
                else
                {
                    genericTypeRef.GenericArguments.Add(SelfSubstitutedRef);
                }
                ClassPointerFieldRef = new FieldReference("NativeClassPtr", AssemblyContext.Imports.IntPtr,
                                                          NewType.Module.ImportReference(genericTypeRef));
            }

            if (OriginalType.IsEnum)
            {
                return;
            }

            var renamedFieldCounts = new Dictionary <string, int>();

            foreach (var originalTypeField in OriginalType.Fields)
            {
                myFieldContexts[originalTypeField] = new FieldRewriteContext(this, originalTypeField, renamedFieldCounts);
            }

            foreach (var originalTypeMethod in OriginalType.Methods)
            {
                if (originalTypeMethod.Name == ".cctor")
                {
                    continue;
                }
                if (originalTypeMethod.Name == ".ctor" && originalTypeMethod.Parameters.Count == 1 &&
                    originalTypeMethod.Parameters[0].ParameterType.FullName == "System.IntPtr")
                {
                    continue;
                }

                var methodRewriteContext = new MethodRewriteContext(this, originalTypeMethod);
                myMethodContexts[originalTypeMethod]            = methodRewriteContext;
                myMethodContextsByName[originalTypeMethod.Name] = methodRewriteContext;
            }
        }