MongoDB.Bson.Serialization.Serializers.IPAddressSerializer.Serialize C# (CSharp) Метод

Serialize() публичный Метод

Serializes an object to a BsonWriter.
public Serialize ( BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options ) : void
bsonWriter MongoDB.Bson.IO.BsonWriter The BsonWriter.
nominalType System.Type The nominal type.
value object The object.
options IBsonSerializationOptions The serialization options.
Результат void
        public override void Serialize(
            BsonWriter bsonWriter,
            Type nominalType,
            object value,
            IBsonSerializationOptions options)
        {
            if (value == null)
            {
                bsonWriter.WriteNull();
            }
            else
            {
                var address = (IPAddress)value;
                string stringValue;
                if (address.AddressFamily == AddressFamily.InterNetwork)
                {
                    stringValue = address.ToString();
                }
                else
                {
                    stringValue = string.Format("[{0}]", address);
                }
                bsonWriter.WriteString(stringValue);
            }
        }
    }