Exemplo n.º 1
0
        /// <summary>
        /// Creates the cacheable method or indexer or property call.
        /// </summary>
        /// <param name="kind">The kind.</param>
        /// <param name="name">The name.</param>
        /// <param name="callInfo">The callInfo.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public static CacheableInvocation CreateCall(InvocationKind kind, String_OR_InvokeMemberName name = null, CallInfo callInfo = null, object context = null)
        {
            var tArgCount = callInfo != null ? callInfo.ArgumentCount : 0;
            var tArgNames = callInfo != null?callInfo.ArgumentNames.ToArray() : null;

            return(new CacheableInvocation(kind, name, tArgCount, tArgNames, context));
        }
    /// <summary>
    /// Sets the OneWayBind invocation.
    /// </summary>
    /// <param name="invocationKind">The invocation kind.</param>
    /// <param name="receiverKind">The receiver kind.</param>
    /// <param name="viewModelExpression">The view model expression.</param>
    /// <param name="viewExpression">The view expression.</param>
    /// <param name="viewModelConvert">The view model conversion function.</param>
    /// <param name="target">The target parameter.</param>
    /// <returns>A reference to this builder.</returns>
    public BindHostBuilder WithOneWayInvocation(
        InvocationKind invocationKind,
        ReceiverKind receiverKind,
        Expression <Func <BindHostProxy, object> > viewModelExpression,
        Expression <Func <WhenChangedHostProxy, object> > viewExpression,
        Expression <Func <object, object, object> > viewModelConvert,
        string target = "ViewModel")
    {
        if (viewModelExpression is null)
        {
            throw new ArgumentNullException(nameof(viewModelExpression));
        }

        if (viewExpression is null)
        {
            throw new ArgumentNullException(nameof(viewExpression));
        }

        if (viewModelConvert is null)
        {
            throw new ArgumentNullException(nameof(viewModelConvert));
        }

        _oneWayBindInvocation = GetOneWayBindInvocation(invocationKind, receiverKind, viewModelExpression.ToString(), viewExpression.ToString(), target, viewModelConvert.ToString());
        return(this);
    }
        /// <summary>
        /// Creates the cacheable method or indexer or property call.
        /// </summary>
        /// <param name="kind">The kind.</param>
        /// <param name="name">The name.</param>
        /// <param name="callInfo">The callInfo.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public static CacheableInvocation CreateCall(InvocationKind kind, String_OR_InvokeMemberName name = null, CallInfo callInfo = null,object context = null)
        {
            var tArgCount = callInfo != null ? callInfo.ArgumentCount : 0;
            var tArgNames = callInfo != null ? callInfo.ArgumentNames.ToArray() : null;

            return new CacheableInvocation(kind, name, tArgCount, tArgNames, context);
        }
 public PartialApplyInvocation(object target, object[] args, string memberName = null, int? totalCount = null, InvocationKind? invocationKind = null)
 {
     _target = target;
     _memberName = memberName;
     _invocationKind = invocationKind ?? (String.IsNullOrWhiteSpace(_memberName)
                              ? InvocationKind.InvokeUnknown
                              : InvocationKind.InvokeMemberUnknown);
     _totalArgCount = totalCount;
     _args = args;
 }
Exemplo n.º 5
0
 internal Currying(object target, string memberName, object[] args, int?totalCount = null,
                   InvocationKind?invocationKind = null)
 {
     _target         = target;
     _memberName     = memberName;
     _invocationKind = invocationKind ?? (String.IsNullOrWhiteSpace(_memberName)
                                              ? InvocationKind.InvokeUnknown
                                              : InvocationKind.InvokeMemberUnknown);
     _totalArgCount = totalCount;
     _args          = args;
 }
Exemplo n.º 6
0
        public static InvocationCacheCompatible CreateCall(
            InvocationKind kind,
            MemberInvocationMoniker name = null,
            CallInfo callinfo            = null,
            object context = null)
        {
            var argumentCount = callinfo != null ? callinfo.ArgumentCount : 0;
            var argumentNames = callinfo != null?callinfo.ArgumentNames.ToArray() : null;

            return(new InvocationCacheCompatible(kind, name, argumentCount, argumentNames, context));
        }
