From bb56b9a5d7ce7f30bd3e6dc0e71fac2755f1401d Mon Sep 17 00:00:00 2001 From: Nic Bell Date: Wed, 17 Jul 2019 12:54:44 +0100 Subject: [PATCH] Potential fix for #21 --- .../DocumentTypes/BaseFromPoco.cs | 20 +++++++++++++++++++ .../NicBell.UCreate.Test.csproj | 2 ++ .../Sync/BaseTreeContentTypeSync.cs | 11 +++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 NicBell.UCreate.Test/DocumentTypes/BaseFromPoco.cs diff --git a/NicBell.UCreate.Test/DocumentTypes/BaseFromPoco.cs b/NicBell.UCreate.Test/DocumentTypes/BaseFromPoco.cs new file mode 100644 index 0000000..5e11fb6 --- /dev/null +++ b/NicBell.UCreate.Test/DocumentTypes/BaseFromPoco.cs @@ -0,0 +1,20 @@ +using NicBell.UCreate.Attributes; +using NicBell.UCreate.Constants; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace NicBell.UCreate.Test.DocumentTypes +{ + [DocType(Name = "BaseFromPoco")] + public class BaseFromPoco : Foo + { + [Property(Alias = nameof(Title), Name = "Title", TypeName = PropertyTypes.Textstring)] + public string Title { get; set; } + } + + public class Foo { + public string Hello { get; set; } + } +} \ No newline at end of file diff --git a/NicBell.UCreate.Test/NicBell.UCreate.Test.csproj b/NicBell.UCreate.Test/NicBell.UCreate.Test.csproj index f7046a7..e544701 100644 --- a/NicBell.UCreate.Test/NicBell.UCreate.Test.csproj +++ b/NicBell.UCreate.Test/NicBell.UCreate.Test.csproj @@ -31,6 +31,7 @@ 4.0 + true @@ -302,6 +303,7 @@ + diff --git a/NicBell.UCreate/Sync/BaseTreeContentTypeSync.cs b/NicBell.UCreate/Sync/BaseTreeContentTypeSync.cs index 3463e55..b9c05e0 100644 --- a/NicBell.UCreate/Sync/BaseTreeContentTypeSync.cs +++ b/NicBell.UCreate/Sync/BaseTreeContentTypeSync.cs @@ -25,7 +25,16 @@ public abstract class BaseTreeContentTypeSync : BaseContentTypeSync where /// public override void SyncAll() { - var firstLevelTypes = TypesToSync.Where(x => x.BaseType == null || x.BaseType == typeof(object) || x.BaseType == typeof(PublishedContentModel)); + // Get first level types to sync as a tree: + // they could be types that don't inherit from anything, + // inherit directly from PublishedContentModel, + // inherit from some other POCO that is's a content type + Func isFirstLevelType = x => x.BaseType == null + || x.BaseType == typeof(object) + || x.BaseType == typeof(PublishedContentModel) + || !x.BaseType.GetCustomAttributes().Any(at => at is BaseContentTypeAttribute); + + var firstLevelTypes = TypesToSync.Where(isFirstLevelType); foreach (var itemType in firstLevelTypes) {