Once something is dynamic, everything is dynamic, so Convert.ToInt32(mediaItem) would be a dynamic (OK, an int really, but a dynamic as far as the compiler is concerned). So Umbraco.TypedMedia(Convert.ToInt32(mediaItem)) is also a dynamic (OK, an IPublishedContent really, but a dynamic as far as the compiler is concerned). Using the (int) cast breaks the dynamic propagation, so Umbraco.TypedMedia((int)Convert.ToInt32(mediaItem)) is considered an IPublishedContent by the compiler.
Compilerwise sense. But things like this creates a lot of trouble for the less developerminded "implementers".
I'm thinking that Umbraco might need a high level api that can be used in razor for the trivial stuff that only takes primitive data types as parameter and return values (and arrays) and fails silently.
Edit: I actually cant believe I'm suggesting this as I think theres already too many ways of doing the same thing but nevertheless ...
Whenever you (the royal you - anybody) have to use .ToString() or need to wrap everything in .IsNullOrEmpty() or that hideous .GetProperty<T>("propertyName") etc. in a View, the tools should just throw a #fail hashtag :-)
To me, they almost always signal that the controller could do a better job, preparing the actual data for the view... (I'm using those terms loosely, but that's the gist of it).
And it's exactly the same (low) sofistication level needed! And just a App_Code thing. Ground rules might be:
- no objects, no exceptions - simple parameters and return (string, int) - failover to default values ... no
Simple.Media
string value = Media.GetFileUrl(id [, defaultvalue])
string value = Media.GetFileName(id [, defaultvalue]) string value = Media.GetName(id [, defaultvalue])
string value = Media.GetFileExtension(id [, defaultvalue])
string value = Media.GetCropped(id, cropAlias [, defaultvalue])
string value = Media.GetString(id, propertyAlias [, defaultvalue])
int value = Media.GetInt(id, propertyAlias [, defaultvalue])
int[] value = Media.GetChildrenIds(id)
Simple.Content
string value = Content.GetString(id, propertyAlias [, defaultvalue])
int value = Content.GetInt(id, propertyAlias [, defaultvalue])
string value = Content.GetUrl(id [, defaultvalue])
string value = Content.GetName(id, [, defaultvalue])
int[] value = Content.GetChildrenIds(id)
bool value = Content.HasAccess(id)
TypedMedia issues?
Hi all,
The first works while the second doesnt:
Why is it different? Both returns something that looks the same but the latter looks like a dynamic?
best
Jesper
What's the type of mediaItem? Is it a dynamic?
Once something is dynamic, everything is dynamic, so Convert.ToInt32(mediaItem) would be a dynamic (OK, an int really, but a dynamic as far as the compiler is concerned). So Umbraco.TypedMedia(Convert.ToInt32(mediaItem)) is also a dynamic (OK, an IPublishedContent really, but a dynamic as far as the compiler is concerned). Using the (int) cast breaks the dynamic propagation, so Umbraco.TypedMedia((int)Convert.ToInt32(mediaItem)) is considered an IPublishedContent by the compiler.
Making sense?
Thanks Stephen. That makes sense. :)
Compilerwise sense. But things like this creates a lot of trouble for the less developerminded "implementers".
I'm thinking that Umbraco might need a high level api that can be used in razor for the trivial stuff that only takes primitive data types as parameter and return values (and arrays) and fails silently.
Edit: I actually cant believe I'm suggesting this as I think theres already too many ways of doing the same thing but nevertheless ...
Just do not, ever, use dynamics.
Well it's there. And it requires dev skills to avoid it :)
I totally follow you, Jesper.
Whenever you (the royal you - anybody) have to use
.ToString()
or need to wrap everything in.IsNullOrEmpty()
or that hideous.GetProperty<T>("propertyName")
etc. in a View, the tools should just throw a #fail hashtag :-)To me, they almost always signal that the controller could do a better job, preparing the actual data for the view... (I'm using those terms loosely, but that's the gist of it).
/Chriztian
@Jesper - Sounds like it's time for an extension library to provide a proof of concept. :) Reminds me of the days of those xslt extensions. :P
And it's exactly the same (low) sofistication level needed! And just a App_Code thing. Ground rules might be:
- no objects, no exceptions
- simple parameters and return (string, int)
- failover to default values ... no
Simple.Media
Simple.Content
is working on a reply...