Change GetField calls to use nameof
This commit is contained in:
@@ -89,7 +89,7 @@ namespace OpenRA
|
||||
try
|
||||
{
|
||||
if (traitInstance.Length > 1)
|
||||
info.GetType().GetField("InstanceName").SetValue(info, traitInstance[1]);
|
||||
info.GetType().GetField(nameof(info.InstanceName)).SetValue(info, traitInstance[1]);
|
||||
|
||||
FieldLoader.Load(info, my);
|
||||
}
|
||||
|
||||
@@ -154,12 +154,12 @@ namespace OpenRA
|
||||
|
||||
public virtual void Initialize(MiniYaml yaml)
|
||||
{
|
||||
Initialize((T)FieldLoader.GetValue("value", typeof(T), yaml.Value));
|
||||
Initialize((T)FieldLoader.GetValue(nameof(value), typeof(T), yaml.Value));
|
||||
}
|
||||
|
||||
public virtual void Initialize(T value)
|
||||
{
|
||||
var field = GetType().GetField("value", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var field = GetType().GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
field.SetValue(this, value);
|
||||
}
|
||||
@@ -246,14 +246,14 @@ namespace OpenRA
|
||||
|
||||
public void Initialize(MiniYaml yaml)
|
||||
{
|
||||
var field = GetType().GetField("InternalName", BindingFlags.Public | BindingFlags.Instance);
|
||||
var field = GetType().GetField(nameof(InternalName), BindingFlags.Public | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
field.SetValue(this, yaml.Value);
|
||||
}
|
||||
|
||||
public void Initialize(Player player)
|
||||
{
|
||||
var field = GetType().GetField("value", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var field = GetType().GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
field.SetValue(this, player);
|
||||
}
|
||||
|
||||
@@ -48,12 +48,12 @@ namespace OpenRA.Mods.Common
|
||||
|
||||
public void Initialize(MiniYaml yaml)
|
||||
{
|
||||
Initialize((int)FieldLoader.GetValue("value", typeof(int), yaml.Value));
|
||||
Initialize((int)FieldLoader.GetValue(nameof(value), typeof(int), yaml.Value));
|
||||
}
|
||||
|
||||
public void Initialize(int value)
|
||||
{
|
||||
var field = GetType().GetField("value", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var field = GetType().GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
field.SetValue(this, value);
|
||||
}
|
||||
|
||||
@@ -50,15 +50,15 @@ namespace OpenRA.Mods.Common.Terrain
|
||||
FieldLoader.Load(tile, my);
|
||||
|
||||
// Terrain type must be converted from a string to an index
|
||||
tile.GetType().GetField("TerrainType").SetValue(tile, terrainInfo.GetTerrainIndex(my.Value));
|
||||
tile.GetType().GetField(nameof(tile.TerrainType)).SetValue(tile, terrainInfo.GetTerrainIndex(my.Value));
|
||||
|
||||
// Fall back to the terrain-type color if necessary
|
||||
var overrideColor = terrainInfo.TerrainTypes[tile.TerrainType].Color;
|
||||
if (tile.MinColor == default)
|
||||
tile.GetType().GetField("MinColor").SetValue(tile, overrideColor);
|
||||
tile.GetType().GetField(nameof(tile.MinColor)).SetValue(tile, overrideColor);
|
||||
|
||||
if (tile.MaxColor == default)
|
||||
tile.GetType().GetField("MaxColor").SetValue(tile, overrideColor);
|
||||
tile.GetType().GetField(nameof(tile.MaxColor)).SetValue(tile, overrideColor);
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
@@ -75,15 +75,15 @@ namespace OpenRA.Mods.Common.Terrain
|
||||
FieldLoader.Load(tile, my);
|
||||
|
||||
// Terrain type must be converted from a string to an index
|
||||
tile.GetType().GetField("TerrainType").SetValue(tile, terrainInfo.GetTerrainIndex(my.Value));
|
||||
tile.GetType().GetField(nameof(tile.TerrainType)).SetValue(tile, terrainInfo.GetTerrainIndex(my.Value));
|
||||
|
||||
// Fall back to the terrain-type color if necessary
|
||||
var overrideColor = terrainInfo.TerrainTypes[tile.TerrainType].Color;
|
||||
if (tile.MinColor == default)
|
||||
tile.GetType().GetField("MinColor").SetValue(tile, overrideColor);
|
||||
tile.GetType().GetField(nameof(tile.MinColor)).SetValue(tile, overrideColor);
|
||||
|
||||
if (tile.MaxColor == default)
|
||||
tile.GetType().GetField("MaxColor").SetValue(tile, overrideColor);
|
||||
tile.GetType().GetField(nameof(tile.MaxColor)).SetValue(tile, overrideColor);
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user