コード例 #1
0
        protected Lambda(NetworkMode mode, T action)
        {
            this.Mode = mode;

            this.action = action;

            Invoke = ExpressionsUtils.GenerateDelegateFromInvoker <T>(this, LocalInvoke);
        }
コード例 #2
0
        public static void RequiredArgumentEmail <T>(this T @object, Expression <Func <string> > propertyLambda)
            where T : class
        {
            var value = (string)ExpressionsUtils.GetValue(propertyLambda);

            if (new EmailAddressAttribute().IsValid(value) == false)
            {
                ThrowArgumentException(propertyLambda, $"Not valid email = {value}", context: @object);
            }
        }
コード例 #3
0
        public static void RequiredArgumentNotDefaultValue <T, TProperty>(this T @object, Expression <Func <TProperty> > propertyLambda)
            where T : class
            where TProperty : struct
        {
            var value = ExpressionsUtils.GetValue(propertyLambda);

            if (value.Equals(default(TProperty)))
            {
                var typeParameterType = typeof(TProperty);

                ThrowArgumentException(propertyLambda: propertyLambda, message: $"{typeParameterType.Name} equals default type value = {value}", context: @object);
            }
        }
コード例 #4
0
        public static void RequiredArgumentDateIsActual <T>(this T @object, Expression <Func <DateTime> > propertyLambda, int yearDelta = 1)
            where T : class
        {
            var dateNow = DateTime.Now;

            var fromDate = dateNow.AddYears(-yearDelta);

            var toDate = dateNow.AddYears(yearDelta);

            var value = (DateTime)ExpressionsUtils.GetValue(propertyLambda);

            if (value < fromDate || value > toDate)
            {
                ThrowArgumentException(propertyLambda, $"DateTime is out of range values from = {fromDate}, to =  {toDate}", context: @object);
            }
        }
コード例 #5
0
        public static void RequiredNotNull <T, TProperty>(this T @object, Expression <Func <TProperty> > propertyLambda) where T : class
        {
            var value = ExpressionsUtils.GetValue(propertyLambda);

            if (value == null)
            {
                ThrowInvalidOperationException(propertyLambda: propertyLambda, context: @object);
            }

            var typeParameterType = typeof(TProperty);

            if (typeParameterType == typeof(string) &&
                string.IsNullOrEmpty((string)value))
            {
                ThrowInvalidOperationException(propertyLambda: propertyLambda, context: @object);
            }
        }
コード例 #6
0
        public static void RequiredArgumentEnumIsDefinedValue <T, TProperty>(this T @object, Expression <Func <TProperty> > propertyLambda)
            where T : class
            where TProperty : struct, IConvertible

        {
            if (typeof(TProperty).IsEnum == false)
            {
                throw new InvalidOperationException("TProperty must be an enumerated type");
            }

            var value = ExpressionsUtils.GetValue(propertyLambda);

            var propertyType = typeof(TProperty);

            if (Enum.IsDefined(propertyType, value) == false)
            {
                ThrowArgumentException(propertyLambda, $"Not defined {propertyType.Name} value = {value}", context: @object);
            }
        }
コード例 #7
0
        public static void RequiredListNotEmpty <T, TProperty>(this T @object, Expression <Func <IEnumerable <TProperty> > > propertyLambda)
            where T : class
        {
            RequiredNotNull(@object, propertyLambda);

            var value = ExpressionsUtils.GetValue(propertyLambda) as IEnumerable <TProperty>;

            if (value == null)
            {
                throw new InvalidOperationException($"value must be IEnumerable<{typeof(TProperty).Name}>");
            }

            if (value.Any() == false)
            {
                var typeParameterType = typeof(TProperty);

                ThrowInvalidOperationException(propertyLambda: propertyLambda, message: $"IEnumerable<{typeParameterType.Name}> must not be empty", context: @object);
            }
        }
コード例 #8
0
        private static ExceptionParameters GenerateExceptionParameters <T>(Expression <Func <T> > propertyLabmda, string message, object context)
        {
            var ret = new ExceptionParameters();

            var messageParts = new List <string>();

            ret.PropertyName = ExpressionsUtils.GetPropertyName <T>(propertyLabmda);

            messageParts.Add($"paramName: {ret.PropertyName}");

            if (string.IsNullOrEmpty(message) == false)
            {
                messageParts.Add(message);
            }

            if (context != null)
            {
                messageParts.Add($"context: {JsonConvert.SerializeObject(context)}");
            }

            ret.ExcMessage = string.Join(", ", messageParts);

            return(ret);
        }
コード例 #9
0
 public SafeEvent()
 {
     Invoke = ExpressionsUtils.GenerateDelegateFromInvoker <T>(this, InvokeAction);
 }
コード例 #10
0
        protected LambdaWrapper(T action)
        {
            this.action = action;

            Invoke = ExpressionsUtils.GenerateLambdaFromInvoker <T>(this, LocalInvoke);
        }
コード例 #11
0
 protected NetworkLambda(NetworkMode mode, T action) : base(mode, action)
 {
     NetworkHandler.Instance.Register(Receive, out Id, out Sender, out Disposer);
     agrumentTypes = ExpressionsUtils.ParameterTypesOfDelegate <T>().ToArray();
 }