void XPropertyChangeListener.propertyChange(PropertyChangeEvent evt)
 {
     if (PropertyChange != null)
     {
         try
         {
             PropertyChange.Invoke(this, new ForwardedEventArgs(evt));
         }
         catch (Exception e)
         {
             Logger.Instance.Log(LogPriority.ALWAYS, this, "[ERROR] Could not forward property change event: " + e);
         }
     }
 }
示例#2
0
        public static void TryInvoke <TOwner, TValue>(
            this PropertyChange <TOwner, TValue> @this,
            DependencyObject dependencyObject,
            DependencyPropertyChangedEventArgs args)
            where TOwner : DependencyObject
        {
            if (!(dependencyObject is TOwner))
            {
                throw new InvalidCastException(
                          $"The \'dependencyObject\' argument must be of type \'{typeof(TOwner).Name}\'.");
            }
            var owner = (TOwner)dependencyObject;

            @this?.Invoke(owner, new DPChangedEventArgs <TValue>(args));
        }
示例#3
0
        private void HandlePropertyChange(MpvEvent @event)
        {
            if (PropertyChange == null)
            {
                return;
            }

            var eventProperty = @event.MarshalDataToStruct <MpvEventProperty>();

            if (eventProperty.HasValue)
            {
                var replyUserData = @event.ReplyUserData;

                var eventArgs = new MpvPropertyChangeEventArgs(replyUserData, eventProperty.Value);
                PropertyChange.Invoke(this, eventArgs);
            }
        }
示例#4
0
        /// <summary>
        /// ?操作符用于在执行成员访问 (?.) 或索引 (?[) 操作之前,测试是否存在 NULL。
        /// 这些运算符可帮助编写更少的代码来处理 null 检查,尤其是对于下降到数据结构。
        /// </summary>
        public void Fun1()
        {
            ArrayList list = null;
            int?      len  = list?.Count;//null if list is null

            Console.WriteLine("length:" + len);

            string item = list?[0].ToString();//最后一个示例演示 NULL 条件运算符会短路。 如果条件成员访问和索引操作链中的某个操作返回 NULL,则该链其余部分的执行将停止。

            Console.WriteLine("item:" + len);

            //NULL 条件成员访问的另一个用途是使用非常少的代码以线程安全的方式调用委托。
            //旧方法需要如下所示的代码:
            PropertyChange handler = null;

            if (handler != null)
            {
                handler.Invoke("hello world");
            }
            //新的方法是要简单得多:
            PropertyChange handler2 = null;

            handler2?.Invoke("hello world");
        }
示例#5
0
 public static void TryInvoke <D, T>(this PropertyChange <D, T> i, DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) where D : DependencyObject
 {
     i?.Invoke((D)dependencyObject, new DPChangedEventArgs <T>(e));
 }