static public ConditionStatement ThrowIfNull(Expression condition, Expression toThrow) { if (condition == null) { throw new ArgumentNullException("condition"); } if (toThrow == null) { throw new ArgumentNullException("toThrow"); } return(IfNull(condition, Stm.Throw(toThrow) )); }
public PropertyDeclaration AddProperty( FieldDeclaration f, string name, bool hasGet, bool hasSet, bool checkNonNull ) { PropertyDeclaration p = this.AddProperty( f.Type, name); if (hasGet) { p.Get.Return(Expr.This.Field(f)); } if (hasSet) { if (checkNonNull) { ConditionStatement ifnull = Stm.If(Expr.Value.Identity(Expr.Null)); p.Set.Add(ifnull); ifnull.TrueStatements.Add( Stm.Throw(typeof(ArgumentNullException)) ); p.SetExceptions.Add(new ThrowedExceptionDeclaration( typeof(ArgumentNullException), "value is a null reference" )); } p.Set.Add( Stm.Assign( Expr.This.Field(f), Expr.Value ) ); } return(p); }