Skip to content
Permalink
Browse files

Merge pull request #2166 from yahiheb/nameof-walletwasabi

Use nameof and add . when necessary (WalletWasabi project)
  • Loading branch information...
lontivero committed Aug 25, 2019
2 parents 82b467d + bfbd39b commit 12d43c351f32ec40911c536d175308b746186361
@@ -41,11 +41,11 @@ internal static EncodationStruct Encode(string content, ErrorCorrectionLevel ecL
int dataCodewordsCount = dataCodewords.Count;
if ((dataCodewordsCount & 0x7) != 0)
{
throw new ArgumentException("datacodewords is not byte sized.");
throw new ArgumentException($"{nameof(dataCodewords)} is not byte sized.");
}
else if (dataCodewordsCount >> 3 != vcStruct.VersionDetail.NumDataBytes)
{
throw new ArgumentException("datacodewords num of bytes not equal to NumDataBytes for current version");
throw new ArgumentException($"{nameof(dataCodewords)} num of bytes not equal to {nameof(vcStruct.VersionDetail.NumDataBytes)} for current version");
}

var encStruct = new EncodationStruct(vcStruct)
@@ -84,11 +84,11 @@ internal static EncodationStruct Encode(IEnumerable<byte> content, ErrorCorrecti
int dataCodewordsCount = dataCodewords.Count;
if ((dataCodewordsCount & 0x7) != 0)
{
throw new ArgumentException("datacodewords is not byte sized.");
throw new ArgumentException($"{nameof(dataCodewords)} is not byte sized.");
}
else if (dataCodewordsCount >> 3 != vcStruct.VersionDetail.NumDataBytes)
{
throw new ArgumentException("datacodewords num of bytes not equal to NumDataBytes for current version");
throw new ArgumentException($"{nameof(dataCodewords)} num of bytes not equal to {nameof(vcStruct.VersionDetail.NumDataBytes)} for current version");
}

var encStruct = new EncodationStruct(vcStruct)
@@ -28,7 +28,7 @@ private void AppendECI(string name, int value, AppendOption option)
break;

default:
throw new InvalidOperationException("There is no such AppendOption");
throw new InvalidOperationException($"There is no such {nameof(AppendOption)}.");
}
}

@@ -60,7 +60,7 @@ private void Initialize(AppendOption option)
break;

default:
throw new InvalidOperationException("There is no such AppendOption");
throw new InvalidOperationException($"There is no such {nameof(AppendOption)}.");
}

//ECI table. Source 01 URL: http://strokescribe.com/en/ECI.html
@@ -97,7 +97,7 @@ internal int GetECIValueByName(string encodingName)
}
else
{
throw new ArgumentOutOfRangeException($"ECI does not contain encoding: {encodingName}");
throw new ArgumentOutOfRangeException($"ECI does not contain encoding: {encodingName}.");
}
}

@@ -114,7 +114,7 @@ internal string GetECINameByValue(int eCIValue)
}
else
{
throw new ArgumentOutOfRangeException($"ECI does not contain value: {eCIValue}");
throw new ArgumentOutOfRangeException($"ECI does not contain value: {eCIValue}.");
}
}

@@ -137,7 +137,7 @@ private static int NumOfCodewords(int eCIValue)
}
else
{
throw new ArgumentOutOfRangeException($"{nameof(eCIValue)} should be in range: 0 to 999999");
throw new ArgumentOutOfRangeException($"{nameof(eCIValue)} should be in range: 0 to 999999.");
}
}

@@ -233,7 +233,7 @@ internal BitList GetECIHeader(string encodingName)
break;

default:
throw new InvalidOperationException("Assignment Codewords should be either 1, 2 or 3");
throw new InvalidOperationException("Assignment Codewords should be either 1, 2 or 3.");
}

dataBits.Add(eciValue, eciAssignmentBits);
@@ -46,7 +46,7 @@ internal override BitList GetDataBits(string content)
{
throw new ArgumentOutOfRangeException(
nameof(Encoding),
"Current ECI table does not support this encoding. Please check ECISet class for more info");
$"Current ECI table does not support this encoding. Please check {nameof(ECISet)} class for more info.");
}

byte[] contentBytes = EncodeContent(content, Encoding);
@@ -56,7 +56,7 @@ internal static void TryEmbedCodewords(this TriStateMatrix tsMatrix, BitList cod

if (bitIndex != codewordsSize)
{
throw new Exception($"Not all bits from codewords consumed by matrix: {bitIndex} / {codewordsSize}");
throw new Exception($"Not all bits from {nameof(codewords)} consumed by matrix: {bitIndex} / {codewordsSize}.");
}
}

@@ -32,7 +32,7 @@ private static TriStateMatrix XorMatrix(TriStateMatrix first, BitMatrix second)
break;

