Ejemplo n.º 1
0
    /// <summary>
    /// replace placeholder
    /// </summary>
    /// <param name="sections"></param>
    /// <param name="serviceInfo"></param>
    private static void ReplacePlaceholder(IEnumerable <IConfigurationSection> sections)
    {
        var serviceInfo = ServiceInfo.GetInstance();

        foreach (var section in sections)
        {
            var childrenSections = section.GetChildren();
            if (childrenSections.IsNotNullOrEmpty())
            {
                ReplacePlaceholder(childrenSections);
            }

            if (section.Value.IsNullOrWhiteSpace())
            {
                continue;
            }

            var sectionValue = section.Value;
            if (sectionValue.Contains("$SERVICENAME"))
            {
                section.Value = sectionValue.Replace("$SERVICENAME", serviceInfo.ServiceName);
            }

            if (sectionValue.Contains("$SHORTNAME"))
            {
                section.Value = sectionValue.Replace("$SHORTNAME", serviceInfo.ShortName);
            }
        }
    }