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
)
32 if (name
== "_IsIgnoreNullReferencingNotNullObject_")
33 return target
!= null;
38 if (IsNullOrEmpty(parameters
))
39 value = ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods
.GetProperty(target
, name
);
41 value = ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods
.GetSlice(target
, name
, parameters
);
42 return new IgnoreNull(value);
45 private static bool IsNullOrEmpty(object[] parameters
)
47 return parameters
== null || parameters
.Length
== 0;
50 public object QuackSet(string name
, object[] parameters
, object obj
)
54 if (IsNullOrEmpty(parameters
))
55 ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods
.SetProperty(target
, name
, obj
);
57 ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods
.SetSlice(target
, name
, GetParameterArray(parameters
, obj
));
61 private static object[] GetParameterArray(object[] parameters
, object obj
)
63 List
<object> args
= new List
<object>(parameters
);
65 return args
.ToArray();
68 public object QuackInvoke(string name
, object[] args
)
72 object value = ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods
.Invoke(target
, name
, args
);
73 return new IgnoreNull(value);
76 public override string ToString()
80 return target
.ToString();
83 public static bool AreEqual(object left
, object right
)
85 IgnoreNull temp
= left
as IgnoreNull
;
88 temp
= right
as IgnoreNull
;
91 return Equals(left
, right
);