diff --git a/build/build.ps1 b/build/build.ps1 index ba48a834c0..ae4fcb679b 100644 --- a/build/build.ps1 +++ b/build/build.ps1 @@ -175,7 +175,7 @@ /p:WebProjectOutputDir="$($this.BuildTemp)\WebApp\\" ` /p:Verbosity=minimal ` /t:Clean`;Rebuild ` - /tv:"$($ubuild.BuildEnv.VisualStudio.ToolsVersion)" ` + /tv:"$($this.BuildEnv.VisualStudio.ToolsVersion)" ` /p:UmbracoBuild=True ` > $log @@ -193,7 +193,7 @@ /p:WebProjectOutputDir="$($this.BuildTemp)\WebApp\\" ` /p:Verbosity=minimal ` /t:Rebuild ` - /tv:"$($ubuild.BuildEnv.VisualStudio.ToolsVersion)" ` + /tv:"$($this.BuildEnv.VisualStudio.ToolsVersion)" ` /p:UmbracoBuild=True ` > $log7 @@ -252,7 +252,7 @@ /p:OutDir="$($this.BuildTemp)\tests\\" ` /p:Verbosity=minimal ` /t:Build ` - /tv:"$($ubuild.BuildEnv.VisualStudio.ToolsVersion)" ` + /tv:"$($this.BuildEnv.VisualStudio.ToolsVersion)" ` /p:UmbracoBuild=True ` /p:NugetPackages="$($this.SolutionRoot)\src\packages" ` > $log diff --git a/src/SolutionInfo.cs b/src/SolutionInfo.cs index cfc2bccd24..8d387ef301 100644 --- a/src/SolutionInfo.cs +++ b/src/SolutionInfo.cs @@ -17,4 +17,4 @@ using System.Resources; // these are FYI and changed automatically [assembly: AssemblyFileVersion("8.0.0")] -[assembly: AssemblyInformationalVersion("8.0.0-alpha.29")] +[assembly: AssemblyInformationalVersion("8.0.0-alpha.30")] diff --git a/src/Umbraco.Core/Configuration/UmbracoVersion.cs b/src/Umbraco.Core/Configuration/UmbracoVersion.cs index cf4f9d9e2c..1d3fd41ac3 100644 --- a/src/Umbraco.Core/Configuration/UmbracoVersion.cs +++ b/src/Umbraco.Core/Configuration/UmbracoVersion.cs @@ -21,7 +21,7 @@ namespace Umbraco.Core.Configuration /// /// Gets the version comment of the executing code (eg "beta"). /// - public static string CurrentComment => "alpha.29"; + public static string CurrentComment => "alpha.30"; /// /// Gets the assembly version of Umbraco.Code.dll. diff --git a/src/Umbraco.Core/Models/PublishedContent/ModelType.cs b/src/Umbraco.Core/Models/PublishedContent/ModelType.cs index c784449523..962148e138 100644 --- a/src/Umbraco.Core/Models/PublishedContent/ModelType.cs +++ b/src/Umbraco.Core/Models/PublishedContent/ModelType.cs @@ -74,6 +74,39 @@ namespace Umbraco.Core.Models.PublishedContent return def.MakeGenericType(args); } + /// + /// Gets the actual Clr type name by replacing model types, if any. + /// + /// The type. + /// The model types map. + /// The actual Clr type name. + public static string MapToName(Type type, Dictionary map) + { + if (type is ModelType modelType) + { + if (map.TryGetValue(modelType.ContentTypeAlias, out var actualTypeName)) + return actualTypeName; + throw new InvalidOperationException($"Don't know how to map ModelType with content type alias \"{modelType.ContentTypeAlias}\"."); + } + + if (type is ModelTypeArrayType arrayType) + { + if (map.TryGetValue(arrayType.ContentTypeAlias, out var actualTypeName)) + return actualTypeName + "[]"; + throw new InvalidOperationException($"Don't know how to map ModelType with content type alias \"{arrayType.ContentTypeAlias}\"."); + } + + if (type.IsGenericType == false) + return type.FullName; + var def = type.GetGenericTypeDefinition(); + if (def == null) + throw new InvalidOperationException("panic"); + + var args = type.GetGenericArguments().Select(x => MapToName(x, map)).ToArray(); + var defFullName = def.FullName.Substring(0, def.FullName.IndexOf('`')); + return defFullName + "<" + string.Join(", ", args) + ">"; + } + /// /// Gets a value indicating whether two instances are equal. /// @@ -229,12 +262,10 @@ namespace Umbraco.Core.Models.PublishedContent public override Guid GUID { get; } = Guid.NewGuid(); /// - //public override Module Module => throw new NotSupportedException(); - public override Module Module => GetType().Module; + public override Module Module => GetType().Module; // hackish but FullName requires something /// - //public override Assembly Assembly => throw new NotSupportedException(); - public override Assembly Assembly => GetType().Assembly; + public override Assembly Assembly => GetType().Assembly; // hackish but FullName requires something /// public override string FullName => Name; @@ -354,8 +385,8 @@ namespace Umbraco.Core.Models.PublishedContent public override string Name { get; } public override Guid GUID { get; } = Guid.NewGuid(); - public override Module Module => throw new NotSupportedException(); - public override Assembly Assembly => throw new NotSupportedException(); + public override Module Module =>GetType().Module; // hackish but FullName requires something + public override Assembly Assembly => GetType().Assembly; // hackish but FullName requires something public override string FullName => Name; public override string Namespace => string.Empty; public override string AssemblyQualifiedName => Name; diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedModelAttribute.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedModelAttribute.cs index 4b4ce120c6..16eb614ee7 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedModelAttribute.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedModelAttribute.cs @@ -10,14 +10,14 @@ namespace Umbraco.Core.Models.PublishedContent /// By default, the name of the class is assumed to be the content type alias. The /// PublishedContentModelAttribute can be used to indicate a different alias. [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] - public sealed class PublishedContentModelAttribute : Attribute + public sealed class PublishedModelAttribute : Attribute { /// /// - /// Initializes a new instance of the class with a content type alias. + /// Initializes a new instance of the class with a content type alias. /// /// The content type alias. - public PublishedContentModelAttribute(string contentTypeAlias) + public PublishedModelAttribute(string contentTypeAlias) { if (string.IsNullOrWhiteSpace(contentTypeAlias)) throw new ArgumentNullOrEmptyException(nameof(contentTypeAlias)); ContentTypeAlias = contentTypeAlias; diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedModelFactory.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedModelFactory.cs index 8af3d013b0..c72a89c1f2 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedModelFactory.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedModelFactory.cs @@ -64,7 +64,7 @@ namespace Umbraco.Core.Models.PublishedContent if (constructor == null) throw new InvalidOperationException($"Type {type.FullName} is missing a public constructor with one argument of type, or implementing, IPublishedElement."); - var attribute = type.GetCustomAttribute(false); + var attribute = type.GetCustomAttribute(false); var typeName = attribute == null ? type.Name : attribute.ContentTypeAlias; if (modelInfos.TryGetValue(typeName, out var modelInfo)) diff --git a/src/Umbraco.Tests/Facade/FacadeTestObjects.cs b/src/Umbraco.Tests/Facade/FacadeTestObjects.cs index 447dd93e3a..4a8cfe47fb 100644 --- a/src/Umbraco.Tests/Facade/FacadeTestObjects.cs +++ b/src/Umbraco.Tests/Facade/FacadeTestObjects.cs @@ -10,7 +10,7 @@ namespace Umbraco.Tests.Facade { #region Published models - [PublishedContentModel("element1")] + [PublishedModel("element1")] public class TestElementModel1 : PublishedElementModel { public TestElementModel1(IPublishedElement content) @@ -20,7 +20,7 @@ namespace Umbraco.Tests.Facade public string Prop1 => this.Value("prop1"); } - [PublishedContentModel("element2")] + [PublishedModel("element2")] public class TestElementModel2 : PublishedElementModel { public TestElementModel2(IPublishedElement content) @@ -30,7 +30,7 @@ namespace Umbraco.Tests.Facade public IEnumerable Prop2 => this.Value>("prop2"); } - [PublishedContentModel("content1")] + [PublishedModel("content1")] public class TestContentModel1 : PublishedContentModel { public TestContentModel1(IPublishedContent content) @@ -40,7 +40,7 @@ namespace Umbraco.Tests.Facade public string Prop1 => this.Value("prop1"); } - [PublishedContentModel("content2")] + [PublishedModel("content2")] public class TestContentModel2 : PublishedContentModel { public TestContentModel2(IPublishedContent content) diff --git a/src/Umbraco.Tests/Facade/ModelTypeTests.cs b/src/Umbraco.Tests/Facade/ModelTypeTests.cs index ad6bdc8598..34d1005448 100644 --- a/src/Umbraco.Tests/Facade/ModelTypeTests.cs +++ b/src/Umbraco.Tests/Facade/ModelTypeTests.cs @@ -33,6 +33,39 @@ namespace Umbraco.Tests.Facade Assert.AreEqual("System.Collections.Generic.IEnumerable`1[{alias1}[*]]", typeof(IEnumerable<>).MakeGenericType(ModelType.For("alias1").MakeArrayType()).ToString()); } + [Test] + public void TypeToStringTests() + { + var type = typeof(int); + Assert.AreEqual("System.Int32", type.ToString()); + Assert.AreEqual("System.Int32[]", type.MakeArrayType().ToString()); + Assert.AreEqual("System.Collections.Generic.IEnumerable`1[System.Int32[]]", typeof(IEnumerable<>).MakeGenericType(type.MakeArrayType()).ToString()); + } + + [Test] + public void ModelTypeFullNameTests() + { + Assert.AreEqual("{alias1}", ModelType.For("alias1").FullName); + + Type type = ModelType.For("alias1"); + Assert.AreEqual("{alias1}", type.FullName); + + // there's an "*" there because the arrays are not true SZArray - but that changes when we map + Assert.AreEqual("{alias1}[*]", ModelType.For("alias1").MakeArrayType().FullName); + // note the inner assembly qualified name + Assert.AreEqual("System.Collections.Generic.IEnumerable`1[[{alias1}[*], Umbraco.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null]]", typeof(IEnumerable<>).MakeGenericType(ModelType.For("alias1").MakeArrayType()).FullName); + } + + [Test] + public void TypeFullNameTests() + { + var type = typeof(int); + Assert.AreEqual("System.Int32", type.FullName); + Assert.AreEqual("System.Int32[]", type.MakeArrayType().FullName); + // note the inner assembly qualified name + Assert.AreEqual("System.Collections.Generic.IEnumerable`1[[System.Int32[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", typeof(IEnumerable<>).MakeGenericType(type.MakeArrayType()).FullName); + } + [Test] public void ModelTypeMapTests() { diff --git a/src/Umbraco.Tests/Facade/NestedContentTests.cs b/src/Umbraco.Tests/Facade/NestedContentTests.cs index 32aad1155b..b5c05bf644 100644 --- a/src/Umbraco.Tests/Facade/NestedContentTests.cs +++ b/src/Umbraco.Tests/Facade/NestedContentTests.cs @@ -32,9 +32,6 @@ namespace Umbraco.Tests.Facade var profiler = Mock.Of(); var proflog = new ProfilingLogger(logger, profiler); - var container = new ServiceContainer(); - container.ConfigureUmbracoCore(); - var dataTypeService = new Mock(); // mocked dataservice returns nested content preValues @@ -47,14 +44,14 @@ namespace Umbraco.Tests.Facade { { "minItems", new PreValue("1") }, { "maxItems", new PreValue("1") }, - { "contentTypes", new PreValue("contentN1") } + { "contentTypes", new PreValue("[{\"ncAlias\":\"contentN1\",\"ncTabAlias\":\"\",\"nameTemplate\":\"\"}]") } }); if (id == 2) return new PreValueCollection(new Dictionary { { "minItems", new PreValue("1") }, { "maxItems", new PreValue("99") }, - { "contentTypes", new PreValue("contentN1") } + { "contentTypes", new PreValue("[{\"ncAlias\":\"contentN1\",\"ncTabAlias\":\"\",\"nameTemplate\":\"\"}]") } }); return null; }); @@ -115,7 +112,7 @@ namespace Umbraco.Tests.Facade PropertyEditorCollection editors = null; editors = new PropertyEditorCollection(new PropertyEditor[] { - new NestedContentPropertyEditor(Mock.Of(), new Lazy(() => editors)) + new NestedContentPropertyEditor(Mock.Of(), new Lazy(() => editors)) }); var source = new DataTypeConfigurationSource(dataTypeService.Object, editors); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs index 9bcddf63d9..c774c7a911 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs @@ -259,7 +259,7 @@ namespace Umbraco.Tests.PublishedContent public object XPathValue { get; set; } } - [PublishedContentModel("ContentType2")] + [PublishedModel("ContentType2")] internal class ContentType2 : PublishedContentModel { #region Plumbing @@ -273,7 +273,7 @@ namespace Umbraco.Tests.PublishedContent public int Prop1 => this.Value("prop1"); } - [PublishedContentModel("ContentType2Sub")] + [PublishedModel("ContentType2Sub")] internal class ContentType2Sub : ContentType2 { #region Plumbing diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs index 1582795dc7..d96034a8c4 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs @@ -190,7 +190,7 @@ namespace Umbraco.Tests.PublishedContent } } - [PublishedContentModel("Home")] + [PublishedModel("Home")] internal class Home : PublishedContentModel { public Home(IPublishedContent content) diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 3d9e0cfd8c..ed0d0c7d7c 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -152,7 +152,7 @@ True - ..\packages\Umbraco.ModelsBuilder.8.0.0-alpha.11\lib\Umbraco.ModelsBuilder.dll + ..\packages\Umbraco.ModelsBuilder.8.0.0-alpha.13\lib\Umbraco.ModelsBuilder.dll diff --git a/src/Umbraco.Web.UI/packages.config b/src/Umbraco.Web.UI/packages.config index 373055df2c..4ec7a3dded 100644 --- a/src/Umbraco.Web.UI/packages.config +++ b/src/Umbraco.Web.UI/packages.config @@ -81,5 +81,5 @@ - + \ No newline at end of file