コード例 #1
0
 private void Awake()
 {
     m_slider = GetComponent <Slider>();
     m_slider.onValueChanged.AddListener((val) => {
         OnPropertyChanged?.Invoke(m_slider, val);
     });
 }
コード例 #2
0
            public static void PropertyChangedEventArgsBeforeCallerMemberName()
            {
                var syntaxTree = CSharpSyntaxTree.ParseText(
                    @"
namespace N
{
    using System.ComponentModel;
    using System.Runtime.CompilerServices;

    public class C : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public int Bar { get; set; }

        protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            this.PropertyChanged?.Invoke(this, e);
        }

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}");
                var compilation      = CSharpCompilation.Create("test", new[] { syntaxTree }, MetadataReferences.FromAttributes());
                var semanticModel    = compilation.GetSemanticModel(syntaxTree);
                var classDeclaration = syntaxTree.FindClassDeclaration("C");
                var type             = semanticModel.GetDeclaredSymbol(classDeclaration);

                Assert.AreEqual(true, OnPropertyChanged.TryFind(type, semanticModel, CancellationToken.None, out var invoker));
                Assert.AreEqual("N.C.OnPropertyChanged(string)", invoker.ToString());
            }
コード例 #3
0
            public static void CachingInConcurrentDictionaryLocal(string expression)
            {
                var syntaxTree = CSharpSyntaxTree.ParseText(
                    @"
namespace N
{
    using System.Collections.Concurrent;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;

    public class C : INotifyPropertyChanged
    {
        private static readonly ConcurrentDictionary<string, PropertyChangedEventArgs> Cache = new ConcurrentDictionary<string, PropertyChangedEventArgs>();

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            var e = Cache.GetOrAdd(propertyName ?? string.Empty, name => new PropertyChangedEventArgs(name));
            this.PropertyChanged?.Invoke(this, e);
        }
    }
}".AssertReplace("propertyName ?? string.Empty", expression));
                var compilation      = CSharpCompilation.Create("test", new[] { syntaxTree }, MetadataReferences.FromAttributes());
                var semanticModel    = compilation.GetSemanticModel(syntaxTree);
                var classDeclaration = syntaxTree.FindClassDeclaration("C");
                var type             = semanticModel.GetDeclaredSymbol(classDeclaration);

                Assert.AreEqual(true, OnPropertyChanged.TryFind(type, semanticModel, CancellationToken.None, out var invoker));
                Assert.AreEqual("N.C.OnPropertyChanged(string)", invoker.ToString());
            }
コード例 #4
0
 internal void RaiseOnPropertyChanged(string sender = null, OnPropertyChangeddataType data = null)
 {
     if (OnPropertyChanged != null)
     {
         OnPropertyChanged.BeginInvoke(sender, data, null, null);
     }
 }
コード例 #5
0
        /// <summary>
        /// Returns performance settings instance for a NetOffice wrapper class
        /// </summary>
        /// <param name="componentName">name of the component. for example:ExcelApi</param>
        /// <param name="entityName">name of the class. for example:Range or Application</param>
        /// <param name="methodName">method or property name. for example: Visible or Activate</param>
        /// <returns>settings instance</returns>
        public PerformanceTraceSetting this[string componentName, string entityName, string methodName]
        {
            get
            {
                if (String.IsNullOrWhiteSpace(componentName))
                {
                    throw new ArgumentNullException("componentName");
                }
                if (String.IsNullOrWhiteSpace(entityName))
                {
                    throw new ArgumentNullException("entityName");
                }
                if (String.IsNullOrWhiteSpace(methodName))
                {
                    throw new ArgumentNullException("methodName");
                }

                lock (_lock)
                {
                    PerformanceTraceSettingCollection list = null;
                    if (!_repository.TryGetValue(componentName, out list))
                    {
                        list = new PerformanceTraceSettingCollection();
                        _repository.Add(componentName, list);
                        OnPropertyChanged?.Invoke("PerformanceTrace.Item");
                    }

                    return(list[entityName, methodName]);
                }
            }
        }
