1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Views
.Brail
18 using System
.Collections
.Generic
;
21 public class IgnoreNull
: IQuackFu
23 private readonly object target
;
25 public IgnoreNull(object target
)
30 public object QuackGet(string name
, object[] parameters
)
35 if (IsNullOrEmpty(parameters
))
36 value = ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods
.GetProperty(target
, name
);
38 value = ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods
.GetSlice(target
, name
, parameters
);
39 return new IgnoreNull(value);
42 private static bool IsNullOrEmpty(object[] parameters
)
44 return parameters
== null || parameters
.Length
== 0;
47 public object QuackSet(string name
, object[] parameters
, object obj
)
51 if (IsNullOrEmpty(parameters
))
52 ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods
.SetProperty(target
, name
, obj
);
54 ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods
.SetSlice(target
, name
, GetParameterArray(parameters
, obj
));
58 private static object[] GetParameterArray(object[] parameters
, object obj
)
60 List
<object> args
= new List
<object>(parameters
);
62 return args
.ToArray();
65 public object QuackInvoke(string name
, object[] args
)
69 object value = ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods
.Invoke(target
, name
, args
);
70 return new IgnoreNull(value);
73 public override string ToString()
77 return target
.ToString();
80 public static bool AreEqual(object left
, object right
)
82 IgnoreNull temp
= left
as IgnoreNull
;
85 temp
= right
as IgnoreNull
;
88 return Equals(left
, right
);