示例#1
0
 internal UserAccount(string name, string password, ElevationLevel?elevationLevel, LinuxUserConfiguration linuxUserConfiguration, WindowsUserConfiguration windowsUserConfiguration)
 {
     Name                     = name;
     Password                 = password;
     ElevationLevel           = elevationLevel;
     LinuxUserConfiguration   = linuxUserConfiguration;
     WindowsUserConfiguration = windowsUserConfiguration;
 }
        internal static UserAccount DeserializeUserAccount(JsonElement element)
        {
            string                   name                     = default;
            string                   password                 = default;
            ElevationLevel?          elevationLevel           = default;
            LinuxUserConfiguration   linuxUserConfiguration   = default;
            WindowsUserConfiguration windowsUserConfiguration = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("password"))
                {
                    password = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("elevationLevel"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    elevationLevel = property.Value.GetString().ToElevationLevel();
                    continue;
                }
                if (property.NameEquals("linuxUserConfiguration"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    linuxUserConfiguration = LinuxUserConfiguration.DeserializeLinuxUserConfiguration(property.Value);
                    continue;
                }
                if (property.NameEquals("windowsUserConfiguration"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    windowsUserConfiguration = WindowsUserConfiguration.DeserializeWindowsUserConfiguration(property.Value);
                    continue;
                }
            }
            return(new UserAccount(name, password, elevationLevel, linuxUserConfiguration, windowsUserConfiguration));
        }