public AttributedMarshallingModelGeneratorFactory(
     IMarshallingGeneratorFactory innerMarshallingGenerator,
     AttributedMarshallingModelOptions options)
 {
     Options = options;
     _innerMarshallingGenerator = innerMarshallingGenerator;
     // Unless overridden, default to using this generator factory for creating generators for collection elements.
     _elementMarshallingGenerator = this;
 }
        public AttributedMarshallingModelGeneratorFactory(
            IMarshallingGeneratorFactory innerMarshallingGenerator,
            IMarshallingGeneratorFactory elementMarshallingGenerator,
            AttributedMarshallingModelOptions options)
        {
            Options = options;
            _innerMarshallingGenerator = innerMarshallingGenerator;

            _elementMarshallingGenerator = elementMarshallingGenerator;
        }
Ejemplo n.º 3
0
        public JSImportCodeGenerator(
            StubEnvironment environment,
            ImmutableArray <TypePositionInfo> argTypes,
            JSImportData attributeData,
            JSSignatureContext signatureContext,
            Action <TypePositionInfo, MarshallingNotSupportedException> marshallingNotSupportedCallback,
            IMarshallingGeneratorFactory generatorFactory)
        {
            _signatureContext = signatureContext;
            ManagedToNativeStubCodeContext innerContext = new ManagedToNativeStubCodeContext(environment, ReturnIdentifier, ReturnIdentifier);

            _context     = new JSImportCodeContext(attributeData, innerContext);
            _marshallers = new BoundGenerators(argTypes, CreateGenerator);
            if (_marshallers.ManagedReturnMarshaller.Generator.UsesNativeIdentifier(_marshallers.ManagedReturnMarshaller.TypeInfo, null))
            {
                // If we need a different native return identifier, then recreate the context with the correct identifier before we generate any code.
                innerContext = new ManagedToNativeStubCodeContext(environment, ReturnIdentifier, ReturnNativeIdentifier);
                _context     = new JSImportCodeContext(attributeData, innerContext);
                _marshallers = new BoundGenerators(argTypes, CreateGenerator);
            }

            // validate task + span mix
            if (_marshallers.ManagedReturnMarshaller.TypeInfo.ManagedType is JSTaskTypeInfo)
            {
                BoundGenerator spanArg = _marshallers.AllMarshallers.FirstOrDefault(m => m.TypeInfo.ManagedType is JSSpanTypeInfo);
                if (spanArg != default)
                {
                    marshallingNotSupportedCallback(spanArg.TypeInfo, new MarshallingNotSupportedException(spanArg.TypeInfo, _context)
                    {
                        NotSupportedDetails = SR.SpanAndTaskNotSupported
                    });
                }
            }


            IMarshallingGenerator CreateGenerator(TypePositionInfo p)
            {
                try
                {
                    return(generatorFactory.Create(p, _context));
                }
                catch (MarshallingNotSupportedException e)
                {
                    marshallingNotSupportedCallback(p, e);
                    return(new EmptyJSGenerator());
                }
            }
        }
Ejemplo n.º 4
0
 public CharMarshallingGeneratorFactory(IMarshallingGeneratorFactory inner, bool useBlittableMarshallerForUtf16)
 {
     _inner = inner;
     _useBlittableMarshallerForUtf16 = useBlittableMarshallerForUtf16;
 }
Ejemplo n.º 5
0
        public PInvokeStubCodeGenerator(
            StubEnvironment environment,
            ImmutableArray <TypePositionInfo> argTypes,
            bool setLastError,
            Action <TypePositionInfo, MarshallingNotSupportedException> marshallingNotSupportedCallback,
            IMarshallingGeneratorFactory generatorFactory)
        {
            _setLastError = setLastError;

            // Support for SetLastError logic requires .NET 6+. Initialize the
            // supports target framework value with this value.
            if (_setLastError)
            {
                SupportsTargetFramework = environment.TargetFramework == TargetFramework.Net &&
                                          environment.TargetFrameworkVersion.Major >= 6;
            }
            else
            {
                SupportsTargetFramework = true;
            }

            _context     = new ManagedToNativeStubCodeContext(environment, ReturnIdentifier, ReturnIdentifier);
            _marshallers = new BoundGenerators(argTypes, CreateGenerator);

            if (_marshallers.ManagedReturnMarshaller.Generator.UsesNativeIdentifier(_marshallers.ManagedReturnMarshaller.TypeInfo, _context))
            {
                // If we need a different native return identifier, then recreate the context with the correct identifier before we generate any code.
                _context = new ManagedToNativeStubCodeContext(environment, ReturnIdentifier, $"{ReturnIdentifier}{StubCodeContext.GeneratedNativeIdentifierSuffix}");
            }

            bool noMarshallingNeeded = true;

            foreach (BoundGenerator generator in _marshallers.AllMarshallers)
            {
                // Check if marshalling info and generator support the current target framework.
                SupportsTargetFramework &= generator.TypeInfo.MarshallingAttributeInfo is not MissingSupportMarshallingInfo &&
                                           generator.Generator.IsSupported(environment.TargetFramework, environment.TargetFrameworkVersion);

                // Check if generator is either blittable or just a forwarder.
                noMarshallingNeeded &= generator is { Generator : BlittableMarshaller, TypeInfo.IsByRef : false }
                or {
                    Generator : Forwarder
                };
            }

            StubIsBasicForwarder = !setLastError &&
                                   _marshallers.ManagedNativeSameReturn && // If the managed return has native return position, then it's the return for both.
                                   noMarshallingNeeded;

            IMarshallingGenerator CreateGenerator(TypePositionInfo p)
            {
                try
                {
                    return(generatorFactory.Create(p, _context));
                }
                catch (MarshallingNotSupportedException e)
                {
                    marshallingNotSupportedCallback(p, e);
                    return(new Forwarder());
                }
            }
        }
 public AttributedMarshallingModelGeneratorFactory(IMarshallingGeneratorFactory innerMarshallingGenerator, InteropGenerationOptions options)
 {
     Options = options;
     _innerMarshallingGenerator         = innerMarshallingGenerator;
     ElementMarshallingGeneratorFactory = this;
 }
Ejemplo n.º 7
0
 public NoPreserveSigMarshallingGeneratorFactory(IMarshallingGeneratorFactory inner)
 {
     _inner = inner;
 }
 public ByValueContentsMarshalKindValidator(IMarshallingGeneratorFactory inner)
 {
     _inner = inner;
 }
 private NoMarshallingInfoErrorMarshallingFactory(IMarshallingGeneratorFactory inner, ImmutableDictionary <ManagedTypeInfo, string> customTypeToErrorMessageMap)
 {
     _inner = inner;
     CustomTypeToErrorMessageMap = customTypeToErrorMessageMap;
 }
 public NoMarshallingInfoErrorMarshallingFactory(IMarshallingGeneratorFactory inner)
     : this(inner, DefaultTypeToErrorMessageMap)
 {
 }