/// <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 VariableDefinition EmitCreateMarshaler(ILProcessor processor, Instruction loadBuffer, FieldDefinition offsetField, FieldDefinition nativePropertyField, ManagedUnrealPropertyInfo propertyInfo) { VariableDefinition marshalerVar = null; if (ManagedUnrealTypeInfo.PropertyRequiresMarshalerInstance(propertyInfo)) { TypeReference marshalerType = assembly.MainModule.ImportEx(ManagedUnrealTypeInfo.GetMarshalerType(ManagedUnrealMarshalerType.Copy, propertyInfo)); marshalerVar = new VariableDefinition(marshalerType); } if (marshalerVar != null) { processor.Emit(OpCodes.Ldc_I4_1); processor.Emit(OpCodes.Ldsfld, nativePropertyField); // New delegate marshaling code, this will use a cached delegate EmitCachedMarshalingDelegates(processor, propertyInfo, ManagedUnrealMarshalerType.Copy); System.Reflection.ConstructorInfo ctor; System.Reflection.MethodInfo fromNativeMethod; System.Reflection.MethodInfo toNativeMethod; GetInstancedMarshalerMethods(propertyInfo, ManagedUnrealMarshalerType.Copy, out ctor, out fromNativeMethod, out toNativeMethod); processor.Emit(OpCodes.Newobj, assembly.MainModule.ImportEx(ctor)); processor.Emit(OpCodes.Stloc, marshalerVar); } return(marshalerVar); }