You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
XmlReader.IsStartElement namespace argument should allow null #41461
Calling the last overload with ns == null doesn't act like calling the middle overload. In other places in XmlReader, the "namespace" parameter is optional and marked with string?, but this one is being annotated as non-nullable because if you passed in null, it would always return false.
I don't think it should treat string localname (local name) as string name (qualified name) just because string ns is null.
If I'm writing an XML deserializer that should compare expanded names regardless of which namespace prefix is used, then I should avoid IsStartElement(string name) and instead use IsStartElement(string localname, string ns). But if ns == null causes the latter to behave like the former, then it will be harder for me to be sure I did it right. I don't think there is a scenario in which the caller of IsStartElement would want a runtime decision on whether to use Namespaces in XML semantics or not.
So, for IsStartElement(localname, ns: null), my order of preference would be:
Return false regardless of localName -- current implementation, no compatibility risk, easy to document
Throw ArgumentNullException -- consistent with XNamespace.GetName, but would be a breaking change
Same as IsStartElement(localName, ns: string.Empty) -- seems inconsistent with existing APIs
Same as IsStartElement(name: localName) -- does not seem useful; consistent with undocumented behavior of XmlWriter.WriteStartElement(string localName, string ns)
If the treatment of string ns in XmlReader.IsStartElement is changed, then XmlReader.ReadStartElement should be changed similarly.
@eerhardt I generally agree with @KalleOlaviNiemitalo + what I wrote above, I'm leaning toward closing this as "won't fix" given the confusion this would cause. Please re-open if you feel strongly about fixing this.
Activity
krwq commentedon Aug 28, 2020
@eerhardt one thing to note is that in case of overload without namespace the namespace is ignored. In case of this overload null may mean:
IsStartElement(string)would dowe should figure out how to interpret that and do some research on what customers would expect
KalleOlaviNiemitalo commentedon Aug 29, 2020
I don't think it should treat
string localname(local name) asstring name(qualified name) just becausestring nsisnull.If I'm writing an XML deserializer that should compare expanded names regardless of which namespace prefix is used, then I should avoid
IsStartElement(string name)and instead useIsStartElement(string localname, string ns). But ifns == nullcauses the latter to behave like the former, then it will be harder for me to be sure I did it right. I don't think there is a scenario in which the caller ofIsStartElementwould want a runtime decision on whether to use Namespaces in XML semantics or not.So, for
IsStartElement(localname, ns: null), my order of preference would be:falseregardless oflocalName-- current implementation, no compatibility risk, easy to documentArgumentNullException-- consistent withXNamespace.GetName, but would be a breaking changeIsStartElement(localName, ns: string.Empty)-- seems inconsistent with existing APIsIsStartElement(name: localName)-- does not seem useful; consistent with undocumented behavior ofXmlWriter.WriteStartElement(string localName, string ns)If the treatment of
string nsinXmlReader.IsStartElementis changed, thenXmlReader.ReadStartElementshould be changed similarly.krwq commentedon Nov 19, 2020
@eerhardt I generally agree with @KalleOlaviNiemitalo + what I wrote above, I'm leaning toward closing this as "won't fix" given the confusion this would cause. Please re-open if you feel strongly about fixing this.