-
Notifications
You must be signed in to change notification settings - Fork 347
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
Design and extend "IScopedNode" #2894
Comments
This was referenced Oct 9, 2024
Kas and I decided to call it "IScopedNode" for now, since it is still basically ITypedElement + more stuff - Definition. |
Merged
Merged
Final design:
|
record ScopedNode<T>(T[] Poco) : ITypedElement where T : Base
{
private Name;
private Parent;
private Index;
public T? Single => Poco.SingleOrDefault();
IEnumerable<ScopedNode<Base>> Children() => // some impl with GetElemPairs on the poco.
ScopedNode<Base>? Child(string name) => // some impl with TryGetValue on the poco.
this[]
SetValue()
Resolve()
GetLocation() // remark: the Location property is part of ITE, so we cant make this a method.
IEnumerable<ITypedElement> ITypedElement.Children(string name) =>
this.Children(name);
bool Equals(object other) => other == this;
public implicit operator Base(ScopedNode sn) => sn.Poco.SingleOrDefault();
public explicit operator Base[](ScopedNode sn) => sn.Poco;
}
static class ScopedNodeExtensions
{
public static IEnumerable<ScopedNode<T>> Children<T>(this ScopedNode<Base>? sn, string? name = null) where T : Base
=> name is null
? sn?.Children().OfType<T>() ?? []
: sn?.Children(name).OfType<T>() ?? [];
public static ScopedNode<T>? Child<T>(this ScopedNode? sn, string name) where T : Base
=> sn.Child() is {Single is T} node
? node
: null;
}
var pat = new Patient();
ScopedNode<HumanName> x = pat.Navigate().Child<HumanName>("name"); // null if multiple or none.
ScopedNode<HumanName> y = pat.Navigate().Children<HumanName>("name"); // empty if none.
HumanName z = pat.Navigate().Child<HumanName>("name").Single; // poco
string s = pat.Navigate().Child("name").Child<FhirString>("given").Value;
// or maybe even:
string s = pat.Navigate().Child<FhirString>("name.given").Value; // Children would have to allow period-delimited names.
`` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We need a new interface with at least Parent (and maybe Resolve()). This is the "ITypedElement" for POCOs. See #2893 for more discussion on the design need and issues for this interface.
The text was updated successfully, but these errors were encountered: