| | | 1 | | using pva.SuperV.Engine.Exceptions; |
| | | 2 | | |
| | | 3 | | namespace pva.SuperV.Engine |
| | | 4 | | { |
| | | 5 | | /// <summary> |
| | | 6 | | /// Generated instance. |
| | | 7 | | /// </summary> |
| | | 8 | | /// <seealso cref="pva.SuperV.Engine.IInstance" /> |
| | | 9 | | public class Instance : IInstance |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Gets or sets the name of the instance. |
| | | 13 | | /// </summary> |
| | | 14 | | /// <value> |
| | | 15 | | /// The name. |
| | | 16 | | /// </value> |
| | 239 | 17 | | public string Name { get; set; } = null!; |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Gets or sets the class of the instance. |
| | | 21 | | /// </summary> |
| | | 22 | | /// <value> |
| | | 23 | | /// The class. |
| | | 24 | | /// </value> |
| | 282 | 25 | | public Class Class { get; set; } = null!; |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Gets or sets the fields contained in instance. |
| | | 29 | | /// </summary> |
| | | 30 | | /// <value> |
| | | 31 | | /// The fields. |
| | | 32 | | /// </value> |
| | 1865 | 33 | | public Dictionary<string, IField> Fields { get; set; } = []; |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
| | | 37 | | /// </summary> |
| | | 38 | | public void Dispose() |
| | 97 | 39 | | { |
| | 97 | 40 | | Dispose(true); |
| | 97 | 41 | | GC.SuppressFinalize(this); |
| | 97 | 42 | | } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Releases unmanaged and - optionally - managed resources. |
| | | 46 | | /// </summary> |
| | | 47 | | /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release |
| | | 48 | | protected virtual void Dispose(bool disposing) |
| | 97 | 49 | | { |
| | 97 | 50 | | Fields.Clear(); |
| | 97 | 51 | | } |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Gets a field of the instance. |
| | | 55 | | /// </summary> |
| | | 56 | | /// <typeparam name="T"></typeparam> |
| | | 57 | | /// <param name="fieldName">Name of the field.</param> |
| | | 58 | | /// <returns>The field.</returns> |
| | | 59 | | /// <exception cref="pva.SuperV.Engine.Exceptions.WrongFieldTypeException"></exception> |
| | | 60 | | public Field<T>? GetField<T>(string fieldName) |
| | 106 | 61 | | { |
| | 106 | 62 | | IField field = GetField(fieldName); |
| | 105 | 63 | | if (field.Type != typeof(T)) |
| | 1 | 64 | | { |
| | 1 | 65 | | throw new WrongFieldTypeException(fieldName, field.Type, typeof(T)); |
| | | 66 | | } |
| | 104 | 67 | | return field as Field<T>; |
| | 104 | 68 | | } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Gets a field of the instance. |
| | | 72 | | /// </summary> |
| | | 73 | | /// <param name="fieldName">Name of the field.</param> |
| | | 74 | | /// <returns>The field.</returns> |
| | | 75 | | /// <exception cref="pva.SuperV.Engine.Exceptions.UnknownEntityException"></exception> |
| | | 76 | | public IField GetField(string fieldName) |
| | 577 | 77 | | { |
| | 577 | 78 | | if (Fields.TryGetValue(fieldName, out var field)) |
| | 576 | 79 | | { |
| | 576 | 80 | | return field; |
| | | 81 | | } |
| | 1 | 82 | | throw new UnknownEntityException(fieldName, Class.Name); |
| | 576 | 83 | | } |
| | | 84 | | } |
| | | 85 | | } |