Anduin2017 / Anduin2017/HSharp

HDoc的索引器是否不妥呢

Open
#7 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
70
Forks
20
PR merge metrics
No merged PRs in 30d

Description

大佬您好,经常在油管看到您的视频学习,受益匪浅
我也是一名C# .NET 的死忠粉

看到项目比较感兴趣,拜读了一下您的代码
关于HDoc获取元素的地方,略有不同看法,请允许在下想发表一点愚见。

  • 在解析时候,是否应该除List以外,再用一个Dictionary来做索引,
    以提高按名称查找的效率,
    每次都Children.Find(t => t.TagName == tagName);
    会全局遍历,元素多的时候是否会性能不佳呢。

  • 关于索引器中的处理,HTag this[string tagName],HTag this[int tagIndex]
    这2个索引器中没有做任何异常处理,如果是示例中的连续调用(newDocument["html"]["head"]["meta",0])
    如果填错了名字或者索引,造成了空指针或者越界异常,不太容易查找错误地点。
    是否应该throw明确的异常信息,是哪个名字错了,或者哪个索引错了。

  • 可能是我个人的爱好
    个人感觉["meta"][0], 要比["meta",0], 更具有可读性。

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining HTag's string and integer indexers and the Children.Find lookup described in the issue. Compare the proposed dictionary index, explicit exception messages, and alternative indexer syntax, then clarify which behavior is intended before implementation; done should include an agreed scope and corresponding behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, html
Domain
tooling, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.