protected static IdentifierNameSyntax GetToJSMethod(MarshalerType marshalerType) { switch (marshalerType) { case MarshalerType.BigInt64: return(IdentifierName(Constants.ToJSBigMethod)); default: return(IdentifierName(Constants.ToJSMethod)); } }
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"); }
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))), }))))))));
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"); } }
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;
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"); }
public TaskJSGenerator(MarshalerType resultMarshalerType) : base(MarshalerType.Task, new Forwarder()) { _resultMarshalerType = resultMarshalerType; }
public SpanJSGenerator(MarshalerType elementMarshalerType) : base(MarshalerType.Span) { _elementMarshalerType = elementMarshalerType; }
public ArrayJSGenerator(MarshalerType elemenetMarshalerType) : base(MarshalerType.Array) { _elemenetMarshalerType = elemenetMarshalerType; }
public VoidGenerator(MarshalerType marshalerType) : base(marshalerType, new Forwarder()) { }
protected static IdentifierNameSyntax MarshalerTypeName(MarshalerType marshalerType) { return(IdentifierName(Constants.JSMarshalerTypeGlobalDot + marshalerType.ToString())); }
protected BaseJSGenerator(MarshalerType marshalerType, IMarshallingGenerator inner) { _inner = inner; Type = marshalerType; }
public NullableJSGenerator(MarshalerType resultMarshalerType) : base(resultMarshalerType) { }
public ArraySegmentJSGenerator(MarshalerType elementMarshalerType) : base(MarshalerType.ArraySegment) { _elementMarshalerType = elementMarshalerType; }
public PrimitiveJSGenerator(MarshalerType marshalerType) : base(marshalerType, new Forwarder()) { }
public PrimitiveJSGenerator(MarshalerType marshalerType, IMarshallingGenerator inner) : base(marshalerType, inner) { }