private MethodReference GetToNativeMarshaler(ManagedUnrealMarshalerType marshalerType, ManagedUnrealPropertyInfo propertyInfo) { ManagedUnrealTypeInfoReference arg1 = propertyInfo.GenericArgs.Count >= 1 ? propertyInfo.GenericArgs[0] : null; ManagedUnrealTypeInfoReference arg2 = propertyInfo.GenericArgs.Count >= 2 ? propertyInfo.GenericArgs[1] : null; return(GetToNativeMarshaler(marshalerType, propertyInfo.Type.TypeCode, propertyInfo.Type.Path, arg1 != null ? arg1.TypeCode : EPropertyType.Unknown, arg1 != null ? arg1.Path : null, arg2 != null ? arg2.TypeCode : EPropertyType.Unknown, arg2 != null ? arg2.Path : null)); }
/// <summary> /// Gets the marshaler methods for a marshaler which has to be instantiated be used (the collection marshalers) /// </summary> private bool GetInstancedMarshalerMethods(ManagedUnrealPropertyInfo propertyInfo, ManagedUnrealMarshalerType marshalerType, out System.Reflection.ConstructorInfo ctor, out System.Reflection.MethodInfo fromNativeMethod, out System.Reflection.MethodInfo toNativeMethod) { Type collectionMarshalerType = ManagedUnrealTypeInfo.GetMarshalerType(marshalerType, propertyInfo); // Find the constructor for the marshaler ctor = null; foreach (System.Reflection.ConstructorInfo ctorInfo in collectionMarshalerType.GetConstructors()) { System.Reflection.ParameterInfo[] ctorParams = ctorInfo.GetParameters(); if (ctorParams.Length > 2 && ctorParams[0].ParameterType == typeof(int) && ctorParams[1].ParameterType == typeof(UFieldAddress)) { ctor = ctorInfo; break; } } fromNativeMethod = GetInstancedMarshalerMethod(collectionMarshalerType, true); toNativeMethod = GetInstancedMarshalerMethod(collectionMarshalerType, false); bool success = ctor != null && fromNativeMethod != null && toNativeMethod != null; if (!success) { throw new RewriteException(propertyInfo.Path, "Failed to get marshaler methods"); } return(success); }
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); }
private MethodReference GetToNativeMarshaler(ManagedUnrealMarshalerType marshalerType, ManagedUnrealTypeInfoReference typeInfo) { return(GetToNativeMarshaler(marshalerType, typeInfo.TypeCode, typeInfo.Path)); }
/// <summary> /// Loads the static delegates FromNative / ToNative from CachedMarshalingDelegates<,> /// e.g. CachedMarshalingDelegates<int, BlittableTypeMarshaler<int>>.FromNative / .ToNative /// </summary> private void EmitCachedMarshalingDelegates(ILProcessor processor, ManagedUnrealPropertyInfo propertyInfo, ManagedUnrealMarshalerType marshalerType) { foreach (ManagedUnrealTypeInfoReference genericArg in propertyInfo.GenericArgs) { Type cachedMarshalingDelegatesType = ManagedUnrealTypeInfo.GetCachedMarshalingDelegatesType(marshalerType, genericArg); FieldReference fromNative = assembly.MainModule.ImportEx( ManagedUnrealTypeInfo.GetCachedMarshalingDelegatesDelegate(cachedMarshalingDelegatesType, true)); FieldReference toNative = assembly.MainModule.ImportEx( ManagedUnrealTypeInfo.GetCachedMarshalingDelegatesDelegate(cachedMarshalingDelegatesType, false)); processor.Emit(OpCodes.Ldsfld, fromNative); processor.Emit(OpCodes.Ldsfld, toNative); } }