Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,7 @@ private void ConvertExceptionTree(Exception exception, ExceptionDetails parentEx

exceptions.Add(exceptionDetails);

AggregateException aggregate = exception as AggregateException;
if (aggregate != null)
if (exception is AggregateException aggregate)
{
foreach (Exception inner in aggregate.InnerExceptions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ internal partial class PageViewData
protected override void ApplyProperties(EventData other)
{
base.ApplyProperties(other);
PageViewData otherPageView = other as PageViewData;
if (otherPageView != null)

if (other is PageViewData otherPageView)
{
otherPageView.url = this.url;
otherPageView.duration = this.duration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ internal partial class PageViewPerfData
protected override void ApplyProperties(EventData other)
{
base.ApplyProperties(other);
PageViewPerfData otherPageViewPerf = other as PageViewPerfData;
if (otherPageViewPerf != null)

if (other is PageViewPerfData otherPageViewPerf)
{
otherPageViewPerf.domProcessing = this.domProcessing;
otherPageViewPerf.perfTotal = this.perfTotal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ public void Dispose()
/// <param name="exception">Exception to log.</param>
private static void LogException(Exception exception)
{
var aggregateException = exception as AggregateException;
if (aggregateException != null)
if (exception is AggregateException aggregateException)
{
aggregateException = aggregateException.Flatten();
foreach (Exception e in aggregateException.InnerExceptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,9 @@ protected static void LoadTelemetrySinks(XElement definition, TelemetryConfigura
}
}
}

// Either name was not specified, or we have encountered it first time--need to create new sink instance.
var sink = LoadInstance(addElement, typeof(TelemetrySink), null, new object[] { telemetryConfiguration, null }, null) as TelemetrySink;
if (sink != null)
if (LoadInstance(addElement, typeof(TelemetrySink), null, new object[] { telemetryConfiguration, null }, null) is TelemetrySink sink)
{
telemetryConfiguration.TelemetrySinks.Add(sink);
}
Expand Down Expand Up @@ -364,8 +363,7 @@ private static void InitializeComponents(IEnumerable components, TelemetryConfig

private static void InitializeComponent(object component, TelemetryConfiguration configuration)
{
var configurable = component as ITelemetryModule;
if (configurable != null)
if (component is ITelemetryModule configurable)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ private void Dispose(bool disposing)
{
foreach (ITelemetryProcessor processor in processors)
{
IDisposable disposableProcessor = processor as IDisposable;

if (disposableProcessor != null)
if (processor is IDisposable disposableProcessor)
{
disposableProcessor.Dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,7 @@ private void InitializeExtractors(TelemetryClient metricsClient)
/// <param name="fromItem">The item from which to extract metrics.</param>
private void ExtractMetrics(ITelemetry fromItem)
{
ISupportSampling potentiallySampledItem = fromItem as ISupportSampling;
if (potentiallySampledItem != null && false == this.EnsureItemNotSampled(potentiallySampledItem))
if (fromItem is ISupportSampling potentiallySampledItem && false == this.EnsureItemNotSampled(potentiallySampledItem))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ internal class DependencyDurationBucketExtractor : IDimensionExtractor

public string ExtractDimension(ITelemetry item)
{
var dep = item as DependencyTelemetry;
if (dep != null)
if (item is DependencyTelemetry dep)
{
return DurationBucketizer.GetPerformanceBucket(dep.Duration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ internal class DependencyResultCodeDimensionExtractor : IDimensionExtractor

public string ExtractDimension(ITelemetry item)
{
var dep = item as DependencyTelemetry;
if (dep != null)
if (item is DependencyTelemetry dep)
{
return dep.ResultCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ internal class SuccessDimensionExtractor : IDimensionExtractor

public string ExtractDimension(ITelemetry item)
{
var dep = item as DependencyTelemetry;
if (dep != null)
if (item is DependencyTelemetry dep)
{
bool dependencyFailed = (dep.Success != null) && (dep.Success == false);
string dependencySuccessString = dependencyFailed ? bool.FalseString : bool.TrueString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ internal class TargetDimensionExtractor : IDimensionExtractor

public string ExtractDimension(ITelemetry item)
{
var dep = item as DependencyTelemetry;
if (dep != null)
if (item is DependencyTelemetry dep)
{
return dep.Target;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ internal class TypeDimensionExtractor : IDimensionExtractor

public string ExtractDimension(ITelemetry item)
{
var dep = item as DependencyTelemetry;
if (dep != null)
if (item is DependencyTelemetry dep)
{
return dep.Type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ internal class DurationBucketExtractor : IDimensionExtractor

public string ExtractDimension(ITelemetry item)
{
var req = item as RequestTelemetry;
if (req != null)
if (item is RequestTelemetry req)
{
return DurationBucketizer.GetPerformanceBucket(req.Duration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ internal class RequestResponseCodeDimensionExtractor : IDimensionExtractor

public string ExtractDimension(ITelemetry item)
{
var req = item as RequestTelemetry;
if (req != null)
if (item is RequestTelemetry req)
{
return req.ResponseCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ internal class RequestSuccessDimensionExtractor : IDimensionExtractor

public string ExtractDimension(ITelemetry item)
{
var req = item as RequestTelemetry;
if (req != null)
if (item is RequestTelemetry req)
{
bool isFailed = req.Success.HasValue
? (req.Success.Value == false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ public static double ConvertToDoubleValue(object metricValue)
}
else
{
string stringValue = metricValue as string;
if (stringValue != null)
if (metricValue is string stringValue)
{
double doubleValue;
if (Double.TryParse(stringValue, NumberStyles.Any, CultureInfo.InvariantCulture, out doubleValue))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ public override bool Equals(object obj)
{
if (obj != null)
{
var otherConfig = obj as MetricConfiguration;
if (otherConfig != null)
if (obj is MetricConfiguration otherConfig)
{
return this.Equals(otherConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,7 @@ public override int GetHashCode()
/// <returns>Whether the specified other object is equal to this object based on the respective namespaces, IDs and dimension names.</returns>
public override bool Equals(object otherObj)
{
MetricIdentifier otherMetricIdentifier = otherObj as MetricIdentifier;

if (otherMetricIdentifier != null)
if (otherObj is MetricIdentifier otherMetricIdentifier)
{
return this.Equals(otherMetricIdentifier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public override bool Equals(object obj)
{
if (obj != null)
{
var otherConfig = obj as MetricSeriesConfigurationForMeasurement;
if (otherConfig != null)
if (obj is MetricSeriesConfigurationForMeasurement otherConfig)
{
return this.Equals(otherConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ public void Dispose()
/// <param name="exception">Exception to log.</param>
private static void LogException(Exception exception)
{
var aggregateException = exception as AggregateException;
if (aggregateException != null)
if (exception is AggregateException aggregateException)
{
aggregateException = aggregateException.Flatten();
foreach (Exception e in aggregateException.InnerExceptions)
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## VNext

- Reduce technical debt: Use pattern matching


## Version 2.18.0-beta1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ private static SeverityLevel GetSeverityLevel(LogLevel logLevel)

private void PopulateTelemetry(ITelemetry telemetry, IReadOnlyList<KeyValuePair<string, object>> stateDictionary, EventId eventId)
{
var telemetryWithProperties = telemetry as ISupportProperties;
if (telemetryWithProperties != null)
if (telemetry is ISupportProperties telemetryWithProperties)
{
IDictionary<string, string> dict = telemetryWithProperties.Properties;
dict["CategoryName"] = this.categoryName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ public void Configure(TelemetryConfiguration configuration)

foreach (ITelemetryProcessor processor in configuration.TelemetryProcessors)
{
ITelemetryModule module = processor as ITelemetryModule;
if (module != null)
if (processor is ITelemetryModule module)
{
module.Initialize(configuration);
}
Expand Down Expand Up @@ -303,8 +302,7 @@ private void AddQuickPulse(TelemetryConfiguration configuration)
{
if (this.applicationInsightsServiceOptions.EnableQuickPulseMetricStream)
{
QuickPulseTelemetryModule quickPulseModule = this.modules.FirstOrDefault((module) => module.GetType() == typeof(QuickPulseTelemetryModule)) as QuickPulseTelemetryModule;
if (quickPulseModule != null)
if (this.modules.FirstOrDefault((module) => module.GetType() == typeof(QuickPulseTelemetryModule)) is QuickPulseTelemetryModule quickPulseModule)
{
QuickPulseTelemetryProcessor processor = null;
configuration.DefaultTelemetrySink.TelemetryProcessorChainBuilder.Use((next) =>
Expand Down
8 changes: 2 additions & 6 deletions WEB/Src/PerformanceCollector/PerformanceCollector/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ private static Expression CreateDictionaryAccessExpression(ParameterExpression d

private static MethodInfo GetMethodInfo<T, TResult>(Expression<Func<T, TResult>> expression)
{
var member = expression.Body as MethodCallExpression;

if (member != null)
if (expression.Body is MethodCallExpression member)
{
return member.Method;
}
Expand All @@ -255,9 +253,7 @@ private static MethodInfo GetMethodInfo<T, TResult>(Expression<Func<T, TResult>>

private static MethodInfo GetMethodInfo<T1, T2, TResult>(Expression<Func<T1, T2, TResult>> expression)
{
var member = expression.Body as MethodCallExpression;

if (member != null)
if (expression.Body is MethodCallExpression member)
{
return member.Method;
}
Expand Down