MongoDB.Bson.Serialization.Options.TimeSpanSerializationOptions.ApplyAttribute C# (CSharp) Méthode

ApplyAttribute() public méthode

Apply an attribute to these serialization options and modify the options accordingly.
public ApplyAttribute ( IBsonSerializer serializer, Attribute attribute ) : void
serializer IBsonSerializer The serializer that these serialization options are for.
attribute System.Attribute The serialization options attribute.
Résultat void
        public override void ApplyAttribute(IBsonSerializer serializer, Attribute attribute)
        {
            EnsureNotFrozen();
            var representationAttribute = attribute as BsonRepresentationAttribute;
            if (representationAttribute != null)
            {
                _representation = representationAttribute.Representation;
                return;
            }

            var optionsAttribute = attribute as BsonTimeSpanOptionsAttribute;
            if (optionsAttribute != null)
            {
                _representation = optionsAttribute.Representation;
                _units = optionsAttribute.Units;
                return;
            }

            var message = string.Format("A serialization options attribute of type {0} cannot be applied to serialization options of type {1}.",
                BsonUtils.GetFriendlyTypeName(attribute.GetType()), BsonUtils.GetFriendlyTypeName(GetType()));
            throw new NotSupportedException(message);
        }