Exemple #1
0
        /// <summary>
        /// Method to convert a <see cref="FrameworkElement"/> Tag to an <see cref="object"/> of <see cref="Type"/> T.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fe">An <see cref="object"/> inherited from <see cref="FrameworkElement"/>.</param>
        /// <param name="defaut">A value by default.</param>
        /// <returns>The Tag value of the element or a default value if null.</returns>
        public static T GetTag <T>(object fe, T defaut = null) where T : class
        {
            if (fe is null)
            {
                ArgumentNullException e = Exceptions.GetArgumentNull(nameof(fe), typeof(object));
                log.Error(e.Output(), e);
                throw e;
            }

            if (!fe.GetType().IsSubclassOf(typeof(FrameworkElement)))
            {
                TypeAccessException e = new TypeAccessException
                                        (
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Fotootof.Libraries.Logs.Properties.Translations.TypeAccessExceptionFrameworkElement,
                        nameof(fe),
                        fe.GetType()
                        )
                                        );
                log.Error(e.Output(), e);
                throw e;
            }

            if (defaut != null)
            {
                return((T)(fe as FrameworkElement).Tag ?? defaut);
            }
            else
            {
                return((T)(fe as FrameworkElement).Tag);
            }
        }
        /// <summary>
        /// 使用指定的原型类型初始化 <see cref="ObservableTypeProvider"/> 类的新实例。
        /// </summary>
        /// <param name="baseType">原型类型,应为接口或非密封类。</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="baseType"/> 不是公共接口,也不是公共非密封类。</exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="baseType"/> 为 <see langword="null"/>。</exception>
        private ObservableTypeProvider(Type baseType)
        {
            if (baseType is null)
            {
                throw new ArgumentNullException(nameof(baseType));
            }
            if (!(baseType.IsVisible && !baseType.IsSealed && !baseType.ContainsGenericParameters))
            {
                var inner = new TypeAccessException();
                throw new ArgumentException(inner.Message, nameof(baseType), inner);
            }

            this.BaseType           = baseType;
            this.LazyObservableType = new Lazy <Type>(this.CreateObservableType);
        }
        /// <summary>
        /// 使用指定的原型类型初始化 <see cref="DirectProxyTypeProvider"/> 类的新实例。
        /// </summary>
        /// <param name="baseType">原型类型,应为接口或非密封类。</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="baseType"/> 不是公共接口,也不是公共非密封类。</exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="baseType"/> 为 <see langword="null"/>。</exception>
        private DirectProxyTypeProvider(Type baseType)
        {
            if (baseType is null)
            {
                throw new ArgumentNullException(nameof(baseType));
            }
            if (!(baseType.IsVisible && !baseType.IsSealed && !baseType.ContainsGenericParameters))
            {
                var inner = new TypeAccessException();
                throw new ArgumentException(inner.Message, nameof(baseType), inner);
            }

            this.BaseType         = baseType;
            this.LazyProxyType    = new Lazy <Type>(this.CreateProxyType);
            this.LazyHandlerField = new Lazy <FieldInfo>(this.FindHandlerField);
        }
 static void TestCall(int v, Type p1, TypeAccessException p2)
 {
     Console.WriteLine("TestCall without params");
 }