Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check property existence

Tags:

umbraco

In umbraco, is it possible to check if certain property exist for particular node?

For example, I am having 5 nodes and I am having media picker property for first node alone. I need to check all the nodes whether media picker property is available for nodes or not?

like image 553
SAK Avatar asked Jun 04 '10 12:06

SAK


People also ask

How do you check if a property of an object exists?

The hasOwnProperty() method will check if an object contains a direct property and will return true or false if it exists or not. The hasOwnProperty() method will only return true for direct properties and not inherited properties from the prototype chain.

How do you check if a property is present in an object in JavaScript?

The hasOwnProperty() method returns true if the specified property is a direct property of the object — even if the value is null or undefined . The method returns false if the property is inherited, or has not been declared at all.

How do you check if the object exists in JavaScript?

Method 1: Using the typeof operator The typeof operator returns the type of the variable on which it is called as a string. The return string for any object that does not exist is “undefined”. This can be used to check if an object exists or not, as a non-existing object will always return “undefined”.

How many types of object property exists?

Every object has general properties including its layer, color, linetype, linetype scale, lineweight, transparency, and plot style.


2 Answers

If you are using Razor you can do it like this:

Model.HasProperty("MyPropertyAlias")

And you can check if the property contains a value as follows:

Model.HasValue("MyPropertyAlias")
like image 196
ProNotion Avatar answered Sep 21 '22 03:09

ProNotion


I think you can just check property existence by comparing to null:

Node somenode = new Node(myNodeID);
if (somenode.GetProperty("myProperty") != null)
{
   string myProperty = somenode.GetProperty("myProperty").Value.ToString();
   //Do something with myProperty
}
like image 22
Soldarnal Avatar answered Sep 19 '22 03:09

Soldarnal