示例#1
0
        protected static IdentifierNameSyntax GetToJSMethod(MarshalerType marshalerType)
        {
            switch (marshalerType)
            {
            case MarshalerType.BigInt64:
                return(IdentifierName(Constants.ToJSBigMethod));

            default:
                return(IdentifierName(Constants.ToJSMethod));
            }
        }
示例#2
0
        internal static void CheckArraySegment(JSMarshalerType underlyingSig)
        {
            MarshalerType underlying = underlyingSig._signatureType.Type;

            if (underlying == MarshalerType.Byte ||
                underlying == MarshalerType.Int32 ||
                underlying == MarshalerType.Double
                )
            {
                return;
            }
            throw new ArgumentException("Bad array element type");
        }
示例#3
0
 private static ArgumentSyntax ArgToJS(int i, TypeSyntax sourceType, MarshalerType marshalerType) => Argument(ParenthesizedLambdaExpression()
                                                                                                              .WithModifiers(TokenList(Token(SyntaxKind.StaticKeyword)))
                                                                                                              .WithParameterList(ParameterList(SeparatedList(new[] {
     Parameter(Identifier("__delegate_arg_arg" + (i + 1)))
     .WithModifiers(TokenList(Token(SyntaxKind.RefKeyword)))
     .WithType(IdentifierName(Constants.JSMarshalerArgumentGlobal)),
     Parameter(Identifier("__delegate_arg" + (i + 1)))
     .WithType(sourceType)
 })))
                                                                                                              .WithBlock(Block(SingletonList <StatementSyntax>(ExpressionStatement(
                                                                                                                                                                   InvocationExpression(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
                                                                                                                                                                                                               IdentifierName("__delegate_arg_arg" + (i + 1)), GetToJSMethod(marshalerType)))
                                                                                                                                                                   .WithArgumentList(ArgumentList(SeparatedList(new[] {
     Argument(IdentifierName("__delegate_arg" + (i + 1))),
 }))))))));
示例#4
0
        internal static void CheckTask(JSMarshalerType underlyingSig)
        {
            MarshalerType underlying = underlyingSig._signatureType.Type;

            // TODO maybe allow Task<byte[]> and Task<int[]> which don't need element marshaler
            if (underlying == MarshalerType.Array ||
                underlying == MarshalerType.ArraySegment ||
                underlying == MarshalerType.Span

                || underlying == MarshalerType.Task ||
                underlying == MarshalerType.Action ||
                underlying == MarshalerType.Function
                )
            {
                throw new ArgumentException("Bad task result type");
            }
        }
示例#5
0
        protected MarshalProcessor(MarshalerType marshalerType, MethodProcessor methodProcessor, ParameterDefinition param, MethodReturnType retParam)
        {
            if (param == null && retParam == null)
            {
                throw new ArgumentNullException("either '" + nameof(param) + "' or '" + nameof(retParam) + "' must not be null");
            }
            if (param != null && retParam != null)
            {
                throw new InvalidOperationException("either '" + nameof(param) + "' or '" + nameof(retParam) + "' must be null");
            }
            MethodProcessor = methodProcessor;
            Marshaler       = marshalerType.TypeDefinition;
            ReturnParameter = retParam;
            Parameter       = param;
            PInvokeInfo     = methodProcessor.Method.PInvokeInfo;
            if (param != null)
            {
                UnmanagedType = (UnmanagedType)param.MarshalInfo.NativeType;
            }
            else
            {
                UnmanagedType = (UnmanagedType)retParam.MarshalInfo.NativeType;
            }

            var supportedUnmanagedTypes = new HashSet <UnmanagedType>();

            if (!marshalerType.SupportedUnmanagedTypes.Contains(UnmanagedType))
            {
                throw new NotSupportedException($"UnmanagedType: '{UnmanagedType}' not supported by {Marshaler.FullName} marshaler for {methodProcessor.Method.FullName}.");
            }

            var marshalerBaseClass = GetMarshalerBaseClass(Marshaler);

            NativeType  = marshalerBaseClass.GenericArguments[2].Resolve();
            ManagedType = marshalerBaseClass.GenericArguments[3].Resolve();

            MarshalInfoVariableType = marshalerBaseClass.GenericArguments[1].Resolve();

            MethodDefinition fittingCtor = null;
示例#6
0
        internal static void CheckNullable(JSMarshalerType underlyingSig)
        {
            MarshalerType underlying = underlyingSig._signatureType.Type;

            if (underlying == MarshalerType.Boolean ||
                underlying == MarshalerType.Byte ||
                underlying == MarshalerType.Int16 ||
                underlying == MarshalerType.Int32 ||
                underlying == MarshalerType.BigInt64 ||
                underlying == MarshalerType.Int52 ||
                underlying == MarshalerType.IntPtr ||
                underlying == MarshalerType.Double ||
                underlying == MarshalerType.Single ||
                underlying == MarshalerType.Single ||
                underlying == MarshalerType.Char ||
                underlying == MarshalerType.DateTime ||
                underlying == MarshalerType.DateTimeOffset
                )
            {
                return;
            }
            throw new ArgumentException("Bad nullable value type");
        }
示例#7
0
 public TaskJSGenerator(MarshalerType resultMarshalerType)
     : base(MarshalerType.Task, new Forwarder())
 {
     _resultMarshalerType = resultMarshalerType;
 }
示例#8
0
 public SpanJSGenerator(MarshalerType elementMarshalerType)
     : base(MarshalerType.Span)
 {
     _elementMarshalerType = elementMarshalerType;
 }
示例#9
0
 public ArrayJSGenerator(MarshalerType elemenetMarshalerType)
     : base(MarshalerType.Array)
 {
     _elemenetMarshalerType = elemenetMarshalerType;
 }
示例#10
0
 public VoidGenerator(MarshalerType marshalerType)
     : base(marshalerType, new Forwarder())
 {
 }
示例#11
0
 protected static IdentifierNameSyntax MarshalerTypeName(MarshalerType marshalerType)
 {
     return(IdentifierName(Constants.JSMarshalerTypeGlobalDot + marshalerType.ToString()));
 }
示例#12
0
 protected BaseJSGenerator(MarshalerType marshalerType, IMarshallingGenerator inner)
 {
     _inner = inner;
     Type   = marshalerType;
 }
示例#13
0
 public NullableJSGenerator(MarshalerType resultMarshalerType)
     : base(resultMarshalerType)
 {
 }
示例#14
0
 public ArraySegmentJSGenerator(MarshalerType elementMarshalerType)
     : base(MarshalerType.ArraySegment)
 {
     _elementMarshalerType = elementMarshalerType;
 }
示例#15
0
 public PrimitiveJSGenerator(MarshalerType marshalerType)
     : base(marshalerType, new Forwarder())
 {
 }
示例#16
0
 public PrimitiveJSGenerator(MarshalerType marshalerType, IMarshallingGenerator inner)
     : base(marshalerType, inner)
 {
 }