public static bool EqualsOrElemMatches(this BsonValue value1, object value2) { var v2 = value2 as BsonValue; if (v2 != null) { return(value1.EqualsOrMatches(v2)); } if (value1.BsonType != BsonType.Document) { return(false); } return(((Func <BsonDocument, bool>)value2)(value1.AsBsonDocument)); }