liugz18
2024-07-18 d80ac2fd2df4e7fb8a28acfa512bb11472b5cc99
runtime/csharp/AliParaformerAsr/AliParaformerAsr/Utils/YamlHelper.cs
@@ -14,16 +14,19 @@
    /// YamlHelper
    /// Copyright (c)  2023 by manyeyes
    /// </summary>
    internal class YamlHelper
    internal class YamlHelper
    {
        public static T ReadYaml<T>(string yamlFilePath)
        public static T ReadYaml<T>(string yamlFilePath) where T:new()
        {
            if (!File.Exists(yamlFilePath))
            {
#pragma warning disable CS8603 // 可能返回 null 引用。
                return default(T);
#pragma warning restore CS8603 // 可能返回 null 引用。
                // 如果允许返回默认对象,则新建一个默认对象,否则应该是抛出异常
                // If allowing to return a default object, create a new default object; otherwise, throw an exception
                return new T();
                // throw new Exception($"not find yaml config file: {yamlFilePath}");
            }
            StreamReader yamlReader = File.OpenText(yamlFilePath);
            Deserializer yamlDeserializer = new Deserializer();
            T info = yamlDeserializer.Deserialize<T>(yamlReader);