Skip to content

Commit 6544788

Browse files
authored
Merge pull request #2811 from FirelyTeam/no-more-exceptions
Integrating generated code for Base, DataType, PrimitiveType and Extension
2 parents f28eaba + 5b9b1e7 commit 6544788

File tree

9 files changed

+447
-278
lines changed

9 files changed

+447
-278
lines changed

src/Hl7.Fhir.Base/Model/Base.cs

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,9 @@ POSSIBILITY OF SUCH DAMAGE.
4040

4141
namespace Hl7.Fhir.Model
4242
{
43-
[Serializable]
44-
[FhirType("Base", "http://hl7.org/fhir/StructureDefinition/Base")]
45-
[DataContract]
46-
public abstract class Base : IDeepCopyable, IDeepComparable,
43+
public abstract partial class Base : IDeepCopyable, IDeepComparable,
4744
IAnnotated, IAnnotatable, IValidatableObject, INotifyPropertyChanged, IReadOnlyDictionary<string, object>
4845
{
49-
public virtual bool IsExactly(IDeepComparable other) => other is Base;
50-
51-
public virtual bool Matches(IDeepComparable other) => other is Base;
52-
53-
/// <summary>
54-
///
55-
/// </summary>
56-
/// <param name="other"></param>
57-
/// <remarks>Does a deep-copy of all elements, except UserData</remarks>
58-
/// <returns></returns>
59-
public virtual IDeepCopyable CopyTo(IDeepCopyable other)
60-
{
61-
if (other is Base dest)
62-
{
63-
if (_annotations is not null)
64-
dest.annotations.AddRange(annotations);
65-
66-
return dest;
67-
}
68-
else
69-
throw new ArgumentException("Can only copy to an object of the same type", nameof(other));
70-
}
71-
72-
public abstract IDeepCopyable DeepCopy();
73-
7446
public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext) => Enumerable.Empty<ValidationResult>();
7547

7648
#region << Annotations >>
@@ -95,27 +67,6 @@ protected virtual void OnPropertyChanged(String property) =>
9567

9668
#endregion
9769

98-
public virtual string TypeName => "Base";
99-
100-
/// <summary>
101-
/// Enumerate all child nodes.
102-
/// Return a sequence of child elements, components and/or properties.
103-
/// Child nodes are returned in the order defined by the FHIR specification.
104-
/// First returns child nodes inherited from any base class(es), recursively.
105-
/// Finally returns child nodes defined by the current class.
106-
/// </summary>
107-
public virtual IEnumerable<Base> Children { get { return Enumerable.Empty<Base>(); } }
108-
109-
/// <summary>
110-
/// Enumerate all child nodes.
111-
/// Return a sequence of child elements, components and/or properties.
112-
/// Child nodes are returned as tuples with the name and the node itself, in the order defined
113-
/// by the FHIR specification.
114-
/// First returns child nodes inherited from any base class(es), recursively.
115-
/// Finally returns child nodes defined by the current class.
116-
/// </summary>
117-
public virtual IEnumerable<ElementValue> NamedChildren => Enumerable.Empty<ElementValue>();
118-
11970
public IReadOnlyDictionary<string, object> AsReadOnlyDictionary() => this;
12071

12172
#region IReadOnlyDictionary
@@ -135,13 +86,5 @@ protected virtual void OnPropertyChanged(String property) =>
13586

13687
bool IReadOnlyDictionary<string, object>.TryGetValue(string key, out object value) => TryGetValue(key, out value);
13788
#endregion
138-
139-
protected virtual bool TryGetValue(string key, out object value)
140-
{
141-
value = default;
142-
return false;
143-
}
144-
145-
protected virtual IEnumerable<KeyValuePair<string, object>> GetElementPairs() => Enumerable.Empty<KeyValuePair<string, object>>();
14689
}
147-
}
90+
}

src/Hl7.Fhir.Base/Model/Extension.cs

Lines changed: 15 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -40,142 +40,22 @@ POSSIBILITY OF SUCH DAMAGE.
4040
using System.Runtime.Serialization;
4141
using SystemPrimitive = Hl7.Fhir.ElementModel.Types;
4242

