Skip to content

Commit

Permalink
C# 7.0 features.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikasoukhov committed Sep 11, 2017
1 parent 77a1a74 commit a162ffe
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 44 deletions.
9 changes: 5 additions & 4 deletions Algo/Export/Database/DbProviders/BaseDbProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public void CreateIfNotExists(Table table)
return;
}

if (result is int)
if (result is int i)
{
if ((int)result != 0)
if (i != 0)
return;
}

Expand Down Expand Up @@ -206,8 +206,9 @@ protected virtual string GetDbType(Type type, object restriction)

if (type == typeof(decimal))
{
var drest = restriction as DecimalRestriction;
return drest != null ? $"decimal({drest.Precision},{drest.Scale})": "decimal";
return restriction is DecimalRestriction drest
? $"decimal({drest.Precision},{drest.Scale})"
: "decimal";
}

if (type == typeof(Enum))
Expand Down
4 changes: 1 addition & 3 deletions Algo/Import/CsvImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ public void Import(string fileName, Action<int> updateProgress, Func<bool> isCan

foreach (var instance in Parse(fileName, isCancelled))
{
var secMsg = instance as SecurityMessage;

if (secMsg == null)
if (!(instance is SecurityMessage secMsg))
{
buffer.Add(instance);

Expand Down
4 changes: 1 addition & 3 deletions Algo/Import/CsvParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ public IEnumerable<dynamic> Parse(string fileName, Func<bool> isCancelled = null
}
}

var secMsg = instance as SecurityMessage;

if (secMsg == null)
if (!(instance is SecurityMessage secMsg))
{
if (instance is ExecutionMessage execMsg)
execMsg.ExecutionType = (ExecutionTypes)DataType.Arg;
Expand Down
4 changes: 1 addition & 3 deletions Algo/MarketRuleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -876,9 +876,7 @@ private void OnNewTrade(Trade trade)

private bool CheckTrades(Security security, Trade trade)
{
var basket = security as BasketSecurity;

return basket != null
return security is BasketSecurity basket
? basket.Contains(SecurityProvider, trade.Security) && _condition(trade.Security)
: trade.Security == security && _condition(trade.Security);
}
Expand Down
4 changes: 2 additions & 2 deletions Algo/Storages/IExchangeInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ public StorageExchangeInfoProvider(IEntityRegistry entityRegistry)

var boardCodes = new HashSet<string>();

var boardList = _entityRegistry.ExchangeBoards as ExchangeBoardList;
boardCodes.AddRange(boardList != null ? boardList.GetIds() : _entityRegistry.ExchangeBoards.Select(b => b.Code));
boardCodes.AddRange(_entityRegistry.ExchangeBoards is ExchangeBoardList boardList
? boardList.GetIds() : _entityRegistry.ExchangeBoards.Select(b => b.Code));

var boards = Boards.Where(b => !boardCodes.Contains(b.Code)).ToArray();

Expand Down
4 changes: 1 addition & 3 deletions Algo/Storages/SecurityList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ public SecurityList(IEntityRegistry registry)
{
_registry = registry;

var database = Storage as Database;

if (database == null)
if (!(Storage is Database database))
return;

var readAllByCodeAndType = database.CommandType == CommandType.StoredProcedure
Expand Down
4 changes: 1 addition & 3 deletions Algo/Strategies/StrategyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,7 @@ private static Strategy GetRuleStrategy(IMarketRule rule)
if (rule == null)
throw new ArgumentNullException(nameof(rule));

var strategy = rule.Container as Strategy;

if (strategy == null)
if (!(rule.Container is Strategy strategy))
throw new ArgumentException(LocalizedStrings.Str1263Params.Put(rule.Name), nameof(rule));

return strategy;
Expand Down
3 changes: 1 addition & 2 deletions Algo/Testing/EmulationMessageAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ protected override void OnSendInMessage(Message message)
case MessageTypes.Reset:
ProcessedMessageCount = 0;

var incGen = TransactionIdGenerator as IncrementalIdGenerator;
if (incGen != null)
if (TransactionIdGenerator is IncrementalIdGenerator incGen)
incGen.Current = Emulator.Settings.InitialTransactionId;

_currentTime = default(DateTimeOffset);
Expand Down
16 changes: 6 additions & 10 deletions Algo/TraderHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1354,9 +1354,7 @@ public static IEnumerable<MyTrade> GetTheoreticalTrades(this MarketDepth depth,

emulator.NewOutMessage += msg =>
{
var execMsg = msg as ExecutionMessage;

if (execMsg == null)
if (!(msg is ExecutionMessage execMsg))
return;

if (execMsg.Error != null)
Expand Down Expand Up @@ -1509,13 +1507,11 @@ public static void CancelOrders(this IConnector connector, IEnumerable<Order> or
public static bool Contains(this BasketSecurity basketSecurity, ISecurityProvider securityProvider, Security security)
{
return basketSecurity.GetInnerSecurities(securityProvider).Any(innerSecurity =>
{
var basket = innerSecurity as BasketSecurity;

if (basket == null)
return innerSecurity == security;

return basket.Contains(securityProvider, security);
{
if (innerSecurity is BasketSecurity basket)
return basket.Contains(securityProvider, security);

return innerSecurity == security;
});
}

Expand Down
4 changes: 1 addition & 3 deletions BusinessEntities/MarketDepth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,7 @@ private void SetQuote(Quote quote, bool isAggregate)

if (UseAggregatedQuotes)
{
var aggQuote = existedQuote as AggregatedQuote;

if (aggQuote == null)
if (!(existedQuote is AggregatedQuote aggQuote))
{
aggQuote = new AggregatedQuote
{
Expand Down
3 changes: 1 addition & 2 deletions Documentation/DocViewer/XMLCommToHTM/GenerateHtml_Member.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ static string GetMethodKindName(MemberDom m)

static XElement BuildReturns(MemberDom m)
{
var meth= m as MethodDom;
if (meth == null)
if (!(m is MethodDom meth))
return BuildMemberType(m);
if (meth.MemberType==null || meth.MemberType == typeof(void))
return null;
Expand Down
3 changes: 1 addition & 2 deletions Messages/SecurityId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ private int EnsureGetHashCode()
/// <returns><see langword="true" />, if the specified object is equal to the current object, otherwise, <see langword="false" />.</returns>
public override bool Equals(object other)
{
var secId = other as SecurityId?;
return secId != null && Equals(secId.Value);
return other is SecurityId secId && Equals(secId);
}

/// <summary>
Expand Down
6 changes: 2 additions & 4 deletions Samples/Chart/SampleChartActiveOrders/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ private void Error(string msg)

private void Fill_Click(object sender, RoutedEventArgs e)
{
var order = _ordersListBox.SelectedItem as Order;
if (order == null)
if (!(_ordersListBox.SelectedItem is Order order))
return;

if (IsInFinalState(order))
Expand All @@ -272,8 +271,7 @@ private void Fill_Click(object sender, RoutedEventArgs e)

private void Remove_Click(object sender, RoutedEventArgs e)
{
var order = _ordersListBox.SelectedItem as Order;
if (order == null)
if (!(_ordersListBox.SelectedItem is Order order))
return;

Log($"Remove order: {order}");
Expand Down

0 comments on commit a162ffe

Please sign in to comment.