summaryrefslogtreecommitdiff
path: root/Ivy/IvyBindingAttribute.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Ivy/IvyBindingAttribute.cs')
-rw-r--r--Ivy/IvyBindingAttribute.cs47
1 files changed, 33 insertions, 14 deletions
diff --git a/Ivy/IvyBindingAttribute.cs b/Ivy/IvyBindingAttribute.cs
index 90c44ce..1380f0f 100644
--- a/Ivy/IvyBindingAttribute.cs
+++ b/Ivy/IvyBindingAttribute.cs
@@ -1,31 +1,50 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
+
namespace IvyBus
{
- [AttributeUsage(AttributeTargets.Method,AllowMultiple = true)]
+ using System;
+ using System.Collections.Generic;
+ using System.Text;
+ using System.Collections.ObjectModel;
+ using System.Globalization;
+
+ [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public sealed class IvyBindingAttribute : Attribute
{
private string expression;
private string[] args;
- // translate part of expression to object property
- public string GetExpression(object obj)
+ public string Expression
{
- if (obj == null) return string.Format(expression);
- object[] values = new object[args.Length];
- for (int i = 0; i < args.Length; i++)
- {
- values[i] = obj.GetType().GetProperty(args[i]).GetValue(obj,null);
- }
- return string.Format(expression,values);
+ get { return this.expression; }
}
-
+
+ public ReadOnlyCollection<string> Args
+ {
+ get { return new ReadOnlyCollection<string>(args); }
+ }
+
public IvyBindingAttribute(string expression, params string[] args)
{
this.expression = expression;
this.args = args;
}
+
+ // translate part of expression to object property
+ public string GetFormattedExpression(object target)
+ {
+ if (target == null)
+ {
+ return string.Format(this.expression);
+ }
+
+ object[] values = new object[this.args.Length];
+ for (int i = 0; i < values.Length; i++)
+ {
+ values[i] = target.GetType().GetProperty(args[i]).GetValue(target, null);
+ }
+
+ return string.Format(this.expression, values);
+ }
}
}