WCF IDictionary<TKey, TValue> - How to indicate that TValue can be null?

165 views Asked by At

Basically, I want to pass back the following in my WCF service:

[DataMember(IsRequired = true)]
IDictionary<int, MyObj> objects { get; set; }

How can I make it so that the MyObj can be null so that when I receive it on the other end it doesn't instantiate a blank item, but instead leaves it null?

1

There are 1 answers

0
carlosfigueira On BEST ANSWER

It can be null, you don't need to do anything special. The IsRequired=true applies to the dictionary itself, not to specific instances of the dictionary.

Also, you shouldn't use IDictionary (unless you want to deal with [KnownType]s), Dictionary should do fine.