default:
throw new ArgumentException("TristateMatrix has None value cell.", nameof(first));
throw new ArgumentException($"{nameof(TriStateMatrix)} has None value cell.", nameof(first));
}
}
}
@@ -53,7 +53,7 @@ internal int Log(int gfValue)
{
if (gfValue == 0)
{
throw new ArgumentException("GaloisField value will not be equal to 0, Log method");
throw new ArgumentException("GaloisField value will not be equal to 0, Log method.");
}

return LogTable[gfValue];
@@ -63,7 +63,7 @@ internal int Inverse(int gfValue)
{
if (gfValue == 0)
{
throw new ArgumentException("GaloisField value will not be equal to 0, Inverse method");
throw new ArgumentException("GaloisField value will not be equal to 0, Inverse method.");
}

return Exponent(255 - Log(gfValue));
@@ -110,7 +110,7 @@ internal int Quotient(int gfValueA, int gfValueB)

if (gfValueB == 0)
{
throw new ArgumentException("gfValueB cannot be zero");
throw new ArgumentException($"{nameof(gfValueB)} cannot be zero.");
}

if (gfValueB == 1)
@@ -20,7 +20,7 @@ internal Polynomial(GaloisField256 gfield, int[] coefficients)

if (coefficientsLength == 0 || coefficients is null)
{
throw new ArithmeticException("Cannot create empty Polynomial");
throw new ArithmeticException($"Cannot create empty {nameof(Polynomial)}.");
}

GField = gfield;
@@ -72,7 +72,8 @@ internal Polynomial AddOrSubtract(Polynomial other)
{
if (Primitive != other.Primitive)
{
throw new ArgumentException("Polynomial cannot perform AddOrSubtract as they do not have same Primitive for GaloisField256");
throw new ArgumentException($"{nameof(Polynomial)} cannot perform {nameof(AddOrSubtract)} as they do not have the same {nameof(Primitive)}" +
$" for {nameof(GaloisField256)}.");
}
if (IsMonomialZero)
{
@@ -100,7 +101,7 @@ internal Polynomial CoefficientXor(int[] smallerCoefficients, int[] largerCoeffi
{
if (smallerCoefficients.Length > largerCoefficients.Length)
{
throw new ArgumentException("Cannot perform CoefficientXor method as smaller Coefficients length is greater than the larger one.");
throw new ArgumentException($"Cannot perform {nameof(CoefficientXor)} method as smaller {nameof(Coefficients)} length is greater than the larger one.");
}

int targetLength = largerCoefficients.Length;
@@ -125,7 +126,8 @@ internal Polynomial Multiply(Polynomial other)
{
if (Primitive != other.Primitive)
{
throw new ArgumentException("Polynomial cannot perform Multiply as they do not have same Primitive for GaloisField256");
throw new ArgumentException($"{nameof(Polynomial)} cannot perform {nameof(Multiply)} as they do not have the same {nameof(Primitive)}" +
$" for {nameof(GaloisField256)}.");
}
if (IsMonomialZero || other.IsMonomialZero)
{
@@ -184,11 +186,12 @@ internal PolyDivideStruct Divide(Polynomial other)
{
if (Primitive != other.Primitive)
{
throw new ArgumentException("Polynomial cannot perform Divide as they do not have same Primitive for GaloisField256");
throw new ArgumentException($"{nameof(Polynomial)} cannot perform {nameof(Divide)} as they do not have the same {nameof(Primitive)}" +
$" for {nameof(GaloisField256)}.");
}
if (other.IsMonomialZero)
{
throw new ArgumentException("Cannot divide by Polynomial Zero");
throw new ArgumentException($"Cannot divide by {nameof(Polynomial)} Zero.");
}
//this divide by other = a divide by b
int aLength = Coefficients.Length;
@@ -16,17 +16,17 @@ internal static byte[] Encode(byte[] dataBytes, int numECBytes, GeneratorPolynom
int dataLength = dataBytes.Length;
if (generatorPoly is null)
{
throw new ArgumentNullException("generator", "GeneratorPolynomial var is null");
throw new ArgumentNullException("generator", $"{nameof(GeneratorPolynomial)} var is null.");
}

if (dataLength == 0)
{
throw new ArgumentException("There is no data bytes to encode");
throw new ArgumentException("There is no data bytes to encode.");
}

if (numECBytes <= 0)
{
throw new ArgumentException("No Error Correction bytes");
throw new ArgumentException("No Error Correction bytes.");
}

int[] toEncode = ConvertToIntArray(dataBytes, dataLength, numECBytes);
@@ -72,7 +72,7 @@ private static byte[] ConvertTosByteArray(int[] remainder, int numECBytes)
int remainderLength = remainder.Length;
if (remainderLength > numECBytes)
{
throw new ArgumentException("Num of remainder bytes cannot be larger than numECBytes");
throw new ArgumentException($"Num of {nameof(remainder)} bytes cannot be larger than {nameof(numECBytes)}.");
}

int numZeroCoeffs = numECBytes - remainderLength;
@@ -40,7 +40,7 @@ private void Initialize()
{
if (ECBlock is null)
{
throw new System.ArgumentNullException("ErrorCorrectionBlocks array does not contain any value");
throw new System.ArgumentNullException($"{nameof(ErrorCorrectionBlocks)} array does not contain any value.");
}

NumBlocks = 0;
@@ -36,7 +36,7 @@ internal ErrorCorrectionBlocks GetECBlocksByLevel(ErrorCorrectionLevel ECLevel)
return ECBlocks[3];

default:
throw new System.ArgumentOutOfRangeException("Invalide ErrorCorrectionLevel");
throw new System.ArgumentOutOfRangeException($"Invalid {nameof(ErrorCorrectionLevel)}.");
}
}
}
@@ -24,7 +24,7 @@ public static RuntimeParams Instance
{
if (InternalInstance is null)
{
throw new InvalidOperationException("Not loaded! Use LoadAsync() first!");
throw new InvalidOperationException($"Not loaded! Use {nameof(LoadAsync)}() first!");
}

if (string.IsNullOrEmpty(FileDir))
@@ -68,7 +68,7 @@ public async Task SaveAsync()
}
catch (Exception ex)
{
Logger.LogInfo<RuntimeParams>($"Could not save RuntimeParams: {ex}.");
Logger.LogInfo<RuntimeParams>($"Could not save {nameof(RuntimeParams)}: {ex}.");
}
}

@@ -88,7 +88,7 @@ public static async Task LoadAsync()
}
catch (Exception ex)
{
Logger.LogInfo<RuntimeParams>($"Could not load RuntimeParams: {ex}.");
Logger.LogInfo<RuntimeParams>($"Could not load {nameof(RuntimeParams)}: {ex}.");
}
InternalInstance = new RuntimeParams();
}
@@ -554,14 +554,14 @@ public async Task ExecuteNextPhaseAsync(CcjRoundPhase expectedPhase, Money feePe
}
catch (Exception ex)
{
Logger.LogWarning<CcjRound>($"Round ({RoundId}): {expectedPhase.ToString()} timeout failed with exception: {ex}");
Logger.LogWarning<CcjRound>($"Round ({RoundId}): {expectedPhase.ToString()} timeout failed with exception: {ex}.");
}
});
}
}
catch (Exception ex)
{
Logger.LogWarning<CcjRound>($"Round ({RoundId}): {expectedPhase.ToString()} timeout failed with exception: {ex}");
Logger.LogWarning<CcjRound>($"Round ({RoundId}): {expectedPhase.ToString()} timeout failed with exception: {ex}.");
}
});
}
@@ -724,7 +724,7 @@ private async Task TryOptimizeFeesAsync(IEnumerable<Coin> spentCoins)
EstimateSmartFeeResponse estimateSmartFeeResponse = await RpcClient.EstimateSmartFeeAsync(AdjustedConfirmationTarget, EstimateSmartFeeMode.Conservative, simulateIfRegTest: true, tryOtherFeeRates: true);
if (estimateSmartFeeResponse is null)
{
throw new InvalidOperationException("FeeRate is not yet initialized");
throw new InvalidOperationException($"{nameof(FeeRate)} is not yet initialized.");
}

