Skip to content

Commit 382a2d2

Browse files
Merge pull request #4 from Gibe/release/1.0.0
Release/1.0.0
2 parents db7735e + 265f99c commit 382a2d2

File tree

10 files changed

+151
-52
lines changed

10 files changed

+151
-52
lines changed

.github/README.md

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,66 @@
1-
# Models Builder .Property Override
1+
# Umbraco.Community.ModelsBuilder.PropertyOverride
22

33
[![Downloads](https://img.shields.io/nuget/dt/Umbraco.Community.ModelsBuilder.PropertyOverride?color=cc9900)](https://www.nuget.org/packages/Umbraco.Community.ModelsBuilder.PropertyOverride/)
44
[![NuGet](https://img.shields.io/nuget/vpre/Umbraco.Community.ModelsBuilder.PropertyOverride?color=0273B3)](https://www.nuget.org/packages/Umbraco.Community.ModelsBuilder.PropertyOverride)
55
[![GitHub license](https://img.shields.io/github/license/Gibe/Umbraco.Community.ModelsBuilder.PropertyOverride?color=8AB803)](../LICENSE)
66

7-
TODO: describe your package
7+
This package re-introduces functionality for overriding ModelsBuilder property implementations that was lost in Umbraco 9+.
88

9-
<!--
10-
Including screenshots is a really good idea!
9+
Umbraco versions 13.x - 15.x are supported.
1110

12-
If you put images into /docs/screenshots, then you would reference them in this readme as, for example:
11+
Properties can be marked up with a re-implemented `[ImplementPropertyType("alias")]` attribute, which causes them to be ignored when generating models through the default ModelsBuilder.
1312

14-
<img alt="..." src="https://github.com/Gibe/Umbraco.Community.ModelsBuilder.PropertyOverride/blob/develop/docs/screenshots/screenshot.png">
15-
-->
13+
In addition, classes can be marked up with `[ImplementAllPropertyTypes]`, which causes all properties on the class to be ignored, this is functionally equivalent to adding `[ImplementPropertyType("alias")]` to every property on the class.
14+
15+
Legacy (Umbraco 8.x) documentation for the `[ImplementPropertyType("alias")]` attribute can be found [here](https://our.umbraco.com/Documentation/Reference/Templating/Modelsbuilder/Control-Generation-vpre8_5#implement-property-type).
16+
17+
## Examples
18+
19+
`[ImplementPropertyType("alias")]` to ignore properties on an individual basis:
20+
21+
```
22+
using Umbraco.Cms.Infrastructure.ModelsBuilder;
23+
24+
namespace ModelsBuilder.PropertyOverride.TestSite.Models
25+
{
26+
public partial class Home
27+
{
28+
[ImplementPropertyType("content")]
29+
public global::Umbraco.Cms.Core.Models.Blocks.BlockListModel Content => this.Value<global::Umbraco.Cms.Core.Models.Blocks.BlockListModel>(_publishedValueFallback, "content");
30+
31+
[ImplementPropertyType("title")]
32+
public virtual string Title => this.Value<string>(_publishedValueFallback, "title");
33+
}
34+
}
35+
```
36+
37+
`[ImplementAllPropertyTypes]` to ignore all properties:
38+
39+
```
40+
using Umbraco.Cms.Infrastructure.ModelsBuilder;
41+
42+
namespace ModelsBuilder.PropertyOverride.TestSite.Models
43+
{
44+
[ImplementAllPropertyTypes]
45+
public partial class HomePageBlock
46+
{
47+
public virtual global::Umbraco.Cms.Core.Models.MediaWithCrops Image { get; set; }
48+
public virtual string SubTitle { get; set; }
49+
public virtual string Title { get; set; }
50+
}
51+
}
52+
```
1653

1754
## Installation
1855

19-
Add the package to an existing Umbraco website (v13+) from nuget:
56+
Add the package to an existing Umbraco website (Umbraco 13+) from nuget:
2057

2158
`dotnet add package Umbraco.Community.ModelsBuilder.PropertyOverride`
2259

23-
TODO *provide any other instructions for someone using your package*
24-
2560
## Contributing
2661

27-
Contributions to this package are most welcome! Please read the [Contributing Guidelines](CONTRIBUTING.md).
62+
Contributions to this package are most welcome!
2863

2964
## Acknowledgments
3065

31-
TODO
66+
[tristanjthompson](https://github.com/tristanjthompson) & [zade107](http://github/zade107)

docs/README_nuget.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,65 @@
22

33
[![Downloads](https://img.shields.io/nuget/dt/Umbraco.Community.ModelsBuilder.PropertyOverride?color=cc9900)](https://www.nuget.org/packages/Umbraco.Community.ModelsBuilder.PropertyOverride/)
44
[![NuGet](https://img.shields.io/nuget/vpre/Umbraco.Community.ModelsBuilder.PropertyOverride?color=0273B3)](https://www.nuget.org/packages/Umbraco.Community.ModelsBuilder.PropertyOverride)
5-
[![GitHub license](https://img.shields.io/github/license/Gibe/Umbraco.Community.ModelsBuilder.PropertyOverride?color=8AB803)](https://github.com/Gibe/Umbraco.Community.ModelsBuilder.PropertyOverride/blob/main/LICENSE)
5+
[![GitHub license](https://img.shields.io/github/license/Gibe/Umbraco.Community.ModelsBuilder.PropertyOverride?color=8AB803)](../LICENSE)
66

7-
TODO: describe your package for nuget audience
7+
This package provides functionality for overriding Models Builder property implementations.
8+
9+
Umbraco versions 13.x - 15.x are supported.
10+
11+
Properties can be marked up with a re-implemented `[ImplementPropertyType("alias")]` attribute, which causes them to be ignored when generating models through the default Models Builder.
12+
13+
In addition, classes can be marked up with `[ImplementAllPropertyTypes]`, which causes all properties on the class to be ignored, this is functionally equivalent to adding `[ImplementPropertyType("alias")]` to every property on the class.
14+
15+
Legacy (8.x) documentation for the `[ImplementPropertyType("alias")]` attribute can be found [here](https://our.umbraco.com/Documentation/Reference/Templating/Modelsbuilder/Control-Generation-vpre8_5#implement-property-type).
16+
17+
## Examples
18+
19+
`[ImplementPropertyType("alias")]` to ignore properties on an individual basis:
20+
21+
```
22+
using Umbraco.Cms.Infrastructure.ModelsBuilder;
23+
24+
namespace ModelsBuilder.PropertyOverride.TestSite.Models
25+
{
26+
public partial class Home
27+
{
28+
[ImplementPropertyType("content")]
29+
public global::Umbraco.Cms.Core.Models.Blocks.BlockListModel Content => this.Value<global::Umbraco.Cms.Core.Models.Blocks.BlockListModel>(_publishedValueFallback, "content");
30+
31+
[ImplementPropertyType("title")]
32+
public virtual string Title => this.Value<string>(_publishedValueFallback, "title");
33+
}
34+
}
35+
```
36+
37+
`[ImplementAllPropertyTypes]` to ignore all properties:
38+
39+
```
40+
using Umbraco.Cms.Infrastructure.ModelsBuilder;
41+
42+
namespace ModelsBuilder.PropertyOverride.TestSite.Models
43+
{
44+
[ImplementAllPropertyTypes]
45+
public partial class HomePageBlock
46+
{
47+
public virtual global::Umbraco.Cms.Core.Models.MediaWithCrops Image { get; set; }
48+
public virtual string SubTitle { get; set; }
49+
public virtual string Title { get; set; }
50+
}
51+
}
52+
```
53+
54+
## Installation
55+
56+
Add the package to an existing Umbraco website (v13+) from nuget:
57+
58+
`dotnet add package Umbraco.Community.ModelsBuilder.PropertyOverride`
59+
60+
## Contributing
61+
62+
Contributions to this package are most welcome!
63+
64+
## Acknowledgments
65+
66+
[tristanjthompson](https://github.com/tristanjthompson) & [zade107](http://github/zade107)

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/ModelsBuilder.PropertyOverride.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<PackageTags>umbraco;umbraco-marketplace</PackageTags>
1313
<RootNamespace>Umbraco.Community.ModelsBuilder.PropertyOverride</RootNamespace>
1414
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
15-
<Version>0.1.0</Version>
15+
<Version>1.0.0</Version>
1616
<Authors>Gibe Digital</Authors>
1717
<Copyright>$([System.DateTime]::UtcNow.ToString(`yyyy`)) © Gibe Digital</Copyright>
1818
<PackageProjectUrl>https://github.com/Gibe/Umbraco.Community.ModelsBuilder.PropertyOverride</PackageProjectUrl>

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)

umbraco-marketplace.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
2-
"$schema": "https://marketplace.umbraco.com/umbraco-marketplace-schema.json",
3-
"AuthorDetails": {
4-
"Name": "Gibe Digital",
5-
"ImageUrl": "https://github.com/Gibe.png"
6-
},
7-
"Category": "",
8-
"Description": "",
9-
"LicenseTypes": [ "Free" ],
10-
"IssueTrackerUrl": "https://github.com/Gibe/Umbraco.Community.ModelsBuilder.PropertyOverride/issues",
11-
"PackageType": "Package",
12-
"Tags": [],
13-
"Title": "ModelsBuilder Property Override"
14-
}
2+
"$schema": "https://marketplace.umbraco.com/umbraco-marketplace-schema.json",
3+
"AuthorDetails": {
4+
"Name": "Gibe Digital",
5+
"Url": "https://github.com/Gibe/Umbraco.Community.ModelsBuilder.PropertyOverride",
6+
"ImageUrl": "https://github.com/Gibe.png",
7+
"SyncContributorsFromRepository": true
8+
},
9+
"Description": "Re-implementation of the ImplementPropertyType functionality to tell ModelsBuilder not to generate properties.",
10+
"DocumentationUrl": "https://github.com/Gibe/Umbraco.Community.ModelsBuilder.PropertyOverride",
11+
"IssueTrackerUrl": "https://github.com/Gibe/Umbraco.Community.ModelsBuilder.PropertyOverride/issues",
12+
"PackageType": "Package",
13+
"Category": "Developer Tools",
14+
"Tags": [ "modelsbuilder", "backoffice" ]
15+
}

0 commit comments

Comments
 (0)