Table of Contents

Class BsonUtils

Namespace
MongoDB.Bson
Assembly
MongoDB.Bson.dll

A static class containing BSON utility methods.

public static class BsonUtils
Inheritance
BsonUtils
Inherited Members

Methods

GetFriendlyTypeName(Type)

Gets a friendly class name suitable for use in error messages.

public static string GetFriendlyTypeName(Type type)

Parameters

type Type

The type.

Returns

string

A friendly class name.

ParseHexString(string)

Parses a hex string into its equivalent byte array.

public static byte[] ParseHexString(string s)

Parameters

s string

The hex string to parse.

Returns

byte[]

The byte equivalent of the hex string.

ToDateTimeFromMillisecondsSinceEpoch(long)

Converts from number of milliseconds since Unix epoch to DateTime.

public static DateTime ToDateTimeFromMillisecondsSinceEpoch(long millisecondsSinceEpoch)

Parameters

millisecondsSinceEpoch long

The number of milliseconds since Unix epoch.

Returns

DateTime

A DateTime.

ToHexChar(int)

Converts a value to a hex character.

public static char ToHexChar(int value)

Parameters

value int

The value (assumed to be between 0 and 15).

Returns

char

The hex character.

ToHexString(byte[])

Converts a byte array to a hex string.

public static string ToHexString(byte[] bytes)

Parameters

bytes byte[]

The byte array.

Returns

string

A hex string.

ToLocalTime(DateTime)

Converts a DateTime to local time (with special handling for MinValue and MaxValue).

public static DateTime ToLocalTime(DateTime dateTime)

Parameters

dateTime DateTime

A DateTime.

Returns

DateTime

The DateTime in local time.

ToMillisecondsSinceEpoch(DateTime)

Converts a DateTime to number of milliseconds since Unix epoch.

public static long ToMillisecondsSinceEpoch(DateTime dateTime)

Parameters

dateTime DateTime

A DateTime.

Returns

long

Number of milliseconds since Unix epoch.

ToSecondsSinceEpoch(DateTime)

Converts a DateTime to number of seconds since Unix epoch.

public static long ToSecondsSinceEpoch(DateTime dateTime)

Parameters

dateTime DateTime

A DateTime.

Returns

long

Number of seconds since Unix epoch.

ToUniversalTime(DateTime)

Converts a DateTime to UTC (with special handling for MinValue and MaxValue).

public static DateTime ToUniversalTime(DateTime dateTime)

Parameters

dateTime DateTime

A DateTime.

Returns

DateTime

The DateTime in UTC.

TryParseHexString(string, out byte[])

Tries to parse a hex string to a byte array.

public static bool TryParseHexString(string s, out byte[] bytes)

Parameters

s string

The hex string.

bytes byte[]

A byte array.

Returns

bool

True if the hex string was successfully parsed.