namespace IvyBus { 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; public string Expression { get { return this.expression; } set { this.expression = value; } } public ReadOnlyCollection Args { get { return new ReadOnlyCollection(args); } } public IvyBindingAttribute(string expression, params string[] args) { this.expression = expression; this.args = args; } public IvyBindingAttribute() { this.expression = ""; this.args = null; } // translate part of expression to object property public string GetFormattedExpression(object target) { if (target == null || args == 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); } } }