43-
namespace Hl7.Fhir.Model
43+
namespace Hl7.Fhir.Model;
44+
45+
/// <summary>
46+
/// Optional Extensions Element
47+
/// </summary>
48+
[System.Diagnostics.DebuggerDisplay(@"\{Value={Value} Url={_url}}")]
49+
[Bindable(true)]
50+
public partial class Extension
4451
{
45-
/// <summary>
46-
/// Optional Extensions Element
47-
/// </summary>
48-
[Serializable]
49-
[System.Diagnostics.DebuggerDisplay(@"\{Value={Value} Url={_url}}")]
50-
[FhirType("Extension", "http://hl7.org/fhir/StructureDefinition/Extension")]
51-
[DataContract]
52-
[Bindable(true)]
53-
public class Extension : DataType
52+
public Extension()
5453
{
55-
public Extension()
56-
{
57-
}
58-
59-
public Extension(string url, DataType value)
60-
{
61-
this.Url = url;
62-
this.Value = value;
63-
}
64-
65-
public override string TypeName { get { return "Extension"; } }
66-
67-
/// <summary>
68-
/// identifies the meaning of the extension
69-
/// </summary>
70-
[FhirElement("url", XmlSerialization = XmlRepresentation.XmlAttr, InSummary = true, Order = 30)]
71-
[DeclaredType(Type = typeof(SystemPrimitive.String))]
72-
[Cardinality(Min = 1, Max = 1)]
73-
[UriPattern]
74-
[DataMember]
75-
public string? Url
76-
{
77-
get { return _url; }
78-
set { _url = value; OnPropertyChanged("Url"); }
79-
}
80-
81-
private string? _url;
82-
83-
/// <summary>
84-
/// Value of extension
85-
/// </summary>
86-
[FhirElement("value", InSummary = true, Order = 40, Choice = ChoiceType.DatatypeChoice)]
87-
[DataMember]
88-
public DataType? Value
89-
{
90-
get { return _value; }
91-
set { _value = value; OnPropertyChanged("Value"); }
92-
}
93-
94-
private DataType? _value;
95-
96-
public override IDeepCopyable CopyTo(IDeepCopyable other)
97-
{
98-
if (other is Extension dest)
99-
{
100-
base.CopyTo(dest);
101-
if (Url != null) dest.Url = Url;
102-
if (Value != null) dest.Value = (Hl7.Fhir.Model.DataType)Value.DeepCopy();
103-
return dest;
104-
}
105-
else
106-
throw new ArgumentException("Can only copy to an object of the same type", nameof(other));
107-
}
108-
109-
public override IDeepCopyable DeepCopy()
110-
{
111-
return CopyTo(new Extension());
112-
}
113-
114-
public override bool Matches(IDeepComparable other)
115-
{
116-
var otherT = other as Extension;
117-
if (otherT == null) return false;
118-
119-
if (!base.Matches(otherT)) return false;
120-
if (Url != otherT.Url) return false;
121-
if (!DeepComparable.Matches(Value, otherT.Value)) return false;
122-
123-
return true;
124-
}
125-
126-
public override bool IsExactly(IDeepComparable other)
127-
{
128-
var otherT = other as Extension;
129-
if (otherT == null) return false;
130-
131-
if (!base.IsExactly(otherT)) return false;
132-
if (Url != otherT.Url) return false;
133-
if (!DeepComparable.IsExactly(Value, otherT.Value)) return false;
134-
135-
return true;
136-
}
137-
138-
public override IEnumerable<Base> Children
139-
{
140-
get
141-
{
142-
foreach (var item in base.Children) yield return item;
143-
if (Url != null) yield return new FhirUri(Url);
144-
if (Value != null) yield return Value;
145-
}
146-
}
147-
148-
public override IEnumerable<ElementValue> NamedChildren
149-
{
150-
get
151-
{
152-
// Extension elements
153-
foreach (var item in base.NamedChildren) yield return item;
154-
if (Url != null) yield return new ElementValue("url", new FhirUri(Url));
155-
if (Value != null) yield return new ElementValue("value", Value);
156-
}
157-
}
158-
159-
protected override bool TryGetValue(string key, [NotNullWhen(true)]out object? value)
160-
{
161-
switch (key)
162-
{
163-
case "url":
164-
value = Url;
165-
return Url is not null;
166-
case "value":
167-
value = Value;
168-
return Value is not null;
169-
default:
170-
return base.TryGetValue(key, out value);
171-
}
172-
}
54+
}
17355

174-
protected override IEnumerable<KeyValuePair<string, object>> GetElementPairs()
175-
{
176-
if (Url is not null) yield return new KeyValuePair<string, object>("url", Url);
177-
if (Value is not null) yield return new KeyValuePair<string, object>("value", Value);
178-
foreach (var kvp in base.GetElementPairs()) yield return kvp;
179-
}
56+
public Extension(string url, DataType value)
57+
{
58+
this.Url = url;
59+
this.Value = value;
18060
}
181-
}
61+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// <auto-generated/>
2+
// Contents of: hl7.fhir.r5.expansions#5.0.0, hl7.fhir.r5.core#5.0.0
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Runtime.Serialization;
8+
using Hl7.Fhir.Introspection;
9+
using Hl7.Fhir.Serialization;
10+
using Hl7.Fhir.Specification;
11+
using Hl7.Fhir.Utility;
12+
using Hl7.Fhir.Validation;
13+
using SystemPrimitive = Hl7.Fhir.ElementModel.Types;
14+
15+
/*
16+
Copyright (c) 2011+, HL7, Inc.
17+
All rights reserved.
18+
19+
Redistribution and use in source and binary forms, with or without modification,
20+
are permitted provided that the following conditions are met:
21+
22+
* Redistributions of source code must retain the above copyright notice, this
23+
list of conditions and the following disclaimer.
24+
* Redistributions in binary form must reproduce the above copyright notice,
25+
this list of conditions and the following disclaimer in the documentation
26+
and/or other materials provided with the distribution.
27+
* Neither the name of HL7 nor the names of its contributors may be used to
28+
endorse or promote products derived from this software without specific
29+
prior written permission.
30+
31+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
32+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
35+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
38+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40+
POSSIBILITY OF SUCH DAMAGE.
41+
42+
*/
43+
44+
namespace Hl7.Fhir.Model
45+
{
46+
/// <summary>
47+
/// Base for all types and resources
48+
/// </summary>
49+
/// <remarks>
50+
/// Base definition for all types defined in FHIR type system.
51+
/// </remarks>
52+
[Serializable]
53+
[DataContract]
54+
[FhirType("Base","http://hl7.org/fhir/StructureDefinition/Base")]
55+
public abstract partial class Base
56+
{
57+
/// <summary>
58+
/// FHIR Type Name
59+
/// </summary>
60+
public virtual string TypeName { get { return "Base"; } }
61+
62+
public virtual IDeepCopyable CopyTo(IDeepCopyable other)
63+
{
64+
var dest = other as Base;
65+
66+
if (dest == null)
67+
{
68+
throw new ArgumentException("Can only copy to an object of the same type", "other");
69+
}
70+
71+
if (_annotations is not null)
72+
dest.annotations.AddRange(annotations);
73+
74+
return dest;
75+
}
76+
77+
public virtual IDeepCopyable DeepCopy() =>
78+
CopyTo((IDeepCopyable)Activator.CreateInstance(GetType())!);
79+
80+
///<inheritdoc />
81+
public virtual bool Matches(IDeepComparable other) => other is Base;
82+
83+
public virtual bool IsExactly(IDeepComparable other) => other is Base;
84+
85+
/// <summary>
86+
/// Enumerate all child nodes.
87+
/// Return a sequence of child elements, components and/or properties.
88+
/// Child nodes are returned in the order defined by the FHIR specification.
89+
/// First returns child nodes inherited from any base class(es), recursively.
90+
/// Finally returns child nodes defined by the current class.
91+
/// </summary>
92+
[IgnoreDataMember]
93+
public virtual IEnumerable<Base> Children => Enumerable.Empty<Base>();
94+
95+
/// <summary>
96+
/// Enumerate all child nodes.
97+
/// Return a sequence of child elements, components and/or properties.
98+
/// Child nodes are returned as tuples with the name and the node itself, in the order defined
99+
/// by the FHIR specification.
100+
/// First returns child nodes inherited from any base class(es), recursively.
101+
/// Finally returns child nodes defined by the current class.
102+
/// </summary>
103+
[IgnoreDataMember]
104+
public virtual IEnumerable<ElementValue> NamedChildren => Enumerable.Empty<ElementValue>();
105+
106+
protected virtual bool TryGetValue(string key, out object value)
107+
{
108+
value = default;
109+
return false;
110+
}
111+
112+
protected virtual IEnumerable<KeyValuePair<string, object>> GetElementPairs() => Enumerable.Empty<KeyValuePair<string, object>>();
113+
114+
}
115+
116+
}
117+
118+
// end of file

src/Hl7.Fhir.Base/Model/Generated/DataType.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,6 @@ public override bool IsExactly(IDeepComparable other)
9393
return true;
9494
}
9595

96-
[IgnoreDataMember]
97-
public override IEnumerable<Base> Children
98-
{
99-
get
100-
{
101-
foreach (var item in base.Children) yield return item;
102-
}
103-
}
104-
105-
[IgnoreDataMember]
106-
public override IEnumerable<ElementValue> NamedChildren
107-
{
108-
get
109-
{
110-
foreach (var item in base.NamedChildren) yield return item;
111-
}
112-
}
113-
11496
}
11597

11698
}

0 commit comments

Comments
 (0)