From a43857d6ef75f74db995fd299e03c54377f52687 Mon Sep 17 00:00:00 2001 From: Scott Dorman Date: Sun, 31 Jan 2021 12:11:00 -0500 Subject: [PATCH] Updates for supporting nullable ref types (#65) --- .../AnchorIconTagHelper.cs | 2 +- .../BootstrapNavLinkTagHelper.cs | 6 +- .../Breadcrumbs/BreadcrumbItemTagHelper.cs | 2 +- .../Cadru.AspNetCore.Mvc.TagHelpers.xml | 212 ------------------ .../InputPlaceholderTagHelper.cs | 19 +- .../Razor/LayoutViewLocationExpander.cs | 11 +- .../Rendering/HtmlHelperExtensions.cs | 15 +- src/Cadru.AspNetCore/Cadru.AspNetCore.xml | 212 ------------------ .../AddReleaseNotesRootEntry.cs | 91 ++++---- src/Cadru.Build.Tasks/Cadru.Build.Tasks.xml | 212 ++++++++++++++++++ src/Cadru.Build.Tasks/GetAssemblyVersion.cs | 16 +- src/Cadru.Build.Tasks/GetVersionProperties.cs | 88 ++++---- .../Internal/ErrorUtilities.cs | 15 +- .../Internal/FileUtilities.cs | 6 +- .../WriteThisAssemblyCodeFile.cs | 190 ++++++++-------- src/Cadru.Core/Cadru.Core.xml | 16 -- src/Cadru.Core/Extensions/StringExtensions.cs | 4 +- src/Cadru.Data.Dapper/CombTypeHandler.cs | 2 +- src/Cadru.Data.Dapper/CommandAdapter.cs | 14 +- src/Cadru.Data.Dapper/DapperContext.cs | 2 +- src/Cadru.Data/Cadru.Data.xml | 212 ------------------ src/Cadru.Data/UnboxT.cs | 18 +- .../IFileInfoExtensions.cs | 13 +- .../Cadru.Net.NetworkInformation.xml | 212 ++++++++++++++++++ src/Cadru.Polly/Cadru.Polly.xml | 212 ------------------ 25 files changed, 707 insertions(+), 1095 deletions(-) diff --git a/src/Cadru.AspNetCore.Mvc.TagHelpers/AnchorIconTagHelper.cs b/src/Cadru.AspNetCore.Mvc.TagHelpers/AnchorIconTagHelper.cs index 12a4697b..96611e9e 100644 --- a/src/Cadru.AspNetCore.Mvc.TagHelpers/AnchorIconTagHelper.cs +++ b/src/Cadru.AspNetCore.Mvc.TagHelpers/AnchorIconTagHelper.cs @@ -49,7 +49,7 @@ public AnchorIconTagHelper(IHtmlGenerator generator) : base(generator) /// The CSS classes for the icon element. /// [HtmlAttributeName(IconAttributeName)] - public string IconCss { get; set; } + public string? IconCss { get; set; } /// public override void Process(TagHelperContext context, TagHelperOutput output) diff --git a/src/Cadru.AspNetCore.Mvc.TagHelpers/BootstrapNavLinkTagHelper.cs b/src/Cadru.AspNetCore.Mvc.TagHelpers/BootstrapNavLinkTagHelper.cs index a4f814f1..39f8feb1 100644 --- a/src/Cadru.AspNetCore.Mvc.TagHelpers/BootstrapNavLinkTagHelper.cs +++ b/src/Cadru.AspNetCore.Mvc.TagHelpers/BootstrapNavLinkTagHelper.cs @@ -52,7 +52,7 @@ public BootstrapNavLinkTagHelper(IHtmlGenerator generator) : base(generator) /// The CSS classes for the icon element. /// [HtmlAttributeName(IconAttributeName)] - public string IconCss { get; set; } + public string? IconCss { get; set; } /// public async override void Process(TagHelperContext context, TagHelperOutput output) @@ -86,11 +86,11 @@ public async override void Process(TagHelperContext context, TagHelperOutput out if (this.ShouldBeActive()) { - this.MakeActive(output); + MakeActive(output); } } - private void MakeActive(TagHelperOutput output) + private static void MakeActive(TagHelperOutput output) { if (output.Attributes.TryGetAttribute("class", out var classAttribute)) { diff --git a/src/Cadru.AspNetCore.Mvc.TagHelpers/Breadcrumbs/BreadcrumbItemTagHelper.cs b/src/Cadru.AspNetCore.Mvc.TagHelpers/Breadcrumbs/BreadcrumbItemTagHelper.cs index bcb975e7..899bd00e 100644 --- a/src/Cadru.AspNetCore.Mvc.TagHelpers/Breadcrumbs/BreadcrumbItemTagHelper.cs +++ b/src/Cadru.AspNetCore.Mvc.TagHelpers/Breadcrumbs/BreadcrumbItemTagHelper.cs @@ -65,7 +65,7 @@ public BreadcrumbItemTagHelper(IHtmlGenerator generator, HtmlEncoder htmlEncoder /// [HtmlAttributeNotBound] [ViewContext] - public ViewContext ViewContext { get; set; } + public ViewContext? ViewContext { get; set; } /// /// Gets the used to generate the diff --git a/src/Cadru.AspNetCore.Mvc.TagHelpers/Cadru.AspNetCore.Mvc.TagHelpers.xml b/src/Cadru.AspNetCore.Mvc.TagHelpers/Cadru.AspNetCore.Mvc.TagHelpers.xml index d615ac00..673e1961 100644 --- a/src/Cadru.AspNetCore.Mvc.TagHelpers/Cadru.AspNetCore.Mvc.TagHelpers.xml +++ b/src/Cadru.AspNetCore.Mvc.TagHelpers/Cadru.AspNetCore.Mvc.TagHelpers.xml @@ -232,217 +232,5 @@ A new representing the HTML tag. - - - Specifies that is allowed as an input even if the - corresponding type disallows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that is disallowed as an input even if the - corresponding type allows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that a method that will never return under any circumstance. - - - - - Initializes a new instance of the class. - - - - - - Specifies that the method will not return if the associated - parameter is passed the specified value. - - - - - Gets the condition parameter value. - Code after the method is considered unreachable by diagnostics if the argument - to the associated parameter matches this value. - - - - - Initializes a new instance of the - class with the specified parameter value. - - - The condition parameter value. - Code after the method is considered unreachable by diagnostics if the argument - to the associated parameter matches this value. - - - - - Specifies that an output may be even if the - corresponding type disallows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that when a method returns , - the parameter may be even if the corresponding type disallows it. - - - - - Gets the return value condition. - If the method returns this value, the associated parameter may be . - - - - - Initializes the attribute with the specified return value condition. - - - The return value condition. - If the method returns this value, the associated parameter may be . - - - - - Specifies that the method or property will ensure that the listed field and property members have - not- values. - - - - - Gets field or property member names. - - - - - Initializes the attribute with a field or property member. - - - The field or property member that is promised to be not-null. - - - - - Initializes the attribute with the list of field and property members. - - - The list of field and property members that are promised to be not-null. - - - - - Specifies that the method or property will ensure that the listed field and property members have - non- values when returning with the specified return value condition. - - - - - Gets the return value condition. - - - - - Gets field or property member names. - - - - - Initializes the attribute with the specified return value condition and a field or property member. - - - The return value condition. If the method returns this value, - the associated parameter will not be . - - - The field or property member that is promised to be not-. - - - - - Initializes the attribute with the specified return value condition and list - of field and property members. - - - The return value condition. If the method returns this value, - the associated parameter will not be . - - - The list of field and property members that are promised to be not-null. - - - - - Specifies that an output is not even if the - corresponding type allows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that the output will be non- if the - named parameter is non-. - - - - - Gets the associated parameter name. - The output will be non- if the argument to the - parameter specified is non-. - - - - - Initializes the attribute with the associated parameter name. - - - The associated parameter name. - The output will be non- if the argument to the - parameter specified is non-. - - - - - Specifies that when a method returns , - the parameter will not be even if the corresponding type allows it. - - - - - Gets the return value condition. - If the method returns this value, the associated parameter will not be . - - - - - Initializes the attribute with the specified return value condition. - - - The return value condition. - If the method returns this value, the associated parameter will not be . - - diff --git a/src/Cadru.AspNetCore.Mvc.TagHelpers/InputPlaceholderTagHelper.cs b/src/Cadru.AspNetCore.Mvc.TagHelpers/InputPlaceholderTagHelper.cs index 2c138449..f5642527 100644 --- a/src/Cadru.AspNetCore.Mvc.TagHelpers/InputPlaceholderTagHelper.cs +++ b/src/Cadru.AspNetCore.Mvc.TagHelpers/InputPlaceholderTagHelper.cs @@ -50,28 +50,31 @@ public InputPlaceholderTagHelper(IHtmlGenerator generator) : base(generator) /// An expression to be evaluated against the current model. /// [HtmlAttributeName(PlaceholderAttributeName)] - public ModelExpression Placeholder { get; set; } + public ModelExpression? Placeholder { get; set; } /// public override void Process(TagHelperContext context, TagHelperOutput output) { base.Process(context, output); - var placeholder = this.GetPlaceholder(this.Placeholder.ModelExplorer); - if (!output.Attributes.TryGetAttribute("placeholder", out _)) + if (this.Placeholder != null) { - output.Attributes.Add(new TagHelperAttribute("placeholder", placeholder)); + var placeholder = this.GetPlaceholder(); + if (!output.Attributes.TryGetAttribute("placeholder", out _)) + { + output.Attributes.Add(new TagHelperAttribute("placeholder", placeholder)); + } } } - private string GetPlaceholder(ModelExplorer modelExplorer) + private string? GetPlaceholder() { - string placeholder; - placeholder = modelExplorer.Metadata.Placeholder; + var modelExplorer = this.Placeholder?.ModelExplorer; + var placeholder = modelExplorer?.Metadata.Placeholder; if (String.IsNullOrWhiteSpace(placeholder)) { - placeholder = modelExplorer.Metadata.GetDisplayName(); + placeholder = modelExplorer?.Metadata.GetDisplayName(); } return placeholder; diff --git a/src/Cadru.AspNetCore.Mvc/Razor/LayoutViewLocationExpander.cs b/src/Cadru.AspNetCore.Mvc/Razor/LayoutViewLocationExpander.cs index e4b4f356..d1ba31ca 100644 --- a/src/Cadru.AspNetCore.Mvc/Razor/LayoutViewLocationExpander.cs +++ b/src/Cadru.AspNetCore.Mvc/Razor/LayoutViewLocationExpander.cs @@ -48,14 +48,15 @@ public IEnumerable ExpandViewLocations(ViewLocationExpanderContext conte throw new ArgumentNullException(nameof(viewLocations)); } - context.Values.TryGetValue(ValueKey, out var value); - - if (!String.IsNullOrEmpty(value)) + if (context.Values.TryGetValue(ValueKey, out var value)) { - return viewLocations; + if (!String.IsNullOrEmpty(value)) + { + } } - return this.ExpandViewLocationsCore(viewLocations, value); + + return viewLocations; } /// diff --git a/src/Cadru.AspNetCore.Mvc/Rendering/HtmlHelperExtensions.cs b/src/Cadru.AspNetCore.Mvc/Rendering/HtmlHelperExtensions.cs index 6ab4ac97..e8eab463 100644 --- a/src/Cadru.AspNetCore.Mvc/Rendering/HtmlHelperExtensions.cs +++ b/src/Cadru.AspNetCore.Mvc/Rendering/HtmlHelperExtensions.cs @@ -92,12 +92,17 @@ public static IEnumerable GetEnumSelectList(this IHtmlHelper htm foreach (var name in Enum.GetNames(underlyingType)) { var field = underlyingType.GetField(name); - if (HasUiHint(field, uiHint)) + if (field != null) { - var displayName = GetDisplayName(field); - var value = ((Enum)field.GetValue(obj: null)).ToString("d"); - - displayNamesAndValues.Add(new KeyValuePair(displayName, value)); + if (HasUiHint(field, uiHint)) + { + var displayName = GetDisplayName(field); + var value = field.GetValue(obj: null); + if (value != null) + { + displayNamesAndValues.Add(new KeyValuePair(displayName, ((Enum)value).ToString())); + } + } } } diff --git a/src/Cadru.AspNetCore/Cadru.AspNetCore.xml b/src/Cadru.AspNetCore/Cadru.AspNetCore.xml index af1c9781..12ada7e9 100644 --- a/src/Cadru.AspNetCore/Cadru.AspNetCore.xml +++ b/src/Cadru.AspNetCore/Cadru.AspNetCore.xml @@ -530,217 +530,5 @@ Looks up a localized string similar to The type '{0}' defines properties '{1}' and '{2}' which differ only by casing. This is not supported by {3} which uses case-insensitive comparisons.. - - - Specifies that is allowed as an input even if the - corresponding type disallows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that is disallowed as an input even if the - corresponding type allows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that a method that will never return under any circumstance. - - - - - Initializes a new instance of the class. - - - - - - Specifies that the method will not return if the associated - parameter is passed the specified value. - - - - - Gets the condition parameter value. - Code after the method is considered unreachable by diagnostics if the argument - to the associated parameter matches this value. - - - - - Initializes a new instance of the - class with the specified parameter value. - - - The condition parameter value. - Code after the method is considered unreachable by diagnostics if the argument - to the associated parameter matches this value. - - - - - Specifies that an output may be even if the - corresponding type disallows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that when a method returns , - the parameter may be even if the corresponding type disallows it. - - - - - Gets the return value condition. - If the method returns this value, the associated parameter may be . - - - - - Initializes the attribute with the specified return value condition. - - - The return value condition. - If the method returns this value, the associated parameter may be . - - - - - Specifies that the method or property will ensure that the listed field and property members have - not- values. - - - - - Gets field or property member names. - - - - - Initializes the attribute with a field or property member. - - - The field or property member that is promised to be not-null. - - - - - Initializes the attribute with the list of field and property members. - - - The list of field and property members that are promised to be not-null. - - - - - Specifies that the method or property will ensure that the listed field and property members have - non- values when returning with the specified return value condition. - - - - - Gets the return value condition. - - - - - Gets field or property member names. - - - - - Initializes the attribute with the specified return value condition and a field or property member. - - - The return value condition. If the method returns this value, - the associated parameter will not be . - - - The field or property member that is promised to be not-. - - - - - Initializes the attribute with the specified return value condition and list - of field and property members. - - - The return value condition. If the method returns this value, - the associated parameter will not be . - - - The list of field and property members that are promised to be not-null. - - - - - Specifies that an output is not even if the - corresponding type allows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that the output will be non- if the - named parameter is non-. - - - - - Gets the associated parameter name. - The output will be non- if the argument to the - parameter specified is non-. - - - - - Initializes the attribute with the associated parameter name. - - - The associated parameter name. - The output will be non- if the argument to the - parameter specified is non-. - - - - - Specifies that when a method returns , - the parameter will not be even if the corresponding type allows it. - - - - - Gets the return value condition. - If the method returns this value, the associated parameter will not be . - - - - - Initializes the attribute with the specified return value condition. - - - The return value condition. - If the method returns this value, the associated parameter will not be . - - diff --git a/src/Cadru.Build.Tasks/AddReleaseNotesRootEntry.cs b/src/Cadru.Build.Tasks/AddReleaseNotesRootEntry.cs index fcf3bfa1..5a1cdcca 100644 --- a/src/Cadru.Build.Tasks/AddReleaseNotesRootEntry.cs +++ b/src/Cadru.Build.Tasks/AddReleaseNotesRootEntry.cs @@ -52,81 +52,88 @@ public class AddReleaseNotesRootEntry : Task /// This can be the property value. /// [Required] - public string BuildDate { get; set; } + public string? BuildDate { get; set; } /// /// The release notes XML file to be updated. /// [Required] - public ITaskItem File { get; set; } + public ITaskItem? File { get; set; } /// /// An optional milestone value to include in the release notes entry. /// - public string Milestone { get; set; } + public string? Milestone { get; set; } /// /// The build version. /// [Required] - public string Version { get; set; } + public string? Version { get; set; } /// /// Main entry point. /// public override bool Execute() { - var document = XDocument.Load(this.File.ItemSpec); - var entry = document.Root.Descendants("entry").SingleOrDefault(e => e.Attribute("version").Value == "vNext" || String.IsNullOrEmpty(e.Attribute("version").Value) || e.Attribute("version").Value == this.Version); - if (entry != null) + if (this.File != null) { - this.Log.LogMessage("Build entry found; updating attributes."); - entry.Attribute("version").Value = this.Version; - entry.Attribute("build-date").Value = this.BuildDate; - - if (!String.IsNullOrWhiteSpace(this.Milestone)) + var document = XDocument.Load(this.File.ItemSpec); + if (document.Root != null) { - var milestoneAttribute = entry.Attribute("milestone"); - if (milestoneAttribute != null) - { - milestoneAttribute.Value = this.Milestone; - } - } + var versionString = this.Version ?? String.Empty; + var buildDateString = this.BuildDate ?? String.Empty; - document.Save(this.File.ItemSpec); - } - else - { - this.Log.LogMessage("Build entry not found."); - if (this.AddIfNotFound) - { - this.Log.LogMessage("Adding new build entry."); - entry = new XElement("entry", - new XAttribute("build-date", this.BuildDate), - new XAttribute("version", this.Version), - new XElement("content", - new XElement("ul"))); - - if (!String.IsNullOrWhiteSpace(this.Milestone)) + var entry = document.Root.Descendants("entry").SingleOrDefault(e => e.Attribute("version")?.Value == "vNext" || String.IsNullOrEmpty(e.Attribute("version")?.Value) || e.Attribute("version")?.Value == this.Version); + if (entry != null) { - entry.Add(new XAttribute("milestone", this.Milestone)); - } + this.Log.LogMessage("Build entry found; updating attributes."); + entry.Attribute("version")?.SetValue(versionString); + entry.Attribute("build-date")?.SetValue(buildDateString); - var commentTemplate = document.DescendantNodes().OfType().FirstOrDefault(); - if (commentTemplate != null) - { - commentTemplate.AddAfterSelf(entry); + if (!String.IsNullOrWhiteSpace(this.Milestone)) + { + entry.Attribute("milestone")?.SetValue(this.Milestone); + } + + document.Save(this.File.ItemSpec); } else { - document.Root.AddFirst(entry); + this.Log.LogMessage("Build entry not found."); + if (this.AddIfNotFound) + { + this.Log.LogMessage("Adding new build entry."); + entry = new XElement("entry", + new XAttribute("build-date", buildDateString), + new XAttribute("version", versionString), + new XElement("content", + new XElement("ul"))); + + if (!String.IsNullOrWhiteSpace(this.Milestone)) + { + entry.Add(new XAttribute("milestone", this.Milestone)); + } + + var commentTemplate = document.DescendantNodes().OfType().FirstOrDefault(); + if (commentTemplate != null) + { + commentTemplate.AddAfterSelf(entry); + } + else + { + document.Root.AddFirst(entry); + } + + document.Save(this.File.ItemSpec); + } } - document.Save(this.File.ItemSpec); + return true; } } - return true; + return false; } } } \ No newline at end of file diff --git a/src/Cadru.Build.Tasks/Cadru.Build.Tasks.xml b/src/Cadru.Build.Tasks/Cadru.Build.Tasks.xml index 99c2da08..7a7932a7 100644 --- a/src/Cadru.Build.Tasks/Cadru.Build.Tasks.xml +++ b/src/Cadru.Build.Tasks/Cadru.Build.Tasks.xml @@ -533,5 +533,217 @@ string. Returns the default language extension as an out parameter. + + + Specifies that is allowed as an input even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that is disallowed as an input even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that a method that will never return under any circumstance. + + + + + Initializes a new instance of the class. + + + + + + Specifies that the method will not return if the associated + parameter is passed the specified value. + + + + + Gets the condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Initializes a new instance of the + class with the specified parameter value. + + + The condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Specifies that an output may be even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that when a method returns , + the parameter may be even if the corresponding type disallows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter may be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter may be . + + + + + Specifies that the method or property will ensure that the listed field and property members have + not- values. + + + + + Gets field or property member names. + + + + + Initializes the attribute with a field or property member. + + + The field or property member that is promised to be not-null. + + + + + Initializes the attribute with the list of field and property members. + + + The list of field and property members that are promised to be not-null. + + + + + Specifies that the method or property will ensure that the listed field and property members have + non- values when returning with the specified return value condition. + + + + + Gets the return value condition. + + + + + Gets field or property member names. + + + + + Initializes the attribute with the specified return value condition and a field or property member. + + + The return value condition. If the method returns this value, + the associated parameter will not be . + + + The field or property member that is promised to be not-. + + + + + Initializes the attribute with the specified return value condition and list + of field and property members. + + + The return value condition. If the method returns this value, + the associated parameter will not be . + + + The list of field and property members that are promised to be not-null. + + + + + Specifies that an output is not even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that the output will be non- if the + named parameter is non-. + + + + + Gets the associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Initializes the attribute with the associated parameter name. + + + The associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Specifies that when a method returns , + the parameter will not be even if the corresponding type allows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter will not be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter will not be . + + diff --git a/src/Cadru.Build.Tasks/GetAssemblyVersion.cs b/src/Cadru.Build.Tasks/GetAssemblyVersion.cs index eefd2ac6..367b2e69 100644 --- a/src/Cadru.Build.Tasks/GetAssemblyVersion.cs +++ b/src/Cadru.Build.Tasks/GetAssemblyVersion.cs @@ -20,6 +20,7 @@ // //------------------------------------------------------------------------------ +using System; using System.Reflection; using Microsoft.Build.Framework; @@ -38,22 +39,27 @@ public class GetAssemblyVersion : Task /// Gets the value. /// [Output] - public string AssemblyVersion { get; private set; } + public string? AssemblyVersion { get; private set; } /// /// The NuGet version used to derive the assembly version from. /// [Required] - public string NuGetVersion { get; set; } + public string? NuGetVersion { get; set; } /// /// Main entry point. /// public override bool Execute() { - var args = this.NuGetVersion.Split('-'); - this.AssemblyVersion = args[0]; - return true; + if (!String.IsNullOrWhiteSpace(this.NuGetVersion)) + { + var args = this.NuGetVersion!.Split('-'); + this.AssemblyVersion = args[0]; + return true; + } + + return false; } } } \ No newline at end of file diff --git a/src/Cadru.Build.Tasks/GetVersionProperties.cs b/src/Cadru.Build.Tasks/GetVersionProperties.cs index c5bdb99e..81bef983 100644 --- a/src/Cadru.Build.Tasks/GetVersionProperties.cs +++ b/src/Cadru.Build.Tasks/GetVersionProperties.cs @@ -128,13 +128,13 @@ public class GetVersionProperties : Task /// Gets the value of the build date. /// [Output] - public string BuildDate { get; private set; } + public string? BuildDate { get; private set; } /// /// Gets or sets the path to the properties file to be updated. /// [Required] - public ITaskItem PropertiesFile { get; set; } + public ITaskItem? PropertiesFile { get; set; } /// /// Gets the value of the revision component of the version number. @@ -152,47 +152,55 @@ public class GetVersionProperties : Task /// public override bool Execute() { - var now = DateTimeOffset.UtcNow; - this.BuildDate = now.ToString(); - - Enum.TryParse(this.Strategy, out var versionStrategy); - - switch (versionStrategy) - { - case VersionStrategy.ShortDate: - this.ShortDateStrategy(now); - break; - - case VersionStrategy.VisualStudio: - this.VisualStudioStrategy(now); - break; - - case VersionStrategy.DayOfYear: - this.DayOfYearStrategy(now); - break; - } - - XDocument document; - - if (!File.Exists(this.PropertiesFile.ItemSpec)) - { - document = new XDocument(new XComment("This file may be overwritten by automation."), - new XElement("Project", - new XElement("PropertyGroup", - new XElement("BuildDate", this.BuildDate), - new XElement("VersionBuild", this.Build), - new XElement("VersionRevision", this.Revision)))); - } - else + if (this.PropertiesFile != null) { - document = XDocument.Load(this.PropertiesFile.ItemSpec); - document.Root.XPathSelectElement("//BuildDate").SetValue(this.BuildDate); - document.Root.XPathSelectElement("//VersionBuild").SetValue(this.Build); - document.Root.XPathSelectElement("//VersionRevision").SetValue(this.Revision); + var now = DateTimeOffset.UtcNow; + this.BuildDate = now.ToString(); + + if (!Enum.TryParse(this.Strategy, out var versionStrategy)) + { + versionStrategy = VersionStrategy.ShortDate; + } + + switch (versionStrategy) + { + case VersionStrategy.ShortDate: + this.ShortDateStrategy(now); + break; + + case VersionStrategy.VisualStudio: + this.VisualStudioStrategy(now); + break; + + case VersionStrategy.DayOfYear: + this.DayOfYearStrategy(now); + break; + } + + XDocument document; + + if (!File.Exists(this.PropertiesFile.ItemSpec)) + { + document = new XDocument(new XComment("This file may be overwritten by automation."), + new XElement("Project", + new XElement("PropertyGroup", + new XElement("BuildDate", this.BuildDate), + new XElement("VersionBuild", this.Build), + new XElement("VersionRevision", this.Revision)))); + } + else + { + document = XDocument.Load(this.PropertiesFile.ItemSpec); + document.Root?.XPathSelectElement("//BuildDate")?.SetValue(this.BuildDate); + document.Root?.XPathSelectElement("//VersionBuild")?.SetValue(this.Build); + document.Root?.XPathSelectElement("//VersionRevision")?.SetValue(this.Revision); + } + + document.Save(this.PropertiesFile.ItemSpec); + return true; } - document.Save(this.PropertiesFile.ItemSpec); - return true; + return false; } private void DayOfYearStrategy(DateTimeOffset now) diff --git a/src/Cadru.Build.Tasks/Internal/ErrorUtilities.cs b/src/Cadru.Build.Tasks/Internal/ErrorUtilities.cs index f1a816ad..821e60c1 100644 --- a/src/Cadru.Build.Tasks/Internal/ErrorUtilities.cs +++ b/src/Cadru.Build.Tasks/Internal/ErrorUtilities.cs @@ -21,14 +21,17 @@ //------------------------------------------------------------------------------ using System; +using System.Diagnostics.CodeAnalysis; using Cadru.Build.Tasks.Resources; +using Validation; + namespace Cadru.Build.Tasks.Internal { internal static class ErrorUtilities { - internal static void ThrowInternalError(string message, Exception innerException, params object[] args) + internal static void ThrowInternalError(string message, Exception? innerException, params object?[] args) { throw new Exception(String.Format(message, args), innerException); } @@ -39,11 +42,11 @@ internal static void VerifyThrow(bool condition, string unformattedMessage) { // PERF NOTE: explicitly passing null for the arguments array // prevents memory allocation - ThrowInternalError(unformattedMessage, null, null); + ThrowInternalError(unformattedMessage, null, Array.Empty()); } } - internal static void VerifyThrowArgumentLength(string parameter, string parameterName) + internal static void VerifyThrowArgumentLength([NotNull] string parameter, string parameterName) { VerifyThrowArgumentNull(parameter, parameterName); @@ -53,7 +56,7 @@ internal static void VerifyThrowArgumentLength(string parameter, string paramete } } - internal static void VerifyThrowArgumentLengthIfNotNull(string parameter, string parameterName) + internal static void VerifyThrowArgumentLengthIfNotNull([ValidatedNotNull] string parameter, string parameterName) { if (parameter != null && parameter.Length == 0) { @@ -61,13 +64,13 @@ internal static void VerifyThrowArgumentLengthIfNotNull(string parameter, string } } - internal static void VerifyThrowArgumentNull(object parameter, string parameterName) + internal static void VerifyThrowArgumentNull([NotNull] object parameter, string parameterName) { if (parameter == null) { // Most ArgumentNullException overloads append its own rather // clunky multi-line message. So use the one overload that doesn't. - throw new ArgumentNullException(String.Format(Strings.Shared_ParameterCannotBeNull, parameterName), (Exception)null); + throw new ArgumentNullException(String.Format(Strings.Shared_ParameterCannotBeNull, parameterName), (Exception?)null); } } } diff --git a/src/Cadru.Build.Tasks/Internal/FileUtilities.cs b/src/Cadru.Build.Tasks/Internal/FileUtilities.cs index f4cef93d..682344ae 100644 --- a/src/Cadru.Build.Tasks/Internal/FileUtilities.cs +++ b/src/Cadru.Build.Tasks/Internal/FileUtilities.cs @@ -84,7 +84,7 @@ internal static string GetTemporaryFile() /// internal static string GetTemporaryFile(string extension) { - return GetTemporaryFile(null, extension); + return GetTemporaryFile(null!, extension); } /// @@ -106,7 +106,7 @@ internal static string GetTemporaryFile(string directory, string extension, bool try { - directory = directory ?? Path.GetTempPath(); + directory ??= Path.GetTempPath(); Directory.CreateDirectory(directory); @@ -134,7 +134,7 @@ internal static string GetTemporaryFile(string directory, string extension, bool /// internal static string GetTemporaryFileName(string extension) { - return GetTemporaryFile(null, extension, false); + return GetTemporaryFile(null!, extension, false); } } } \ No newline at end of file diff --git a/src/Cadru.Build.Tasks/WriteThisAssemblyCodeFile.cs b/src/Cadru.Build.Tasks/WriteThisAssemblyCodeFile.cs index 5715f69e..dc9997f6 100644 --- a/src/Cadru.Build.Tasks/WriteThisAssemblyCodeFile.cs +++ b/src/Cadru.Build.Tasks/WriteThisAssemblyCodeFile.cs @@ -60,13 +60,13 @@ public WriteThisAssemblyCodeFile() : base(Strings.ResourceManager) /// "VisualBasic". Emitted file will have the default extension for that language. /// [Required] - public string Language { get; set; } + public string? Language { get; set; } /// /// The root namespace for the generated code. /// [Required] - public string RootNamespace { get; set; } + public string? RootNamespace { get; set; } /// /// Description of attributes to write. Item include is the full type @@ -78,14 +78,13 @@ public WriteThisAssemblyCodeFile() : base(Strings.ResourceManager) /// "_Parameter1", "_Parameter2" etc. If a parameter index is skipped, /// it's an error. /// - [SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "")] - public ITaskItem[] AssemblyAttributes { get; set; } + public ITaskItem[] AssemblyAttributes { get; set; } = Array.Empty(); /// /// Destination folder for the generated code. Typically the /// intermediate folder. /// - public ITaskItem OutputDirectory { get; set; } + public ITaskItem? OutputDirectory { get; set; } /// /// The path to the file that was generated. If this is set, and a file @@ -95,7 +94,7 @@ public WriteThisAssemblyCodeFile() : base(Strings.ResourceManager) /// will be used, and the default extension for the language selected. /// [Output] - public ITaskItem OutputFile { get; set; } + public ITaskItem? OutputFile { get; set; } /// /// Main entry point. @@ -135,7 +134,7 @@ public override bool Execute() this.OutputFile = new TaskItem(Path.Combine(this.OutputDirectory.ItemSpec, this.OutputFile.ItemSpec)); } - this.OutputFile = this.OutputFile ?? new TaskItem(FileUtilities.GetTemporaryFile(this.OutputDirectory.ItemSpec, extension)); + this.OutputFile ??= new TaskItem(FileUtilities.GetTemporaryFile(this.OutputDirectory!.ItemSpec, extension)); File.WriteAllText(this.OutputFile.ItemSpec, code); // Overwrites file if it already exists (and can be overwritten) } @@ -150,7 +149,7 @@ public override bool Execute() return !this.Log.HasLoggedErrors; } - private static CodeMemberField CreateConstant(string name, object value, CodeTypeReference codeTypeReference) + private static CodeMemberField CreateConstant(string? name, object? value, CodeTypeReference codeTypeReference) { var member = new CodeMemberField(codeTypeReference, name); member.Attributes = (member.Attributes & ~MemberAttributes.AccessMask & ~MemberAttributes.ScopeMask) | MemberAttributes.Public | MemberAttributes.Const; @@ -163,129 +162,136 @@ private static CodeMemberField CreateConstant(string name, object value, CodeTyp /// returns null. If no meaningful code is generated, returns empty /// string. Returns the default language extension as an out parameter. /// - [SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.IO.StringWriter.#ctor(System.Text.StringBuilder)", Justification = "Reads fine to me")] + // [SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.IO.StringWriter.#ctor(System.Text.StringBuilder)", Justification = "Reads fine to me")] private string GenerateCode(out string extension) { - var excludeAttributes = new List + extension = String.Empty; + var haveGeneratedContent = false; + var generatedCode = new StringBuilder(); + + if (!String.IsNullOrWhiteSpace(this.Language)) + { + var excludeAttributes = new List { "InternalsVisibleTo" }; - extension = null; - var haveGeneratedContent = false; - - CodeDomProvider provider; + CodeDomProvider provider; - try - { - provider = CodeDomProvider.CreateProvider(this.Language); - } - catch (SystemException e) when + try + { + provider = CodeDomProvider.CreateProvider(this.Language); + } + catch (SystemException e) when #if FEATURE_SYSTEM_CONFIGURATION (e is ConfigurationException || e is SecurityException) #else (e.GetType().Name == "ConfigurationErrorsException") //TODO: catch specific exception type once it is public https://github.com/dotnet/corefx/issues/40456 #endif - { - this.Log.LogErrorWithCodeFromResources("WriteCodeFragment.CouldNotCreateProvider", this.Language, e.Message); - return null; - } + { + this.Log.LogErrorWithCodeFromResources("WriteCodeFragment.CouldNotCreateProvider", this.Language, e.Message); + return String.Empty; + } - extension = provider.FileExtension; + extension = provider.FileExtension; - var unit = new CodeCompileUnit(); - var globalNamespace = new CodeNamespace(this.RootNamespace); - unit.Namespaces.Add(globalNamespace); + var unit = new CodeCompileUnit(); + var globalNamespace = new CodeNamespace(this.RootNamespace); + unit.Namespaces.Add(globalNamespace); - // Declare authorship. Unfortunately CodeDOM puts this comment after - // the attributes. - var comment = String.Format(Strings.WriteCodeFragment_Comment, this.GetType().Name); - globalNamespace.Comments.Add(new CodeCommentStatement(comment)); + // Declare authorship. Unfortunately CodeDOM puts this comment after + // the attributes. + var comment = String.Format(Strings.WriteCodeFragment_Comment, this.GetType().Name); + globalNamespace.Comments.Add(new CodeCommentStatement(comment)); - if (this.AssemblyAttributes == null) - { - return String.Empty; - } + if (this.AssemblyAttributes == null) + { + return String.Empty; + } - // For convenience, bring in the namespaces, where many assembly - // attributes lie - globalNamespace.Imports.Add(new CodeNamespaceImport("System")); - var codeTypeMembers = new CodeTypeMemberCollection(); + // For convenience, bring in the namespaces, where many assembly + // attributes lie + globalNamespace.Imports.Add(new CodeNamespaceImport("System")); + var codeTypeMembers = new CodeTypeMemberCollection(); - var rawFieldData = new Dictionary>>(); + var rawFieldData = new Dictionary>>(); - foreach (var attributeItem in this.AssemblyAttributes) - { - // All of the possible assembly attributes take a single - // constructor argument with the exception of AssemblyMetadata. - // That means, they all have only one entry in the metadata - // collection except AssemblyMetadata attributes, which will - // have two. - var customMetadata = attributeItem.CloneCustomMetadata(); - - foreach (DictionaryEntry entry in customMetadata) + foreach (var attributeItem in this.AssemblyAttributes) { - var name = (string)entry.Key; - var value = (string)entry.Value; - if (name.StartsWith("_Parameter", StringComparison.OrdinalIgnoreCase)) + // All of the possible assembly attributes take a single + // constructor argument with the exception of AssemblyMetadata. + // That means, they all have only one entry in the metadata + // collection except AssemblyMetadata attributes, which will + // have two. + var customMetadata = attributeItem.CloneCustomMetadata(); + + foreach (DictionaryEntry entry in customMetadata) { - if (!rawFieldData.TryGetValue(attributeItem.ItemSpec, out var data)) + var name = (string)entry.Key; + var value = (string?)entry.Value; + if (name.StartsWith("_Parameter", StringComparison.OrdinalIgnoreCase)) { - data = new List>(); - rawFieldData.Add(attributeItem.ItemSpec, data); - } + if (!rawFieldData.TryGetValue(attributeItem.ItemSpec, out var data)) + { + data = new List>(); + rawFieldData.Add(attributeItem.ItemSpec, data); + } - data.Add(new KeyValuePair(name, value)); + data.Add(new KeyValuePair(name, value)); + } } } - } - foreach (var entry in rawFieldData) - { - var name = entry.Key.Substring(entry.Key.LastIndexOf('.') + 1).Replace("Attribute", ""); - - if (excludeAttributes.Contains(name)) + foreach (var entry in rawFieldData) { - continue; - } +#if NETSTANDARD2_0 + var name = entry.Key.Substring(entry.Key.LastIndexOf('.') + 1).Replace("Attribute", ""); +#else + var name = entry.Key[(entry.Key.LastIndexOf('.') + 1)..].Replace("Attribute", ""); +#endif - if (entry.Value.Count == 1) - { - var expressionValue = entry.Value.First().Value; - codeTypeMembers.Add(CreateConstant(name, expressionValue, new CodeTypeReference(typeof(string)))); - } - else - { - for (var i = 0; i < entry.Value.Count; i += 2) + if (excludeAttributes.Contains(name)) { - codeTypeMembers.Add(CreateConstant((string)entry.Value.ElementAt(i + 1).Value, entry.Value.ElementAt(i).Value, new CodeTypeReference(typeof(string)))); + continue; } - } - haveGeneratedContent = true; - } + if (entry.Value.Count == 1) + { + var expressionValue = entry.Value.First().Value; + codeTypeMembers.Add(CreateConstant(name, expressionValue, new CodeTypeReference(typeof(string)))); + } + else + { + for (var i = 0; i < entry.Value.Count; i += 2) + { + var entryValue = entry.Value; + if (entryValue != null) + { + codeTypeMembers.Add(CreateConstant(entryValue.ElementAt(i + 1).Value?.ToString(), entryValue.ElementAt(i).Value, new CodeTypeReference(typeof(string)))); + } + } + } - var thisAssembly = new CodeTypeDeclaration("ThisAssembly") - { - IsStruct = true - }; + haveGeneratedContent = true; + } - thisAssembly.Members.AddRange(codeTypeMembers); - globalNamespace.Types.Add(thisAssembly); + var thisAssembly = new CodeTypeDeclaration("ThisAssembly") + { + IsStruct = true + }; - var generatedCode = new StringBuilder(); - using (var writer = new StringWriter(generatedCode, CultureInfo.CurrentCulture)) - { - generatedCode.AppendLine(new CodeWarningPragmaDirective(WarningPragmaMode.Disable, new string[] { "CS1591" }).ToPragmaString(this.Language)); + thisAssembly.Members.AddRange(codeTypeMembers); + globalNamespace.Types.Add(thisAssembly); + + using var writer = new StringWriter(generatedCode, CultureInfo.CurrentCulture); + generatedCode.AppendLine(new CodeWarningPragmaDirective(WarningPragmaMode.Disable, new string[] { "CS1591" }).ToPragmaString(this.Language!)); provider.GenerateCodeFromCompileUnit(unit, writer, new CodeGeneratorOptions()); - generatedCode.AppendLine(new CodeWarningPragmaDirective(WarningPragmaMode.Restore, new string[] { "CS1591" }).ToPragmaString(this.Language)); + generatedCode.AppendLine(new CodeWarningPragmaDirective(WarningPragmaMode.Restore, new string[] { "CS1591" }).ToPragmaString(this.Language!)); } - var code = generatedCode.ToString(); - // If we just generated infrastructure, don't bother returning // anything as there's no point writing the file - return haveGeneratedContent ? code : String.Empty; + return haveGeneratedContent ? generatedCode.ToString() : String.Empty; } } } \ No newline at end of file diff --git a/src/Cadru.Core/Cadru.Core.xml b/src/Cadru.Core/Cadru.Core.xml index 884756d7..0e34d245 100644 --- a/src/Cadru.Core/Cadru.Core.xml +++ b/src/Cadru.Core/Cadru.Core.xml @@ -5418,22 +5418,6 @@ A new, normalized string. - - - Returns a value indicating whether the specified - object occurs within this string. - - The source . - The string to seek. - - One of the enumeration values that specifies how the strings will be compared. - - - if the parameter - occurs within this string, or if is the - empty string (""); otherwise, . - - Determines whether the end of this string instance matches any of diff --git a/src/Cadru.Core/Extensions/StringExtensions.cs b/src/Cadru.Core/Extensions/StringExtensions.cs index a5e6edfa..6041283c 100644 --- a/src/Cadru.Core/Extensions/StringExtensions.cs +++ b/src/Cadru.Core/Extensions/StringExtensions.cs @@ -102,7 +102,7 @@ public static string Clean(this string source, NormalizationOptions options) if (whitespaceCount >= 0) { - builder.Append(" "); + builder.Append(' '); } whitespaceCount = 0; @@ -131,6 +131,7 @@ public static string Clean(this string source, NormalizationOptions options) return builder.ToString(); } +#if NETSTANDARD2_0 /// /// Returns a value indicating whether the specified /// object occurs within this string. @@ -152,6 +153,7 @@ public static bool Contains(this string source, string value, StringComparison c return source.IndexOf(value, comparisonType) >= 0; } +#endif /// /// Determines whether the end of this string instance matches any of diff --git a/src/Cadru.Data.Dapper/CombTypeHandler.cs b/src/Cadru.Data.Dapper/CombTypeHandler.cs index 0bcc9aff..18462105 100644 --- a/src/Cadru.Data.Dapper/CombTypeHandler.cs +++ b/src/Cadru.Data.Dapper/CombTypeHandler.cs @@ -35,7 +35,7 @@ public class CombTypeHandler : SqlMapper.TypeHandler /// public override Comb Parse(object value) { - return new Comb(value.ToString()); + return new Comb(value.ToString() ?? String.Empty); } /// diff --git a/src/Cadru.Data.Dapper/CommandAdapter.cs b/src/Cadru.Data.Dapper/CommandAdapter.cs index 3a035ae1..7400b7f9 100644 --- a/src/Cadru.Data.Dapper/CommandAdapter.cs +++ b/src/Cadru.Data.Dapper/CommandAdapter.cs @@ -121,7 +121,7 @@ public virtual string QuoteIdentifier(string identifier) Requires.That(this.IsValidIdentifier(identifier), nameof(identifier), Strings.InvalidIdentifier); this.ConsistentQuoteDelimiters(this.IdentifierPrefix, this.IdentifierSuffix); - return this.BuildQuotedString(this.IdentifierPrefix, this.IdentifierSuffix, identifier); + return BuildQuotedString(this.IdentifierPrefix, this.IdentifierSuffix, identifier); } /// @@ -129,7 +129,7 @@ public virtual string QuoteStringLiteral(string value) { Requires.NotNullOrWhiteSpace(value, nameof(value)); this.ConsistentQuoteDelimiters(this.QuotePrefix, this.QuoteSuffix); - return this.BuildQuotedString(this.QuotePrefix, this.QuoteSuffix, value); + return BuildQuotedString(this.QuotePrefix, this.QuoteSuffix, value); } /// @@ -139,7 +139,7 @@ public virtual string UnquoteIdentifier(string identifier) this.ConsistentQuoteDelimiters(this.IdentifierPrefix, this.IdentifierSuffix); - if (this.RemoveStringQuotes(identifier, this.IdentifierPrefix, this.IdentifierSuffix, out var unquotedIdentifier) + if (RemoveStringQuotes(identifier, this.IdentifierPrefix, this.IdentifierSuffix, out var unquotedIdentifier) && !this.IsValidIdentifier(unquotedIdentifier)) { throw new InvalidOperationException(); @@ -148,7 +148,7 @@ public virtual string UnquoteIdentifier(string identifier) return unquotedIdentifier; } - internal string BuildQuotedString(string prefix, string suffix, string value) + internal static string BuildQuotedString(string prefix, string suffix, string value) { var resultString = new StringBuilder(value.Length + prefix.Length + suffix.Length); AppendQuotedString(resultString, prefix, suffix, value); @@ -184,7 +184,7 @@ private static void AppendQuotedString(StringBuilder buffer, string quotePrefix, // the return value is true if the string was quoted and false if it was // not this allows the caller to determine if it is an error or not for // the quotedString to not be quoted - private bool RemoveStringQuotes(string quotedString, string prefix, string suffix, out string unquotedString) + private static bool RemoveStringQuotes(string quotedString, string prefix, string suffix, out string unquotedString) { var prefixLength = prefix != null ? prefix.Length : 0; var suffixLength = suffix != null ? suffix.Length : 0; @@ -205,7 +205,7 @@ private bool RemoveStringQuotes(string quotedString, string prefix, string suffi } // is the prefix present? - if (prefixLength > 0 && !quotedString.StartsWith(prefix, StringComparison.Ordinal)) + if (prefixLength > 0 && !quotedString.StartsWith(prefix!, StringComparison.Ordinal)) { unquotedString = quotedString; return false; @@ -214,7 +214,7 @@ private bool RemoveStringQuotes(string quotedString, string prefix, string suffi // is the suffix present? if (suffixLength > 0) { - if (!quotedString.EndsWith(suffix, StringComparison.Ordinal)) + if (!quotedString.EndsWith(suffix!, StringComparison.Ordinal)) { unquotedString = quotedString; return false; diff --git a/src/Cadru.Data.Dapper/DapperContext.cs b/src/Cadru.Data.Dapper/DapperContext.cs index 8c6b87e1..f18ca65b 100644 --- a/src/Cadru.Data.Dapper/DapperContext.cs +++ b/src/Cadru.Data.Dapper/DapperContext.cs @@ -82,7 +82,7 @@ protected DapperContext([NotNull] DapperContextBuilder contextBuilder, IOptions< var instance = Activator.CreateInstance(contextProperty.PropertyType, this); if (instance != null) { - contextProperty.MethodInfo.Invoke(this, new[] { instance }); + contextProperty.MethodInfo?.Invoke(this, new[] { instance }); } } } diff --git a/src/Cadru.Data/Cadru.Data.xml b/src/Cadru.Data/Cadru.Data.xml index e8d130cf..43a59ec2 100644 --- a/src/Cadru.Data/Cadru.Data.xml +++ b/src/Cadru.Data/Cadru.Data.xml @@ -1472,217 +1472,5 @@ Looks up a localized string similar to TextFieldParser does not support comment tokens that contain white space.. - - - Specifies that is allowed as an input even if the - corresponding type disallows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that is disallowed as an input even if the - corresponding type allows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that a method that will never return under any circumstance. - - - - - Initializes a new instance of the class. - - - - - - Specifies that the method will not return if the associated - parameter is passed the specified value. - - - - - Gets the condition parameter value. - Code after the method is considered unreachable by diagnostics if the argument - to the associated parameter matches this value. - - - - - Initializes a new instance of the - class with the specified parameter value. - - - The condition parameter value. - Code after the method is considered unreachable by diagnostics if the argument - to the associated parameter matches this value. - - - - - Specifies that an output may be even if the - corresponding type disallows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that when a method returns , - the parameter may be even if the corresponding type disallows it. - - - - - Gets the return value condition. - If the method returns this value, the associated parameter may be . - - - - - Initializes the attribute with the specified return value condition. - - - The return value condition. - If the method returns this value, the associated parameter may be . - - - - - Specifies that the method or property will ensure that the listed field and property members have - not- values. - - - - - Gets field or property member names. - - - - - Initializes the attribute with a field or property member. - - - The field or property member that is promised to be not-null. - - - - - Initializes the attribute with the list of field and property members. - - - The list of field and property members that are promised to be not-null. - - - - - Specifies that the method or property will ensure that the listed field and property members have - non- values when returning with the specified return value condition. - - - - - Gets the return value condition. - - - - - Gets field or property member names. - - - - - Initializes the attribute with the specified return value condition and a field or property member. - - - The return value condition. If the method returns this value, - the associated parameter will not be . - - - The field or property member that is promised to be not-. - - - - - Initializes the attribute with the specified return value condition and list - of field and property members. - - - The return value condition. If the method returns this value, - the associated parameter will not be . - - - The list of field and property members that are promised to be not-null. - - - - - Specifies that an output is not even if the - corresponding type allows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that the output will be non- if the - named parameter is non-. - - - - - Gets the associated parameter name. - The output will be non- if the argument to the - parameter specified is non-. - - - - - Initializes the attribute with the associated parameter name. - - - The associated parameter name. - The output will be non- if the argument to the - parameter specified is non-. - - - - - Specifies that when a method returns , - the parameter will not be even if the corresponding type allows it. - - - - - Gets the return value condition. - If the method returns this value, the associated parameter will not be . - - - - - Initializes the attribute with the specified return value condition. - - - The return value condition. - If the method returns this value, the associated parameter will not be . - - diff --git a/src/Cadru.Data/UnboxT.cs b/src/Cadru.Data/UnboxT.cs index b4307020..5d1db391 100644 --- a/src/Cadru.Data/UnboxT.cs +++ b/src/Cadru.Data/UnboxT.cs @@ -56,7 +56,7 @@ private static T BooleanField(object value) { if (typeInfo.IsNullable()) { - return (Func)typeof(UnboxT).GetTypeInfo().DeclaredMethods.SingleOrDefault(m => m.Name == "NullableField" && m.IsStatic && !m.IsPublic).MakeGenericMethod(type.GenericTypeArguments[0]).CreateDelegate(typeof(Func)); + return (Func)typeof(UnboxT).GetTypeInfo().DeclaredMethods.Single(m => m.Name == "NullableField" && m.IsStatic && !m.IsPublic).MakeGenericMethod(type.GenericTypeArguments[0]).CreateDelegate(typeof(Func)); } if (typeInfo.IsBoolean()) @@ -96,18 +96,25 @@ private static T DateTimeField(object value) } else { - DateTime.TryParse(value.ToString(), out var parsedResult); - result = parsedResult; + if (DateTime.TryParse(value.ToString(), out var parsedResult)) + { + result = parsedResult; + } + else + { + throw new InvalidCastException(); + } } return (T)result; } +#pragma warning disable IDE0051 // Remove unused private members private static Nullable NullableField(object value) where TElem : struct { if (DBNull.Value == value || value == null) { - return default(TElem?); + return default; } try @@ -116,9 +123,10 @@ private static T DateTimeField(object value) } catch { - return default(TElem?); + return default; } } +#pragma warning restore IDE0051 // Remove unused private members private static T ReferenceField(object value) { diff --git a/src/Cadru.Extensions.FileProviders/IFileInfoExtensions.cs b/src/Cadru.Extensions.FileProviders/IFileInfoExtensions.cs index d0425875..0ae671cc 100644 --- a/src/Cadru.Extensions.FileProviders/IFileInfoExtensions.cs +++ b/src/Cadru.Extensions.FileProviders/IFileInfoExtensions.cs @@ -47,10 +47,8 @@ public static class IFileInfoExtensions /// A string containing all the text in the file. public static async Task ReadAllText(this IFileInfo fileInfo) { - using (var streamReader = new StreamReader(fileInfo.CreateReadStream())) - { - return await streamReader.ReadToEndAsync(); - } + using var streamReader = new StreamReader(fileInfo.CreateReadStream()); + return await streamReader.ReadToEndAsync(); } /// @@ -76,7 +74,12 @@ public static ExtendedFileInfo ToExtendedFileInfo(this IFileInfo fileInfo) /// A representing the path. public static Uri ToUri(this IFileInfo fileInfo) { - return new Uri(String.Concat(@"//", fqdn, @"/", fileInfo.PhysicalPath.Substring(Path.GetPathRoot(fileInfo.PhysicalPath).Length))); + var pathLength = Path.GetPathRoot(fileInfo.PhysicalPath)?.Length ?? 0; +#if NETSTANDARD2_0 + return new Uri(String.Concat(@"//", fqdn, @"/", fileInfo.PhysicalPath.Substring(pathLength))); +#else + return new Uri(String.Concat(@"//", fqdn, @"/", fileInfo.PhysicalPath[pathLength..])); +#endif } private static string GetFullyQualifiedDomainName() diff --git a/src/Cadru.Net.NetworkInformation/Cadru.Net.NetworkInformation.xml b/src/Cadru.Net.NetworkInformation/Cadru.Net.NetworkInformation.xml index 73754724..af9c1373 100644 --- a/src/Cadru.Net.NetworkInformation/Cadru.Net.NetworkInformation.xml +++ b/src/Cadru.Net.NetworkInformation/Cadru.Net.NetworkInformation.xml @@ -1388,5 +1388,217 @@ server type for the given domain. + + + Specifies that is allowed as an input even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that is disallowed as an input even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that a method that will never return under any circumstance. + + + + + Initializes a new instance of the class. + + + + + + Specifies that the method will not return if the associated + parameter is passed the specified value. + + + + + Gets the condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Initializes a new instance of the + class with the specified parameter value. + + + The condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Specifies that an output may be even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that when a method returns , + the parameter may be even if the corresponding type disallows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter may be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter may be . + + + + + Specifies that the method or property will ensure that the listed field and property members have + not- values. + + + + + Gets field or property member names. + + + + + Initializes the attribute with a field or property member. + + + The field or property member that is promised to be not-null. + + + + + Initializes the attribute with the list of field and property members. + + + The list of field and property members that are promised to be not-null. + + + + + Specifies that the method or property will ensure that the listed field and property members have + non- values when returning with the specified return value condition. + + + + + Gets the return value condition. + + + + + Gets field or property member names. + + + + + Initializes the attribute with the specified return value condition and a field or property member. + + + The return value condition. If the method returns this value, + the associated parameter will not be . + + + The field or property member that is promised to be not-. + + + + + Initializes the attribute with the specified return value condition and list + of field and property members. + + + The return value condition. If the method returns this value, + the associated parameter will not be . + + + The list of field and property members that are promised to be not-null. + + + + + Specifies that an output is not even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that the output will be non- if the + named parameter is non-. + + + + + Gets the associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Initializes the attribute with the associated parameter name. + + + The associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Specifies that when a method returns , + the parameter will not be even if the corresponding type allows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter will not be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter will not be . + + diff --git a/src/Cadru.Polly/Cadru.Polly.xml b/src/Cadru.Polly/Cadru.Polly.xml index d7d7aa63..7df34ad0 100644 --- a/src/Cadru.Polly/Cadru.Polly.xml +++ b/src/Cadru.Polly/Cadru.Polly.xml @@ -1221,217 +1221,5 @@ A representing the timeout. - - - Specifies that is allowed as an input even if the - corresponding type disallows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that is disallowed as an input even if the - corresponding type allows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that a method that will never return under any circumstance. - - - - - Initializes a new instance of the class. - - - - - - Specifies that the method will not return if the associated - parameter is passed the specified value. - - - - - Gets the condition parameter value. - Code after the method is considered unreachable by diagnostics if the argument - to the associated parameter matches this value. - - - - - Initializes a new instance of the - class with the specified parameter value. - - - The condition parameter value. - Code after the method is considered unreachable by diagnostics if the argument - to the associated parameter matches this value. - - - - - Specifies that an output may be even if the - corresponding type disallows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that when a method returns , - the parameter may be even if the corresponding type disallows it. - - - - - Gets the return value condition. - If the method returns this value, the associated parameter may be . - - - - - Initializes the attribute with the specified return value condition. - - - The return value condition. - If the method returns this value, the associated parameter may be . - - - - - Specifies that the method or property will ensure that the listed field and property members have - not- values. - - - - - Gets field or property member names. - - - - - Initializes the attribute with a field or property member. - - - The field or property member that is promised to be not-null. - - - - - Initializes the attribute with the list of field and property members. - - - The list of field and property members that are promised to be not-null. - - - - - Specifies that the method or property will ensure that the listed field and property members have - non- values when returning with the specified return value condition. - - - - - Gets the return value condition. - - - - - Gets field or property member names. - - - - - Initializes the attribute with the specified return value condition and a field or property member. - - - The return value condition. If the method returns this value, - the associated parameter will not be . - - - The field or property member that is promised to be not-. - - - - - Initializes the attribute with the specified return value condition and list - of field and property members. - - - The return value condition. If the method returns this value, - the associated parameter will not be . - - - The list of field and property members that are promised to be not-null. - - - - - Specifies that an output is not even if the - corresponding type allows it. - - - - - Initializes a new instance of the class. - - - - - Specifies that the output will be non- if the - named parameter is non-. - - - - - Gets the associated parameter name. - The output will be non- if the argument to the - parameter specified is non-. - - - - - Initializes the attribute with the associated parameter name. - - - The associated parameter name. - The output will be non- if the argument to the - parameter specified is non-. - - - - - Specifies that when a method returns , - the parameter will not be even if the corresponding type allows it. - - - - - Gets the return value condition. - If the method returns this value, the associated parameter will not be . - - - - - Initializes the attribute with the specified return value condition. - - - The return value condition. - If the method returns this value, the associated parameter will not be . - -