I would like to see if a property exist in a C# Expando Class.
much like the hasattr function in python. I would like the c# equalant for hasattr.
something like this…
if (HasAttr(model, "Id"))
{
# Do something with model.Id
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try:
An ExpandoObject explicitly implements
IDictionary<string, Object>, where the Key is a property name. You can then check to see if the dictionary contains the key. You can also write a little helper method if you need to do this kind of check often:And use it like so: