private MethodReference GetToNativeMarshaler(ManagedUnrealMarshalerType marshalerType,
                                                     EPropertyType typeCode, string typePath,
                                                     EPropertyType arg1TypeCode = EPropertyType.Unknown, string arg1TypePath = null,
                                                     EPropertyType arg2TypeCode = EPropertyType.Unknown, string arg2TypePath = null)
        {
            ManagedUnrealMarshalerInfo marshalerInfo = new ManagedUnrealMarshalerInfo(
                typeCode, typePath, arg1TypeCode, arg1TypePath, arg2TypeCode, arg2TypePath, marshalerType);

            MethodReference method;

            if (toNativeMarshalers.TryGetValue(marshalerInfo, out method))
            {
                return(method);
            }

            int paramCount = marshalerToNativeParamCountMin;

            if (!codeSettings.MinimalMarshalingParams || ManagedUnrealTypeInfo.MarshalerRequiresNativePropertyField(typeCode))
            {
                paramCount = marshalerToNativeParamCount;
            }

            Type type = ManagedUnrealTypeInfo.GetTypeFromMarshalerInfo(marshalerInfo);

            if (type != null)
            {
                if (typeCode == EPropertyType.Struct && !type.IsGenericType)
                {
                    // Struct marshaling methods are generated, find the existing type by path
                    TypeDefinition typeDef = typeDef = assembly.MainModule.GetType(type.FullName);

                    foreach (MethodDefinition methodDef in typeDef.Methods)
                    {
                        if (methodDef.Name == "ToNative" && methodDef.IsPublic && methodDef.IsStatic && methodDef.Parameters.Count == paramCount)
                        {
                            method = methodDef;
                            break;
                        }
                    }
                }
                else
                {
                    foreach (System.Reflection.MethodInfo methodInfo in type.GetMethods())
                    {
                        if (methodInfo.Name == "ToNative" && methodInfo.IsPublic && methodInfo.GetParameters().Length == paramCount &&
                            (methodInfo.IsStatic || ManagedUnrealTypeInfo.IsCollectionType(typeCode)))
                        {
                            method = assembly.MainModule.ImportEx(methodInfo);
                            break;
                        }
                    }
                }
            }

            if (method != null)
            {
                toNativeMarshalers.Add(marshalerInfo, method);
            }

            if (method == null)
            {
                throw new RewriteException(typePath, "Failed to get ToNative marshaler");
            }

            return(method);
        }