コード例 #1
0
ファイル: EngineVersion.cs プロジェクト: phspies/OculiService
 private EngineVersion(int[] numbers)
 {
     Invariant.ArgumentNotNull((object)numbers, "numbers");
     if (numbers.Length != 5)
     {
         throw new ArgumentException();
     }
     this.versionNumbers = numbers;
 }
コード例 #2
0
ファイル: Invariant.cs プロジェクト: phspies/OculiService
 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);
     }
 }
コード例 #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");
        }
コード例 #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");
        }
コード例 #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");
        }
コード例 #6
0
ファイル: Invariant.cs プロジェクト: phspies/OculiService
        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);
            }
        }
コード例 #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);
 }