/// <summary> /// Добавить элемент. /// </summary> public void Add(Category category) { int idx = InnerList.BinarySearch(category, _comparer); if (idx >= 0) return; List.Insert(-idx - 1, category); }
/// <summary> /// Инициализирует экземпляр. /// </summary> protected ItemBase(string name, Category parent) { _parent = parent; _name = name; if (_name != null) { string[] parts = _name.Split('.'); _shortName = parts[parts.Length - 1]; } }
/// <summary> /// Получить индекс элемента. /// </summary> public int IndexOf(Category cat) { return List.IndexOf(cat); }
/// <summary> /// Инициализирует экземпляр. /// </summary> public ResourceItem(string name, Category parent) : base(name, parent) { }
private Category FindCategory(Category startCategory, string[] parts) { if (parts.Length == 0) return startCategory; Category ic = null; foreach (Category c in startCategory.Categories) if (c.ShortName == parts[0]) { ic = c; break; } if (ic == null) { string prefix = startCategory.Name != null ? startCategory.Name + '.' : ""; ic = new Category(prefix + parts[0], startCategory); startCategory.Categories.Add(ic); } string[] sa = new string[parts.Length - 1]; Array.Copy(parts, 1, sa, 0, sa.Length); return FindCategory(ic, sa); }
private static void GenerateCategory(IList memberList, Category cat, string rmType, bool isInternal) { var rc = cat as RootCategory; var ctd = new CodeTypeDeclaration(rc == null ? cat.ShortName : rc.TreeName) {IsPartial = true}; if (isInternal) { ctd.TypeAttributes = TypeAttributes.NestedAssembly; // для внутренних типов должен остаться public isInternal = false; } ctd.IsClass = true; memberList.Add(ctd); if (rmType == null) { var rmField = new CodeMemberField(typeof (ResourceManager),_rmFieldName) { Attributes = MemberAttributes.Public | MemberAttributes.Static | MemberAttributes.Final, InitExpression = new CodePrimitiveExpression(null) }; ctd.Members.Add(rmField); var rmProp = new CodeMemberProperty { Name = _rmPropertyName, Type = new CodeTypeReference(typeof (ResourceManager)), Attributes = (MemberAttributes.Public | MemberAttributes.Static | MemberAttributes.Final) }; var cmrs = new CodeMethodReturnStatement( new CodeFieldReferenceExpression(null, _rmFieldName)); rmProp.GetStatements.Add(cmrs); rmProp.SetStatements.Add( new CodeAssignStatement( new CodeFieldReferenceExpression(null, _rmFieldName), new CodeVariableReferenceExpression("value"))); ctd.Members.Add(rmProp); rmType = rc.TreeName; } foreach (ResourceItem ri in cat.ResourceItems) { var cmf = new CodeMemberField(typeof (string), ri.ShortName + _resNameFieldPostfix) { Attributes = (MemberAttributes.Const | MemberAttributes.Public), InitExpression = new CodePrimitiveExpression(ri.Name) }; ctd.Members.Add(cmf); var cmp = new CodeMemberProperty { Name = ri.ShortName, Type = new CodeTypeReference(typeof (string)), Attributes = (MemberAttributes.Static | MemberAttributes.Public) }; var cmrs = new CodeMethodReturnStatement( new CodeMethodInvokeExpression( new CodePropertyReferenceExpression( new CodeTypeReferenceExpression(rmType), _rmPropertyName), "GetString", new CodeFieldReferenceExpression(null, ri.ShortName + _resNameFieldPostfix) )); cmp.GetStatements.Add(cmrs); ctd.Members.Add(cmp); } foreach (Category c in cat.Categories) GenerateCategory(ctd.Members, c, rmType, isInternal); }
/// <summary> /// Инициализирует экземпляр. /// </summary> public Category(string name, Category parent) : base(name, parent) { }
internal void DeleteCategory(Category category) { int idx = _categories.IndexOf(category); if (idx == -1) return; _categories.RemoveAt(idx); DeleteIfEmpty(); }