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
.Framework
.Views
.NVelocity
17 using System
.Reflection
;
20 /// Provides a helper to access static operations on types to NVelocity.
22 /// <typeparam name="T">the type to access</typeparam>
23 public class StaticAccessorHelper
<T
> : global::NVelocity
.IDuck
28 /// Invoke a get operation on the value type
30 /// <param name="propName">the property or field to get</param>
31 /// <returns>the value</returns>
32 public object GetInvoke(string propName
)
35 typeof (T
).InvokeMember(propName
,
36 BindingFlags
.Public
| BindingFlags
.Static
| BindingFlags
.GetField
|
37 BindingFlags
.GetProperty
,
38 null, null, new object[] {});
42 /// Invoke a method on the value type
44 /// <param name="method">the method name</param>
45 /// <param name="args">the argumenents.</param>
46 /// <returns>the result of the method invocation.</returns>
47 public object Invoke(string method
, params object[] args
)
50 typeof (T
).InvokeMember(method
, BindingFlags
.Public
| BindingFlags
.Static
| BindingFlags
.InvokeMethod
,
55 /// Invoke a set operation on the value type
57 /// <param name="propName">the property or field to set</param>
58 /// <param name="value">the value to set the property or field to.</param>
59 public void SetInvoke(string propName
, object value)
61 typeof (T
).InvokeMember(propName
,
62 BindingFlags
.Public
| BindingFlags
.Static
| BindingFlags
.SetField
|
63 BindingFlags
.SetProperty
,
64 null, null, new object[] {value}
);