Пример #1
0
        public static IEnumerable <object[]> CodeSnippetsToCompile()
        {
            // Not LibraryImportAttribute
            yield return(new object[] { CodeSnippets.UserDefinedPrefixedAttributes, 0, 3 });

            // No explicit marshalling for char or string
            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <char>(), 5, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <string>(), 5, 0 });

            yield return(new object[] { CodeSnippets.MarshalAsArrayParametersAndModifiers <char>(), 5, 0 });

            yield return(new object[] { CodeSnippets.MarshalAsArrayParametersAndModifiers <string>(), 5, 0 });

            // No explicit marshaling for bool
            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <bool>(), 5, 0 });

            yield return(new object[] { CodeSnippets.MarshalAsArrayParametersAndModifiers <bool>(), 5, 0 });

            // Unsupported StringMarshalling configuration
            yield return(new object[] { CodeSnippets.BasicParametersAndModifiersWithStringMarshalling <char>(StringMarshalling.Utf8), 5, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiersWithStringMarshalling <char>(StringMarshalling.Custom), 6, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiersWithStringMarshalling <string>(StringMarshalling.Custom), 6, 0 });

            yield return(new object[] { CodeSnippets.CustomStringMarshallingParametersAndModifiers <char>(), 5, 0 });

            // Unsupported UnmanagedType
            yield return(new object[] { CodeSnippets.MarshalAsParametersAndModifiers <char>(UnmanagedType.I1), 5, 0 });

            yield return(new object[] { CodeSnippets.MarshalAsParametersAndModifiers <char>(UnmanagedType.U1), 5, 0 });

            yield return(new object[] { CodeSnippets.MarshalAsParametersAndModifiers <int[]>(UnmanagedType.SafeArray), 10, 0 });

            // Unsupported MarshalAsAttribute usage
            //  * UnmanagedType.CustomMarshaler, MarshalTypeRef, MarshalType, MarshalCookie
            yield return(new object[] { CodeSnippets.MarshalAsCustomMarshalerOnTypes, 16, 0 });

            // Unsupported [In, Out] attributes usage
            // Blittable array
            yield return(new object[] { CodeSnippets.ByValueParameterWithModifier <int[]>("Out"), 1, 0 });

            yield return(new object[] { CodeSnippets.ByValueParameterWithModifier <int[]>("In, Out"), 1, 0 });

            // By ref with [In, Out] attributes
            yield return(new object[] { CodeSnippets.ByValueParameterWithModifier("in int", "In"), 1, 0 });

            yield return(new object[] { CodeSnippets.ByValueParameterWithModifier("ref int", "In"), 1, 0 });

            yield return(new object[] { CodeSnippets.ByValueParameterWithModifier("ref int", "In, Out"), 1, 0 });

            yield return(new object[] { CodeSnippets.ByValueParameterWithModifier("out int", "Out"), 1, 0 });

            // By value non-array with [In, Out] attributes
            yield return(new object[] { CodeSnippets.ByValueParameterWithModifier <byte>("In"), 1, 0 });

            yield return(new object[] { CodeSnippets.ByValueParameterWithModifier <byte>("Out"), 1, 0 });

            yield return(new object[] { CodeSnippets.ByValueParameterWithModifier <byte>("In, Out"), 1, 0 });

            // LCIDConversion
            yield return(new object[] { CodeSnippets.LCIDConversionAttribute, 1, 0 });

            // No size information for array marshalling from unmanaged to managed
            //   * return, out, ref
            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <byte[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <sbyte[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <short[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <ushort[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <char[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <string[]>(CodeSnippets.DisableRuntimeMarshalling), 5, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <int[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <uint[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <long[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <ulong[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <float[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <double[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <bool[]>(CodeSnippets.DisableRuntimeMarshalling), 5, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <IntPtr[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 });

            yield return(new object[] { CodeSnippets.BasicParametersAndModifiers <UIntPtr[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 });

            // Collection with non-integer size param
            yield return(new object[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <float>(isByRef: false), 1, 0 });

            yield return(new object[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <double>(isByRef: false), 1, 0 });

            yield return(new object[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <bool>(isByRef: false), 2, 0 });

            yield return(new object[] { CodeSnippets.MarshalUsingArrayParameterWithSizeParam <float>(isByRef: false), 1, 0 });

            yield return(new object[] { CodeSnippets.MarshalUsingArrayParameterWithSizeParam <double>(isByRef: false), 1, 0 });

            yield return(new object[] { CodeSnippets.MarshalUsingArrayParameterWithSizeParam <bool>(isByRef: false), 2, 0 });

            // Custom type marshalling with invalid members
            yield return(new object[] { CodeSnippets.CustomStructMarshalling.NonStaticMarshallerEntryPoint, 2, 0 });

            yield return(new object[] { CodeSnippets.CustomStructMarshalling.Stateless.ManagedToNativeOnlyOutParameter, 1, 0 });

            yield return(new object[] { CodeSnippets.CustomStructMarshalling.Stateless.ManagedToNativeOnlyReturnValue, 1, 0 });

            yield return(new object[] { CodeSnippets.CustomStructMarshalling.Stateless.NativeToManagedOnlyInParameter, 1, 0 });

            yield return(new object[] { CodeSnippets.CustomStructMarshalling.Stateless.StackallocOnlyRefParameter, 1, 0 });

            yield return(new object[] { CodeSnippets.CustomStructMarshalling.Stateful.ManagedToNativeOnlyOutParameter, 1, 0 });

            yield return(new object[] { CodeSnippets.CustomStructMarshalling.Stateful.ManagedToNativeOnlyReturnValue, 1, 0 });

            yield return(new object[] { CodeSnippets.CustomStructMarshalling.Stateful.NativeToManagedOnlyInParameter, 1, 0 });

            yield return(new object[] { CodeSnippets.CustomStructMarshalling.Stateful.StackallocOnlyRefParameter, 1, 0 });

            yield return(new object[] { CodeSnippets.CustomStructMarshalling_V1.TwoStageRefReturn, 3, 0 });

            yield return(new object[] { CodeSnippets.CustomStructMarshalling_V1.ManagedToNativeOnlyOutParameter, 1, 0 });

            yield return(new object[] { CodeSnippets.CustomStructMarshalling_V1.ManagedToNativeOnlyReturnValue, 1, 0 });

            yield return(new object[] { CodeSnippets.CustomStructMarshalling_V1.NativeToManagedOnlyInParameter, 1, 0 });

            yield return(new object[] { CodeSnippets.CustomStructMarshalling_V1.StackallocOnlyRefParameter, 1, 0 });

            // Abstract SafeHandle type by reference
            yield return(new object[] { CodeSnippets.BasicParameterWithByRefModifier("ref", "System.Runtime.InteropServices.SafeHandle"), 1, 0 });

            // Collection with constant and element size parameter
            yield return(new object[] { CodeSnippets.MarshalUsingCollectionWithConstantAndElementCount, 2, 0 });

            // Collection with null element size parameter name
            yield return(new object[] { CodeSnippets.MarshalUsingCollectionWithNullElementName, 2, 0 });

            // Generic collection marshaller has different arity than collection.
            yield return(new object[] { CodeSnippets.CustomCollectionMarshalling.Stateless.GenericCollectionMarshallingArityMismatch, 2, 0 });

            yield return(new object[] { CodeSnippets.CustomCollectionMarshalling_V1.GenericCollectionMarshallingArityMismatch, 2, 0 });

            yield return(new object[] { CodeSnippets.MarshalAsAndMarshalUsingOnReturnValue, 2, 0 });

            yield return(new object[] { CodeSnippets.CustomCollectionMarshalling_V1.GenericCollectionWithCustomElementMarshallingDuplicateElementIndirectionDepth, 2, 0 });

            yield return(new object[] { CodeSnippets.CustomCollectionMarshalling_V1.GenericCollectionWithCustomElementMarshallingUnusedElementIndirectionDepth, 1, 0 });

            yield return(new object[] { CodeSnippets.RecursiveCountElementNameOnReturnValue, 2, 0 });

            yield return(new object[] { CodeSnippets.RecursiveCountElementNameOnParameter, 2, 0 });

            yield return(new object[] { CodeSnippets.MutuallyRecursiveCountElementNameOnParameter, 4, 0 });

            yield return(new object[] { CodeSnippets.MutuallyRecursiveSizeParamIndexOnParameter, 4, 0 });

            // Ref returns
            yield return(new object[] { CodeSnippets.RefReturn("int"), 2, 2 });
        }
Пример #2
0
        public static IEnumerable <object[]> CodeSnippetsToCompileMultipleSources()
        {
            yield return(new object[] { new[] { CodeSnippets.BasicParametersAndModifiers <int>(), CodeSnippets.MarshalAsParametersAndModifiers <bool>(UnmanagedType.Bool) } });

            yield return(new object[] { new[] { CodeSnippets.BasicParametersAndModifiersWithStringMarshalling <int>(StringMarshalling.Utf16), CodeSnippets.MarshalAsParametersAndModifiers <bool>(UnmanagedType.Bool) } });

            yield return(new object[] { new[] { CodeSnippets.BasicParameterByValue("int[]", CodeSnippets.DisableRuntimeMarshalling), CodeSnippets.BasicParameterWithByRefModifier("ref", "int") } });
        }