OrchardCore icon indicating copy to clipboard operation
OrchardCore copied to clipboard

Concrete Classes and Definitions for Content Types

Open deanmarcussen opened this issue 5 years ago • 1 comments

A great suggestion from Sebastien on gitter last night that's worth tracking

Someone should add some helper in C# so that we could define a class like MyCustomer.cs which would have content parts and fields as its properties, and be able to register this as a content type definition. So the model would be driven by code. And we could use these classes directly when loading the content items, to get full intellisense in the templates.

@johnrom I think you are the one who showed me we could use fields directly in classes, right? This is the idea, to be able to register a class as a content type, and when we resolve the ContentDefinitionManager they would be there too. So all statically. And yes we can also provide some helper to cast a content item to a class. IT can't be without some custom call as the intellsiense wouldn't know the actual type

@johnrom Your documentation on using Fields in Part Classes was great. Do you think you might work on this feature? I'd be happy to help if you were able to

deanmarcussen avatar Aug 30 '19 07:08 deanmarcussen

My initial thought is:

  • ContentItem.As<TContentType extends ContentType>()
  • GetContentItemByIdAsync<ContentType>(id)

johnrom avatar Aug 30 '19 14:08 johnrom