Use out var syntax
This commit is contained in:
@@ -185,14 +185,13 @@ namespace OpenRA
|
||||
|
||||
public virtual void Initialize(Dictionary<string, object> values)
|
||||
{
|
||||
object value;
|
||||
foreach (var field in GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
|
||||
{
|
||||
var sa = field.GetCustomAttributes<FieldLoader.SerializeAttribute>(false).DefaultIfEmpty(FieldLoader.SerializeAttribute.Default).First();
|
||||
if (!sa.Serialize)
|
||||
continue;
|
||||
|
||||
if (values.TryGetValue(field.Name, out value))
|
||||
if (values.TryGetValue(field.Name, out var value))
|
||||
field.SetValue(this, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,8 +131,7 @@ namespace OpenRA
|
||||
// Enumerate map directories
|
||||
foreach (var kv in modData.Manifest.MapFolders)
|
||||
{
|
||||
MapClassification packageClassification;
|
||||
if (!Enum.TryParse(kv.Value, out packageClassification))
|
||||
if (!Enum.TryParse(kv.Value, out MapClassification packageClassification))
|
||||
continue;
|
||||
|
||||
if (!classification.HasFlag(packageClassification))
|
||||
|
||||
@@ -233,8 +233,7 @@ namespace OpenRA
|
||||
newData.GridType = gridType;
|
||||
newData.Class = classification;
|
||||
|
||||
MiniYaml temp;
|
||||
if (yaml.TryGetValue("MapFormat", out temp))
|
||||
if (yaml.TryGetValue("MapFormat", out var temp))
|
||||
{
|
||||
var format = FieldLoader.GetValue<int>("MapFormat", temp.Value);
|
||||
if (format != Map.SupportedMapFormat)
|
||||
@@ -269,8 +268,7 @@ namespace OpenRA
|
||||
try
|
||||
{
|
||||
// Actor definitions may change if the map format changes
|
||||
MiniYaml actorDefinitions;
|
||||
if (yaml.TryGetValue("Actors", out actorDefinitions))
|
||||
if (yaml.TryGetValue("Actors", out var actorDefinitions))
|
||||
{
|
||||
var spawns = new List<CPos>();
|
||||
foreach (var kv in actorDefinitions.Nodes.Where(d => d.Value.Value == "mpspawn"))
|
||||
@@ -293,8 +291,7 @@ namespace OpenRA
|
||||
try
|
||||
{
|
||||
// Player definitions may change if the map format changes
|
||||
MiniYaml playerDefinitions;
|
||||
if (yaml.TryGetValue("Players", out playerDefinitions))
|
||||
if (yaml.TryGetValue("Players", out var playerDefinitions))
|
||||
{
|
||||
newData.Players = new MapPlayers(playerDefinitions.Nodes);
|
||||
newData.PlayerCount = newData.Players.Players.Count(x => x.Value.Playable);
|
||||
@@ -331,8 +328,7 @@ namespace OpenRA
|
||||
|
||||
MiniYaml LoadRuleSection(Dictionary<string, MiniYaml> yaml, string section)
|
||||
{
|
||||
MiniYaml node;
|
||||
if (!yaml.TryGetValue(section, out node))
|
||||
if (!yaml.TryGetValue(section, out var node))
|
||||
return null;
|
||||
|
||||
return node;
|
||||
|
||||
@@ -72,8 +72,7 @@ namespace OpenRA
|
||||
tileInfo = new TerrainTileInfo[Size.X * Size.Y];
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
int key;
|
||||
if (!int.TryParse(node.Key, out key) || key < 0 || key >= tileInfo.Length)
|
||||
if (!int.TryParse(node.Key, out var key) || key < 0 || key >= tileInfo.Length)
|
||||
throw new InvalidDataException("Invalid tile key '{0}' on template '{1}' of tileset '{2}'.".F(node.Key, Id, tileSet.Id));
|
||||
|
||||
tileInfo[key] = LoadTileInfo(tileSet, node.Value);
|
||||
@@ -86,8 +85,7 @@ namespace OpenRA
|
||||
var i = 0;
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
int key;
|
||||
if (!int.TryParse(node.Key, out key) || key != i++)
|
||||
if (!int.TryParse(node.Key, out var key) || key != i++)
|
||||
throw new InvalidDataException("Invalid tile key '{0}' on template '{1}' of tileset '{2}'.".F(node.Key, Id, tileSet.Id));
|
||||
|
||||
tileInfo[key] = LoadTileInfo(tileSet, node.Value);
|
||||
@@ -216,8 +214,7 @@ namespace OpenRA
|
||||
|
||||
public byte GetTerrainIndex(string type)
|
||||
{
|
||||
byte index;
|
||||
if (terrainIndexByType.TryGetValue(type, out index))
|
||||
if (terrainIndexByType.TryGetValue(type, out var index))
|
||||
return index;
|
||||
|
||||
throw new InvalidDataException("Tileset '{0}' lacks terrain type '{1}'".F(Id, type));
|
||||
@@ -225,8 +222,7 @@ namespace OpenRA
|
||||
|
||||
public byte GetTerrainIndex(TerrainTile r)
|
||||
{
|
||||
TerrainTemplateInfo tpl;
|
||||
if (!Templates.TryGetValue(r.Type, out tpl))
|
||||
if (!Templates.TryGetValue(r.Type, out var tpl))
|
||||
return defaultWalkableTerrainIndex;
|
||||
|
||||
if (tpl.Contains(r.Index))
|
||||
@@ -241,8 +237,7 @@ namespace OpenRA
|
||||
|
||||
public TerrainTileInfo GetTileInfo(TerrainTile r)
|
||||
{
|
||||
TerrainTemplateInfo tpl;
|
||||
if (!Templates.TryGetValue(r.Type, out tpl))
|
||||
if (!Templates.TryGetValue(r.Type, out var tpl))
|
||||
return null;
|
||||
|
||||
return tpl.Contains(r.Index) ? tpl[r.Index] : null;
|
||||
|
||||
Reference in New Issue
Block a user