Skip to content

Commit

Permalink
Fix violations of RS1032: Define diagnostic message correctly
Browse files Browse the repository at this point in the history
Update README to point out emitting generated source to disk
  • Loading branch information
elinor-fung committed Oct 9, 2020
1 parent ed79ba8 commit f18d239
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
14 changes: 14 additions & 0 deletions DllImportGenerator/DllImportGenerator/GeneratorDiagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public static Diagnostic CreateDiagnostic(
}
}

/// <summary>
/// Class for reporting diagnostics in the DLL import generator
/// </summary>
public class GeneratorDiagnostics
{
private class Ids
Expand Down Expand Up @@ -121,6 +124,12 @@ public GeneratorDiagnostics(GeneratorExecutionContext context)
this.context = context;
}

/// <summary>
/// Report diagnostic for configuration that is not supported by the DLL import source generator
/// </summary>
/// <param name="attributeData">Attribute specifying the unsupported configuration</param>
/// <param name="configurationName">Name of the configuration</param>
/// <param name="unsupportedValue">[Optiona] Unsupported configuration value</param>
public void ReportConfigurationNotSupported(
AttributeData attributeData,
string configurationName,
Expand All @@ -143,6 +152,11 @@ public void ReportConfigurationNotSupported(
}
}

/// <summary>
/// Report diagnostic for marshalling of a parameter/return that is not supported
/// </summary>
/// <param name="method">Method with the parameter/return</param>
/// <param name="info">Type info for the parameter/return</param>
internal void ReportMarshallingNotSupported(
IMethodSymbol method,
TypePositionInfo info)
Expand Down
22 changes: 11 additions & 11 deletions DllImportGenerator/DllImportGenerator/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions DllImportGenerator/DllImportGenerator/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<value>A type marked with 'BlittableTypeAttribute' must be blittable.</value>
</data>
<data name="BlittableTypeMustBeBlittableMessage" xml:space="preserve">
<value>Type '{0}' is marked with 'BlittableTypeAttribute' but is not blittable.</value>
<value>Type '{0}' is marked with 'BlittableTypeAttribute' but is not blittable</value>
</data>
<data name="CannotHaveMultipleMarshallingAttributesDescription" xml:space="preserve">
<value>The 'BlittableTypeAttribute' and 'NativeMarshallingAttribute' attributes are mutually exclusive.</value>
Expand Down Expand Up @@ -151,49 +151,49 @@
<value>The return type of 'GetPinnableReference' (after accounting for 'ref') must be blittable.</value>
</data>
<data name="GetPinnableReferenceReturnTypeBlittableMessage" xml:space="preserve">
<value>The dereferenced type of the return type of the 'GetPinnableReference' method must be blittable.</value>
<value>The dereferenced type of the return type of the 'GetPinnableReference' method must be blittable</value>
</data>
<data name="GetPinnableReferenceShouldSupportAllocatingMarshallingFallbackDescription" xml:space="preserve">
<value>A type that supports marshalling from managed to native by pinning should also support marshalling from managed to native where pinning is impossible.</value>
</data>
<data name="GetPinnableReferenceShouldSupportAllocatingMarshallingFallbackMessage" xml:space="preserve">
<value>Type '{0}' has a 'GetPinnableReference' method but its native type does not support marshalling in scenarios where pinning is impossible.</value>
<value>Type '{0}' has a 'GetPinnableReference' method but its native type does not support marshalling in scenarios where pinning is impossible</value>
</data>
<data name="NativeTypeMustBeBlittableDescription" xml:space="preserve">
<value>A native type for a given type must be blittable.</value>
</data>
<data name="NativeTypeMustBeBlittableMessage" xml:space="preserve">
<value>The native type '{0}' for the type '{1}' is not blittable.</value>
<value>The native type '{0}' for the type '{1}' is not blittable</value>
</data>
<data name="NativeTypeMustBeNonNullDescription" xml:space="preserve">
<value>A native type for a given type must be non-null.</value>
</data>
<data name="NativeTypeMustBeNonNullMessage" xml:space="preserve">
<value>The native type for the type '{0}' is null.</value>
<value>The native type for the type '{0}' is null</value>
</data>
<data name="NativeTypeMustBePointerSizedDescription" xml:space="preserve">
<value>The native type must be pointer sized so the pinned result of 'GetPinnableReference' can be cast to the native type.</value>
</data>
<data name="NativeTypeMustBePointerSizedMessage" xml:space="preserve">
<value>The native type '{0}' must be pointer sized because the managed type '{1}' has a 'GetPinnableReference' method.</value>
<value>The native type '{0}' must be pointer sized because the managed type '{1}' has a 'GetPinnableReference' method</value>
</data>
<data name="NativeTypeMustHaveRequiredShapeDescription" xml:space="preserve">
<value>The native type must have at least one of the two marshalling methods to enable marshalling the managed type.</value>
</data>
<data name="NativeTypeMustHaveRequiredShapeMessage" xml:space="preserve">
<value>The native type '{0}' must be a value type and have a constructor that takes one parameter of type '{1}' or a parameterless instance method named 'ToManaged' that returns '{1}'.</value>
<value>The native type '{0}' must be a value type and have a constructor that takes one parameter of type '{1}' or a parameterless instance method named 'ToManaged' that returns '{1}'</value>
</data>
<data name="StackallocConstructorMustHaveStackBufferSizeConstantDescription" xml:space="preserve">
<value>When constructor taking a Span&lt;byte&gt; is specified on the native type, the type must also have a public integer constant named StackBufferSize to provide the size of the stack-allocated buffer.</value>
</data>
<data name="StackallocConstructorMustHaveStackBufferSizeConstantMessage" xml:space="preserve">
<value>The native type '{0}' must have a 'public const int StackBufferSize' field that specifies the size of the stack buffer because it has a constructor that takes a stack-allocated Span&lt;byte&gt;.</value>
<value>The native type '{0}' must have a 'public const int StackBufferSize' field that specifies the size of the stack buffer because it has a constructor that takes a stack-allocated Span&lt;byte&gt;</value>
</data>
<data name="StackallocMarshallingShouldSupportAllocatingMarshallingFallbackDescription" xml:space="preserve">
<value>A type that supports marshalling from managed to native by stack allocation should also support marshalling from managed to native where stack allocation is impossible.</value>
</data>
<data name="StackallocMarshallingShouldSupportAllocatingMarshallingFallbackMessage" xml:space="preserve">
<value>Native type '{0}' has a stack-allocating constructor does not support marshalling in scenarios where stack allocation is impossible.</value>
<value>Native type '{0}' has a stack-allocating constructor does not support marshalling in scenarios where stack allocation is impossible</value>
</data>
<data name="TypeNotSupportedDescription" xml:space="preserve">
<value>For types that are not supported by source-generated P/Invokes, the resulting P/Invoke will rely on the underlying runtime to marshal the specified type.</value>
Expand All @@ -211,12 +211,12 @@
<value>The native type's 'Value' property must have a getter to support marshalling from managed to native.</value>
</data>
<data name="ValuePropertyMustHaveGetterMessage" xml:space="preserve">
<value>The 'Value' property on the native type '{0}' must have a getter.</value>
<value>The 'Value' property on the native type '{0}' must have a getter</value>
</data>
<data name="ValuePropertyMustHaveSetterDescription" xml:space="preserve">
<value>The native type's 'Value' property must have a setter to support marshalling from native to managed.</value>
</data>
<data name="ValuePropertyMustHaveSetterMessage" xml:space="preserve">
<value>The 'Value' property on the native type '{0}' must have a setter.</value>
<value>The 'Value' property on the native type '{0}' must have a setter</value>
</data>
</root>
2 changes: 1 addition & 1 deletion DllImportGenerator/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Work on this project can be tracked and discussed via the [official issue](https

## Example

The [Demo project](./DllImportGenerator/Demo) is designed to be immediately consumable by everyone. It demonstrates a simple use case where the marshalling code is generated and a native function call with only [blittable types](https://docs.microsoft.com/dotnet/framework/interop/blittable-and-non-blittable-types) is made. A managed assembly with [native exports](./DllImportGenerator/TestAssets/NativeExports) is used in the P/Invoke scenario.
The [Demo project](./DllImportGenerator/Demo) is designed to be immediately consumable by everyone. It demonstrates a simple use case where the marshalling code is generated and a native function call with only [blittable types](https://docs.microsoft.com/dotnet/framework/interop/blittable-and-non-blittable-types) is made. The project is configured to output the generated source to disk; the files can be found in the project's intermediate directory (`obj/<Configuration>/<TargetFramework>/generated`). A managed assembly with [native exports](./DllImportGenerator/TestAssets/NativeExports) is used in the P/Invoke scenario.

### Recommended scenarios:

Expand Down

0 comments on commit f18d239

Please sign in to comment.