Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# 10 - Migrate to targeted new #244

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Setup .NET Core SDK
uses: actions/[email protected]
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x

- name: Restore
run: dotnet restore
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup .NET Core SDK
uses: actions/[email protected]
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x

- name: Restore
run: dotnet restore
Expand Down
2 changes: 1 addition & 1 deletion Alexa.NET.Tests/Alexa.NET.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<NoWarn>CS0612,CS0618</NoWarn>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions Alexa.NET/Alexa.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<VersionPrefix>1.20.0</VersionPrefix>
<Authors>Tim Heuer, Steven Pears</Authors>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Alexa.NET</AssemblyName>
<AssemblyName>Alexa.NET</AssemblyName>
<PackageId>Alexa.NET</PackageId>
<PackageTags>amazon;alexa;echo;dot;echo dot;skills</PackageTags>
<PackageReleaseNotes>Adds support for PIN confirmation support . Thanks @stoiveyp</PackageReleaseNotes>
Expand All @@ -19,7 +19,7 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<LangVersion>8</LangVersion>
<LangVersion>10</LangVersion>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<DebugType>embedded</DebugType>
Expand Down
2 changes: 1 addition & 1 deletion Alexa.NET/ConnectionTasks/IConnectionTaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class IConnectionTaskExtensions

public static StartConnectionDirective ToConnectionDirective(this IConnectionTask task, string token = null)
{
return new StartConnectionDirective(task, token);
return new(task, token);
}
}
}
5 changes: 3 additions & 2 deletions Alexa.NET/ConnectionTasks/Inputs/PinConfirmation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ public class PinConfirmation:IConnectionTask

[JsonProperty("requestedAuthenticationConfidenceLevel")]
public AuthenticationConfidenceLevel RequestedAuthenticationConfidenceLevel { get; } =
new AuthenticationConfidenceLevel {
new()
{
Level = 400,
Custom = new AuthenticationConfidenceLevelCustomPolicy("VOICE_PIN")
Custom = new("VOICE_PIN")

};
}
Expand Down
2 changes: 1 addition & 1 deletion Alexa.NET/Helpers/MixedDateTimeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Alexa.NET.Helpers
{
public class MixedDateTimeConverter : Newtonsoft.Json.Converters.DateTimeConverterBase
{
static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
static readonly DateTime UnixEpoch = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
Expand Down
6 changes: 3 additions & 3 deletions Alexa.NET/Request/IntentSignature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed class IntentSignature
public string Action { get; private set; }
public System.Collections.ObjectModel.ReadOnlyDictionary<string, IntentProperty> Properties { get; private set; }

private static Regex PropertyFinder = new Regex(@"(\w+?)@(\w+?)\b(\[(\w+)\])*", RegexOptions.Compiled);
private static Regex PropertyFinder = new(@"(\w+?)@(\w+?)\b(\[(\w+)\])*", RegexOptions.Compiled);

private IntentSignature(string fullName)
{
Expand Down Expand Up @@ -89,11 +89,11 @@ private static void ParseComplex(string action, IntentSignature name)
{
propertyDictionary.Add(
match.Groups[1].Value,
new IntentProperty(match.Groups[2].Value,match.Groups[4].Value)
new(match.Groups[2].Value,match.Groups[4].Value)
);
}

name.Properties = new System.Collections.ObjectModel.ReadOnlyDictionary<string, IntentProperty>(propertyDictionary);
name.Properties = new(propertyDictionary);
}
}
}
4 changes: 2 additions & 2 deletions Alexa.NET/Request/RequestVerification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public static async Task<X509Certificate2> GetCertificate(Uri certificatePath)
{
var response = await new HttpClient().GetAsync(certificatePath);
var bytes = await response.Content.ReadAsByteArrayAsync();
return new X509Certificate2(bytes);
return new(bytes);
}

