Beispiel #1
0
        protected ArrayMarshalInfoWriter(ArrayType type, MarshalType marshalType, MarshalInfo marshalInfo) : base(type)
        {
            this._marshalInfo = marshalInfo;
            this._marshalType = marshalType;
            this._arrayType   = type;
            this._elementType = type.ElementType;
            MarshalInfo           info  = null;
            ArrayMarshalInfo      info2 = marshalInfo as ArrayMarshalInfo;
            FixedArrayMarshalInfo info3 = marshalInfo as FixedArrayMarshalInfo;

            this._arraySize         = 1;
            this._nativeElementType = NativeType.None;
            if (info2 != null)
            {
                this._arraySize          = info2.Size;
                this._sizeParameterIndex = info2.SizeParameterIndex;
                if ((this._arraySize == 0) || ((this._arraySize == -1) && (this._sizeParameterIndex >= 0)))
                {
                    this._arraySizeSelection = ArraySizeOptions.UseSizeParameterIndex;
                }
                else
                {
                    this._arraySizeSelection = ArraySizeOptions.UseArraySize;
                }
                this._nativeElementType = info2.ElementType;
                info = new MarshalInfo(this._nativeElementType);
            }
            else if (info3 != null)
            {
                this._arraySize         = info3.Size;
                this._nativeElementType = info3.ElementType;
                info = new MarshalInfo(this._nativeElementType);
            }
            if (this._arraySize == -1)
            {
                this._arraySize = 1;
            }
            this._elementTypeMarshalInfoWriter = MarshalDataCollector.MarshalInfoWriterFor(this._elementType, marshalType, info, false, false, true, null);
            if (this._elementTypeMarshalInfoWriter.MarshaledTypes.Length > 1)
            {
                throw new InvalidOperationException($"ArrayMarshalInfoWriter cannot marshal arrays of {this._elementType.FullName}.");
            }
            this._arrayMarshaledTypeName = this._elementTypeMarshalInfoWriter.MarshaledTypes[0].DecoratedName + "*";
            if (marshalType == MarshalType.WindowsRuntime)
            {
                string name = DefaultMarshalInfoWriter.Naming.ForVariable(DefaultMarshalInfoWriter.TypeProvider.UInt32TypeReference);
                this._arraySizeSelection = ArraySizeOptions.UseFirstMarshaledType;
                this._marshaledTypes     = new MarshaledType[] { new MarshaledType(name, name, "ArraySize"), new MarshaledType(this._arrayMarshaledTypeName, this._arrayMarshaledTypeName) };
            }
            else
            {
                this._marshaledTypes = new MarshaledType[] { new MarshaledType(this._arrayMarshaledTypeName, this._arrayMarshaledTypeName) };
            }
            StringMarshalInfoWriter writer = this._elementTypeMarshalInfoWriter as StringMarshalInfoWriter;

            if (writer != null)
            {
                this._nativeElementType = writer.NativeType;
            }
        }
        internal static string BuildMethodParameterList(MethodReference interopMethod, MethodReference interfaceMethod, Unity.IL2CPP.ILPreProcessor.TypeResolver typeResolver, MarshalType marshalType, bool includeTypeNames)
        {
            List <string> elements = new List <string>();
            int           num      = 0;

            foreach (ParameterDefinition definition in interopMethod.Parameters)
            {
                MarshalInfo marshalInfo         = interfaceMethod.Parameters[num].MarshalInfo;
                DefaultMarshalInfoWriter writer = MarshalDataCollector.MarshalInfoWriterFor(typeResolver.Resolve(definition.ParameterType), marshalType, marshalInfo, true, false, false, null);
                foreach (MarshaledType type in writer.MarshaledTypes)
                {
                    elements.Add(string.Format(!includeTypeNames ? "{1}" : "{0} {1}", type.DecoratedName, Naming.ForParameterName(definition) + type.VariableName));
                }
                num++;
            }
            TypeReference reference2 = typeResolver.Resolve(interopMethod.ReturnType);

            if (reference2.MetadataType != MetadataType.Void)
            {
                MarshalInfo     info2          = interfaceMethod.MethodReturnType.MarshalInfo;
                MarshaledType[] marshaledTypes = MarshalDataCollector.MarshalInfoWriterFor(reference2, marshalType, info2, true, false, false, null).MarshaledTypes;
                for (int i = 0; i < (marshaledTypes.Length - 1); i++)
                {
                    elements.Add(string.Format(!includeTypeNames ? "{1}" : "{0}* {1}", marshaledTypes[i].DecoratedName, Naming.ForComInterfaceReturnParameterName() + marshaledTypes[i].VariableName));
                }
                elements.Add(string.Format(!includeTypeNames ? "{1}" : "{0}* {1}", marshaledTypes[marshaledTypes.Length - 1].DecoratedName, Naming.ForComInterfaceReturnParameterName()));
            }
            return(elements.AggregateWithComma());
        }
        private static string Sizes(TypeDefinition type)
        {
            DefaultMarshalInfoWriter writer = MarshalDataCollector.MarshalInfoWriterFor(type, MarshalType.PInvoke, null, false, false, false, null);

            object[] args = new object[4];
            args[0] = !type.HasGenericParameters ? InstanceSizeFor(type) : "0";
            args[1] = !type.HasGenericParameters ? writer.NativeSize : "0";
            if (!type.HasGenericParameters && (< > f__am$cacheB == null))
            {
Beispiel #4
0
 public BlittableByReferenceMarshalInfoWriter(ByReferenceType type, MarshalType marshalType, MarshalInfo marshalInfo) : base(type)
 {
     this._elementType = type.ElementType;
     this._elementTypeMarshalInfoWriter = MarshalDataCollector.MarshalInfoWriterFor(this._elementType, marshalType, marshalInfo, false, true, false, null);
     if (this._elementTypeMarshalInfoWriter.MarshaledTypes.Length > 1)
     {
         throw new InvalidOperationException($"BlittableByReferenceMarshalInfoWriter cannot marshal {type.ElementType.FullName}&.");
     }
     this._marshaledTypes = new MarshaledType[] { new MarshaledType(this._elementTypeMarshalInfoWriter.MarshaledTypes[0].Name + "*", this._elementTypeMarshalInfoWriter.MarshaledTypes[0].DecoratedName + "*") };
 }
        private void WriteForwardDeclarations(TypeReference type)
        {
            Unity.IL2CPP.ILPreProcessor.TypeResolver resolver = Unity.IL2CPP.ILPreProcessor.TypeResolver.For(type);
            MarshalType marshalType = !type.Resolve().IsWindowsRuntime ? MarshalType.COM : MarshalType.WindowsRuntime;

            foreach (MethodDefinition definition in type.Resolve().Methods)
            {
                foreach (ParameterDefinition definition2 in definition.Parameters)
                {
                    MarshalDataCollector.MarshalInfoWriterFor(resolver.Resolve(definition2.ParameterType), marshalType, definition2.MarshalInfo, true, false, false, null).WriteMarshaledTypeForwardDeclaration(this._writer);
                }
                if (definition.ReturnType.MetadataType != MetadataType.Void)
                {
                    MarshalDataCollector.MarshalInfoWriterFor(resolver.Resolve(definition.ReturnType), marshalType, definition.MethodReturnType.MarshalInfo, true, false, false, null).WriteMarshaledTypeForwardDeclaration(this._writer);
                }
            }
        }
        public ComSafeArrayMarshalInfoWriter(ArrayType type, MarshalInfo marshalInfo) : base(type)
        {
            this._elementType = type.ElementType;
            this._marshalInfo = marshalInfo as SafeArrayMarshalInfo;
            if (this._marshalInfo == null)
            {
                throw new InvalidOperationException($"SafeArray type '{type.FullName}' has invalid MarshalAsAttribute.");
            }
            if ((this._marshalInfo.ElementType == VariantType.BStr) && (this._elementType.MetadataType != MetadataType.String))
            {
                throw new InvalidOperationException($"SafeArray(BSTR) type '{type.FullName}' has invalid MarshalAsAttribute.");
            }
            NativeType nativeElementType = this.GetNativeElementType();

            this._elementTypeMarshalInfoWriter = MarshalDataCollector.MarshalInfoWriterFor(this._elementType, MarshalType.COM, new MarshalInfo(nativeElementType), false, false, false, null);
            string name = $"Il2CppSafeArray/*{this._marshalInfo.ElementType.ToString().ToUpper()}*/*";

            this._marshaledTypes = new MarshaledType[] { new MarshaledType(name, name) };
        }
 public ByReferenceMarshalInfoWriter(ByReferenceType type, MarshalType marshalType, MarshalInfo marshalInfo) : base(type)
 {
     this._elementType = type.ElementType;
     this._elementTypeMarshalInfoWriter = MarshalDataCollector.MarshalInfoWriterFor(type.ElementType, marshalType, marshalInfo, false, true, false, null);
     if (< > f__am$cache0 == null)
     {
        private static string FormatIl2CppMarshalingFunction(TypeDefinition marshalableType)
        {
            DefaultMarshalInfoWriter writer = MarshalDataCollector.MarshalInfoWriterFor(marshalableType, MarshalType.PInvoke, null, false, false, false, null);

            return($"{{ {writer.MarshalToNativeFunctionName}, {writer.MarshalFromNativeFunctionName}, {writer.MarshalCleanupFunctionName} }}");
        }
 public DefaultMarshalInfoWriter MarshalInfoWriterFor(MarshaledParameter parameter) =>
 MarshalDataCollector.MarshalInfoWriterFor(parameter.ParameterType, this._marshalType, parameter.MarshalInfo, this._useUnicodeCharset, false, false, null);
 public DefaultMarshalInfoWriter MarshalInfoWriterFor(MethodReturnType methodReturnType) =>
 MarshalDataCollector.MarshalInfoWriterFor(this._typeResolver.Resolve(methodReturnType.ReturnType), this._marshalType, methodReturnType.MarshalInfo, this._useUnicodeCharset, false, false, null);