michael
michael

Reputation: 15302

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

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?

Upvotes: 0

Views: 164

Answers (1)

carlosfigueira
carlosfigueira

Reputation: 87273

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.

Upvotes: 3

Related Questions