コード例 #6
0
            public static void CopyLocalInvoke()
            {
                var syntaxTree    = CSharpSyntaxTree.ParseText(@"
namespace N
{
    using System.ComponentModel;
    using System.Runtime.CompilerServices;

    internal class Foo : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            var handler = this.PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}");
                var compilation   = CSharpCompilation.Create("test", new[] { syntaxTree }, MetadataReferences.FromAttributes());
                var semanticModel = compilation.GetSemanticModel(syntaxTree);
                var invocation    = syntaxTree.FindMethodDeclaration("OnPropertyChanged");
                var method        = semanticModel.GetDeclaredSymbol(invocation, CancellationToken.None);

                Assert.AreEqual(AnalysisResult.Yes, OnPropertyChanged.IsMatch(method, semanticModel, CancellationToken.None));
            }
コード例 #7
0
 private void TrackDescription_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (OnPropertyChanged != null)
     {
         OnPropertyChanged.Invoke(sender, EventArgs.Empty);
     }
 }
コード例 #8
0
 internal void RaiseOnPropertyChanged(string sender = null, XBMCRPC.Player.OnPropertyChanged_data data = null)
 {
     if (OnPropertyChanged != null)
     {
         OnPropertyChanged.BeginInvoke(sender, data, null, null);
     }
 }
コード例 #9
0
 private void Awake()
 {
     m_inputField = GetComponent <TMP_InputField>();
     m_inputField.onValueChanged.AddListener(val => {
         OnPropertyChanged?.Invoke(m_inputField, val);
     });
 }
コード例 #10
0
            public static void Stylet()
            {
                var syntaxTree = CSharpSyntaxTree.ParseText(
                    @"
namespace N
{
    public class Foo : Stylet.PropertyChangedBase
    {
        private int bar;

        public int Bar
        {
            get => this.bar;
            set
            {
                if (value == this.bar)
                {
                    return;
                }

                this.bar = value;
                this.NotifyOfPropertyChange();
            }
        }
    }
}");
                var compilation   = CSharpCompilation.Create("test", new[] { syntaxTree }, SpecialMetadataReferences.Stylet);
                var semanticModel = compilation.GetSemanticModel(syntaxTree);
                var invocation    = syntaxTree.FindInvocation("NotifyOfPropertyChange");
                var method        = semanticModel.GetSymbolSafe(invocation, CancellationToken.None);

                Assert.AreEqual(AnalysisResult.Yes, OnPropertyChanged.IsMatch(method, semanticModel, CancellationToken.None));
            }
コード例 #11
0
 private void Awake()
 {
     m_toggle = GetComponent <Toggle>();
     m_toggle.onValueChanged.AddListener((val) => {
         OnPropertyChanged?.Invoke(m_toggle, val);
     });
 }
コード例 #12
0
        /// <summary>
        /// Create a new abstract entity.
        /// </summary>
        /// <param name="Id">The unique entity identification.</param>
        /// <param name="CustomData">An optional dictionary of customer-specific data.</param>
        public AEMobilityEntity(TId Id,
                                IReadOnlyDictionary <String, Object> CustomData = null)

            : base(CustomData)

        {
            #region Initial checks

            if (Id.IsNullOrEmpty)
            {
                throw new ArgumentNullException(nameof(Id), "The given Id must not be null or empty!");
            }

            #endregion

            this._Ids = new List <TId> {
                Id
            };
            this.DataSource   = String.Empty;
            this.LastChange   = DateTime.UtcNow;
            this._UserDefined = new UserDefinedDictionary();

            this._UserDefined.OnPropertyChanged += (timestamp, eventtrackingid, sender, key, oldValue, newValue)
                                                   => OnPropertyChanged?.Invoke(timestamp, eventtrackingid, sender, key, oldValue, newValue);
        }
コード例 #13
0
 protected override void RaisePropertyChanged(string propertyName)
 {
     base.RaisePropertyChanged(propertyName);
     OnPropertyChanged?.Invoke(this, new PropertyChangedEventArgs
     {
         Property = GetType().GetTypeInfo().GetDeclaredProperty(propertyName),
         Value    = GetType().GetTypeInfo().GetDeclaredProperty(propertyName).GetValue(this, null)
     });
 }
コード例 #14
0
ファイル: ServerItem.cs プロジェクト: usaweili/V2RayGCon
 public void InvokeEventOnPropertyChange()
 {
     // things happen while invoking
     try
     {
         OnPropertyChanged?.Invoke(this, EventArgs.Empty);
     }
     catch { }
 }
コード例 #15
0
 public IndexViewModel(IMessageHub eventAggregator, ITicketRepository ticketRepository)
 {
     _eventAggregator             = eventAggregator;
     _ticketRepository            = ticketRepository;
     _ticketScanAddedSubscription = _eventAggregator.Subscribe <TicketScanAdded>(
         message => OnPropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TicketScans))));
     _ticketScanUpdatedSubscription = _eventAggregator.Subscribe <TicketScanUpdated>(
         message => OnPropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TicketScans))));
 }
