-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathNoMarshallingInfoErrorResolver.cs
47 lines (41 loc) · 1.89 KB
/
NoMarshallingInfoErrorResolver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// 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 NoMarshallingInfoErrorResolver : IMarshallingGeneratorResolver
{
public ResolvedGenerator Create(
TypePositionInfo info,
StubCodeContext context)
{
if (info.MarshallingAttributeInfo is NoMarshallingInfo && CustomTypeToErrorMessageMap.TryGetValue(info.ManagedType, out string errorMessage))
{
return ResolvedGenerator.NotSupported(info, context, new(info)
{
NotSupportedDetails = errorMessage
});
}
return ResolvedGenerator.UnresolvedGenerator;
}
public NoMarshallingInfoErrorResolver(string stringMarshallingAttribute)
: this(DefaultTypeToErrorMessageMap(stringMarshallingAttribute))
{
}
private NoMarshallingInfoErrorResolver(ImmutableDictionary<ManagedTypeInfo, string> customTypeToErrorMessageMap)
{
CustomTypeToErrorMessageMap = customTypeToErrorMessageMap;
}
public ImmutableDictionary<ManagedTypeInfo, string> CustomTypeToErrorMessageMap { get; }
private static ImmutableDictionary<ManagedTypeInfo, string> DefaultTypeToErrorMessageMap(string stringMarshallingAttribute)
=> ImmutableDictionary.CreateRange(new Dictionary<ManagedTypeInfo, string>
{
{ SpecialTypeInfo.String, string.Format(SR.MarshallingStringOrCharAsUndefinedNotSupported, stringMarshallingAttribute) },
{ SpecialTypeInfo.Boolean, SR.MarshallingBoolAsUndefinedNotSupported },
});
}
}