summaryrefslogtreecommitdiff
path: root/Ivy/IvyBindingAttribute.cs
diff options
context:
space:
mode:
authorfcolin2008-08-22 16:44:01 +0000
committerfcolin2008-08-22 16:44:01 +0000
commit8d10e8bbd1e19adc7c70e1101dbb69c213c910dd (patch)
treef41034ab66b1b3174277b07c8aa45791dadbaae8 /Ivy/IvyBindingAttribute.cs
parent7053d3d604920ab708076e107be4b55666c5af80 (diff)
downloadivy-csharp-8d10e8bbd1e19adc7c70e1101dbb69c213c910dd.zip
ivy-csharp-8d10e8bbd1e19adc7c70e1101dbb69c213c910dd.tar.gz
ivy-csharp-8d10e8bbd1e19adc7c70e1101dbb69c213c910dd.tar.bz2
ivy-csharp-8d10e8bbd1e19adc7c70e1101dbb69c213c910dd.tar.xz
optimisation for parsing same regular expression from multiple client
using fxCop for code beauty fix bug on concurrent connect
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);
+ }
}
}