コード例 #16
0
        public SetPropertyResult Set(String Key,
                                     Object NewValue,
                                     Object OldValue = null,
                                     EventTracking_Id EventTrackingId = null)
        {
            // Locks are shit, but ConcurrentDictionary does not compare values correctly!
            lock (_Dictionary)
            {
                Object _CurrentValue;

                if (!_Dictionary.TryGetValue(Key, out _CurrentValue))
                {
                    _Dictionary.Add(Key, NewValue);

                    OnPropertyChanged?.Invoke(DateTime.UtcNow,
                                              EventTrackingId,
                                              this,
                                              Key,
                                              OldValue,
                                              NewValue);

                    return(SetPropertyResult.Added);
                }

                if (_CurrentValue.ToString() != OldValue.ToString())
                {
                    return(SetPropertyResult.Conflict);
                }

                if (NewValue != null)
                {
                    _Dictionary[Key] = NewValue;

                    OnPropertyChanged?.Invoke(DateTime.UtcNow,
                                              EventTrackingId,
                                              this,
                                              Key,
                                              OldValue,
                                              NewValue);

                    return(SetPropertyResult.Changed);
                }


                _Dictionary.Remove(Key);

                OnPropertyChanged?.Invoke(DateTime.UtcNow,
                                          EventTrackingId,
                                          this,
                                          Key,
                                          OldValue,
                                          null);

                return(SetPropertyResult.Removed);
            }
        }
コード例 #17
0
 internal void method_36(OnPropertyChanged onPropertyChanged_0)
 {
     if (this.strategy__0 != null && this.strategy__0.Status == StrategyStatus.Running)
     {
         for (int i = 0; i < this.list_0.Count; i++)
         {
             this.list_0[i].vmethod_38(onPropertyChanged_0);
         }
     }
 }
コード例 #18
0
        public TickerEintrag Add(string Text)
        {
            var t = new TickerEintrag();

            t.ID   = TickerListe.Count() + 1;
            t.Text = Text;
            t.Zeit = DateTime.Now;
            TickerListe.Add(t);
            OnPropertyChanged?.Invoke();
            return(t);
        }
