Fixes string interpolation

This commit is contained in:
Kamron Batman 2018-09-14 13:07:43 -07:00
parent 42d0b6271f
commit 7d3a0ca265
233 changed files with 758 additions and 690 deletions

View file

@ -385,7 +385,7 @@ namespace Server.Commands
}
catch ( Exception e )
{
throw new Exception( String.Format( "Bad type: {0}", m_Type ), e );
throw new Exception($"Bad type: {m_Type}", e );
}
if ( item is BaseAddon addon )
@ -1061,7 +1061,7 @@ namespace Server.Commands
list.m_Type = ScriptCompiler.FindTypeByName( line.Substring( 0, indexOf++ ), true );
if ( list.m_Type == null )
throw new ArgumentException( String.Format( "Type not found for header: '{0}'", line ) );
throw new ArgumentException($"Type not found for header: '{line}'");
line = line.Substring( indexOf );
indexOf = line.IndexOf( '(' );

View file

@ -382,7 +382,7 @@ namespace Server.Commands
}
catch ( Exception e )
{
throw new Exception( String.Format( "Bad type: {0}", m_Type ), e );
throw new Exception($"Bad type: {m_Type}", e );
}
if ( item is BaseAddon addon )
@ -1058,7 +1058,7 @@ namespace Server.Commands
list.m_Type = ScriptCompiler.FindTypeByName( line.Substring( 0, indexOf++ ), true );
if ( list.m_Type == null )
throw new ArgumentException( String.Format( "Type not found for header: '{0}'", line ) );
throw new ArgumentException($"Type not found for header: '{line}'");
line = line.Substring( indexOf );
indexOf = line.IndexOf( '(' );

View file

@ -982,7 +982,7 @@ namespace Server.Commands
break;
}
html.WriteLine( " <td width=\"{0}\"{1} class=\"entry\">&nbsp;</td>", count*25, count==1?"":String.Format( " colspan=\"{0}\"", count ) );
html.WriteLine( " <td width=\"{0}\"{1} class=\"entry\">&nbsp;</td>", count*25, count==1?"": $" colspan=\"{count}\"");
}
}
@ -998,7 +998,7 @@ namespace Server.Commands
lbod.Entries = LargeBulkEntry.ConvertEntries( lbod, entries );
WriteSmithBODHeader( html, String.Format( "(Large) {0}: Normal", name ) );
WriteSmithBODHeader( html, $"(Large) {name}: Normal");
lbod.RequireExceptional = false;
for( BulkMaterialType mat = BulkMaterialType.None; mat <= BulkMaterialType.Valorite; ++mat )
@ -1012,7 +1012,7 @@ namespace Server.Commands
html.WriteLine( " <br><br>" );
WriteSmithBODHeader( html, String.Format( "(Large) {0}: Exceptional", name ) );
WriteSmithBODHeader( html, $"(Large) {name}: Exceptional");
lbod.RequireExceptional = true;
for( BulkMaterialType mat = BulkMaterialType.None; mat <= BulkMaterialType.Valorite; ++mat )
@ -1205,7 +1205,7 @@ namespace Server.Commands
break;
}
html.WriteLine( " <td width=\"{0}\"{1} class=\"entry\">&nbsp;</td>", count*25, count==1?"":String.Format( " colspan=\"{0}\"", count ) );
html.WriteLine( " <td width=\"{0}\"{1} class=\"entry\">&nbsp;</td>", count*25, count==1?"": $" colspan=\"{count}\"");
}
}

View file

@ -332,14 +332,14 @@ namespace Server.Commands
int start = text.IndexOf( '(' );
if ( start < 0 )
throw new FormatException( String.Format( "Input string not correctly formatted ('{0}')", text ) );
throw new FormatException($"Input string not correctly formatted ('{text}')");
m_Title = text.Substring( 0, start ).Trim();
int end = text.IndexOf( ')', ++start );
if ( end < start )
throw new FormatException( String.Format( "Input string not correctly formatted ('{0}')", text ) );
throw new FormatException($"Input string not correctly formatted ('{text}')");
text = text.Substring( start, end-start );
string[] split = text.Split( ';' );
@ -392,7 +392,7 @@ namespace Server.Commands
}
if ( index >= input.Length )
throw new FormatException( String.Format( "Input string not correctly formatted ('{0}')", input ) );
throw new FormatException($"Input string not correctly formatted ('{input}')");
m_Indentation = index;
m_Text = input.Substring( index );

