using System.IO;
using System.Linq;
using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
-using Microsoft.CodeAnalysis.CSharp;
namespace Microsoft.Interop
{
private sealed record ComClassInfo(string ClassName, ContainingSyntaxContext ContainingSyntaxContext, ContainingSyntax ClassSyntax, SequenceEqualImmutableArray<string> ImplementedInterfacesNames);
public void Initialize(IncrementalGeneratorInitializationContext context)
{
+ var unsafeCodeIsEnabled = context.CompilationProvider.Select((comp, ct) => comp.Options is CSharpCompilationOptions { AllowUnsafe: true }); // Unsafe code enabled
// Get all types with the [GeneratedComClassAttribute] attribute.
- var attributedClasses = context.SyntaxProvider
+ var attributedClassesOrDiagnostics = context.SyntaxProvider
.ForAttributeWithMetadataName(
TypeNames.GeneratedComClassAttribute,
static (node, ct) => node is ClassDeclarationSyntax,
- static (context, ct) =>
+ static (context, ct) => context)
+ .Combine(unsafeCodeIsEnabled)
+ .Select((data, ct) =>
{
+ var context = data.Left;
+ var unsafeCodeIsEnabled = data.Right;
var type = (INamedTypeSymbol)context.TargetSymbol;
var syntax = (ClassDeclarationSyntax)context.TargetNode;
+ if (!unsafeCodeIsEnabled)
+ {
+ return DiagnosticOr<ComClassInfo>.From(DiagnosticInfo.Create(GeneratorDiagnostics.RequiresAllowUnsafeBlocks, syntax.Identifier.GetLocation()));
+ }
+
+ if (!syntax.IsInPartialContext(out _))
+ {
+ return DiagnosticOr<ComClassInfo>.From(
+ DiagnosticInfo.Create(
+ GeneratorDiagnostics.InvalidAttributedClassMissingPartialModifier,
+ syntax.Identifier.GetLocation(),
+ type.ToDisplayString()));
+ }
+
ImmutableArray<string>.Builder names = ImmutableArray.CreateBuilder<string>();
foreach (INamedTypeSymbol iface in type.AllInterfaces)
{
names.Add(iface.ToDisplayString());
}
}
- return new ComClassInfo(
- type.ToDisplayString(),
- new ContainingSyntaxContext(syntax),
- new ContainingSyntax(syntax.Modifiers, syntax.Kind(), syntax.Identifier, syntax.TypeParameterList),
- new(names.ToImmutable()));
+
+ if (names.Count == 0)
+ {
+ return DiagnosticOr<ComClassInfo>.From(DiagnosticInfo.Create(GeneratorDiagnostics.ClassDoesNotImplementAnyGeneratedComInterface,
+ syntax.Identifier.GetLocation(),
+ type.ToDisplayString()));
+ }
+
+
+ return DiagnosticOr<ComClassInfo>.From(
+ new ComClassInfo(
+ type.ToDisplayString(),
+ new ContainingSyntaxContext(syntax),
+ new ContainingSyntax(syntax.Modifiers, syntax.Kind(), syntax.Identifier, syntax.TypeParameterList),
+ new(names.ToImmutable())));
});
+ var attributedClasses = context.FilterAndReportDiagnostics(attributedClassesOrDiagnostics);
+
var className = attributedClasses.Select(static (info, ct) => info.ClassName);
var classInfoType = attributedClasses
using System;
using System.Diagnostics.CodeAnalysis;
-using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
private static bool IsInPartialContext(INamedTypeSymbol symbol, InterfaceDeclarationSyntax syntax, [NotNullWhen(false)] out DiagnosticInfo? diagnostic)
{
// Verify that the types the interface is declared in are marked partial.
- for (SyntaxNode? parentNode = syntax; parentNode is TypeDeclarationSyntax typeDecl; parentNode = parentNode.Parent)
+ if (!syntax.IsInPartialContext(out var nonPartialIdentifier))
{
- if (!typeDecl.Modifiers.Any(SyntaxKind.PartialKeyword))
- {
- diagnostic = DiagnosticInfo.Create(
- GeneratorDiagnostics.InvalidAttributedInterfaceMissingPartialModifiers,
- syntax.Identifier.GetLocation(),
- symbol.Name,
- typeDecl.Identifier);
- return false;
- }
+ diagnostic = DiagnosticInfo.Create(
+ GeneratorDiagnostics.InvalidAttributedInterfaceMissingPartialModifiers,
+ syntax.Identifier.GetLocation(),
+ symbol.Name,
+ nonPartialIdentifier);
+ return false;
}
diagnostic = null;
return true;
private const string Category = "ComInterfaceGenerator";
+ /// <inheritdoc cref="SR.RequiresAllowUnsafeBlocksMessage"/>
public static readonly DiagnosticDescriptor RequiresAllowUnsafeBlocks =
new DiagnosticDescriptor(
Ids.RequiresAllowUnsafeBlocks,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.InterfaceTypeNotSupportedMessage)));
+ /// <inheritdoc cref="SR.ClassDoesNotImplementAnyGeneratedComInterfacesMessage"/>
+ public static readonly DiagnosticDescriptor ClassDoesNotImplementAnyGeneratedComInterface =
+ new DiagnosticDescriptor(
+ Ids.InvalidGeneratedComClassAttributeUsage,
+ GetResourceString(nameof(SR.InvalidGeneratedComClassAttributeUsageTitle)),
+ GetResourceString(nameof(SR.ClassDoesNotImplementAnyGeneratedComInterfacesMessage)),
+ Category,
+ DiagnosticSeverity.Warning,
+ isEnabledByDefault: true,
+ description: GetResourceString(nameof(SR.ClassDoesNotImplementAnyGeneratedComInterfacesDescription)));
+
+
private readonly List<DiagnosticInfo> _diagnostics = new List<DiagnosticInfo>();
public IEnumerable<DiagnosticInfo> Diagnostics => _diagnostics;
<?xml version="1.0" encoding="utf-8"?>
<root>
- <!--
- Microsoft ResX Schema
-
+ <!--
+ Microsoft ResX Schema
+
Version 2.0
-
- The primary goals of this format is to allow a simple XML format
- that is mostly human readable. The generation and parsing of the
- various data types are done through the TypeConverter classes
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
associated with the data types.
-
+
Example:
-
+
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
-
- There are any number of "resheader" rows that contain simple
+
+ There are any number of "resheader" rows that contain simple
name/value pairs.
-
- Each data row contains a name, and value. The row also contains a
- type or mimetype. Type corresponds to a .NET class that support
- text/value conversion through the TypeConverter architecture.
- Classes that don't support this are serialized and stored with the
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
mimetype set.
-
- The mimetype is used for serialized objects, and tells the
- ResXResourceReader how to depersist the object. This is currently not
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
-
- Note - application/x-microsoft.net.object.binary.base64 is the format
- that the ResXResourceWriter will generate, however the reader can
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
-
+
mimetype: application/x-microsoft.net.object.binary.base64
- value : The object must be serialized with
+ value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
-
+
mimetype: application/x-microsoft.net.object.soap.base64
- value : The object must be serialized with
+ value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
- value : The object must be serialized into a byte array
+ value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<value>The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1}</value>
</data>
<data name="RequiresAllowUnsafeBlocksDescription" xml:space="preserve">
- <value>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</value>
+ <value>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</value>
</data>
<data name="RequiresAllowUnsafeBlocksMessage" xml:space="preserve">
- <value>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</value>
+ <value>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</value>
</data>
<data name="RequiresAllowUnsafeBlocksTitle" xml:space="preserve">
- <value>GeneratedComInterfaceAttribute requires unsafe code.</value>
+ <value>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</value>
</data>
<data name="InvalidGeneratedComInterfaceUsageMissingPartialModifier" xml:space="preserve">
<value>The interface '{0}' or one of its containing types is missing the 'partial' keyword. Code will not be generated for '{0}'.</value>
<value>Classes with 'GeneratedComClassAttribute' must implement one or more interfaces with 'GeneratedComInterfaceAttribute', be marked partial, and be non-generic.</value>
</data>
<data name="InvalidGeneratedComClassAttributeUsageMissingPartialModifier" xml:space="preserve">
- <value>Class '{0}' or one of its containing types is not marked 'partial'.</value>
+ <value>Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</value>
</data>
<data name="InvalidGeneratedComClassAttributeUsageTitle" xml:space="preserve">
<value>Invalid 'GeneratedComClassAttribute' usage</value>
<data name="ConvertComInterfaceMayProduceInvalidCode" xml:space="preserve">
<value>Converting this interface to use 'GeneratedComInterfaceAttribute' may produce invalid code and may require additional work</value>
</data>
+ <data name="ClassDoesNotImplementAnyGeneratedComInterfacesDescription" xml:space="preserve">
+ <value>A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</value>
+ </data>
+ <data name="ClassDoesNotImplementAnyGeneratedComInterfacesMessage" xml:space="preserve">
+ <value>Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</value>
+ </data>
<data name="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedDescription" xml:space="preserve">
<value>Casting between a 'ComImport' type and a source-generated COM type is not supported and will fail at runtime</value>
</data>
<data name="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedTitle" xml:space="preserve">
<value>Casting between a 'ComImport' type and a source-generated COM type is not supported</value>
</data>
-</root>
\ No newline at end of file
+</root>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesDescription">
+ <source>A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</source>
+ <target state="new">A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</target>
+ <note />
+ </trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesMessage">
+ <source>Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</target>
+ <note />
+ </trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageMissingPartialModifier">
- <source>Class '{0}' or one of its containing types is not marked 'partial'.</source>
- <target state="new">Class '{0}' or one of its containing types is not marked 'partial'.</target>
+ <source>Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageTitle">
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksDescription">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksMessage">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksTitle">
- <source>GeneratedComInterfaceAttribute requires unsafe code.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</target>
<note />
</trans-unit>
<trans-unit id="RuntimeComApisDoNotSupportSourceGeneratedComDescription">
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesDescription">
+ <source>A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</source>
+ <target state="new">A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</target>
+ <note />
+ </trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesMessage">
+ <source>Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</target>
+ <note />
+ </trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageMissingPartialModifier">
- <source>Class '{0}' or one of its containing types is not marked 'partial'.</source>
- <target state="new">Class '{0}' or one of its containing types is not marked 'partial'.</target>
+ <source>Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageTitle">
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksDescription">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksMessage">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksTitle">
- <source>GeneratedComInterfaceAttribute requires unsafe code.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</target>
<note />
</trans-unit>
<trans-unit id="RuntimeComApisDoNotSupportSourceGeneratedComDescription">
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesDescription">
+ <source>A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</source>
+ <target state="new">A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</target>
+ <note />
+ </trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesMessage">
+ <source>Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</target>
+ <note />
+ </trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageMissingPartialModifier">
- <source>Class '{0}' or one of its containing types is not marked 'partial'.</source>
- <target state="new">Class '{0}' or one of its containing types is not marked 'partial'.</target>
+ <source>Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageTitle">
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksDescription">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksMessage">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksTitle">
- <source>GeneratedComInterfaceAttribute requires unsafe code.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</target>
<note />
</trans-unit>
<trans-unit id="RuntimeComApisDoNotSupportSourceGeneratedComDescription">
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesDescription">
+ <source>A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</source>
+ <target state="new">A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</target>
+ <note />
+ </trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesMessage">
+ <source>Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</target>
+ <note />
+ </trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageMissingPartialModifier">
- <source>Class '{0}' or one of its containing types is not marked 'partial'.</source>
- <target state="new">Class '{0}' or one of its containing types is not marked 'partial'.</target>
+ <source>Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageTitle">
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksDescription">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksMessage">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksTitle">
- <source>GeneratedComInterfaceAttribute requires unsafe code.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</target>
<note />
</trans-unit>
<trans-unit id="RuntimeComApisDoNotSupportSourceGeneratedComDescription">
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesDescription">
+ <source>A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</source>
+ <target state="new">A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</target>
+ <note />
+ </trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesMessage">
+ <source>Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</target>
+ <note />
+ </trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageMissingPartialModifier">
- <source>Class '{0}' or one of its containing types is not marked 'partial'.</source>
- <target state="new">Class '{0}' or one of its containing types is not marked 'partial'.</target>
+ <source>Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageTitle">
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksDescription">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksMessage">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksTitle">
- <source>GeneratedComInterfaceAttribute requires unsafe code.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</target>
<note />
</trans-unit>
<trans-unit id="RuntimeComApisDoNotSupportSourceGeneratedComDescription">
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesDescription">
+ <source>A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</source>
+ <target state="new">A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</target>
+ <note />
+ </trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesMessage">
+ <source>Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</target>
+ <note />
+ </trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageMissingPartialModifier">
- <source>Class '{0}' or one of its containing types is not marked 'partial'.</source>
- <target state="new">Class '{0}' or one of its containing types is not marked 'partial'.</target>
+ <source>Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageTitle">
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksDescription">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksMessage">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksTitle">
- <source>GeneratedComInterfaceAttribute requires unsafe code.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</target>
<note />
</trans-unit>
<trans-unit id="RuntimeComApisDoNotSupportSourceGeneratedComDescription">
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesDescription">
+ <source>A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</source>
+ <target state="new">A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</target>
+ <note />
+ </trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesMessage">
+ <source>Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</target>
+ <note />
+ </trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageMissingPartialModifier">
- <source>Class '{0}' or one of its containing types is not marked 'partial'.</source>
- <target state="new">Class '{0}' or one of its containing types is not marked 'partial'.</target>
+ <source>Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageTitle">
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksDescription">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksMessage">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksTitle">
- <source>GeneratedComInterfaceAttribute requires unsafe code.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</target>
<note />
</trans-unit>
<trans-unit id="RuntimeComApisDoNotSupportSourceGeneratedComDescription">
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesDescription">
+ <source>A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</source>
+ <target state="new">A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</target>
+ <note />
+ </trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesMessage">
+ <source>Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</target>
+ <note />
+ </trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageMissingPartialModifier">
- <source>Class '{0}' or one of its containing types is not marked 'partial'.</source>
- <target state="new">Class '{0}' or one of its containing types is not marked 'partial'.</target>
+ <source>Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageTitle">
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksDescription">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksMessage">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksTitle">
- <source>GeneratedComInterfaceAttribute requires unsafe code.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</target>
<note />
</trans-unit>
<trans-unit id="RuntimeComApisDoNotSupportSourceGeneratedComDescription">
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesDescription">
+ <source>A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</source>
+ <target state="new">A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</target>
+ <note />
+ </trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesMessage">
+ <source>Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</target>
+ <note />
+ </trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageMissingPartialModifier">
- <source>Class '{0}' or one of its containing types is not marked 'partial'.</source>
- <target state="new">Class '{0}' or one of its containing types is not marked 'partial'.</target>
+ <source>Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageTitle">
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksDescription">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksMessage">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksTitle">
- <source>GeneratedComInterfaceAttribute requires unsafe code.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</target>
<note />
</trans-unit>
<trans-unit id="RuntimeComApisDoNotSupportSourceGeneratedComDescription">
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesDescription">
+ <source>A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</source>
+ <target state="new">A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</target>
+ <note />
+ </trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesMessage">
+ <source>Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</target>
+ <note />
+ </trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageMissingPartialModifier">
- <source>Class '{0}' or one of its containing types is not marked 'partial'.</source>
- <target state="new">Class '{0}' or one of its containing types is not marked 'partial'.</target>
+ <source>Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageTitle">
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksDescription">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksMessage">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksTitle">
- <source>GeneratedComInterfaceAttribute requires unsafe code.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</target>
<note />
</trans-unit>
<trans-unit id="RuntimeComApisDoNotSupportSourceGeneratedComDescription">
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesDescription">
+ <source>A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</source>
+ <target state="new">A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</target>
+ <note />
+ </trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesMessage">
+ <source>Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</target>
+ <note />
+ </trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageMissingPartialModifier">
- <source>Class '{0}' or one of its containing types is not marked 'partial'.</source>
- <target state="new">Class '{0}' or one of its containing types is not marked 'partial'.</target>
+ <source>Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageTitle">
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksDescription">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksMessage">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksTitle">
- <source>GeneratedComInterfaceAttribute requires unsafe code.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</target>
<note />
</trans-unit>
<trans-unit id="RuntimeComApisDoNotSupportSourceGeneratedComDescription">
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesDescription">
+ <source>A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</source>
+ <target state="new">A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</target>
+ <note />
+ </trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesMessage">
+ <source>Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</target>
+ <note />
+ </trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageMissingPartialModifier">
- <source>Class '{0}' or one of its containing types is not marked 'partial'.</source>
- <target state="new">Class '{0}' or one of its containing types is not marked 'partial'.</target>
+ <source>Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageTitle">
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksDescription">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksMessage">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksTitle">
- <source>GeneratedComInterfaceAttribute requires unsafe code.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</target>
<note />
</trans-unit>
<trans-unit id="RuntimeComApisDoNotSupportSourceGeneratedComDescription">
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesDescription">
+ <source>A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</source>
+ <target state="new">A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect.</target>
+ <note />
+ </trans-unit>
+ <trans-unit id="ClassDoesNotImplementAnyGeneratedComInterfacesMessage">
+ <source>Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'.</target>
+ <note />
+ </trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageMissingPartialModifier">
- <source>Class '{0}' or one of its containing types is not marked 'partial'.</source>
- <target state="new">Class '{0}' or one of its containing types is not marked 'partial'.</target>
+ <source>Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</source>
+ <target state="new">Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidGeneratedComClassAttributeUsageTitle">
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksDescription">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksMessage">
- <source>GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.</target>
<note />
</trans-unit>
<trans-unit id="RequiresAllowUnsafeBlocksTitle">
- <source>GeneratedComInterfaceAttribute requires unsafe code.</source>
- <target state="new">GeneratedComInterfaceAttribute requires unsafe code.</target>
+ <source>'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</source>
+ <target state="new">'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code.</target>
<note />
</trans-unit>
<trans-unit id="RuntimeComApisDoNotSupportSourceGeneratedComDescription">
}
// Verify that the types the method is declared in are marked partial.
- for (SyntaxNode? parentNode = methodSyntax.Parent; parentNode is TypeDeclarationSyntax typeDecl; parentNode = parentNode.Parent)
+ if (methodSyntax.Parent is TypeDeclarationSyntax typeDecl && !typeDecl.IsInPartialContext(out var nonPartialIdentifier))
{
- if (!typeDecl.Modifiers.Any(SyntaxKind.PartialKeyword))
- {
- return DiagnosticInfo.Create(GeneratorDiagnostics.InvalidAttributedMethodContainingTypeMissingModifiers, methodSyntax.Identifier.GetLocation(), method.Name, typeDecl.Identifier);
- }
+ return DiagnosticInfo.Create(GeneratorDiagnostics.InvalidAttributedMethodContainingTypeMissingModifiers, methodSyntax.Identifier.GetLocation(), method.Name, nonPartialIdentifier);
}
// Verify the method does not have a ref return
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
-using System.Text;
+using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
public static SyntaxTokenList StripAccessibilityModifiers(this SyntaxTokenList tokenList)
{
- List<SyntaxToken> strippedTokens = new ();
+ List<SyntaxToken> strippedTokens = new();
for (int i = 0; i < tokenList.Count; i++)
{
if (tokenList[i].Kind() is SyntaxKind.PublicKeyword or SyntaxKind.InternalKeyword or SyntaxKind.ProtectedKeyword or SyntaxKind.PrivateKeyword)
? modifiers.Insert(idx, SyntaxFactory.Token(modifierToAdd))
: modifiers.Add(SyntaxFactory.Token(modifierToAdd));
}
+
+ public static bool IsInPartialContext(this TypeDeclarationSyntax syntax, [NotNullWhen(false)] out SyntaxToken? nonPartialIdentifier)
+ {
+ for (SyntaxNode? parentNode = syntax; parentNode is TypeDeclarationSyntax typeDecl; parentNode = parentNode.Parent)
+ {
+ if (!typeDecl.Modifiers.Any(SyntaxKind.PartialKeyword))
+ {
+ nonPartialIdentifier = typeDecl.Identifier;
+ return false;
+ }
+ }
+ nonPartialIdentifier = null;
+ return true;
+ }
}
}
// The .NET Foundation licenses this file to you under the MIT license.
using System;
-using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
-using System.Text;
-using System.Threading.Tasks;
using SharedTypes.ComInterfaces;
using Xunit;
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Threading.Tasks;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.Testing;
+using Microsoft.Interop;
+using Xunit;
+using VerifyCS = Microsoft.Interop.UnitTests.Verifiers.CSharpSourceGeneratorVerifier<Microsoft.Interop.ComClassGenerator>;
+
+namespace ComInterfaceGenerator.Unit.Tests
+{
+ public class ComClassGeneratorDiagnostics
+ {
+ [Fact]
+ public async Task NonPartialClassWarns()
+ {
+ string source = """
+ using System.Runtime.InteropServices;
+ using System.Runtime.InteropServices.Marshalling;
+
+ [GeneratedComInterface]
+ partial interface INativeAPI
+ {
+ }
+
+ [GeneratedComClass]
+ internal class {|#0:C|} : INativeAPI {}
+
+ """;
+
+ await VerifyCS.VerifySourceGeneratorAsync(
+ source,
+ new DiagnosticResult(GeneratorDiagnostics.InvalidAttributedClassMissingPartialModifier)
+ .WithLocation(0)
+ .WithArguments("C"));
+ }
+
+ [Fact]
+ public async Task NonPartialContainingTypeWarns()
+ {
+ string source = """
+ using System.Runtime.InteropServices;
+ using System.Runtime.InteropServices.Marshalling;
+
+ public class Test
+ {
+ [GeneratedComInterface]
+ partial interface INativeAPI
+ {
+ }
+
+ [GeneratedComClass]
+ internal partial class {|#0:C|} : INativeAPI {}
+ }
+
+ """;
+
+ await VerifyCS.VerifySourceGeneratorAsync(
+ source,
+ new DiagnosticResult(GeneratorDiagnostics.InvalidAttributedClassMissingPartialModifier)
+ .WithLocation(0)
+ .WithArguments("Test.C"));
+ }
+
+ internal class UnsafeBlocksNotAllowedTest : VerifyCS.Test
+ {
+ internal UnsafeBlocksNotAllowedTest(bool referenceAncillaryInterop) : base(referenceAncillaryInterop) { }
+ protected override CompilationOptions CreateCompilationOptions()
+ => new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: false);
+ }
+
+ [Fact]
+ public async Task UnsafeCodeNotEnabledWarns()
+ {
+ string source = """
+ using System.Runtime.InteropServices;
+ using System.Runtime.InteropServices.Marshalling;
+
+ public partial class Test
+ {
+ [GeneratedComInterface]
+ internal partial interface INativeAPI
+ {
+ }
+
+ [GeneratedComClass]
+ internal partial class {|#0:C|} : INativeAPI {}
+ }
+
+ """;
+
+ var test = new UnsafeBlocksNotAllowedTest(false);
+ test.TestState.Sources.Add(source);
+ test.ExpectedDiagnostics.Add(
+ new DiagnosticResult(GeneratorDiagnostics.RequiresAllowUnsafeBlocks)
+ .WithLocation(0)
+ .WithArguments("Test.C"));
+
+ await test.RunAsync();
+ }
+
+ [Fact]
+ public async Task ClassThatDoesNotInheritFromGeneratedInterfaceWarns()
+ {
+ string source = """
+ using System.Runtime.InteropServices;
+ using System.Runtime.InteropServices.Marshalling;
+
+ public partial class Test{
+ internal interface INativeAPI
+ {
+ }
+
+ [GeneratedComClass]
+ internal partial class {|#0:C|} : INativeAPI {}
+ }
+
+ """;
+
+ await VerifyCS.VerifySourceGeneratorAsync(
+ source,
+ new DiagnosticResult(GeneratorDiagnostics.ClassDoesNotImplementAnyGeneratedComInterface)
+ .WithLocation(0)
+ .WithArguments("Test.C"));
+ }
+ }
+}
// The .NET Foundation licenses this file to you under the MIT license.
using System;
-using System.Collections.Generic;
using System.Drawing;
-using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
-using System.Text;
-using System.Threading.Tasks;
namespace SharedTypes.ComInterfaces
{