Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: How to perform a null-check on a dynamic object

How do I perform a null-check on a dynamic object?

Pseudo code:

public void Main() {     dynamic dynamicObject = 33;     if(true) { // Arbitrary logic         dynamicObject = null;     }     Method(dynamicObject); }  public void Method(dynamic param) {     // TODO: check if the content of 'param' is equal to null } 
like image 1000
Seb Nilsson Avatar asked Aug 11 '11 16:08

Seb Nilsson


1 Answers

Are you worried about the possibility the dynamic object will have a custom equality operator that will change the way the null is interpreted? If so just use Object.ReferenceEquals

if (Object.ReferenceEquals(null, param)) {   ....... } 
like image 80
JaredPar Avatar answered Sep 19 '22 14:09

JaredPar