View file

@ -116,7 +116,7 @@ namespace Server.Commands.Generic
public override string ToString()
{
if ( m_Count > 1 )
return String.Format( "{0} ({1})", m_Message, m_Count );
return $"{m_Message} ({m_Count})";
return m_Message;
}

View file

@ -190,7 +190,7 @@ namespace Server.Commands.Generic
if ( list.Count == 1 )
AddResponse( "There is one matching object." );
else
AddResponse( String.Format( "There are {0} matching objects.", list.Count ) );
AddResponse($"There are {list.Count} matching objects.");
}
}
@ -255,7 +255,8 @@ namespace Server.Commands.Generic
else
AddResponse( "Open web browser request sent." );
mob.SendGump( new WarningGump( 1060637, 30720, String.Format( "A game master is requesting to open your web browser to the following URL:<br>{0}", url ), 0xFFC000, 320, 240, new WarningGumpCallback( OpenBrowser_Callback ), new object[]{ from, url, echo } ) );
mob.SendGump( new WarningGump( 1060637, 30720,
$"A game master is requesting to open your web browser to the following URL:<br>{url}", 0xFFC000, 320, 240, new WarningGumpCallback( OpenBrowser_Callback ), new object[]{ from, url, echo } ) );
}
}
else
@ -636,9 +637,9 @@ namespace Server.Commands.Generic
Type type = obj.GetType();
if ( type.DeclaringType == null )
AddResponse( String.Format( "The type of that object is {0}.", type.Name ) );
AddResponse($"The type of that object is {type.Name}.");
else
AddResponse( String.Format( "The type of that object is {0}.", type.FullName ) );
AddResponse($"The type of that object is {type.FullName}.");
}
}
}
@ -698,7 +699,7 @@ namespace Server.Commands.Generic
Commands = new[]{ command };
ObjectTypes = objects;
Usage = command;
Description = String.Format( "Sets the {0} property to {1}.", name, value );
Description = $"Sets the {name} property to {value}.";
}
public override void Execute( CommandEventArgs e, object obj )
@ -796,7 +797,8 @@ namespace Server.Commands.Generic
{
if ( list.Count > 1 )
{
e.Mobile.SendGump( new WarningGump( 1060637, 30720, String.Format( "You are about to delete {0} objects. This cannot be undone without a full server revert.<br><br>Continue?", list.Count ), 0xFFC000, 420, 280, new WarningGumpCallback( OnConfirmCallback ), new object[]{ e, list } ) );
e.Mobile.SendGump( new WarningGump( 1060637, 30720,
$"You are about to delete {list.Count} objects. This cannot be undone without a full server revert.<br><br>Continue?", 0xFFC000, 420, 280, new WarningGumpCallback( OnConfirmCallback ), new object[]{ e, list } ) );
AddResponse( "Awaiting confirmation..." );
}
else
@ -1043,7 +1045,7 @@ namespace Server.Commands.Generic
targ.Say( "I've been {0}!", m_Ban ? "banned" : "kicked" );
AddResponse( String.Format( "They have been {0}.", m_Ban ? "banned" : "kicked" ) );
AddResponse($"They have been {(m_Ban ? "banned" : "kicked")}.");
targState.Dispose();

View file

@ -95,7 +95,8 @@ namespace Server.Commands.Generic
#region Area targeting mode
public override void ExecuteList( CommandEventArgs e, ArrayList list )
{
e.Mobile.SendGump( new WarningGump( 1060637, 30720, String.Format( "You are about to insert {0} objects. This cannot be undone without a full server revert.<br><br>Continue?", list.Count ), 0xFFC000, 420, 280, new WarningGumpCallback( OnConfirmCallback ), new object[] { e, list, ( e.Length < 1 || !e.GetBoolean( 0 ) ) } ) );
e.Mobile.SendGump( new WarningGump( 1060637, 30720,
$"You are about to insert {list.Count} objects. This cannot be undone without a full server revert.<br><br>Continue?", 0xFFC000, 420, 280, new WarningGumpCallback( OnConfirmCallback ), new object[] { e, list, ( e.Length < 1 || !e.GetBoolean( 0 ) ) } ) );
AddResponse( "Awaiting confirmation..." );
}

View file

@ -85,7 +85,8 @@ namespace Server.Commands.Generic
else
AddEntryHeader( 20 );
AddEntryHtml( 40 + ( m_Columns.Length * 130 ) - 20 + ( ( m_Columns.Length - 2 ) * OffsetSize ), Center( String.Format( "Page {0} of {1}", m_Page+1, (m_List.Count + EntriesPerPage - 1) / EntriesPerPage ) ) );
AddEntryHtml( 40 + ( m_Columns.Length * 130 ) - 20 + ( ( m_Columns.Length - 2 ) * OffsetSize ), Center(
$"Page {m_Page + 1} of {(m_List.Count + EntriesPerPage - 1) / EntriesPerPage}") );
if ( (m_Page + 1) * EntriesPerPage < m_List.Count )
AddEntryButton( 20, ArrowRightID1, ArrowRightID2, 2, ArrowRightWidth, ArrowRightHeight );
@ -297,7 +298,7 @@ namespace Server.Commands.Generic
private void InvokeCommand( string ip )
{
CommandSystem.Handle( m_From, String.Format( "{0}{1}", CommandSystem.Prefix, ip ) );
CommandSystem.Handle( m_From, $"{CommandSystem.Prefix}{ip}");
}
public override void OnResponse( NetState sender, RelayInfo info )
@ -338,7 +339,7 @@ namespace Server.Commands.Generic
case 4: // Go there
{
m_From.SendGump( new InterfaceItemGump( m_From, m_Columns, m_List, m_Page, m_Item ) );
InvokeCommand( String.Format( "Go {0}", m_Item.Serial.Value ) );
InvokeCommand($"Go {m_Item.Serial.Value}");
break;
}
case 5: // Move to target
@ -458,7 +459,7 @@ namespace Server.Commands.Generic
private void InvokeCommand( string ip )
{
CommandSystem.Handle( m_From, String.Format( "{0}{1}", CommandSystem.Prefix, ip ) );
CommandSystem.Handle( m_From, $"{CommandSystem.Prefix}{ip}");
}
public override void OnResponse( NetState sender, RelayInfo info )
@ -503,7 +504,7 @@ namespace Server.Commands.Generic
case 4: // Go there
{
m_From.SendGump( new InterfaceMobileGump( m_From, m_Columns, m_List, m_Page, m_Mobile ) );
InvokeCommand( String.Format( "Go {0}", m_Mobile.Serial.Value ) );
InvokeCommand($"Go {m_Mobile.Serial.Value}");
break;
}
case 5: // Bring them here

View file

@ -177,11 +177,7 @@ namespace Server.Commands.Generic
else
{
throw new InvalidOperationException(
String.Format(
"Unable to convert string \"{0}\" into type '{1}'.",
m_Value,
m_Type
)
$"Unable to convert string \"{m_Value}\" into type '{m_Type}'."
);
}
}

