Exemplo n.º 1
0
 private EngineVersion(int[] numbers)
 {
     Invariant.ArgumentNotNull((object)numbers, "numbers");
     if (numbers.Length != 5)
     {
         throw new ArgumentException();
     }
     this.versionNumbers = numbers;
 }
Exemplo n.º 2
0
 public static void ArgumentTypeIsAssignable(Type targetType, Type sourceType, string argumentName)
 {
     Invariant.ArgumentNotNull((object)targetType, "targetType");
     Invariant.ArgumentNotNull((object)sourceType, "sourceType");
     if (!targetType.IsAssignableFrom(sourceType))
     {
         throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.TypesAreNotAssignable, new object[2] {
             (object)targetType, (object)sourceType
         }), argumentName);
     }
 }
Exemplo n.º 3
0
        public static MethodInfo GetMethod <T>(Expression <Func <T> > methodExpression)
        {
            Invariant.ArgumentNotNull((object)methodExpression, "methodExpression");
            MethodInfo memberInfo = Reflect.GetMemberInfo((LambdaExpression)methodExpression) as MethodInfo;

            object local = null;

            if (!(memberInfo == (MethodInfo)local))
            {
                return(memberInfo);
            }
            throw new ArgumentException("Expression is not a method call expression.", "memberExpression");
        }
Exemplo n.º 4
0
        public static FieldInfo GetField <T>(Expression <Func <T> > fieldExpression)
        {
            Invariant.ArgumentNotNull((object)fieldExpression, "fieldExpression");
            FieldInfo memberInfo = Reflect.GetMemberInfo((LambdaExpression)fieldExpression) as FieldInfo;

            object local = null;

            if (!(memberInfo == (FieldInfo)local))
            {
                return(memberInfo);
            }
            throw new ArgumentException("Expression is not a field access expression.", "memberExpression");
        }
Exemplo n.º 5
0
        public static PropertyInfo GetProperty <TSource, T>(Expression <Func <TSource, T> > propertyExpression)
        {
            Invariant.ArgumentNotNull((object)propertyExpression, "propertyExpression");
            PropertyInfo memberInfo = Reflect.GetMemberInfo((LambdaExpression)propertyExpression) as PropertyInfo;

            object local = null;

            if (!(memberInfo == (PropertyInfo)local))
            {
                return(memberInfo);
            }
            throw new ArgumentException("Expression is not a property access expression.", "memberExpression");
        }
Exemplo n.º 6
0
        public static void ArgumentEnumIsValidValue(Enum value, string argumentName)
        {
            Invariant.ArgumentNotNull((object)value, argumentName);
            bool flag = true;

            if (value.GetType().GetCustomAttributes(typeof(FlagsAttribute), false).Length != 0)
            {
                if (!Invariant.AreFlagsValid(value))
                {
                    flag = false;
                }
            }
            else if (!Enum.IsDefined(value.GetType(), (object)value))
            {
                flag = false;
            }
            if (!flag)
            {
                string message = string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.InvalidEnumValue, new object[2] {
                    (object)value, (object)value.GetType()
                });
                throw new ArgumentOutOfRangeException(argumentName, (object)value, message);
            }
        }
Exemplo n.º 7
0
 public static T GetAssemblyAttribute <T>(Assembly assembly) where T : Attribute
 {
     Invariant.ArgumentNotNull((object)assembly, "assembly");
     return(Attribute.GetCustomAttribute(assembly, typeof(T)) as T);
 }