Exemplo n.º 1
0
 internal Alias(string name, IReadOnlyList <AliasPath> paths, AliasType?type, string defaultPath, AliasPattern defaultPattern)
 {
     Name           = name;
     Paths          = paths;
     Type           = type;
     DefaultPath    = defaultPath;
     DefaultPattern = defaultPattern;
 }
Exemplo n.º 2
0
        internal static AliasPath DeserializeAliasPath(JsonElement element)
        {
            string path = default;
            IReadOnlyList <string> apiVersions = default;
            AliasPattern           pattern     = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("path"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    path = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("apiVersions"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <string> array = new List <string>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(item.GetString());
                        }
                    }
                    apiVersions = array;
                    continue;
                }
                if (property.NameEquals("pattern"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    pattern = AliasPattern.DeserializeAliasPattern(property.Value);
                    continue;
                }
            }
            return(new AliasPath(path, apiVersions, pattern));
        }
        internal static Alias DeserializeAlias(JsonElement element)
        {
            string name = default;
            IReadOnlyList <AliasPath> paths = default;
            AliasType?   type           = default;
            string       defaultPath    = default;
            AliasPattern defaultPattern = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("name"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("paths"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <AliasPath> array = new List <AliasPath>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(AliasPath.DeserializeAliasPath(item));
                        }
                    }
                    paths = array;
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    type = property.Value.GetString().ToAliasType();
                    continue;
                }
                if (property.NameEquals("defaultPath"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    defaultPath = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("defaultPattern"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    defaultPattern = AliasPattern.DeserializeAliasPattern(property.Value);
                    continue;
                }
            }
            return(new Alias(name, paths, type, defaultPath, defaultPattern));
        }
Exemplo n.º 4
0
 internal AliasPath(string path, IReadOnlyList <string> apiVersions, AliasPattern pattern)
 {
     Path        = path;
     ApiVersions = apiVersions;
     Pattern     = pattern;
 }