コード例 #19
0
            public static void IgnoreWhenRaiseForOtherInstance()
            {
                var syntaxTree    = CSharpSyntaxTree.ParseText(@"
namespace N
{
    using System.ComponentModel;
    using System.Runtime.CompilerServices;

    public class C : INotifyPropertyChanged
    {
        private int value;

        public event PropertyChangedEventHandler PropertyChanged;

        public int Value
        {
            get
            {
                return this.value;
            }

            set
            {
                if (value == this.value)
                {
                    return;
                }

                this.value = value;
                this.OnPropertyChanged();
            }
        }

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        public void RaiseForChild(string propertyName)
        {
            var vm = new ViewModel();
            vm.OnPropertyChanged(propertyName);
        }
    }
}");
                var compilation   = CSharpCompilation.Create("test", new[] { syntaxTree }, MetadataReferences.FromAttributes());
                var semanticModel = compilation.GetSemanticModel(syntaxTree);
                var invocation    = syntaxTree.FindMethodDeclaration("RaiseForChild");
                var method        = semanticModel.GetDeclaredSymbol(invocation, CancellationToken.None);

                Assert.AreEqual(AnalysisResult.No, OnPropertyChanged.IsMatch(method, semanticModel, CancellationToken.None));
            }
コード例 #20
0
        private void UpdateBorder()
        {
            if (Rectangle.IsNullOrZero(border))
            {
                propertyMap[Visual.Property.Type] = new PropertyValue((int)Visual.Type.Image);
            }
            else
            {
                propertyMap[Visual.Property.Type] = new PropertyValue((int)Visual.Type.NPatch);
            }

            propertyMap[ImageVisualProperty.Border] = PropertyValue.CreateWithGuard(border);
            OnPropertyChanged?.Invoke(this);
        }
コード例 #21
0
            public static void WhenCreatingPropertyChangedEventArgsSeparately()
            {
                var syntaxTree = CSharpSyntaxTree.ParseText(@"
namespace N
{
    using System.ComponentModel;
    using System.Runtime.CompilerServices;

    public class C : INotifyPropertyChanged
    {
        private int bar;

        public event PropertyChangedEventHandler PropertyChanged;

        public int Bar
        {
            get => this.bar;

            set
            {
                if (value == this.bar)
                {
                    return;
                }

                this.bar = value;
                this.OnPropertyChanged();
            }
        }

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            var handler = this.PropertyChanged;
            if (handler != null)
            {
                var args = new PropertyChangedEventArgs(propertyName);
                handler.Invoke(this, args);
            }
        }
    }
}");

                var compilation      = CSharpCompilation.Create("test", new[] { syntaxTree }, MetadataReferences.FromAttributes());
                var semanticModel    = compilation.GetSemanticModel(syntaxTree);
                var classDeclaration = syntaxTree.FindClassDeclaration("C");
                var type             = semanticModel.GetDeclaredSymbol(classDeclaration);

                Assert.AreEqual(true, OnPropertyChanged.TryFind(type, semanticModel, CancellationToken.None, out var invoker));
                Assert.AreEqual("N.C.OnPropertyChanged(string)", invoker.ToString());
            }
コード例 #22
0
            public static void WhenCreatingPropertyChangedEventArgsSeparately()
            {
                var syntaxTree = CSharpSyntaxTree.ParseText(@"
namespace N
{
    using System.ComponentModel;
    using System.Runtime.CompilerServices;

    public class Foo : INotifyPropertyChanged
    {
        private int bar;

        public event PropertyChangedEventHandler PropertyChanged;

        public int Bar
        {
            get => this.bar;

            set
            {
                if (value == this.bar)
                {
                    return;
                }

                this.bar = value;
                this.OnPropertyChanged();
            }
        }

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            var handler = this.PropertyChanged;
            if (handler != null)
            {
                var args = new PropertyChangedEventArgs(propertyName);
                handler.Invoke(this, args);
            }
        }
    }
}");

                var compilation   = CSharpCompilation.Create("test", new[] { syntaxTree }, MetadataReferences.FromAttributes());
                var semanticModel = compilation.GetSemanticModel(syntaxTree);
                var invocation    = syntaxTree.FindMethodDeclaration("OnPropertyChanged");
                var method        = semanticModel.GetDeclaredSymbol(invocation, CancellationToken.None);

                Assert.AreEqual(AnalysisResult.Yes, OnPropertyChanged.IsMatch(method, semanticModel, CancellationToken.None));
            }
コード例 #23
0
    //!注册一个属性改变回调
    public void RegisterReceiver(int objectID, OnPropertyChanged callback)
    {
        List <OnPropertyChanged> notifyList = null;

        if (!m_receivers.ContainsKey(objectID))
        {
            notifyList            = new List <OnPropertyChanged>();
            m_receivers[objectID] = notifyList;
        }
        else
        {
            notifyList = m_receivers[objectID];
        }
        notifyList.Add(callback);
    }
コード例 #24
0
    public void RemoveReceiver(int objectID, OnPropertyChanged callback)
    {
        if (!m_receivers.ContainsKey(objectID))
        {
            return;
        }
        List <OnPropertyChanged> notifyList = m_receivers[objectID];

        foreach (OnPropertyChanged notify in notifyList)
        {
            if (notify == callback)
            {
                notifyList.Remove(callback);
                break;
            }
        }
    }
コード例 #25
0
            public static void WhenNotInvokerINotifyPropertyChangedFullyQualified(string call, AnalysisResult expected)
            {
                var syntaxTree = CSharpSyntaxTree.ParseText(
                    @"
namespace N
{
    public class Foo : System.ComponentModel.INotifyPropertyChanged
    {
        public Foo()
        {
            Bar1();
            var a = Bar2();
            a = Bar3();
            if (Bar4())
            {
            }

            OnPropertyChanged();
        }
        
        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }

        private void Bar1()
        {
        }

        private int Bar2() => 1;

        private int Bar3() => 2;

        private bool Bar4() => true;
    }
}");
                var compilation   = CSharpCompilation.Create("test", new[] { syntaxTree }, MetadataReferences.FromAttributes());
                var semanticModel = compilation.GetSemanticModel(syntaxTree);
                var invocation    = syntaxTree.FindInvocation(call);

                Assert.AreEqual(expected, OnPropertyChanged.IsMatch(invocation, semanticModel, CancellationToken.None));
            }
コード例 #26
0
    public void NotifyChange(int objectID, int eventType, IPropertyObject obj, object eventObj)
    {
        if (!m_receivers.ContainsKey(objectID))
        {
            return;
        }
        List <OnPropertyChanged> notifyList = m_receivers[objectID];

        for (int i = 0; i < notifyList.Count;)
        {
            int cacheCount           = notifyList.Count;
            OnPropertyChanged notify = notifyList[i];
            notify(objectID, eventType, obj, eventObj);
            if (cacheCount >= notifyList.Count)
            {
                i++;
            }
        }
    }
コード例 #27
0
            public static void ExceptionHandlingRelayCommand()
            {
                var syntaxTree = CSharpSyntaxTree.ParseText(@"
namespace N
{
    using System;
    using Gu.Reactive;
    using Gu.Wpf.Reactive;

    public class ExceptionHandlingRelayCommand : ConditionRelayCommand
    {
        private Exception _exception;

        public ExceptionHandlingRelayCommand(Action action, ICondition condition)
            : base(action, condition)
        {
        }

        public Exception Exception
        {
            get => _exception;

            private set
            {
                if (Equals(value, _exception))
                {
                    return;
                }

                _exception = value;
                OnPropertyChanged();
            }
        }
    }
}");

                var compilation   = CSharpCompilation.Create("test", new[] { syntaxTree }, MetadataReferences.FromAttributes());
                var semanticModel = compilation.GetSemanticModel(syntaxTree);
                var invocation    = syntaxTree.FindInvocation("OnPropertyChanged()");

                Assert.AreEqual(AnalysisResult.Maybe, OnPropertyChanged.IsMatch(invocation, semanticModel, CancellationToken.None, out var method));
                Assert.AreEqual("Gu.Wpf.Reactive.CommandBase<object>.OnPropertyChanged(string)", method.ToString());
            }
コード例 #28
0
        public void RetrieveTicketScan(string identifier)
        {
            if (!(_identifier is null))
            {
                throw new InvalidOperationException("Already retrieved ticket scan");
            }

            if (identifier is null)
            {
                throw new ArgumentNullException(nameof(identifier), "Identifier cannot be null");
            }

            _identifier = identifier;

            if (Result?.Status == TicketScanStatus.Started)
            {
                _ticketScanUpdatedSubscription = _eventAggregator.Subscribe <TicketScanUpdated>(
                    message => OnPropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Message))));
            }
        }
