所以基本上我想做: json代码, 声明, 当语句为true时,其他一些json文本 以前的json代码的延续
这是我目前的代码,我正在寻找一种缩短它的方法,任何解决方案?
if (textBox1.Text != "Enter Address")
{
if (textBox2.Text != "Enter Address")
{
//1+2+3 OK
if (textBox3.Text != "Enter Address")
{
var item = new Item
{
version = 1,
schema_version = 2,
id = textBox14.Text,
title = textBox7.Text,
title_localized = textBox18.Text,
artist = textBox6.Text,
artist_localized = textBox8.Text,
artist_source = textBox9.Text,
illustrator = textBox10.Text,
illustrator_source = textBox11.Text,
charter = textBox13.Text,
music = new ItemMusic {
path = textBox4.Text
},
music_preview = new ItemMusicPreview
{
path = textBox5.Text
},
background = new ItemBackground
{
path = open3.SafeFileName
},
charts = new List<ItemChart>
{
new ItemChart
{
type = "easy",
name = textBox15.Text,
difficulty = Convert.ToInt32(numericUpDown1.Value),
path = textBox1.Text
},
new ItemChart
{
type = "hard",
name = textBox16.Text,
difficulty = Convert.ToInt32(numericUpDown2.Value),
path = textBox2.Text
},
new ItemChart
{
type = "extreme",
name = textBox17.Text,
difficulty = Convert.ToInt32(numericUpDown3.Value),
path = textBox3.Text
}
}
};
var settings = new JsonSerializerSettings()
{
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
}
};
var json = JsonConvert.SerializeObject(item, settings);
if (File.Exists(@"C:\Users\Public\Desktop\level files\") == false)
{
// Make a path
System.IO.Directory.CreateDirectory(@"C:\Users\Public\Desktop\level files\");
}
if (File.Exists($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\") == false)
{
// Make a path
System.IO.Directory.CreateDirectory($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\");
}
File.WriteAllText($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\level.json", json, new UTF8Encoding(false));
}
//1+2 (3) OK
else
{
var item = new Item
{
version = 1,
schema_version = 2,
id = textBox14.Text,
title = textBox7.Text,
title_localized = textBox18.Text,
artist = textBox6.Text,
artist_localized = textBox8.Text,
artist_source = textBox9.Text,
illustrator = textBox10.Text,
illustrator_source = textBox11.Text,
charter = textBox13.Text,
music = new ItemMusic
{
path = textBox4.Text
},
music_preview = new ItemMusicPreview
{
path = textBox5.Text
},
background = new ItemBackground
{
path = open3.SafeFileName
},
charts = new List<ItemChart>
{
new ItemChart
{
type = "easy",
name = textBox15.Text,
difficulty = Convert.ToInt32(numericUpDown1.Value),
path = textBox1.Text
},
new ItemChart
{
type = "hard",
name = textBox16.Text,
difficulty = Convert.ToInt32(numericUpDown2.Value),
path = textBox2.Text
}
}
};
var settings = new JsonSerializerSettings()
{
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
}
};
var json = JsonConvert.SerializeObject(item, settings);
if (File.Exists(@"C:\Users\Public\Desktop\level files\") == false)
{
// Make a path
System.IO.Directory.CreateDirectory(@"C:\Users\Public\Desktop\level files\");
}
if (File.Exists($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\") == false)
{
// Make a path
System.IO.Directory.CreateDirectory($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\");
}
File.WriteAllText($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\level.json", json, new UTF8Encoding(false));
}
}
else
{
//1+3 (2) OK
if (textBox3.Text != "Enter Address")
{
var item = new Item
{
version = 1,
schema_version = 2,
id = textBox14.Text,
title = textBox7.Text,
title_localized = textBox18.Text,
artist = textBox6.Text,
artist_localized = textBox8.Text,
artist_source = textBox9.Text,
illustrator = textBox10.Text,
illustrator_source = textBox11.Text,
charter = textBox13.Text,
music = new ItemMusic
{
path = textBox4.Text
},
music_preview = new ItemMusicPreview
{
path = textBox5.Text
},
background = new ItemBackground
{
path = open3.SafeFileName
},
charts = new List<ItemChart>
{
new ItemChart
{
type = "easy",
name = textBox15.Text,
difficulty = Convert.ToInt32(numericUpDown1.Value),
path = textBox1.Text
},
new ItemChart
{
type = "extreme",
name = textBox17.Text,
difficulty = Convert.ToInt32(numericUpDown3.Value),
path = textBox3.Text
}
}
};
var settings = new JsonSerializerSettings()
{
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
}
};
var json = JsonConvert.SerializeObject(item, settings);
if (File.Exists(@"C:\Users\Public\Desktop\level files\") == false)
{
// Make a path
System.IO.Directory.CreateDirectory(@"C:\Users\Public\Desktop\level files\");
}
if (File.Exists($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\") == false)
{
// Make a path
System.IO.Directory.CreateDirectory($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\");
}
File.WriteAllText($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\level.json", json, new UTF8Encoding(false));
}
//1 (2)(3) OK
else
{
var item = new Item
{
version = 1,
schema_version = 2,
id = textBox14.Text,
title = textBox7.Text,
title_localized = textBox18.Text,
artist = textBox6.Text,
artist_localized = textBox8.Text,
artist_source = textBox9.Text,
illustrator = textBox10.Text,
illustrator_source = textBox11.Text,
charter = textBox13.Text,
music = new ItemMusic
{
path = textBox4.Text
},
music_preview = new ItemMusicPreview
{
path = textBox5.Text
},
background = new ItemBackground
{
path = open3.SafeFileName
},
charts = new List<ItemChart>
{
new ItemChart
{
type = "easy",
name = textBox15.Text,
difficulty = Convert.ToInt32(numericUpDown1.Value),
path = textBox1.Text
}
}
};
var settings = new JsonSerializerSettings()
{
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
}
};
var json = JsonConvert.SerializeObject(item, settings);
if (File.Exists(@"C:\Users\Public\Desktop\level files\") == false)
{
// Make a path
System.IO.Directory.CreateDirectory(@"C:\Users\Public\Desktop\level files\");
}
if (File.Exists($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\") == false)
{
// Make a path
System.IO.Directory.CreateDirectory($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\");
}
File.WriteAllText($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\level.json", json, new UTF8Encoding(false));
}
}
}
else
if (textBox2.Text != "Enter Address")
{
//2+3 (1) OK
if (textBox3.Text != "Enter Address")
{
var item = new Item
{
version = 1,
schema_version = 2,
id = textBox14.Text,
title = textBox7.Text,
title_localized = textBox18.Text,
artist = textBox6.Text,
artist_localized = textBox8.Text,
artist_source = textBox9.Text,
illustrator = textBox10.Text,
illustrator_source = textBox11.Text,
charter = textBox13.Text,
music = new ItemMusic
{
path = textBox4.Text
},
music_preview = new ItemMusicPreview
{
path = textBox5.Text
},
background = new ItemBackground
{
path = open3.SafeFileName
},
charts = new List<ItemChart>
{
new ItemChart
{
type = "hard",
name = textBox16.Text,
difficulty = Convert.ToInt32(numericUpDown2.Value),
path = textBox2.Text
},
new ItemChart
{
type = "extreme",
name = textBox17.Text,
difficulty = Convert.ToInt32(numericUpDown3.Value),
path = textBox3.Text
}
}
};
var settings = new JsonSerializerSettings()
{
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
}
};
var json = JsonConvert.SerializeObject(item, settings);
if (File.Exists(@"C:\Users\Public\Desktop\level files\") == false)
{
// Make a path
System.IO.Directory.CreateDirectory(@"C:\Users\Public\Desktop\level files\");
}
if (File.Exists($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\") == false)
{
// Make a path
System.IO.Directory.CreateDirectory($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\");
}
File.WriteAllText($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\level.json", json, new UTF8Encoding(false));
}
//2 (1)(3)
else
{
var item = new Item
{
version = 1,
schema_version = 2,
id = textBox14.Text,
title = textBox7.Text,
title_localized = textBox18.Text,
artist = textBox6.Text,
artist_localized = textBox8.Text,
artist_source = textBox9.Text,
illustrator = textBox10.Text,
illustrator_source = textBox11.Text,
charter = textBox13.Text,
music = new ItemMusic
{
path = textBox4.Text
},
music_preview = new ItemMusicPreview
{
path = textBox5.Text
},
background = new ItemBackground
{
path = open3.SafeFileName
},
charts = new List<ItemChart>
{
new ItemChart
{
type = "hard",
name = textBox16.Text,
difficulty = Convert.ToInt32(numericUpDown2.Value),
path = textBox2.Text
}
}
};
var settings = new JsonSerializerSettings()
{
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
}
};
var json = JsonConvert.SerializeObject(item, settings);
if (File.Exists(@"C:\Users\Public\Desktop\level files\") == false)
{
// Make a path
System.IO.Directory.CreateDirectory(@"C:\Users\Public\Desktop\level files\");
}
if (File.Exists($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\") == false)
{
// Make a path
System.IO.Directory.CreateDirectory($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\");
}
File.WriteAllText($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\level.json", json, new UTF8Encoding(false));
}
}
else
{
var item = new Item
{
version = 1,
schema_version = 2,
id = textBox14.Text,
title = textBox7.Text,
title_localized = textBox18.Text,
artist = textBox6.Text,
artist_localized = textBox8.Text,
artist_source = textBox9.Text,
illustrator = textBox10.Text,
illustrator_source = textBox11.Text,
charter = textBox13.Text,
music = new ItemMusic
{
path = textBox4.Text
},
music_preview = new ItemMusicPreview
{
path = textBox5.Text
},
background = new ItemBackground
{
path = open3.SafeFileName
},
charts = new List<ItemChart>
{
new ItemChart
{
type = "extreme",
name = textBox17.Text,
difficulty = Convert.ToInt32(numericUpDown3.Value),
path = textBox3.Text
},
}
};
var settings = new JsonSerializerSettings()
{
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
}
};
var json = JsonConvert.SerializeObject(item, settings);
if (File.Exists(@"C:\Users\Public\Desktop\level files\") == false)
{
// Make a path
System.IO.Directory.CreateDirectory(@"C:\Users\Public\Desktop\level files\");
}
if (File.Exists($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\") == false)
{
// Make a path
System.IO.Directory.CreateDirectory($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\");
}
File.WriteAllText($@"C:\Users\Public\Desktop\level files\{textBox14.Text}\level.json", json, new UTF8Encoding(false));
}
我打算在“ new ItemChart”中添加“ storyboard = open9.FileName”,但不在未导入文件地址时添加情节提要行。