Exemple #1
0
        public static IEnumerable <object[]> CodeSnippetsToCompile()
        {
            yield return(new[] { CodeSnippets.TrivialClassDeclarations });

            yield return(new[] { CodeSnippets.TrivialStructDeclarations });

            yield return(new[] { CodeSnippets.MultipleAttributes });

            yield return(new[] { CodeSnippets.NestedNamespace });

            yield return(new[] { CodeSnippets.NestedTypes });

            yield return(new[] { CodeSnippets.UnsafeContext });

            yield return(new[] { CodeSnippets.UserDefinedEntryPoint });

            yield return(new[] { CodeSnippets.AllLibraryImportNamedArguments });

            yield return(new[] { CodeSnippets.DefaultParameters });

            yield return(new[] { CodeSnippets.UseCSharpFeaturesForConstants });

            // Parameter / return types
            yield return(new[] { CodeSnippets.BasicParametersAndModifiers <byte>() });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiers <sbyte>() });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiers <short>() });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiers <ushort>() });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiers <int>() });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiers <uint>() });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiers <long>() });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiers <ulong>() });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiers <float>() });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiers <double>() });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiers <IntPtr>() });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiers <UIntPtr>() });

            // Arrays
            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers <byte>() });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers <sbyte>() });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers <short>() });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers <ushort>() });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers <int>() });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers <uint>() });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers <long>() });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers <ulong>() });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers <float>() });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers <double>() });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers <IntPtr>() });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers <UIntPtr>() });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers("byte*", "unsafe") });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers("sbyte*", "unsafe") });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers("short*", "unsafe") });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers("ushort*", "unsafe") });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers("int*", "unsafe") });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers("uint*", "unsafe") });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers("long*", "unsafe") });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers("ulong*", "unsafe") });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers("float*", "unsafe") });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers("double*", "unsafe") });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers("System.IntPtr*", "unsafe") });

            yield return(new[] { CodeSnippets.MarshalAsArrayParametersAndModifiers("System.UIntPtr*", "unsafe") });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <byte>(isByRef: false) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <sbyte>(isByRef: false) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <short>(isByRef: false) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <ushort>(isByRef: false) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <int>(isByRef: false) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <uint>(isByRef: false) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <long>(isByRef: false) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <ulong>(isByRef: false) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <IntPtr>(isByRef: false) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <UIntPtr>(isByRef: false) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <byte>(isByRef: true) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <sbyte>(isByRef: true) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <short>(isByRef: true) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <ushort>(isByRef: true) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <int>(isByRef: true) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <uint>(isByRef: true) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <long>(isByRef: true) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <ulong>(isByRef: true) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <IntPtr>(isByRef: true) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam <UIntPtr>(isByRef: true) });

            // StringMarshalling
            yield return(new[] { CodeSnippets.BasicParametersAndModifiersWithStringMarshalling <char>(StringMarshalling.Utf16) });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiersWithStringMarshalling <string>(StringMarshalling.Utf16) });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiersWithStringMarshalling <string>(StringMarshalling.Utf8) });

            // StringMarshallingCustomType
            yield return(new[] { CodeSnippets.CustomStringMarshallingParametersAndModifiers <string>() });

            // MarshalAs
            yield return(new[] { CodeSnippets.MarshalAsParametersAndModifiers <bool>(UnmanagedType.Bool) });

            yield return(new[] { CodeSnippets.MarshalAsParametersAndModifiers <bool>(UnmanagedType.VariantBool) });

            yield return(new[] { CodeSnippets.MarshalAsParametersAndModifiers <bool>(UnmanagedType.I1) });

            yield return(new[] { CodeSnippets.MarshalAsParametersAndModifiers <char>(UnmanagedType.I2) });

            yield return(new[] { CodeSnippets.MarshalAsParametersAndModifiers <char>(UnmanagedType.U2) });

            yield return(new[] { CodeSnippets.MarshalAsParametersAndModifiers <IntPtr>(UnmanagedType.SysInt) });

            yield return(new[] { CodeSnippets.MarshalAsParametersAndModifiers <UIntPtr>(UnmanagedType.SysUInt) });

            yield return(new[] { CodeSnippets.MarshalAsParametersAndModifiers <string>(UnmanagedType.LPWStr) });

            yield return(new[] { CodeSnippets.MarshalAsParametersAndModifiers <string>(UnmanagedType.LPTStr) });

            yield return(new[] { CodeSnippets.MarshalAsParametersAndModifiers <string>(UnmanagedType.LPUTF8Str) });

            yield return(new[] { CodeSnippets.MarshalAsParametersAndModifiers <string>(UnmanagedType.LPStr) });

            yield return(new[] { CodeSnippets.MarshalAsParametersAndModifiers <string>(UnmanagedType.BStr) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithNestedMarshalInfo <string>(UnmanagedType.LPWStr) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithNestedMarshalInfo <string>(UnmanagedType.LPUTF8Str) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithNestedMarshalInfo <string>(UnmanagedType.LPStr) });

            yield return(new[] { CodeSnippets.MarshalAsArrayParameterWithNestedMarshalInfo <string>(UnmanagedType.BStr) });

            // [In, Out] attributes
            // By value non-blittable array
            yield return(new [] { CodeSnippets.ByValueParameterWithModifier("S[]", "Out")
                                  + CodeSnippets.CustomStructMarshalling.NonBlittableUserDefinedType()
                                  + CodeSnippets.CustomStructMarshalling.NativeTypeRef });

            yield return(new [] { CodeSnippets.ByValueParameterWithModifier("S[]", "In, Out")
                                  + CodeSnippets.CustomStructMarshalling.NonBlittableUserDefinedType()
                                  + CodeSnippets.CustomStructMarshalling.NativeTypeRef });

            // Enums
            yield return(new[] { CodeSnippets.EnumParameters });

            // Pointers
            yield return(new[] { CodeSnippets.PointerParameters <byte>() });

            yield return(new[] { CodeSnippets.PointerParameters <sbyte>() });

            yield return(new[] { CodeSnippets.PointerParameters <short>() });

            yield return(new[] { CodeSnippets.PointerParameters <ushort>() });

            yield return(new[] { CodeSnippets.PointerParameters <int>() });

            yield return(new[] { CodeSnippets.PointerParameters <uint>() });

            yield return(new[] { CodeSnippets.PointerParameters <long>() });

            yield return(new[] { CodeSnippets.PointerParameters <ulong>() });

            yield return(new[] { CodeSnippets.PointerParameters <float>() });

            yield return(new[] { CodeSnippets.PointerParameters <double>() });

            yield return(new[] { CodeSnippets.PointerParameters <bool>() });

            yield return(new[] { CodeSnippets.PointerParameters <IntPtr>() });

            yield return(new[] { CodeSnippets.PointerParameters <UIntPtr>() });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiersUnsafe("void*") });

            // Delegates
            yield return(new[] { CodeSnippets.DelegateParametersAndModifiers });

            yield return(new[] { CodeSnippets.DelegateMarshalAsParametersAndModifiers });

            // Function pointers
            yield return(new[] { CodeSnippets.BasicParametersAndModifiersUnsafe("delegate* <void>") });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiersUnsafe("delegate* unmanaged<void>") });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiersUnsafe("delegate* unmanaged<int, int>") });

            yield return(new[] { CodeSnippets.BasicParametersAndModifiersUnsafe("delegate* unmanaged[Stdcall]<int, int>") });

            yield return(new[] { CodeSnippets.MarshalAsParametersAndModifiersUnsafe("delegate* <int>", UnmanagedType.FunctionPtr) });

            yield return(new[] { CodeSnippets.MarshalAsParametersAndModifiersUnsafe("delegate* unmanaged<int>", UnmanagedType.FunctionPtr) });

            // Structs
            yield return(new[] { CodeSnippets.BlittableStructParametersAndModifiers(string.Empty) });

            yield return(new[] { CodeSnippets.BlittableStructParametersAndModifiers(CodeSnippets.DisableRuntimeMarshalling) });

            yield return(new[] { CodeSnippets.ValidateDisableRuntimeMarshalling.TypeUsage(string.Empty)
                                 + CodeSnippets.ValidateDisableRuntimeMarshalling.NonBlittableUserDefinedTypeWithNativeType });

            yield return(new[] { CodeSnippets.ValidateDisableRuntimeMarshalling.TypeUsage(CodeSnippets.DisableRuntimeMarshalling)
                                 + CodeSnippets.ValidateDisableRuntimeMarshalling.NonBlittableUserDefinedTypeWithNativeType });

            // SafeHandle
            yield return(new[] { CodeSnippets.BasicParametersAndModifiers("Microsoft.Win32.SafeHandles.SafeFileHandle") });

            yield return(new[] { CodeSnippets.BasicParameterByValue("System.Runtime.InteropServices.SafeHandle") });

            yield return(new[] { CodeSnippets.SafeHandleWithCustomDefaultConstructorAccessibility(privateCtor: false) });

            yield return(new[] { CodeSnippets.SafeHandleWithCustomDefaultConstructorAccessibility(privateCtor: true) });

            // Custom type marshalling
            yield return(new[] { CodeSnippets.CustomStructMarshalling.ParametersAndModifiers });

            yield return(new[] { CodeSnippets.CustomStructMarshalling.StackallocParametersAndModifiersNoRef });

            yield return(new[] { CodeSnippets.CustomStructMarshalling.StackallocTwoStageParametersAndModifiersNoRef });

            yield return(new[] { CodeSnippets.CustomStructMarshalling.OptionalStackallocParametersAndModifiers });

            yield return(new[] { CodeSnippets.CustomStructMarshalling.TwoStageParametersAndModifiers });

            yield return(new[] { CodeSnippets.CustomStructMarshalling.PinnableParametersAndModifiers });

            yield return(new[] { CodeSnippets.CustomStructMarshalling.NativeTypePinnable("byte", "byte") });

            yield return(new[] { CodeSnippets.CustomStructMarshalling.NativeTypePinnable("byte", "int") });

            yield return(new[] { CodeSnippets.CustomStructMarshalling.MarshalUsingParametersAndModifiers });

            yield return(new[] { CodeSnippets.CustomStructMarshalling.NativeToManagedOnlyOutParameter });

            yield return(new[] { CodeSnippets.CustomStructMarshalling.NativeToManagedOnlyReturnValue });

            yield return(new[] { CodeSnippets.ArrayMarshallingWithCustomStructElement });

            yield return(new[] { CodeSnippets.ArrayMarshallingWithCustomStructElementWithValueProperty });

            // Escaped C# keyword identifiers
            yield return(new[] { CodeSnippets.ByValueParameterWithName("Method", "@event") });

            yield return(new[] { CodeSnippets.ByValueParameterWithName("Method", "@var") });

            yield return(new[] { CodeSnippets.ByValueParameterWithName("@params", "i") });

            //Generics
            yield return(new[] { CodeSnippets.MaybeBlittableGenericTypeParametersAndModifiers <byte>() });

            yield return(new[] { CodeSnippets.MaybeBlittableGenericTypeParametersAndModifiers <sbyte>() });

            yield return(new[] { CodeSnippets.MaybeBlittableGenericTypeParametersAndModifiers <short>() });

            yield return(new[] { CodeSnippets.MaybeBlittableGenericTypeParametersAndModifiers <ushort>() });

            yield return(new[] { CodeSnippets.MaybeBlittableGenericTypeParametersAndModifiers <int>() });

            yield return(new[] { CodeSnippets.MaybeBlittableGenericTypeParametersAndModifiers <uint>() });

            yield return(new[] { CodeSnippets.MaybeBlittableGenericTypeParametersAndModifiers <long>() });

            yield return(new[] { CodeSnippets.MaybeBlittableGenericTypeParametersAndModifiers <ulong>() });

            yield return(new[] { CodeSnippets.MaybeBlittableGenericTypeParametersAndModifiers <float>() });

            yield return(new[] { CodeSnippets.MaybeBlittableGenericTypeParametersAndModifiers <double>() });

            yield return(new[] { CodeSnippets.MaybeBlittableGenericTypeParametersAndModifiers <IntPtr>() });

            yield return(new[] { CodeSnippets.MaybeBlittableGenericTypeParametersAndModifiers <UIntPtr>() });

            // Custom collection marshalling
            yield return(new[] { CodeSnippets.CollectionByValue <byte>() });

            yield return(new[] { CodeSnippets.CollectionByValue <sbyte>() });

            yield return(new[] { CodeSnippets.CollectionByValue <short>() });

            yield return(new[] { CodeSnippets.CollectionByValue <ushort>() });

            yield return(new[] { CodeSnippets.CollectionByValue <int>() });

            yield return(new[] { CodeSnippets.CollectionByValue <uint>() });

            yield return(new[] { CodeSnippets.CollectionByValue <long>() });

            yield return(new[] { CodeSnippets.CollectionByValue <ulong>() });

            yield return(new[] { CodeSnippets.CollectionByValue <float>() });

            yield return(new[] { CodeSnippets.CollectionByValue <double>() });

            yield return(new[] { CodeSnippets.CollectionByValue <IntPtr>() });

            yield return(new[] { CodeSnippets.CollectionByValue <UIntPtr>() });

            yield return(new[] { CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers <byte[]>() });

            yield return(new[] { CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers <sbyte[]>() });

            yield return(new[] { CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers <short[]>() });

            yield return(new[] { CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers <ushort[]>() });

            yield return(new[] { CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers <int[]>() });

            yield return(new[] { CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers <uint[]>() });

            yield return(new[] { CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers <long[]>() });

            yield return(new[] { CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers <ulong[]>() });

            yield return(new[] { CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers <float[]>() });

            yield return(new[] { CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers <double[]>() });

            yield return(new[] { CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers <IntPtr[]>() });

            yield return(new[] { CodeSnippets.MarshalUsingCollectionCountInfoParametersAndModifiers <UIntPtr[]>() });

            yield return(new[] { CodeSnippets.CustomCollectionDefaultMarshallerParametersAndModifiers <byte>() });

            yield return(new[] { CodeSnippets.CustomCollectionDefaultMarshallerParametersAndModifiers <sbyte>() });

            yield return(new[] { CodeSnippets.CustomCollectionDefaultMarshallerParametersAndModifiers <short>() });

            yield return(new[] { CodeSnippets.CustomCollectionDefaultMarshallerParametersAndModifiers <ushort>() });

            yield return(new[] { CodeSnippets.CustomCollectionDefaultMarshallerParametersAndModifiers <int>() });

            yield return(new[] { CodeSnippets.CustomCollectionDefaultMarshallerParametersAndModifiers <uint>() });

            yield return(new[] { CodeSnippets.CustomCollectionDefaultMarshallerParametersAndModifiers <long>() });

            yield return(new[] { CodeSnippets.CustomCollectionDefaultMarshallerParametersAndModifiers <ulong>() });

            yield return(new[] { CodeSnippets.CustomCollectionDefaultMarshallerParametersAndModifiers <float>() });

            yield return(new[] { CodeSnippets.CustomCollectionDefaultMarshallerParametersAndModifiers <double>() });

            yield return(new[] { CodeSnippets.CustomCollectionDefaultMarshallerParametersAndModifiers <IntPtr>() });

            yield return(new[] { CodeSnippets.CustomCollectionDefaultMarshallerParametersAndModifiers <UIntPtr>() });

            yield return(new[] { CodeSnippets.CustomCollectionCustomMarshallerParametersAndModifiers <byte>() });

            yield return(new[] { CodeSnippets.CustomCollectionCustomMarshallerParametersAndModifiers <sbyte>() });

            yield return(new[] { CodeSnippets.CustomCollectionCustomMarshallerParametersAndModifiers <short>() });

            yield return(new[] { CodeSnippets.CustomCollectionCustomMarshallerParametersAndModifiers <ushort>() });

            yield return(new[] { CodeSnippets.CustomCollectionCustomMarshallerParametersAndModifiers <int>() });

            yield return(new[] { CodeSnippets.CustomCollectionCustomMarshallerParametersAndModifiers <uint>() });

            yield return(new[] { CodeSnippets.CustomCollectionCustomMarshallerParametersAndModifiers <long>() });

            yield return(new[] { CodeSnippets.CustomCollectionCustomMarshallerParametersAndModifiers <ulong>() });

            yield return(new[] { CodeSnippets.CustomCollectionCustomMarshallerParametersAndModifiers <float>() });

            yield return(new[] { CodeSnippets.CustomCollectionCustomMarshallerParametersAndModifiers <double>() });

            yield return(new[] { CodeSnippets.CustomCollectionCustomMarshallerParametersAndModifiers <IntPtr>() });

            yield return(new[] { CodeSnippets.CustomCollectionCustomMarshallerParametersAndModifiers <UIntPtr>() });

            yield return(new[] { CodeSnippets.CustomCollectionCustomMarshallerReturnValueLength <int>() });

            yield return(new[] { CodeSnippets.GenericCollectionWithCustomElementMarshalling });

            yield return(new[] { CodeSnippets.CollectionsOfCollectionsStress });
        }