-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented interface for text-links #16
Conversation
Thanks for your PR! I got your point, but when thinking about your goal twice, I'm wondering if it makes much contribution. Before going through my justifications, could you please share with me a bit with your actual usage scenario? Perhaps we can find another way to make your days better 😀 The major issue here is that
For Then what you are proposing is basically a "Type Class" (c.f. dotnet/csharplang#110, or
But please also note that C# originated from the concept of OOP. I suggest that for now we do not add the interface until we can see there is enough common traits that we can abstract based on, since OOP is representing objects with abstrations (classes and interfaces). |
Thank you for the detailed response! You made me overthink some stuff. I'm extracting all links from a page and store them inside a collection. To make it easier I introduced |
Sometimes the line is pretty blurred. This is why I thought it could be helpful if you can share your usage scenario. I have been wondering all the time "how are you consuming this
Okay so with some C# 8 language features (basic pattern matching), you can write something like this (string text, string target) ParseLink(InlineNode linkNode) {
switch (someNode) {
case WikiLink wikilink:
return (wikilink.Text.ToString(), GetFullUrl(wikilink.Target.ToString());
case ExternalLink externalLink:
return (externalLink.Text.ToString(), externalLink.Target.ToString());
default:
throw new ArgumentException("Expect link node.", nameof(linkNode));
} Note that I'm using parseLink(linkNode: WikiLink | ExternalLink): [text: string, target: string] But no, not for C#. We need to wait for dotnet/csharplang#3737, instead of introducing interfaces only in order to represent such type union rather than an abstraction of certain trait. Otherwise things could get very awkward. As for MwParserFromScratch/MwParserFromScratch/Nodes/Wikitext.cs Lines 78 to 106 in 5f47c6f
In the implementation of the methods above, I care about what are in the If your usage scenario is similar to this, introducing an interface should help. But then that interface could be |
Yes, I also thought about the detection of the actual link-type, since the target is handled completely different. A interface would be not a clear approach here, that's also why I wrote a wrapper class, I'm much more happy with this solution now. Thanks for taking your time to explain all those things! |
Just added a small interface to make it more comfortable to work with text links from outside.