Пример #1
0
        /// <summary>
        /// Gets the creation expression used to produce a <see cref="TypeRegistration"/> during
        /// <see cref="TraceListenerData.GetRegistrations"/>.
        /// </summary>
        /// <remarks>
        /// This must be overridden by a subclass, but is not marked as abstract due to configuration serialization needs.
        /// </remarks>
        /// <returns>A <see cref="Expression"/> that creates a <see cref="TraceListener"/></returns>
        /// <exception cref="ArgumentException">Throws an argument exception if it cannot locate an appropriate constructor for the <see cref="NameTypeConfigurationElement.Type"/>.</exception>
        protected override Expression <Func <TraceListener> > GetCreationExpression()
        {
            Expression <Func <TraceListener> > expression;

            Type[]       constructorParameters = new Type[0];
            Expression[] expressionArguments   = new Expression[0];

            if (!string.IsNullOrEmpty(InitData))
            {
                constructorParameters = new Type[] { InitData.GetType() };
                expressionArguments   = new Expression[] { Expression.Constant(InitData) };
            }

            ConstructorInfo constructor = GetConstructor(constructorParameters);

            expression =
                Expression.Lambda <Func <TraceListener> >(
                    Expression.New(
                        constructor,
                        expressionArguments)
                    );

            return(expression);
        }