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

OSOE-60: .NET 6 and Orchard Core 1.3 upgrade #58

Merged
merged 8 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
45 changes: 27 additions & 18 deletions Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using OrchardCore.DisplayManagement.Views;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

Expand All @@ -27,8 +28,16 @@ public override IDisplayResult Edit(ContentTypeDefinition model) =>

// Building the code for the type.
var name = model.Name;
codeBuilder.AppendLine($"_contentDefinitionManager.AlterTypeDefinition(\"{name}\", type => type");
codeBuilder.AppendLine($" .DisplayedAs(\"{model.DisplayName}\")");

// This can't be added to a Helpful Libraries extension method because one with the
// public static StringBuilder AppendLineInvariant(
// this StringBuilder stringBuilder,
// [InterpolatedStringHandlerArgument("", "provider")] ref StringBuilder.AppendInterpolatedStringHandler handler)
// signature causes the following error:
// "'StringBuilderExtensions.AppendLineInvariant(StringBuilder, ref StringBuilder.AppendInterpolatedStringHandler)'
// is not an instance method, the receiver cannot be an interpolated string handler argument
codeBuilder.AppendLine(CultureInfo.InvariantCulture, $"_contentDefinitionManager.AlterTypeDefinition(\"{name}\", type => type");
codeBuilder.AppendLine(CultureInfo.InvariantCulture, $" .DisplayedAs(\"{model.DisplayName}\")");
sarahelsaig marked this conversation as resolved.
Show resolved Hide resolved

