else
{
generatorFactory = new DefaultMarshallingGeneratorFactory(options);
- AttributedMarshallingModelGeneratorFactory attributedMarshallingFactory = new(generatorFactory, options);
- generatorFactory = attributedMarshallingFactory;
+ IMarshallingGeneratorFactory elementFactory = new AttributedMarshallingModelGeneratorFactory(generatorFactory, options);
+ // We don't need to include the later generator factories for collection elements
+ // as the later generator factories only apply to parameters or to the synthetic return value for PreserveSig support.
+ generatorFactory = new AttributedMarshallingModelGeneratorFactory(generatorFactory, elementFactory, options);
if (!dllImportData.PreserveSig)
{
// Create type info for native out param
}
generatorFactory = new ByValueContentsMarshalKindValidator(generatorFactory);
- attributedMarshallingFactory.ElementMarshallingGeneratorFactory = generatorFactory;
}
typeInfos.Add(retTypeInfo);
private static readonly Forwarder s_forwarder = new Forwarder();
private readonly IMarshallingGeneratorFactory _innerMarshallingGenerator;
+ private readonly IMarshallingGeneratorFactory _elementMarshallingGenerator;
- public AttributedMarshallingModelGeneratorFactory(IMarshallingGeneratorFactory innerMarshallingGenerator, InteropGenerationOptions options)
+ public AttributedMarshallingModelGeneratorFactory(
+ IMarshallingGeneratorFactory innerMarshallingGenerator,
+ InteropGenerationOptions options)
{
Options = options;
_innerMarshallingGenerator = innerMarshallingGenerator;
- ElementMarshallingGeneratorFactory = this;
+ // Unless overridden, default to using this generator factory for creating generators for collection elements.
+ _elementMarshallingGenerator = this;
}
- public InteropGenerationOptions Options { get; }
+ public AttributedMarshallingModelGeneratorFactory(
+ IMarshallingGeneratorFactory innerMarshallingGenerator,
+ IMarshallingGeneratorFactory elementMarshallingGenerator,
+ InteropGenerationOptions options)
+ {
+ Options = options;
+ _innerMarshallingGenerator = innerMarshallingGenerator;
- /// <summary>
- /// The <see cref="IMarshallingGeneratorFactory"/> to use for collection elements.
- /// This property is settable to enable decorating factories to ensure that element marshalling also goes through the decorator support.
- /// </summary>
- public IMarshallingGeneratorFactory ElementMarshallingGeneratorFactory { get; set; }
+ _elementMarshallingGenerator = elementMarshallingGenerator;
+ }
+
+ public InteropGenerationOptions Options { get; }
public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context)
{
ICustomNativeTypeMarshallingStrategy marshallingStrategy)
{
var elementInfo = new TypePositionInfo(collectionInfo.ElementType, collectionInfo.ElementMarshallingInfo) { ManagedIndex = info.ManagedIndex };
- IMarshallingGenerator elementMarshaller = Create(
+ IMarshallingGenerator elementMarshaller = _elementMarshallingGenerator.Create(
elementInfo,
new ContiguousCollectionElementMarshallingCodeContext(StubCodeContext.Stage.Setup, string.Empty, context));
TypeSyntax elementType = elementMarshaller.AsNativeType(elementInfo);