private EngineVersion(int[] numbers) { Invariant.ArgumentNotNull((object)numbers, "numbers"); if (numbers.Length != 5) { throw new ArgumentException(); } this.versionNumbers = numbers; }
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); } }
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)); }
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"); }
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"); }
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"); }
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); }
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); } }
public static T GetAssemblyAttribute <T>(Assembly assembly) where T : Attribute { Invariant.ArgumentNotNull((object)assembly, "assembly"); return(Attribute.GetCustomAttribute(assembly, typeof(T)) as T); }
protected void RegisterDisposable(IDisposable disposable) { Invariant.ArgumentNotNull((object)disposable, "disposable"); this.VerifyAccess(); this.disposables.Add(disposable); }