From 9d6e262d795a04d42a6113f97cf8f614c8cdb2c5 Mon Sep 17 00:00:00 2001 From: ayende Date: Fri, 13 Jul 2007 15:47:31 +0000 Subject: [PATCH] Allowing Null Propagation for ?error.Foo.Bar git-svn-id: https://svn.castleproject.org/svn/castle/trunk@4050 73e77b4c-caa6-f847-a29a-24ab75ae54b6 --- .../BrailBasicFunctionality.cs | 10 ++++-- .../XmlTestCase.cs | 40 +++++++++++----------- MonoRail/Castle.MonoRail.Views.Brail/BrailBase.cs | 2 +- MonoRail/Castle.MonoRail.Views.Brail/IgnoreNull.cs | 19 ++++++---- .../TestSiteBrail/Controllers/HomeController.cs | 5 +++ MonoRail/TestSiteBrail/TestSiteBrail.csproj | 1 + .../TestSiteBrail/Views/home/NullPropagation.brail | 3 ++ 7 files changed, 51 insertions(+), 29 deletions(-) create mode 100644 MonoRail/TestSiteBrail/Views/home/NullPropagation.brail diff --git a/MonoRail/Castle.MonoRail.Views.Brail.Tests/BrailBasicFunctionality.cs b/MonoRail/Castle.MonoRail.Views.Brail.Tests/BrailBasicFunctionality.cs index cf424fa90..5d33a1296 100644 --- a/MonoRail/Castle.MonoRail.Views.Brail.Tests/BrailBasicFunctionality.cs +++ b/MonoRail/Castle.MonoRail.Views.Brail.Tests/BrailBasicFunctionality.cs @@ -247,8 +247,14 @@ Contents for heyhello View public void DuckOverloadToString() { DoGet("home/DuckOverloadToString.rails"); - AssertReplyEqualTo("20-12-1981"); - + AssertReplyEqualTo("20-12-1981"); + } + + [Test] + public void NullPropagation() + { + DoGet("home/NullPropagation.rails"); + AssertReplyIsBlank(); } } } diff --git a/MonoRail/Castle.MonoRail.Views.Brail.Tests/XmlTestCase.cs b/MonoRail/Castle.MonoRail.Views.Brail.Tests/XmlTestCase.cs index f7334823d..590778232 100644 --- a/MonoRail/Castle.MonoRail.Views.Brail.Tests/XmlTestCase.cs +++ b/MonoRail/Castle.MonoRail.Views.Brail.Tests/XmlTestCase.cs @@ -14,16 +14,16 @@ namespace Castle.MonoRail.Views.Brail.Tests { - using Castle.MonoRail.Framework.Tests; - using NUnit.Framework; + using Castle.MonoRail.Framework.Tests; + using NUnit.Framework; - [TestFixture] - public class XmlTestCase : AbstractTestCase - { - [Test] - public void ComplexXml() - { - string expected = @" + [TestFixture] + public class XmlTestCase : AbstractTestCase + { + [Test] + public void ComplexXml() + { + string expected = @" 0,1,2,3,4,5,6,7,8,9, html string
    @@ -35,16 +35,16 @@ html string
  1. 2
"; - DoGet("Xml/Complex.rails"); - AssertReplyEqualTo(expected); - } + DoGet("Xml/Complex.rails"); + AssertReplyEqualTo(expected); + } - [Test] - public void PureXml() - { - string expected = "0,1,2,3,4,5,6,7,8,9,"; - DoGet("Xml/Pure.rails"); - AssertReplyEqualTo(expected); - } - } + [Test] + public void PureXml() + { + string expected = "0,1,2,3,4,5,6,7,8,9,"; + DoGet("Xml/Pure.rails"); + AssertReplyEqualTo(expected); + } + } } diff --git a/MonoRail/Castle.MonoRail.Views.Brail/BrailBase.cs b/MonoRail/Castle.MonoRail.Views.Brail/BrailBase.cs index deab92692..634bdc2cf 100644 --- a/MonoRail/Castle.MonoRail.Views.Brail/BrailBase.cs +++ b/MonoRail/Castle.MonoRail.Views.Brail/BrailBase.cs @@ -204,7 +204,7 @@ namespace Castle.MonoRail.Views.Brail public object TryGetParameter(string name) { ParameterSearch search = GetParameterInternal(name); - return search.Value; + return new IgnoreNull(search.Value); } /// diff --git a/MonoRail/Castle.MonoRail.Views.Brail/IgnoreNull.cs b/MonoRail/Castle.MonoRail.Views.Brail/IgnoreNull.cs index 4fa31cce8..18b14e494 100644 --- a/MonoRail/Castle.MonoRail.Views.Brail/IgnoreNull.cs +++ b/MonoRail/Castle.MonoRail.Views.Brail/IgnoreNull.cs @@ -30,32 +30,39 @@ namespace Castle.MonoRail.Views.Brail public object QuackGet(string name, object[] parameters) { if (target == null) - return null; + return this; PropertyInfo property = target.GetType().GetProperty(name); if (property == null) throw new RailsException("Could not find property " + name + " on " + target.GetType().FullName); - return property.GetValue(target, parameters); + return new IgnoreNull(property.GetValue(target, parameters)); } public object QuackSet(string name, object[] parameters, object obj) { if (target == null) - return null; + return this; PropertyInfo property = target.GetType().GetProperty(name); if (property == null) throw new RailsException("Could not find property " + name + " on " + target.GetType().FullName); property.SetValue(target, obj, parameters); - return null; + return this; } public object QuackInvoke(string name, object[] args) { if (target == null) - return null; + return this; MethodInfo method = target.GetType().GetMethod(name); if (method == null) throw new RailsException("Could not find method " + name + " on " + target.GetType().FullName); - return method.Invoke(target, args); + return new IgnoreNull(method.Invoke(target, args)); + } + + public override string ToString() + { + if(target == null) + return string.Empty; + return target.ToString(); } } } diff --git a/MonoRail/TestSiteBrail/Controllers/HomeController.cs b/MonoRail/TestSiteBrail/Controllers/HomeController.cs index 9d3ef6ef2..d0e19120f 100644 --- a/MonoRail/TestSiteBrail/Controllers/HomeController.cs +++ b/MonoRail/TestSiteBrail/Controllers/HomeController.cs @@ -170,6 +170,11 @@ namespace Castle.MonoRail.Views.Brail.TestSite.Controllers { PropertyBag["birthday"] = new DateTime(1981, 12, 20); } + + public void NullPropagation() + { + + } } } diff --git a/MonoRail/TestSiteBrail/TestSiteBrail.csproj b/MonoRail/TestSiteBrail/TestSiteBrail.csproj index d1ff8b82a..41b99c1a6 100644 --- a/MonoRail/TestSiteBrail/TestSiteBrail.csproj +++ b/MonoRail/TestSiteBrail/TestSiteBrail.csproj @@ -209,6 +209,7 @@ + diff --git a/MonoRail/TestSiteBrail/Views/home/NullPropagation.brail b/MonoRail/TestSiteBrail/Views/home/NullPropagation.brail new file mode 100644 index 000000000..8db820ef4 --- /dev/null +++ b/MonoRail/TestSiteBrail/Views/home/NullPropagation.brail @@ -0,0 +1,3 @@ +<% +output ?error.Foo.Bar +%> \ No newline at end of file -- 2.11.4.GIT