コード例 #29
0
            public static void WhenTrue(string signature)
            {
                var syntaxTree = CSharpSyntaxTree.ParseText(
                    @"
namespace N
{
    using System;
    using System.ComponentModel;
    using System.Linq.Expressions;
    using System.Runtime.CompilerServices;

    public class Foo : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged<T>(Expression<Func<T>> property)
        {
            this.OnPropertyChanged(((MemberExpression)property.Body).Member.Name);
        }

        protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            this.PropertyChanged?.Invoke(this, e);
        }

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}");
                var compilation       = CSharpCompilation.Create("test", new[] { syntaxTree }, MetadataReferences.FromAttributes());
                var semanticModel     = compilation.GetSemanticModel(syntaxTree);
                var methodDeclaration = syntaxTree.FindMethodDeclaration(signature);
                var method            = semanticModel.GetDeclaredSymbol(methodDeclaration);

                Assert.AreEqual(AnalysisResult.Yes, OnPropertyChanged.IsMatch(method, semanticModel, CancellationToken.None));
            }
コード例 #30
0
            public static void OverridingEvent()
            {
                var viewModelBaseCode = CSharpSyntaxTree.ParseText(@"
namespace N
{
    using System.ComponentModel;
    using System.Runtime.CompilerServices;

    public class ViewModelBase : INotifyPropertyChanged
    {
        public virtual event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}");

                var code = CSharpSyntaxTree.ParseText(@"
namespace N
{
    using System.ComponentModel;

    public class C : N.ViewModelBase
    {
        public override event PropertyChangedEventHandler PropertyChanged;
    }
}");

                var compilation      = CSharpCompilation.Create("test", new[] { viewModelBaseCode, code }, MetadataReferences.FromAttributes());
                var semanticModel    = compilation.GetSemanticModel(code);
                var classDeclaration = code.FindClassDeclaration("ViewModel");
                var type             = semanticModel.GetDeclaredSymbol(classDeclaration);

                Assert.AreEqual(true, OnPropertyChanged.TryFind(type, semanticModel, CancellationToken.None, out var invoker));
                Assert.AreEqual("N.ViewModelBase.OnPropertyChanged(string)", invoker.ToString());
            }
コード例 #31
0
 internal void method_36(OnPropertyChanged onPropertyChanged_0)
 {
     if (this.strategy__0 != null && this.strategy__0.Status == StrategyStatus.Running)
     {
         for (int i = 0; i < this.list_0.Count; i++)
         {
             this.list_0[i].vmethod_38(onPropertyChanged_0);
         }
     }
 }