/// <summary>Generates the code for all described types (e.g. interfaces, classes, enums, etc).</summary>
        /// <returns>The code.</returns>
        public string GenerateTypes(ExtensionCode extensionCode)
        {
            var processedTypes = new List <string>();
            var types          = new Dictionary <string, TypeGeneratorResult>();

            while (_types.Any(t => !processedTypes.Contains(t.Key)))
            {
                foreach (var pair in _types.ToList())
                {
                    processedTypes.Add(pair.Key);
                    var result = pair.Value.GenerateType(pair.Key);
                    types[result.TypeName] = result;
                }
            }

            return(string.Join("\n\n", ClassOrderUtilities.Order(types.Values)
                               .Where(p => !_settings.ExcludedTypeNames.Contains(p.TypeName))
                               .Select(p =>
            {
                if (extensionCode?.ExtensionClasses.ContainsKey(p.TypeName) == true)
                {
                    var classCode = p.Code;

                    var index = classCode.IndexOf("class");
                    index = classCode.IndexOf("{", index);

                    return classCode.Insert(index + 1, extensionCode.GetExtensionClassBody(p.TypeName));
                }

                return p.Code;
            })));
        }
        /// <summary>Generates the code for all described types (e.g. interfaces, classes, enums, etc).</summary>
        /// <returns>The code.</returns>
        public string GenerateTypes(ExtensionCode extensionCode)
        {
            var processedTypes = new List <string>();
            var types          = new Dictionary <string, TypeGeneratorResult>();

            while (_types.Any(t => !processedTypes.Contains(t.Key)))
            {
                foreach (var pair in _types.ToList())
                {
                    processedTypes.Add(pair.Key);
                    var result = pair.Value.GenerateType(pair.Key);
                    types[result.TypeName] = result;
                }
            }

            return(string.Join("\n\n", ClassOrderUtilities.Order(types.Values).Select(p =>
            {
                if (extensionCode?.Classes.ContainsKey(p.TypeName) == true)
                {
                    return p.Code + "\n\n" + extensionCode.Classes[p.TypeName];
                }

                return p.Code;
            })));
        }
Exemple #3
0
 /// <summary>Initializes a new instance of the <see cref="TypeResolverBase" /> class.</summary>
 /// <param name="artifacts">The artifacts.</param>
 /// <param name="extensionCode">The extension code.</param>
 public CodeArtifactCollection(IEnumerable <CodeArtifact> artifacts, ExtensionCode extensionCode)
 {
     Artifacts     = OrderByBaseDependency(artifacts);
     ExtensionCode = extensionCode;
 }