Coder Social home page Coder Social logo

Comments (8)

zpqrtbnk avatar zpqrtbnk commented on August 17, 2024

What do you exactly mean by "the right type"? Is it the CLR type of each property, eg property "MyTitle" is an IHtmlString? Then, you need to retrieve the PublishedPropertyType for the property: it has a ClrType property which returns a Type object describing the CLR type of the property.

from modelsbuilder.original.

W3SRotterdam avatar W3SRotterdam commented on August 17, 2024

I'm not using the PublishedProperty for getting the data. I'm getting the datatype like this

IDataTypeDefinition dataType = umbracoContext.Application.Services.DataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(propertyType.PropertyEditorAlias).First();

And from that i only can find a dataType.DatabaseType but nowhere a CLR type? I've searched the Umbraco source code but can't really find it. How do you find the object type?

from modelsbuilder.original.

zpqrtbnk avatar zpqrtbnk commented on August 17, 2024

You need to switch from the "database" world over to the "published content" world. Assuming that "contentTypeAlias" is the alias of your content type, and "propertyTypeAlias" the alias of your property type, you'll want to do something like PublishedContentType.Get("contentTypeAlias").GetPropertyType("propertyTypeAlias")... and the object that's returned has a ClrType property which is I believe the type you're looking for.

from modelsbuilder.original.

W3SRotterdam avatar W3SRotterdam commented on August 17, 2024

I can't find that object as a method? I've tried now to find it in the umbracoContext.Application.Services.ContentService and umbracoContext.Application.Services.ContentTypeService but nowhere a ClrType..

from modelsbuilder.original.

W3SRotterdam avatar W3SRotterdam commented on August 17, 2024

Umbraco source found it.. but still a error
new Umbraco.Core.Models.PublishedContent.PublishedPropertyType(contentType, propertyType).ClrType;

it need a PublishedContentType and i got a ContentType..

from modelsbuilder.original.

zpqrtbnk avatar zpqrtbnk commented on August 17, 2024

The full type name is Umbraco.Core.Models.PublishedContent.PublishedContentType. Has a public static method named Get that you should call to get the type. Do NOT "new" a published content type nor a published property type. Get the type, get the property from the type, get the ClrType from the property.

from modelsbuilder.original.

W3SRotterdam avatar W3SRotterdam commented on August 17, 2024

Got it! Umbraco.Core.Models.PublishedContent.PublishedContentType.Get(publishedItemType, contentType.Alias).GetPropertyType(propertyType.Alias).ClrType;

The problem wat i had a static method Umbraco in my class so he can't find the namespace.. stupid me!

Much thanks!

from modelsbuilder.original.

zpqrtbnk avatar zpqrtbnk commented on August 17, 2024

Glad I could help!

from modelsbuilder.original.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.