GenerateCodeForSettings(codeBuilder, model.GetSettings<ContentTypeSettings>());
AddSettingsWithout<ContentTypeSettings>(codeBuilder, model.Settings, 4);
Expand All @@ -47,7 +56,7 @@ private void GenerateCodeForParts(StringBuilder codeBuilder, IEnumerable<Content
{
var partSettings = part.GetSettings<ContentTypePartSettings>();

codeBuilder.AppendLine($" .WithPart(\"{part.Name}\", part => part");
codeBuilder.AppendLine(CultureInfo.InvariantCulture, $" .WithPart(\"{part.Name}\", part => part");

var partStartingLength = codeBuilder.Length;

Expand Down Expand Up @@ -86,7 +95,7 @@ private void GenerateCodeForPartsWithFields(
foreach (var part in partDefinitions)
{
codeBuilder.AppendLine();
codeBuilder.AppendLine($"_contentDefinitionManager.AlterPartDefinition(\"{part.Name}\", part => part");
codeBuilder.AppendLine(CultureInfo.InvariantCulture, $"_contentDefinitionManager.AlterPartDefinition(\"{part.Name}\", part => part");

var partSettings = part.GetSettings<ContentPartSettings>();
if (partSettings.Attachable) codeBuilder.AppendLine(" .Attachable()");
Expand All @@ -100,8 +109,8 @@ private void GenerateCodeForPartsWithFields(

foreach (var field in part.Fields)
{
codeBuilder.AppendLine($" .WithField(\"{field.Name}\", field => field");
codeBuilder.AppendLine($" .OfType(\"{field.FieldDefinition.Name}\")");
codeBuilder.AppendLine(CultureInfo.InvariantCulture, $" .WithField(\"{field.Name}\", field => field");
codeBuilder.AppendLine(CultureInfo.InvariantCulture, $" .OfType(\"{field.FieldDefinition.Name}\")");

var fieldSettings = field.GetSettings<ContentPartFieldSettings>();
AddWithLine(codeBuilder, nameof(fieldSettings.DisplayName), fieldSettings.DisplayName);
Expand Down Expand Up @@ -147,16 +156,16 @@ private string ConvertJToken(JToken jToken, int indentationDepth)
// Otherwise, make sure that we have proper formatting for string arrays.
var stringArrayCodeBuilder = new StringBuilder("new[]");
stringArrayCodeBuilder.AppendLine();
stringArrayCodeBuilder.AppendLine($"{indentation}{{");
stringArrayCodeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{indentation}{{");

var itemIndentation = new string(' ', indentationDepth + 8);

foreach (var item in items)
{
stringArrayCodeBuilder.AppendLine($"{itemIndentation}{item},");
stringArrayCodeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{itemIndentation}{item},");
}

stringArrayCodeBuilder.Append($"{indentation}}}");
stringArrayCodeBuilder.Append(CultureInfo.InvariantCulture, $"{indentation}}}");

return stringArrayCodeBuilder.ToString();

Expand All @@ -166,11 +175,11 @@ private string ConvertJToken(JToken jToken, int indentationDepth)
if (jObject["name"] != null && jObject["value"] != null)
{
var objectCodeBuilder = new StringBuilder();
objectCodeBuilder.AppendLine($"{braceIndentation}new ListValueOption");
objectCodeBuilder.AppendLine($"{braceIndentation}{{");
objectCodeBuilder.AppendLine($"{propertyIndentation}Name = \"{jObject["name"]}\",");
objectCodeBuilder.AppendLine($"{propertyIndentation}Value = \"{jObject["value"]}\",");
objectCodeBuilder.AppendLine($"{braceIndentation}}},");
objectCodeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{braceIndentation}new ListValueOption");
objectCodeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{braceIndentation}{{");
objectCodeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{propertyIndentation}Name = \"{jObject["name"]}\",");
objectCodeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{propertyIndentation}Value = \"{jObject["value"]}\",");
objectCodeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{braceIndentation}}},");

return objectCodeBuilder.ToString();
}
Expand All @@ -196,7 +205,7 @@ private void AddSettingsWithout<T>(StringBuilder codeBuilder, JObject settings,

if (properties.Length == 0) continue;

codeBuilder.AppendLine($"{indentation}.WithSettings(new {setting.Key}");
codeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{indentation}.WithSettings(new {setting.Key}");
codeBuilder.AppendLine(indentation + "{");

// This doesn't support multi-level object hierarchies for settings but come on, who uses complex
Expand All @@ -209,7 +218,7 @@ private void AddSettingsWithout<T>(StringBuilder codeBuilder, JObject settings,

propertyValue ??= "\"\"";

codeBuilder.AppendLine($"{indentation} {property.Name} = {propertyValue},");
codeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{indentation} {property.Name} = {propertyValue},");
}

codeBuilder.AppendLine(indentation + "})");
Expand All @@ -225,15 +234,15 @@ private static void GenerateCodeForSettings(StringBuilder codeBuilder, ContentTy
if (contentTypeSettings.Securable) codeBuilder.AppendLine(" .Securable()");
if (!string.IsNullOrEmpty(contentTypeSettings.Stereotype))
{
codeBuilder.AppendLine($" .Stereotype(\"{contentTypeSettings.Stereotype}\")");
codeBuilder.AppendLine(CultureInfo.InvariantCulture, $" .Stereotype(\"{contentTypeSettings.Stereotype}\")");
}
}

private static void AddWithLine(StringBuilder codeBuilder, string name, string value)
{
if (!string.IsNullOrEmpty(value))
{
codeBuilder.AppendLine($" .With{name}(\"{value}\")");
codeBuilder.AppendLine(CultureInfo.InvariantCulture, $" .With{name}(\"{value}\")");
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions Lombiq.HelpfulExtensions.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<DefaultItemExcludes>$(DefaultItemExcludes);.git*;node_modules\**</DefaultItemExcludes>
</PropertyGroup>
Expand Down Expand Up @@ -34,12 +34,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Autoroute" Version="1.2.2" />
<PackageReference Include="OrchardCore.Contents" Version="1.2.2" />
<PackageReference Include="OrchardCore.Flows" Version="1.2.2" />
<PackageReference Include="OrchardCore.Html" Version="1.2.2" />
<PackageReference Include="OrchardCore.MetaWeblog.Abstractions" Version="1.2.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.2.2" />
<PackageReference Include="OrchardCore.Autoroute" Version="1.3.0" />
<PackageReference Include="OrchardCore.Contents" Version="1.3.0" />
<PackageReference Include="OrchardCore.Flows" Version="1.3.0" />
<PackageReference Include="OrchardCore.Html" Version="1.3.0" />
<PackageReference Include="OrchardCore.MetaWeblog.Abstractions" Version="1.3.0" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.3.0" />
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' != 'true'">
Expand Down