Exemplo n.º 7
0
        private void DecideArgumentCountBasedOnType(InvocationKind kind, int argCount, Type convertType)
        {
            switch (kind)
            {
            case InvocationKind.GetIndex:
                if (argCount < 1)
                {
                    throw new ArgumentException("Arg Count must be at least 1 for a GetIndex", "argCount");
                }
                _argumentCount = argCount;
                break;

            case InvocationKind.SetIndex:
                if (argCount < 2)
                {
                    throw new ArgumentException("Arg Count Must be at least 2 for a SetIndex", "argCount");
                }
                _argumentCount = argCount;
                break;

            case InvocationKind.Convert:
                _argumentCount = 0;
                if (convertType == null)
                {
                    throw new ArgumentNullException("convertType", " Convert Requires Convert Type ");
                }
                break;

            case InvocationKind.SubtractAssign:
            case InvocationKind.AddAssign:
            case InvocationKind.Set:
                _argumentCount = 1;
                break;

            case InvocationKind.Get:
            case InvocationKind.IsEvent:
                _argumentCount = 0;
                break;

            default:
                _argumentCount = Math.Max(argCount, _argumentNames.Length);
                break;
            }
        }
    private static string GetOneWayBindInvocation(
        InvocationKind invocationKind,
        ReceiverKind viewModelKind,
        string viewModelArgs,
        string viewArgs,
        string targetName,
        string?viewModelConvertFunc = null)
    {
        var receiver = viewModelKind == ReceiverKind.This ? "this" : "instance";

        if (viewModelConvertFunc is not null)
        {
            viewArgs = viewArgs + ", " + viewModelConvertFunc;
        }

        return(invocationKind == InvocationKind.MemberAccess ?
               $"{receiver}.BindOneWay({targetName}, {viewModelArgs}, {viewArgs})" :
               $"BindExtensions.BindOneWay({receiver}, {targetName}, {viewModelArgs}, {viewArgs})");
    }
Exemplo n.º 9
0
        public InvocationCacheCompatible(InvocationKind kind,
                                         MemberInvocationMoniker name = null,
                                         int argCount        = 0,
                                         string[] argNames   = null,
                                         object context      = null,
                                         Type convertType    = null,
                                         bool convertExplict = false,
                                         object[] storedArgs = null)
            : base(kind, name, storedArgs)
        {
            _convertType    = convertType;
            _convertExplict = convertExplict;

            ExtractArguments(argNames, storedArgs);

            DecideArgumentCountBasedOnType(kind, argCount, convertType);

            SetArgumentNames();

            InitializeContext(context);
        }
    public async Task NoDiagnostics_InstanceReceiverKind(InvocationKind invocationKind)
    {
        var receiverPropertyTypeInfo = new EmptyClassBuilder()
                                       .WithClassAccess(Accessibility.Public);
        var externalReceiverTypeInfo = new WhenChangedHostBuilder()
                                       .WithClassName("ReactiveType")
                                       .WithClassAccess(Accessibility.Public)
                                       .WithPropertyType(receiverPropertyTypeInfo)
                                       .WithPropertyAccess(Accessibility.Public)
                                       .WithInvocation("null");
        var hostTypeInfo = new WhenChangedHostBuilder()
                           .WithClassName("HostClass")
                           .WithClassAccess(Accessibility.Public)
                           .WithInvocation(invocationKind, x => x.Value, externalReceiverTypeInfo);

        var fixture = await WhenChangedFixture.Create(hostTypeInfo, externalReceiverTypeInfo, x => TestContext.WriteLine(x), ("ReceiverPropertyTypeInfo.cs", receiverPropertyTypeInfo.BuildRoot())).ConfigureAwait(false);

        fixture.RunGenerator(out var compilationDiagnostics, out var generatorDiagnostics);

        generatorDiagnostics.Where(x => x.Severity >= DiagnosticSeverity.Warning).Should().BeEmpty();
        compilationDiagnostics.Where(x => x.Severity >= DiagnosticSeverity.Warning).Should().BeEmpty();

        var host     = fixture.NewHostInstance();
        var receiver = fixture.NewReceiverInstance();

        host.Receiver  = receiver;
        receiver.Value = fixture.NewValuePropertyInstance();
        var    observable = host.GetWhenChangedObservable(_ => TestContext.WriteLine(fixture.Sources));
        object value      = null;

        observable.Subscribe(x => value = x);
        receiver.Value.Should().Equals(value);
        receiver.Value = fixture.NewValuePropertyInstance();
        receiver.Value.Should().Equals(value);
        receiver.Value = null;
        receiver.Value.Should().Equals(value);
    }
Exemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CacheableInvocation"/> class.
        /// </summary>
        /// <param name="kind">The kind.</param>
        /// <param name="name">The name.</param>
        /// <param name="argCount">The arg count.</param>
        /// <param name="argNames">The arg names.</param>
        /// <param name="context">The context.</param>
        /// <param name="convertType">Type of the convert.</param>
        /// <param name="convertExplicit">if set to <c>true</c> [convert explict].</param>
        /// <param name="storedArgs">The stored args.</param>
        public CacheableInvocation(InvocationKind kind,
                                   String_OR_InvokeMemberName name = null,
                                   int argCount         = 0,
                                   string[] argNames    = null,
                                   object context       = null,
                                   Type convertType     = null,
                                   bool convertExplicit = false,
                                   object[] storedArgs  = null)
            : base(kind, name, storedArgs)
        {
            _convertType     = convertType;
            _convertExplicit = convertExplicit;

            _argNames = argNames ?? new string[] {};

            if (storedArgs != null)
            {
                _argCount = storedArgs.Length;
                string[] tArgNames;
                Args = Util.GetArgsAndNames(storedArgs, out tArgNames);
                if (_argNames.Length < tArgNames.Length)
                {
                    _argNames = tArgNames;
                }
            }

            switch (kind) //Set required argcount values
            {
            case InvocationKind.GetIndex:
                if (argCount < 1)
                {
                    throw new ArgumentException("Arg Count must be at least 1 for a GetIndex", "argCount");
                }
                _argCount = argCount;
                break;

            case InvocationKind.SetIndex:
                if (argCount < 2)
                {
                    throw new ArgumentException("Arg Count Must be at least 2 for a SetIndex", "argCount");
                }
                _argCount = argCount;
                break;

            case InvocationKind.Convert:
                _argCount = 0;
                if (convertType == null)
                {
                    throw new ArgumentNullException("convertType", " Convert Requires Convert Type ");
                }
                break;

            case InvocationKind.SubtractAssign:
            case InvocationKind.AddAssign:
            case InvocationKind.Set:
                _argCount = 1;
                break;

            case InvocationKind.Get:
            case InvocationKind.IsEvent:
                _argCount = 0;
                break;

            default:
                _argCount = Math.Max(argCount, _argNames.Length);
                break;
            }

            if (_argCount > 0)//setup argname array
            {
                var tBlank = new string[_argCount];
                if (_argNames.Length != 0)
                {
                    Array.Copy(_argNames, 0, tBlank, tBlank.Length - _argNames.Length, tBlank.Length);
                }
                else
                {
                    tBlank = null;
                }
                _argNames = tBlank;
            }


            if (context != null)
            {
#pragma warning disable 168
                var tDummy = context.GetTargetContext(out _context, out _staticContext);
#pragma warning restore 168
            }
            else
            {
                _context = typeof(object);
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RemoteInvocation"/> class.
 /// </summary>
 /// <param name="kind">The kind.</param>
 /// <param name="name">The name.</param>
 /// <param name="storedArgs">The args.</param>
 public RemoteInvocation(InvocationKind kind, string name, params object[] storedArgs)
 {
     Kind = kind;
     Name = name;
     Args = storedArgs;
 }
Exemplo n.º 13
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="CacheableInvocation" /> class.
        /// </summary>
        /// <param name="kind"> The kind. </param>
        /// <param name="name"> The name. </param>
        /// <param name="argCount"> The arg count. </param>
        /// <param name="argNames"> The arg names. </param>
        /// <param name="context"> The context. </param>
        /// <param name="convertType"> Type of the convert. </param>
        /// <param name="convertExplict"> if set to <c>true</c> [convert explict]. </param>
        /// <param name="storedArgs"> The stored args. </param>
        public CacheableInvocation(InvocationKind kind,
            String_OR_InvokeMemberName name = null,
            int argCount = 0,
            string[] argNames = null,
            object context = null,
            Type convertType = null,
            bool convertExplict = false,
            object[] storedArgs = null)
            : base(kind, name, storedArgs)
        {
            _convertType = convertType;
            _convertExplict = convertExplict;

            _argNames = argNames ?? new string[] {};

            if (storedArgs != null) {
                _argCount = storedArgs.Length;
                string[] tArgNames;
                Args = Util.GetArgsAndNames(storedArgs, out tArgNames);
                if (_argNames.Length < tArgNames.Length) {
                    _argNames = tArgNames;
                }
            }

            switch (kind) //Set required argcount values
            {
                case InvocationKind.GetIndex:
                    if (argCount < 1) {
                        throw new ArgumentException("Arg Count must be at least 1 for a GetIndex", "argCount");
                    }
                    _argCount = argCount;
                    break;
                case InvocationKind.SetIndex:
                    if (argCount < 2) {
                        throw new ArgumentException("Arg Count Must be at least 2 for a SetIndex", "argCount");
                    }
                    _argCount = argCount;
                    break;
                case InvocationKind.Convert:
                    _argCount = 0;
                    if (convertType == null) {
                        throw new ArgumentNullException("convertType", " Convert Requires Convert Type ");
                    }
                    break;
                case InvocationKind.SubtractAssign:
                case InvocationKind.AddAssign:
                case InvocationKind.Set:
                    _argCount = 1;
                    break;
                case InvocationKind.Get:
                case InvocationKind.IsEvent:
                    _argCount = 0;
                    break;
                default:
                    _argCount = Math.Max(argCount, _argNames.Length);
                    break;
            }

            if (_argCount > 0) //setup argname array
            {
                var tBlank = new string[_argCount];
                if (_argNames.Length != 0) {
                    Array.Copy(_argNames, 0, tBlank, tBlank.Length - _argNames.Length, tBlank.Length);
                } else {
                    tBlank = null;
                }
                _argNames = tBlank;
            }

            if (context != null) {
            #pragma warning disable 168
                var tDummy = context.GetTargetContext(out _context, out _staticContext);
            #pragma warning restore 168
            } else {
                _context = typeof (object);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CacheableInvocation"/> class.
        /// </summary>
        /// <param name="kind">The kind.</param>
        /// <param name="name">The name.</param>
        /// <param name="argCount">The arg count.</param>
        /// <param name="argNames">The arg names.</param>
        /// <param name="context">The context.</param>
        /// <param name="convertType">Type of the convert.</param>
        /// <param name="convertExplicit">if set to <c>true</c> [convert explict].</param>
        /// <param name="storedArgs">The stored args.</param>
        public CacheableInvocation(InvocationKind kind,
                                   String_OR_InvokeMemberName name = null,
                                   int argCount         = 0,
                                   string[] argNames    = null,
                                   object context       = null,
                                   Type convertType     = null,
                                   bool convertExplicit = false,
                                   object[] storedArgs  = null)
            : base(kind, name, storedArgs)
        {
            this._convertType     = convertType;
            this._convertExplicit = convertExplicit;

            this._argNames = argNames ?? new string[] {};

            if (storedArgs != null)
            {
                this._argCount = storedArgs.Length;
                this.Args      = Util.GetArgsAndNames(storedArgs, out var tArgNames);
                if (this._argNames.Length < tArgNames.Length)
                {
                    this._argNames = tArgNames;
                }
            }

            switch (kind) //Set required argcount values
            {
            case InvocationKind.GetIndex:
                if (argCount < 1)
                {
                    throw new ArgumentException("Arg Count must be at least 1 for a GetIndex", nameof(argCount));
                }
                this._argCount = argCount;
                break;

            case InvocationKind.SetIndex:
                if (argCount < 2)
                {
                    throw new ArgumentException("Arg Count Must be at least 2 for a SetIndex", nameof(argCount));
                }
                this._argCount = argCount;
                break;

            case InvocationKind.Convert:
                this._argCount = 0;
                if (convertType == null)
                {
                    throw new ArgumentNullException(nameof(convertType), " Convert Requires Convert Type ");
                }
                break;

            case InvocationKind.SubtractAssign:
            case InvocationKind.AddAssign:
            case InvocationKind.Set:
                this._argCount = 1;
                break;

            case InvocationKind.Get:
            case InvocationKind.IsEvent:
                this._argCount = 0;
                break;

            default:
                this._argCount = Math.Max(argCount, this._argNames.Length);
                break;
            }

            if (this._argCount > 0)//setup argName array
            {
                var tBlank = new string[this._argCount];
                if (this._argNames.Length != 0)
                {
                    Array.Copy(this._argNames, 0, tBlank, tBlank.Length - this._argNames.Length, tBlank.Length);
                }
                else
                {
                    tBlank = null;
                }
                this._argNames = tBlank;
            }


            if (context != null)
            {
                var dummy = context.GetTargetContext(out this._context, out this._staticContext); //lgtm [cs/useless-assignment-to-local]
            }
            else
            {
                this._context = typeof(object);
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// Creates the invocation.
 /// </summary>
 /// <param name="kind">The kind.</param>
 /// <param name="name">The name.</param>
 /// <param name="storedArgs">The args.</param>
 /// <returns></returns>
 public static Invocation Create(InvocationKind kind, String_OR_InvokeMemberName name, params object[] storedArgs)
 {
     return new Invocation(kind,name,storedArgs);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Invocation"/> class.
 /// </summary>
 /// <param name="kind">The kind.</param>
 /// <param name="name">The name.</param>
 /// <param name="storedArgs">The args.</param>
 public Invocation(InvocationKind kind, String_OR_InvokeMemberName name, params object[] storedArgs)
 {
     Kind = kind;
     Name = name;
     Args = storedArgs;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Invocation"/> class.
 /// </summary>
 /// <param name="kind">The kind.</param>
 /// <param name="name">The name.</param>
 /// <param name="storedArgs">The args.</param>
 public Invocation(InvocationKind kind, String_OR_InvokeMemberName name, params object[] storedArgs)
 {
     Kind = kind;
     Name = name;
     Args = storedArgs;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Creates the invocation.
 /// </summary>
 /// <param name="kind">The kind.</param>
 /// <param name="name">The name.</param>
 /// <param name="storedArgs">The args.</param>
 /// <returns></returns>
 public static Invocation Create(InvocationKind kind, String_OR_InvokeMemberName name, params object[] storedArgs)
 {
     return(new Invocation(kind, name, storedArgs));
 }
 private async Task AssertTestCase_MultiExpression(WhenChangedHostBuilder hostTypeInfo, InvocationKind invocationKind, params (string FileName, string Source)[] extraSources)
Exemplo n.º 20
0
 public Invocation(InvocationKind kind, MemberInvocationMoniker name, params object[] storedArgs)
 {
     Kind      = kind;
     Name      = name;
     Arguments = storedArgs;
 }
Exemplo n.º 21
0
 public static Invocation Create(InvocationKind kind, MemberInvocationMoniker name, params object[] storedArgs)
 {
     return(new Invocation(kind, name, storedArgs));
 }