MongoDB.Bson.Serialization.BsonCreatorMap.HasDefaultValue C# (CSharp) Method

HasDefaultValue() public method

Gets whether there is a default value for a missing element.
public HasDefaultValue ( string elementName ) : bool
elementName string The element name.
return bool
        public bool HasDefaultValue(string elementName)
        {
            if (!_isFrozen) { ThrowNotFrozenException(); }
            return _defaultValues.ContainsKey(elementName);
        }

Usage Example

Ejemplo n.º 1
0
        private MatchData Match(BsonCreatorMap creatorMap, Dictionary <string, object> values)
        {
            var argumentCount     = 0;
            var defaultValueCount = 0;

            // a creator is a match if we have a value for each parameter (either a deserialized value or a default value)
            foreach (var elementName in creatorMap.ElementNames)
            {
                if (values.ContainsKey(elementName))
                {
                    argumentCount++;
                }
                else if (creatorMap.HasDefaultValue(elementName))
                {
                    defaultValueCount++;
                }
                else
                {
                    return(null);
                }
            }

            return(new MatchData {
                CreatorMap = creatorMap, ArgumentCount = argumentCount, DefaultValueCount = defaultValueCount
            });
        }
All Usage Examples Of MongoDB.Bson.Serialization.BsonCreatorMap::HasDefaultValue