/// <summary>
        /// Gets the value of the DataValue, or the specified default value.
        /// </summary>
        /// <typeparam name="T">The expected type.</typeparam>
        /// <param name="dataValue">A DataValue</param>
        /// <param name="defaultValue">A default value.</param>
        /// <returns>The value if an instance of the specified Type, otherwise the specified default value.</returns>
        public static T GetValueOrDefault <T>(this DataValue dataValue, T defaultValue)
        {
            var value = dataValue.GetValue();

            if (value != null)
            {
                if (typeof(T).GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo()))
                {
                    return((T)value);
                }
            }

            return(defaultValue);
        }
示例#2
0
        /// <summary>
        /// Gets the value of the DataValue, or the specified default value.
        /// </summary>
        /// <typeparam name="T">The expected type.</typeparam>
        /// <param name="dataValue">A DataValue</param>
        /// <param name="defaultValue">A default value.</param>
        /// <returns>The value, if an instance of the specified Type, otherwise the specified default value.</returns>
        public static T GetValueOrDefault <T>(this DataValue dataValue, T defaultValue)
        {
            var value = dataValue.GetValue();

            if (value != null)
            {
                if (value is T)
                {
                    return((T)value);
                }
            }

            return(defaultValue);
        }
        /// <summary>
        /// Gets the value of the DataValue, or the type's default value.
        /// </summary>
        /// <param name="dataValue">A DataValue</param>
        /// <param name="dataType">The expected type.</param>
        /// <param name="defaultValue">A default value.</param>
        /// <returns>The value if an instance of the specified Type, otherwise the specified default value.</returns>
        public static object GetValueOrDefault(this DataValue dataValue, Type dataType, object defaultValue)
        {
            var value = dataValue.GetValue();

            if (value != null)
            {
                if (dataType.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo()))
                {
                    return(value);
                }
            }

            return(defaultValue);
        }
        public static T GetValueOrDefault <T>(this DataValue dataValue)
        {
            var value = dataValue.GetValue();

            if (value != null)
            {
                if (value is T)
                {
                    return((T)value);
                }
            }

            // While [MaybeNull] attribute signals to the caller
            // that the return value can be null. It is ignored
            // by the compiler inside of the method, hence we
            // have to use the bang operator.
            return(default !);
        /// <summary>
        /// Gets the value of the DataValue, or the default value of the type.
        /// </summary>
        /// <param name="dataValue">A DataValue</param>
        /// <param name="dataType">A data type.</param>
        /// <returns>The value if an instance of the specified Type, otherwise the Type's default value.</returns>
        public static object GetValueOrDefault(this DataValue dataValue, Type dataType)
        {
            var value = dataValue.GetValue();

            if (value != null)
            {
                if (dataType.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo()))
                {
                    return(value);
                }
            }

            if (dataType.GetTypeInfo().IsValueType)
            {
                return(Activator.CreateInstance(dataType));
            }
            else
            {
                return(null);
            }
        }
 public override void Publish(DataValue dataValue)
 {
     this.Property.SetValue(this.Target, dataValue.GetValue());
     base.Publish(dataValue);
 }
示例#7
0
 public override void Publish(object target, DataValue dataValue)
 {
     this.Property.SetValue(target, dataValue.GetValue());
     base.Publish(target, dataValue);
 }
示例#8
0
 public override void Publish(DataValue dataValue)
 {
     this.Property.SetValue(this.Target, dataValue.GetValue());
     this.SetDataErrorInfo(dataValue.StatusCode);
 }