Skip to content

Commit bdcdcda

Browse files
authored
Merge pull request #2 from Gibe/feature/implement-all-property-types-attribute
Add ImplementAllPropertyTypes attribute
2 parents eae24bd + 98c2ffc commit bdcdcda

File tree

6 files changed

+28
-24
lines changed

6 files changed

+28
-24
lines changed

src/ModelsBuilder.PropertyOverride.TestSite/Models/Generated/HomePageBlock.generated.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,5 @@ public HomePageBlock(IPublishedElement content, IPublishedValueFallback publishe
4848
}
4949

5050
// properties
51-
52-
///<summary>
53-
/// Image
54-
///</summary>
55-
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "13.0.0+9dfb300")]
56-
[global::System.Diagnostics.CodeAnalysis.MaybeNull]
57-
[ImplementPropertyType("image")]
58-
public virtual global::Umbraco.Cms.Core.Models.MediaWithCrops Image => this.Value<global::Umbraco.Cms.Core.Models.MediaWithCrops>(_publishedValueFallback, "image");
59-
60-
///<summary>
61-
/// Sub title
62-
///</summary>
63-
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "13.0.0+9dfb300")]
64-
[global::System.Diagnostics.CodeAnalysis.MaybeNull]
65-
[ImplementPropertyType("subTitle")]
66-
public virtual string SubTitle => this.Value<string>(_publishedValueFallback, "subTitle");
67-
68-
///<summary>
69-
/// Title
70-
///</summary>
71-
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "13.0.0+9dfb300")]
72-
[global::System.Diagnostics.CodeAnalysis.MaybeNull]
73-
[ImplementPropertyType("title")]
74-
public virtual string Title => this.Value<string>(_publishedValueFallback, "title");
7551
}
7652
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Umbraco.Cms.Infrastructure.ModelsBuilder;
2+
3+
namespace ModelsBuilder.PropertyOverride.TestSite.Models
4+
{
5+
[ImplementAllPropertyTypes]
6+
public partial class HomePageBlock
7+
{
8+
public virtual global::Umbraco.Cms.Core.Models.MediaWithCrops Image { get; set; }
9+
public virtual string SubTitle { get; set; }
10+
public virtual string Title { get; set; }
11+
}
12+
}
Binary file not shown.
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Umbraco.Cms.Infrastructure.ModelsBuilder
2+
{
3+
/// <summary>
4+
/// Attribute which can be used to ignore every property when building models.
5+
/// </summary>
6+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
7+
public class ImplementAllPropertyTypesAttribute : Attribute
8+
{
9+
}
10+
}

src/ModelsBuilder.PropertyOverride/PropertyOverrideModelsGenerator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ private IList<TypeModel> FilterForImplementedProperties(IList<TypeModel> typeMod
9393
continue;
9494
}
9595

96+
if (underlyingType.GetCustomAttribute<ImplementAllPropertyTypesAttribute>(inherit: true) is not null)
97+
{
98+
model.Properties.Clear();
99+
continue;
100+
}
101+
96102
var aliasOverrides = underlyingType
97103
.GetProperties()
98104
.Where(propertyInfo => propertyInfo.GetCustomAttribute<GeneratedCodeAttribute>(inherit: true) is null)

0 commit comments

Comments
 (0)