-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure we emit diagnostics for "unsupported" marshalling for downl…
…evel platforms (#71342)
- Loading branch information
1 parent
601ef26
commit d99caf1
Showing
3 changed files
with
53 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...icrosoft.Interop.SourceGeneration/Marshalling/NoMarshallingInfoErrorMarshallingFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Runtime.InteropServices; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Microsoft.Interop | ||
{ | ||
public sealed class NoMarshallingInfoErrorMarshallingFactory : IMarshallingGeneratorFactory | ||
{ | ||
private readonly IMarshallingGeneratorFactory _inner; | ||
|
||
public IMarshallingGenerator Create( | ||
TypePositionInfo info, | ||
StubCodeContext context) | ||
{ | ||
if (info.MarshallingAttributeInfo is NoMarshallingInfo && CustomTypeToErrorMessageMap.TryGetValue(info.ManagedType, out string errorMessage)) | ||
{ | ||
throw new MarshallingNotSupportedException(info, context) | ||
{ | ||
NotSupportedDetails = errorMessage | ||
}; | ||
} | ||
return _inner.Create(info, context); | ||
} | ||
|
||
public NoMarshallingInfoErrorMarshallingFactory(IMarshallingGeneratorFactory inner) | ||
: this(inner, DefaultTypeToErrorMessageMap) | ||
{ | ||
} | ||
|
||
private NoMarshallingInfoErrorMarshallingFactory(IMarshallingGeneratorFactory inner, ImmutableDictionary<ManagedTypeInfo, string> customTypeToErrorMessageMap) | ||
{ | ||
_inner = inner; | ||
CustomTypeToErrorMessageMap = customTypeToErrorMessageMap; | ||
} | ||
|
||
public ImmutableDictionary<ManagedTypeInfo, string> CustomTypeToErrorMessageMap { get; } | ||
|
||
private static ImmutableDictionary<ManagedTypeInfo, string> DefaultTypeToErrorMessageMap { get; } = | ||
ImmutableDictionary.CreateRange(new Dictionary<ManagedTypeInfo, string> | ||
{ | ||
{ SpecialTypeInfo.String, SR.MarshallingStringOrCharAsUndefinedNotSupported }, | ||
{ SpecialTypeInfo.Boolean, SR.MarshallingBoolAsUndefinedNotSupported }, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters