public PropertyDeclaration AddProperty(
            FieldDeclaration f,
            bool hasGet,
            bool hasSet,
            bool checkNonNull
            )
        {
            var p = AddProperty(
                f.Type,
                Conformer.ToCapitalized(f.Name));

            if (hasGet)
            {
                p.Get.Return(Expr.This.Field(f));
            }
            if (hasSet)
            {
                if (checkNonNull)
                {
                    var 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);
        }
Example #2
0
 static public ConditionStatement ThrowIfNull(Expression condition, Expression toThrow)
 {
     return(IfNull(condition,
                   Stm.Throw(toThrow)
                   ));
 }