View file

@ -94,7 +94,7 @@ namespace Server.Commands.Generic
Type objectType = ScriptCompiler.FindTypeByName( args[offset + index], true );
if ( objectType == null )
throw new Exception( String.Format( "No type with that name ({0}) was found.", args[offset + index] ) );
throw new Exception($"No type with that name ({args[offset + index]}) was found.");
++index;
@ -231,7 +231,7 @@ namespace Server.Commands.Generic
}
if ( condition == null )
throw new InvalidOperationException( String.Format( "Unrecognized operator (\"{0}\").", oper ) );
throw new InvalidOperationException($"Unrecognized operator (\"{oper}\").");
current.Add( condition );
}

View file

@ -233,8 +233,7 @@ namespace Server.Commands
e.Mobile.SendGump(
new WarningGump( 1060635, 30720,
String.Format( "You are about to delete {0} object{1} from this facet. Do you really wish to continue?",
list.Count, list.Count == 1 ? "" : "s" ),
$"You are about to delete {list.Count} object{(list.Count == 1 ? "" : "s")} from this facet. Do you really wish to continue?",
0xFFC000, 360, 260, new WarningGumpCallback( DeleteList_Callback ), list ) );
}
else
@ -345,7 +344,7 @@ namespace Server.Commands
{
Item item = m.Items[i];
entries[i] = new ItemListEntry( String.Format( "{0}: {1}", item.Layer, item.GetType().Name ), item.ItemID, item.Hue );
entries[i] = new ItemListEntry($"{item.Layer}: {item.GetType().Name}", item.ItemID, item.Hue );
}
return entries;
@ -377,7 +376,7 @@ namespace Server.Commands
private Mobile m_Mobile;
private Item m_Item;
public EquipDetailsMenu( Mobile m, Item item ) : base( String.Format( "{0}: {1}", item.Layer, item.GetType().Name ), new[]{"Move","Delete","Props"})
public EquipDetailsMenu( Mobile m, Item item ) : base($"{item.Layer}: {item.GetType().Name}", new[]{"Move","Delete","Props"})
{
m_Mobile = m;
m_Item = item;
@ -828,7 +827,7 @@ namespace Server.Commands
[Description( "Broadcasts a message to all online staff." )]
public static void StaffMessage_OnCommand( CommandEventArgs e )
{
BroadcastMessage( AccessLevel.Counselor, e.Mobile.SpeechHue, String.Format( "[{0}] {1}", e.Mobile.Name, e.ArgString ) );
BroadcastMessage( AccessLevel.Counselor, e.Mobile.SpeechHue, $"[{e.Mobile.Name}] {e.ArgString}");
}
[Usage( "BCast <text>" )]
@ -836,7 +835,7 @@ namespace Server.Commands
[Description( "Broadcasts a message to everyone online." )]
public static void BroadcastMessage_OnCommand( CommandEventArgs e )
{
BroadcastMessage( AccessLevel.Player, 0x482, String.Format( "Staff message from {0}:", e.Mobile.Name ) );
BroadcastMessage( AccessLevel.Player, 0x482, $"Staff message from {e.Mobile.Name}:");
BroadcastMessage( AccessLevel.Player, 0x482, e.ArgString );
}

View file

@ -46,7 +46,7 @@ namespace Server.Commands
return;
}
else
e.Mobile.SendMessage( String.Format( "Command '{0}' not found!", arg ) );
e.Mobile.SendMessage($"Command '{arg}' not found!");
}
e.Mobile.SendGump( new CommandListGump( 0, e.Mobile, null ) );
@ -255,7 +255,8 @@ namespace Server.Commands
else
AddEntryHeader( 20 );
AddEntryHtml( 160, Center( String.Format( "Page {0} of {1}", m_Page+1, (m_List.Count + EntriesPerPage - 1) / EntriesPerPage ) ) );
AddEntryHtml( 160, Center(
$"Page {m_Page + 1} of {(m_List.Count + EntriesPerPage - 1) / EntriesPerPage}") );
if ( (m_Page + 1) * EntriesPerPage < m_List.Count )
AddEntryButton( 20, ArrowRightID1, ArrowRightID2, 2, ArrowRightWidth, ArrowRightHeight );
@ -346,12 +347,12 @@ namespace Server.Commands
{
public string Color( string text, int color )
{
return String.Format( "<BASEFONT COLOR=#{0:X6}>{1}</BASEFONT>", color, text );
return $"<BASEFONT COLOR=#{color:X6}>{text}</BASEFONT>";
}
public string Center( string text )
{
return String.Format( "<CENTER>{0}</CENTER>", text );
return $"<CENTER>{text}</CENTER>";
}
public CommandInfoGump( CommandInfo info )
@ -384,7 +385,7 @@ namespace Server.Commands
if ( aliases != null && aliases.Length != 0 )
{
sb.Append( String.Format( "Alias{0}: ", aliases.Length == 1 ? "" : "es" ) );
sb.Append($"Alias{(aliases.Length == 1 ? "" : "es")}: ");
for( int i = 0; i < aliases.Length; ++i )
{

View file

@ -29,7 +29,7 @@ namespace Server.Commands
try
{
m_Output = new StreamWriter( Path.Combine( directory, String.Format( "{0}.log", DateTime.UtcNow.ToLongDateString() ) ), true );
m_Output = new StreamWriter( Path.Combine( directory, $"{DateTime.UtcNow.ToLongDateString()}.log"), true );
m_Output.AutoFlush = true;
@ -47,13 +47,13 @@ namespace Server.Commands
if ( o is Mobile m )
{
if ( m.Account == null )
return String.Format( "{0} (no account)", m );
return $"{m} (no account)";
return String.Format( "{0} ('{1}')", m, m.Account.Username );
return $"{m} ('{m.Account.Username}')";
}
if ( o is Item item )
{
return String.Format( "0x{0:X} ({1})", item.Serial.Value, item.GetType().Name );
return $"0x{item.Serial.Value:X} ({item.GetType().Name})";
}
return o;
@ -83,7 +83,7 @@ namespace Server.Commands
AppendPath( ref path, "Logs" );
AppendPath( ref path, "Commands" );
AppendPath( ref path, from.AccessLevel.ToString() );
path = Path.Combine( path, String.Format( "{0}.log", name ) );
path = Path.Combine( path, $"{name}.log");
using ( StreamWriter sw = new StreamWriter( path, true ) )
sw.WriteLine( "{0}: {1}: {2}", DateTime.UtcNow, from.NetState, text );

View file

@ -110,31 +110,31 @@ namespace Server.Commands
if ( attr == null )
{
failReason = String.Format( "Property '{0}' not found.", propertyName );
failReason = $"Property '{propertyName}' not found.";
return null;
}
else if ( (access & PropertyAccess.Read) != 0 && from.AccessLevel < attr.ReadLevel )
{
failReason = String.Format( "You must be at least {0} to get the property '{1}'.",
Mobile.GetAccessLevelName( attr.ReadLevel ), propertyName );
failReason =
$"You must be at least {Mobile.GetAccessLevelName(attr.ReadLevel)} to get the property '{propertyName}'.";
return null;
}
else if ( (access & PropertyAccess.Write) != 0 && from.AccessLevel < attr.WriteLevel )
{
failReason = String.Format( "You must be at least {0} to set the property '{1}'.",
Mobile.GetAccessLevelName( attr.WriteLevel ), propertyName );
failReason =
$"You must be at least {Mobile.GetAccessLevelName(attr.WriteLevel)} to set the property '{propertyName}'.";
return null;
}
else if ( (access & PropertyAccess.Read) != 0 && !p.CanRead )
{
failReason = String.Format( "Property '{0}' is write only.", propertyName );
failReason = $"Property '{propertyName}' is write only.";
return null;
}
else if ( (access & PropertyAccess.Write) != 0 && (!p.CanWrite || attr.ReadOnly) && isFinal )
{
failReason = String.Format( "Property '{0}' is read only.", propertyName );
failReason = $"Property '{propertyName}' is read only.";
return null;
}
@ -146,7 +146,7 @@ namespace Server.Commands
if ( info[i] == null )
{
failReason = String.Format( "Property '{0}' not found.", propertyName );
failReason = $"Property '{propertyName}' not found.";
return null;
}
}
@ -181,7 +181,7 @@ namespace Server.Commands
if ( obj == null )
{
failReason = String.Format( "Property '{0}' is null.", chain[i] );
failReason = $"Property '{chain[i]}' is null.";
return null;
}
}
@ -313,14 +313,14 @@ namespace Server.Commands
else if ( IsChar( type ) )
toString = String.Format( "'{0}' ({1} [0x{1:X}])", value, (int) value );
else if ( IsString( type ) )
toString = ( (string) value == "null" ? @"@""null""" : String.Format( "\"{0}\"", value ) );
toString = ( (string) value == "null" ? @"@""null""" : $"\"{value}\"");
else if ( IsText( type ) )
toString = ( (TextDefinition) value ).Format( false );
else
toString = value.ToString();
if ( chain == null )
return String.Format( "{0} = {1}", p.Name, toString );
return $"{p.Name} = {toString}";
string[] concat = new string[chain.Length*2+1];
@ -615,7 +615,7 @@ namespace Server
public sealed class UnknownPropertyException : BindingException
{
public UnknownPropertyException( Property property, string current )
: base( property, String.Format( "Property '{0}' not found.", current ) )
: base( property, $"Property '{current}' not found.")
{
}
}
@ -662,11 +662,8 @@ namespace Server
public AccessLevel NeededAccess => m_NeededAccess;
public ClearanceException( Property property, AccessLevel playerAccess, AccessLevel neededAccess, string accessType )
: base( property, string.Format(
"You must be at least {0} to {1} this property.",
Mobile.GetAccessLevelName( neededAccess ),
accessType
) )
: base( property,
$"You must be at least {Mobile.GetAccessLevelName(neededAccess)} to {accessType} this property.")
{
}
}

View file

@ -128,7 +128,7 @@ namespace Server.Commands
if ( m_Set )
{
skill.Base = m_Value;
CommandLogging.LogChangeProperty( from, targ, String.Format( "{0}.Base", m_Skill ), m_Value.ToString() );
CommandLogging.LogChangeProperty( from, targ, $"{m_Skill}.Base", m_Value.ToString() );
}
from.SendMessage( "{0} : {1} (Base: {2})", m_Skill, skill.Value, skill.Base );

View file

@ -272,7 +272,8 @@ namespace Server
if ( totalFrozen == 0 && badDataFile )
from.SendGump( new NoticeGump( 1060637, 30720, "Output data files could not be opened and the freeze operation has been aborted.<br><br>This probably means your server and client are using the same data files. Instructions on how to resolve this can be found in the first warning window.", 0xFFC000, 320, 240, null, null ) );
else
from.SendGump( new NoticeGump( 1060637, 30720, String.Format( "Freeze operation completed successfully.<br><br>{0} item{1} frozen.<br><br>You must restart your client and update it's data files to see the changes.", totalFrozen, totalFrozen != 1 ? "s were" : " was" ), 0xFFC000, 320, 240, null, null ) );
from.SendGump( new NoticeGump( 1060637, 30720,
$"Freeze operation completed successfully.<br><br>{totalFrozen} item{(totalFrozen != 1 ? "s were" : " was")} frozen.<br><br>You must restart your client and update it's data files to see the changes.", 0xFFC000, 320, 240, null, null ) );
}
private const string BaseUnfreezeWarning = "{0} " +
@ -470,7 +471,8 @@ namespace Server
if ( totalUnfrozen == 0 && badDataFile )
from.SendGump( new NoticeGump( 1060637, 30720, "Output data files could not be opened and the unfreeze operation has been aborted.<br><br>This probably means your server and client are using the same data files. Instructions on how to resolve this can be found in the first warning window.", 0xFFC000, 320, 240, null, null ) );
else
from.SendGump( new NoticeGump( 1060637, 30720, String.Format( "Unfreeze operation completed successfully.<br><br>{0} item{1} unfrozen.<br><br>You must restart your client and update it's data files to see the changes.", totalUnfrozen, totalUnfrozen != 1 ? "s were" : " was" ), 0xFFC000, 320, 240, null, null ) );
from.SendGump( new NoticeGump( 1060637, 30720,
$"Unfreeze operation completed successfully.<br><br>{totalUnfrozen} item{(totalUnfrozen != 1 ? "s were" : " was")} unfrozen.<br><br>You must restart your client and update it's data files to see the changes.", 0xFFC000, 320, 240, null, null ) );
}
private static FileStream OpenWrite( FileStream orig )