예제 #1
0
 private EngineVersion(int[] numbers)
 {
     Invariant.ArgumentNotNull((object)numbers, "numbers");
     if (numbers.Length != 5)
     {
         throw new ArgumentException();
     }
     this.versionNumbers = numbers;
 }
예제 #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);
     }
 }
예제 #3
0
        protected virtual void OnPropertyChanged(PropertyChangedEventInfo info)
        {
            Invariant.ArgumentNotNull((object)info, "info");
            this.propertyChangedSubject.OnNext(info);
            PropertyChangedEventHandler propertyChanged = this.PropertyChanged;

            if (propertyChanged == null)
            {
                return;
            }
            propertyChanged((object)this, new PropertyChangedEventArgs(info.PropertyName));
        }
예제 #4
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");
        }
예제 #5
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");
        }
예제 #6
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");
        }
예제 #7
0
        protected bool SetValue <T>(ref T backingField, T value, [CallerMemberName] string propertyName = null)
        {
            Invariant.ArgumentNotNull((object)propertyName, "propertyName");
            this.VerifyAccess();
            if (EqualityComparer <T> .Default.Equals(backingField, value))
            {
                return(false);
            }
            PropertyChangedEventInfo <T> changedEventInfo = new PropertyChangedEventInfo <T>((object)this, propertyName, backingField, value);

            backingField = value;
            this.OnPropertyChanged((PropertyChangedEventInfo)changedEventInfo);
            return(true);
        }
예제 #8
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);
            }
        }
예제 #9
0
 public static T GetAssemblyAttribute <T>(Assembly assembly) where T : Attribute
 {
     Invariant.ArgumentNotNull((object)assembly, "assembly");
     return(Attribute.GetCustomAttribute(assembly, typeof(T)) as T);
 }
예제 #10
0
 protected void RegisterDisposable(IDisposable disposable)
 {
     Invariant.ArgumentNotNull((object)disposable, "disposable");
     this.VerifyAccess();
     this.disposables.Add(disposable);
 }