|
| 1 | +//***************************************************************************** |
| 2 | +//* Code Factory SDK |
| 3 | +//* Copyright (c) 2023 CodeFactory, LLC |
| 4 | +//***************************************************************************** |
| 5 | + |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Collections.Immutable; |
| 8 | +using System.Linq; |
| 9 | +using CodeFactory.SourceCode; |
| 10 | + |
| 11 | +namespace CodeFactory.DotNet.CSharp |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Data model that implements the base implement for all models that support members. |
| 15 | + /// </summary> |
| 16 | + public abstract class CsContainerWithNestedContainers:CsContainer,ICsNestedContainers,ICsNestedModel |
| 17 | + { |
| 18 | + #region Property backing fields |
| 19 | + private readonly bool _isNested; |
| 20 | + private readonly CsNestedType _nestedType; |
| 21 | + private readonly IReadOnlyList<ICsNestedModel> _nestedModels; |
| 22 | + |
| 23 | + #endregion |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Constructor for the <see cref="CsContainerWithNestedContainers"/> |
| 27 | + /// </summary> |
| 28 | + /// <param name="isLoaded">Flag that determines if the model was loaded.</param> |
| 29 | + /// <param name="hasErrors">Flag that determine if errors were found creating the model.</param> |
| 30 | + /// <param name="loadedFromSource">Flag that determines if the model was loaded from source code or from an existing library.</param> |
| 31 | + /// <param name="language">The target language the model was generated from.</param> |
| 32 | + /// <param name="modelType">The type of code model created.</param> |
| 33 | + /// <param name="members">The members assigned to this container.</param> |
| 34 | + /// <param name="isNested">Flag that determines if the container type is nested in another type definition.</param> |
| 35 | + /// <param name="nestedType">Enumeration of the type of nesting the container is.</param> |
| 36 | + /// <param name="nestedModels">List of nested models assigned to this container. This is an optional parameter and can be null</param> |
| 37 | + /// <param name="sourceDocument">The source document that was used to build this model. This is optional parameter and can be null.</param> |
| 38 | + /// <param name="modelStore">Optional the lookup storage for models created during the compile or lookup of the model.</param> |
| 39 | + /// <param name="modelErrors">Optional the error that occurred while creating the model.</param> |
| 40 | + /// <param name="attributes">List of the attributes assigned to this model.</param> |
| 41 | + /// <param name="isGeneric">Flag that determines if the container is a generic definition.</param> |
| 42 | + /// <param name="hasStrongTypesInGenerics">Flag that determines if the generics use strong type definitions.</param> |
| 43 | + /// <param name="genericParameters">Generic parameters assigned to the container.</param> |
| 44 | + /// <param name="genericTypes">Target types for the generic parameters assigned to the container.</param> |
| 45 | + /// <param name="modelSourceFile">The source file the model was loaded from.</param> |
| 46 | + /// <param name="sourceFiles">List of the fully qualified paths to the source code files this model is defined in.</param> |
| 47 | + /// <param name="hasDocumentation">Flag that determines if the model has XML documentation assigned to it.</param> |
| 48 | + /// <param name="documentation">The xml documentation assigned to the model.</param> |
| 49 | + /// <param name="lookupPath">The fully qualified model lookup path for this model.</param> |
| 50 | + /// <param name="name">The name of the model.</param> |
| 51 | + /// <param name="ns">The namespace the container belongs to.</param> |
| 52 | + /// <param name="parentPath">The fully qualified lookup path for the parent model to this one.</param> |
| 53 | + /// <param name="containerType">The type of container this model represents.</param> |
| 54 | + /// <param name="security">The security scope assigned to this model.</param> |
| 55 | + /// <param name="inheritedInterfaces">The interfaces that are inherited by this container.</param> |
| 56 | + protected CsContainerWithNestedContainers(bool isLoaded, bool hasErrors, bool loadedFromSource, SourceCodeType language, CsModelType modelType, |
| 57 | + IReadOnlyList<CsAttribute> attributes, bool isGeneric, bool hasStrongTypesInGenerics, |
| 58 | + IReadOnlyList<CsGenericParameter> genericParameters, IReadOnlyList<CsType> genericTypes, string modelSourceFile, |
| 59 | + IReadOnlyList<string> sourceFiles, bool hasDocumentation, string documentation, string lookupPath, |
| 60 | + string name, string ns, string parentPath, CsContainerType containerType, CsSecurity security, |
| 61 | + IReadOnlyList<CsInterface> inheritedInterfaces, IReadOnlyList<CsMember> members, bool isNested, CsNestedType nestedType, IReadOnlyList<ICsNestedModel> nestedModels = null, |
| 62 | + string sourceDocument = null, ModelStore<ICsModel> modelStore = null, IReadOnlyList<ModelLoadException> modelErrors = null) |
| 63 | + :base(isLoaded, hasErrors, loadedFromSource, language, modelType, attributes, isGeneric, hasStrongTypesInGenerics, genericParameters, |
| 64 | + genericTypes, modelSourceFile, sourceFiles, hasDocumentation, documentation, lookupPath, name, ns, parentPath, containerType, security, |
| 65 | + inheritedInterfaces, members, sourceDocument, modelStore, modelErrors) |
| 66 | + { |
| 67 | + _isNested = isNested; |
| 68 | + _nestedType = nestedType; |
| 69 | + _nestedModels = nestedModels ?? ImmutableList<ICsNestedModel>.Empty; |
| 70 | + } |
| 71 | + |
| 72 | + /// <summary> |
| 73 | + /// Models that are nested in the implementation of this container. |
| 74 | + /// </summary> |
| 75 | + public IReadOnlyList<ICsNestedModel> NestedModels => _nestedModels; |
| 76 | + |
| 77 | + /// <summary> |
| 78 | + /// Classes that are nested in this container. |
| 79 | + /// </summary> |
| 80 | + public IReadOnlyList<CsClass> NestedClasses => |
| 81 | + _nestedModels.Where(n => n.NestedType == CsNestedType.Class).Cast<CsClass>().ToImmutableList(); |
| 82 | + |
| 83 | + /// <summary> |
| 84 | + /// Interfaces that are nested in this container. |
| 85 | + /// </summary> |
| 86 | + public IReadOnlyList<CsInterface> NestedInterfaces => |
| 87 | + _nestedModels.Where(n => n.NestedType == CsNestedType.Interface).Cast<CsInterface>().ToImmutableList(); |
| 88 | + |
| 89 | + /// <summary> |
| 90 | + /// Structures that are nested in this container. |
| 91 | + /// </summary> |
| 92 | + public IReadOnlyList<CsStructure> NestedStructures => |
| 93 | + _nestedModels.Where(n => n.NestedType == CsNestedType.Structure).Cast<CsStructure>().ToImmutableList(); |
| 94 | + |
| 95 | + /// <summary> |
| 96 | + /// Enums that are nested in this container. |
| 97 | + /// </summary> |
| 98 | + public IReadOnlyList<CsEnum> NestedEnums => |
| 99 | + _nestedModels.Where(n => n.NestedType == CsNestedType.Enum).Cast<CsEnum>().ToImmutableList(); |
| 100 | + |
| 101 | + /// <summary> |
| 102 | + /// Models that are nested in the implementation of this container. |
| 103 | + /// </summary> |
| 104 | + IReadOnlyList<IDotNetNestedModel> IDotNetNestedContainers.NestedModels => NestedModels; |
| 105 | + |
| 106 | + /// <summary> |
| 107 | + /// Classes that are nested in this container. |
| 108 | + /// </summary> |
| 109 | + IReadOnlyList<IDotNetClass> IDotNetNestedContainers.NestedClasses => NestedClasses; |
| 110 | + |
| 111 | + /// <summary> |
| 112 | + /// Interfaces that are nested in this container. |
| 113 | + /// </summary> |
| 114 | + IReadOnlyList<IDotNetInterface> IDotNetNestedContainers.NestedInterfaces => NestedInterfaces; |
| 115 | + |
| 116 | + /// <summary> |
| 117 | + /// Structures that are nested in this container. |
| 118 | + /// </summary> |
| 119 | + IReadOnlyList<IDotNetStructure> IDotNetNestedContainers.NestedStructures => NestedStructures; |
| 120 | + |
| 121 | + /// <summary> |
| 122 | + /// Enums that are nested in this container. |
| 123 | + /// </summary> |
| 124 | + IReadOnlyList<IDotNetEnum> IDotNetNestedContainers.NestedEnums => NestedEnums; |
| 125 | + |
| 126 | + /// <summary> |
| 127 | + /// Identifies the type of model that has been nested. |
| 128 | + /// </summary> |
| 129 | + DotNetNestedType IDotNetNestedModel.NestedType => (DotNetNestedType)_nestedType; |
| 130 | + |
| 131 | + /// <summary> |
| 132 | + /// Identifies the type of model that has been nested. |
| 133 | + /// </summary> |
| 134 | + public CsNestedType NestedType => _nestedType; |
| 135 | + |
| 136 | + /// <summary> |
| 137 | + /// Flag that determines if this model is nested in a parent model. |
| 138 | + /// </summary> |
| 139 | + public bool IsNested => _isNested; |
| 140 | + |
| 141 | + } |
| 142 | +} |
0 commit comments