public static FilterDefinition <BsonDocument> FilterDefinitionOfInputId(object value) { value = Actor.BaseObject(value, out PSObject custom); if (custom == null) { if (value is IConvertibleToBsonDocument cd) { var doc = cd.ToBsonDocument(); if (doc.TryGetElement(BsonId.Name, out BsonElement elem)) { return(new BsonDocument(elem)); } else { throw new InvalidOperationException(Res.InputDocId); } } if (value is IDictionary dic) { if (!dic.Contains(BsonId.Name)) { throw new InvalidOperationException(Res.InputDocId); } var id = dic[BsonId.Name]; return(FilterDefinitionOfId(id)); } if (Actor.TypeIsDriverSerialized(value.GetType())) { var cm = BsonClassMap.LookupClassMap(value.GetType()); var mm = cm.GetMemberMapForElement(BsonId.Name); var id = mm.Getter(value); return(FilterDefinitionOfId(id)); } } var ps = custom ?? PSObject.AsPSObject(value); var pi = ps.Properties[BsonId.Name]; if (pi == null) { throw new InvalidOperationException(Res.InputDocId); } else { return(FilterDefinitionOfId(pi.Value)); } }