public static bool VerifyChain(X509Certificate2 certificate)
{
//https://stackoverflow.com/questions/24618798/automated-downloading-of-x509-certificatePath-chain-from-remote-host

X509Chain certificateChain = new X509Chain();
X509Chain certificateChain = new();
//If you do not provide revokation information, use the following line.
certificateChain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
return certificateChain.Build(certificate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Alexa.NET.Request.Type
{
public class ConnectionResponseTypeConverter : IDataDrivenRequestTypeConverter
{
public static List<IConnectionResponseHandler> Handlers = new List<IConnectionResponseHandler>
public static List<IConnectionResponseHandler> Handlers = new()
{
new AskForRequestHandler()
};
Expand Down
2 changes: 1 addition & 1 deletion Alexa.NET/Request/Type/RequestConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Alexa.NET.Request.Type
{
public class RequestConverter : JsonConverter
{
public static readonly List<IRequestTypeConverter> RequestConverters = new List<IRequestTypeConverter>(new IRequestTypeConverter[]
public static readonly List<IRequestTypeConverter> RequestConverters = new(new IRequestTypeConverter[]
{
new DefaultRequestTypeConverter(),
new AudioPlayerRequestTypeConverter(),
Expand Down
2 changes: 1 addition & 1 deletion Alexa.NET/Response/AskForPermissionsConsentCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public string Type

[JsonProperty("permissions")]
[JsonRequired]
public List<string> Permissions { get; set; } = new List<string>();
public List<string> Permissions { get; set; } = new();
}
}
4 changes: 2 additions & 2 deletions Alexa.NET/Response/Converters/CardConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CardConverter : JsonConverter

public override bool CanRead => true;

public static Dictionary<string, Func<ICard>> TypeFactories = new Dictionary<string, Func<ICard>>
public static Dictionary<string, Func<ICard>> TypeFactories = new()
{
{ "Simple", () => new SimpleCard() },
{ "Standard", () => new StandardCard() },
Expand All @@ -33,7 +33,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
var hasFactory = TypeFactories.ContainsKey(typeValue);

if (!hasFactory)
throw new Exception(
throw new(
$"unable to deserialize response. " +
$"unrecognized card type '{typeValue}'"
);
Expand Down
6 changes: 3 additions & 3 deletions Alexa.NET/Response/Converters/ConnectionTaskConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Alexa.NET.Response.Converters
{
public class ConnectionTaskConverter : JsonConverter
{
public static Dictionary<string, Func<IConnectionTask>> TaskFactoryFromUri = new Dictionary<string, Func<IConnectionTask>>
public static Dictionary<string, Func<IConnectionTask>> TaskFactoryFromUri = new()
{
{"PrintPDFRequest/1",() => new PrintPdfV1() },
{"PrintImageRequest/1", () => new PrintImageV1() },
Expand All @@ -20,7 +20,7 @@ public class ConnectionTaskConverter : JsonConverter
{"ScheduleFoodEstablishmentReservationRequest/1",() => new ScheduleFoodEstablishmentReservation()}
};

public static readonly List<IConnectionTaskConverter> ConnectionTaskConverters = new List<IConnectionTaskConverter>();
public static readonly List<IConnectionTaskConverter> ConnectionTaskConverters = new();

public override bool CanRead => true;
public override bool CanWrite => false;
Expand Down Expand Up @@ -49,7 +49,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
// Check task converters
var converter = ConnectionTaskConverters.FirstOrDefault(c => c.CanConvert(jsonObject));
if(converter is null)
throw new Exception(
throw new(
$"unable to deserialize response. " +
$"unrecognized task type '{typeKey}' with version '{versionKey}'"
);
Expand Down
4 changes: 2 additions & 2 deletions Alexa.NET/Response/Converters/DirectiveConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class DirectiveConverter : JsonConverter

public override bool CanWrite => false;

public static Dictionary<string, Func<IDirective>> TypeFactories = new Dictionary<string, Func<IDirective>>
public static Dictionary<string, Func<IDirective>> TypeFactories = new()
{
{ "AudioPlayer.Play", () => new AudioPlayerPlayDirective() },
{ "AudioPlayer.ClearQueue", () => new ClearQueueDirective() },
Expand All @@ -30,7 +30,7 @@ public class DirectiveConverter : JsonConverter
};

public static Dictionary<string, Func<JObject, IDirective>> DataDrivenTypeFactory =
new Dictionary<string, Func<JObject, IDirective>>
new()
{
{"Connections.SendRequest", ConnectionSendRequestFactory.Create}
};
Expand Down
4 changes: 2 additions & 2 deletions Alexa.NET/Response/Converters/OutputSpeechConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class OutputSpeechConverter : JsonConverter

public override bool CanWrite => false;

public static Dictionary<string, Func<IOutputSpeech>> TypeFactories = new Dictionary<string, Func<IOutputSpeech>>
public static Dictionary<string, Func<IOutputSpeech>> TypeFactories = new()
{
{ "SSML", () => new SsmlOutputSpeech() },
{ "PlainText", () => new PlainTextOutputSpeech() },
Expand All @@ -31,7 +31,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
var hasFactory = TypeFactories.ContainsKey(typeValue);

if (!hasFactory)
throw new Exception(
throw new(
$"unable to deserialize response. " +
$"unrecognized output speech type '{typeValue}'"
);
Expand Down
4 changes: 2 additions & 2 deletions Alexa.NET/Response/Converters/TemplateConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TemplateConverter : JsonConverter

public override bool CanWrite => false;

public static Dictionary<string, Func<ITemplate>> TypeFactories = new Dictionary<string, Func<ITemplate>>
public static Dictionary<string, Func<ITemplate>> TypeFactories = new()
{
{ "BodyTemplate1", () => new BodyTemplate1() },
{ "BodyTemplate2", () => new BodyTemplate2() },
Expand All @@ -38,7 +38,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
var hasFactory = TypeFactories.ContainsKey(typeValue);

if (!hasFactory)
throw new Exception(
throw new(
$"unable to deserialize response. " +
$"unrecognized template type '{typeValue}'"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public AskForPermissionDirective()

public AskForPermissionDirective(string permissionScope)
{
this.Payload = new AskForPermissionPayload(permissionScope);
this.Payload = new(permissionScope);
}
}
}
4 changes: 2 additions & 2 deletions Alexa.NET/Response/Directive/AudioItemMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class AudioItemMetadata
public string Subtitle { get; set; }

[JsonProperty("art")]
public AudioItemSources Art { get; set; } = new AudioItemSources();
public AudioItemSources Art { get; set; } = new();

[JsonProperty("backgroundImage")]
public AudioItemSources BackgroundImage { get; set; } = new AudioItemSources();
public AudioItemSources BackgroundImage { get; set; } = new();
}
}
2 changes: 1 addition & 1 deletion Alexa.NET/Response/Directive/AudioItemSources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace Alexa.NET.Response.Directive
public class AudioItemSources
{
[JsonProperty("sources")]
public List<AudioItemSource> Sources { get; set; } = new List<AudioItemSource>();
public List<AudioItemSource> Sources { get; set; } = new();
}
}
2 changes: 1 addition & 1 deletion Alexa.NET/Response/Directive/CompleteTaskDirective.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public CompleteTaskDirective() { }

public CompleteTaskDirective(int statusCode, string statusMessage)
{
Status = new ConnectionStatus(statusCode,statusMessage);
Status = new(statusCode,statusMessage);
}

[JsonProperty("type")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Alexa.NET.Response.Directive
{
public static class ConnectionSendRequestFactory
{
public static List<IConnectionSendRequestHandler> Handlers = new List<IConnectionSendRequestHandler>
public static List<IConnectionSendRequestHandler> Handlers = new()
{
new AskForPermissionDirectiveHandler()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class DialogUpdateDynamicEntities : IDirective
public UpdateBehavior UpdateBehavior { get; set; }

[JsonProperty("types")]
public List<SlotType> Types { get; set; } = new List<SlotType>();
public List<SlotType> Types { get; set; } = new();
}
}
2 changes: 1 addition & 1 deletion Alexa.NET/Response/Directive/HintDirective.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public HintDirective()

public HintDirective(string hintText, string textType = TextType.Plain)
{
Hint = new Hint(hintText, textType);
Hint = new(hintText, textType);
}

[JsonProperty("type")]
Expand Down
2 changes: 1 addition & 1 deletion Alexa.NET/Response/Directive/JsonDirective.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public JsonDirective(string type)
public string Type { get; }

[JsonExtensionData]
public Dictionary<string, object> Properties { get; set; } = new Dictionary<string, object>();
public Dictionary<string, object> Properties { get; set; } = new();
}
}
2 changes: 1 addition & 1 deletion Alexa.NET/Response/Directive/Templates/TemplateImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class TemplateImage
public string ContentDescription { get; set; }

[JsonProperty("sources")]
public List<ImageSource> Sources {get;set;} = new List<ImageSource>();
public List<ImageSource> Sources {get;set;} = new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ListTemplate1:IListTemplate
[JsonProperty("backgroundImage", NullValueHandling = NullValueHandling.Ignore)]
public TemplateImage BackgroundImage { get; set; }

public List<ListItem> Items { get; set; } = new List<ListItem>();
public List<ListItem> Items { get; set; } = new();

public bool ShouldSerializeItems()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ListTemplate2:IListTemplate
[JsonProperty("backgroundImage", NullValueHandling = NullValueHandling.Ignore)]
public TemplateImage BackgroundImage { get; set; }

public List<ListItem> Items { get; set; } = new List<ListItem>();
public List<ListItem> Items { get; set; } = new();

public bool ShouldSerializeItems()
{
Expand Down
2 changes: 1 addition & 1 deletion Alexa.NET/Response/Directive/VideoAppDirective.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public VideoAppDirective()

public VideoAppDirective(string source)
{
VideoItem = new VideoItem(source);
VideoItem = new(source);
}

[JsonProperty("type")]
Expand Down
10 changes: 5 additions & 5 deletions Alexa.NET/Response/ProgressiveResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static bool IsSupported(SkillRequest request)
}


public ProgressiveResponse(SkillRequest request) : this(request, new HttpClient())
public ProgressiveResponse(SkillRequest request) : this(request, new())
{

}
Expand All @@ -34,7 +34,7 @@ public ProgressiveResponse(SkillRequest request,HttpClient client) : this(
{
}

public ProgressiveResponse(string requestId, string authToken, string baseAddress):this(requestId,authToken,baseAddress,new HttpClient())
public ProgressiveResponse(string requestId, string authToken, string baseAddress):this(requestId,authToken,baseAddress,new())
{

}
Expand All @@ -44,17 +44,17 @@ public ProgressiveResponse(string requestId, string authToken,string baseAddress
Client = client;
if (!string.IsNullOrWhiteSpace(baseAddress))
{
Client.BaseAddress = new Uri(baseAddress, UriKind.Absolute);
Client.BaseAddress = new(baseAddress, UriKind.Absolute);
}

if (!string.IsNullOrWhiteSpace(authToken))
{
Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
Client.DefaultRequestHeaders.Authorization = new("Bearer", authToken);
}

if (!string.IsNullOrWhiteSpace(requestId))
{
Header = new ProgressiveResponseHeader(requestId);
Header = new(requestId);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Alexa.NET/Response/Ssml/AmazonDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class AmazonDomain : ICommonSsml
{
public string Name { get; set; }

public List<ISsml> Elements { get; set; } = new List<ISsml>();
public List<ISsml> Elements { get; set; } = new();

public AmazonDomain(string name)
{
Expand Down
Loading