我正在尝试构建一个简单的 Windows 窗体,该窗体应该将值写入 yaml 配置文件。发布后,exe 文件保存在config目录中。
private void buttonSaveSettings_Click(object sender, EventArgs e)
{
string hostname = hostnameBox.Text;
var path = "C:\\Users\\Nick\\Desktop\\packages\\doctrine.yaml";
var deserializer = new YamlDotNet.Serialization.Deserializer();
try
{
using (var reader = new StreamReader(path))
{
var obj = deserializer.Deserialize<Dictionary<object, object>>(reader);
var doctrine = (Dictionary<object, object>)obj["doctrine"];
var dbal = (Dictionary<object, object>)doctrine["dbal"];
var connections = (Dictionary<object, object>)dbal["connections"];
var dict = (Dictionary<object, object>)connections["default"];
// TODO: Modify the dictionary
// dict["dbname"] = "test";
dict["dbname"] = "test";
using (StreamWriter writer = new StreamWriter(path)) …Run Code Online (Sandbox Code Playgroud) jobs我有一个查询从表及其作者中获取行(每个作业都有一个author),但我想选择特定字段。
type User struct {
ID uint `gorm:"primarykey" json:"-"`
UUID uuid.UUID `gorm:"type:uuid not null" json:"-"`
Email string `gorm:"type:varchar(255); not null" json:"email"`
Name string `gorm:"type:varchar(255); not null" json:"name"`
AvatarURL string `gorm:"type:varchar(255); not null" json:"avatar_url"`
Provider string `gorm:"type:varchar(255); not null" json:"provider"`
ProviderID string `gorm:"type:varchar(255); not null" json:"-"`
Jobs []Job `json:"-"`
}
type Job struct {
ID uint `gorm:"primarykey" json:"id"`
Title string `gorm:"type:varchar(255); not null" json:"title"`
Content string `gorm:"not null" json:"content"`
UserID uint `json:"-"`
User User `json:"author"`
}
func (jobRepo …Run Code Online (Sandbox Code Playgroud)