using System; namespace IcecreamView { [AttributeUsage(AttributeTargets.Field)] public class BindUIPath : Attribute { public string Path; private string ItemPath; private int StartIndex; public bool IsArray; /// /// 绑定一个UI控件 /// /// 控件相对该组件对应的相对地址 public BindUIPath(string path) { this.IsArray = false; this.Path = path; } /// /// 绑定一个List类型的UI控件 /// /// 该list的根节点路径 /// 每个item的路径,如果有递增类型的值请使用{n}关键字代替递增数字, *代表根节点下的所有对象 /// 递增值的初始值,默认为0 public BindUIPath(string path, string itemPath , int startIndex = 0 ) { this.IsArray = true; if (itemPath == null) { itemPath = "*"; } this.Path = path; this.ItemPath = itemPath; this.StartIndex = startIndex; } public string GetElementPath(int Index) { if (this.IsArray) { return this.ItemPath.Replace("{n}", Index + this.StartIndex + ""); } return null; } } }