From 8d10e8bbd1e19adc7c70e1101dbb69c213c910dd Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 22 Aug 2008 16:44:01 +0000 Subject: optimisation for parsing same regular expression from multiple client using fxCop for code beauty fix bug on concurrent connect --- Ivy/IvyBindingAttribute.cs | 47 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'Ivy/IvyBindingAttribute.cs') 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 Args + { + get { return new ReadOnlyCollection(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); + } } } -- cgit v1.1