FeeRate optimalFeeRate = estimateSmartFeeResponse.FeeRate;
@@ -807,7 +807,7 @@ public static async Task<(Money feePerInputs, Money feePerOutputs)> CalculateFee
var estimateSmartFeeResponse = await rpc.EstimateSmartFeeAsync(confirmationTarget, EstimateSmartFeeMode.Conservative, simulateIfRegTest: true, tryOtherFeeRates: true);
if (estimateSmartFeeResponse is null)
{
throw new InvalidOperationException("FeeRate is not yet initialized");
throw new InvalidOperationException($"{nameof(FeeRate)} is not yet initialized.");
}

var feeRate = estimateSmartFeeResponse.FeeRate;
@@ -873,7 +873,7 @@ public void Abort(string loggingCategory, string reason, bool syncLock = true)
}
else
{
Logger.LogInfo($"Round ({RoundId}): Aborted. Reason: {reason}", category);
Logger.LogInfo($"Round ({RoundId}): Aborted. Reason: {reason}.", category);
}
}

@@ -178,7 +178,7 @@ public CommandOption(Command command, string commandName = null, bool hidden = f

protected override void OnParseComplete(OptionContext c)
{
throw new NotSupportedException("CommandOption.OnParseComplete should not be invoked.");
throw new NotSupportedException($"{nameof(CommandOption)}.{nameof(CommandOption.OnParseComplete)} should not be invoked.");
}
}
}
@@ -213,7 +213,7 @@ private void AddCommand(Command value)
{
if (value.CommandSet != null && value.CommandSet != this)
{
throw new ArgumentException("Command instances can only be added to a single CommandSet.", nameof(value));
throw new ArgumentException($"Command instances can only be added to a single {nameof(CommandSet)}.", nameof(value));
}
value.CommandSet = this;
if (value.Options != null)

0 comments on commit 12d43c3

Please sign in to comment.
You can’t perform that action at this time.