/// <summary> /// Adds a field named TypeIDFieldName with the type id of the object instance, force=true to emit the field even if it is a known type. /// Returns true if type id element was added /// </summary> public virtual bool AddTypeIDField(BSONDocument doc, IBSONSerializable parent, IBSONSerializable self, object ctx, bool force = false) { if (doc == null) { return(false); } if (self == null) { return(false); } var add = force || parent == null; var t = self.GetType(); if (!add) { add = !parent.IsKnownTypeForBSONDeserialization(t); } if (add) { var id = BSONSerializableAttribute.GetGuidTypeAttribute <object, BSONSerializableAttribute>(t) .TypeGuid; var telm = new BSONBinaryElement(TypeIDFieldName, new BSONBinary(BSONBinaryType.UUID, id.ToByteArray())); doc.Set(telm); return(true); } return(false); }
public static GDID GDID_BSONtoCLR(BSONBinaryElement el) { try { var buf = el.Value.Data; return(new GDID(buf)); } catch (Exception e) { throw new BSONException(StringConsts.GDID_BUFFER_ERROR.Args(e.ToMessageWithType()), e); } }
public static Guid GUID_BSONtoCLR(BSONBinaryElement el) { try { var val = el.Value; if (val.Type != BSONBinaryType.UUID && val.Type != BSONBinaryType.UUIDOld) { throw new BSONException("type != BSONBinaryType.UUID"); } var buf = val.Data; return(new Guid(buf)); } catch (Exception e) { throw new BSONException(StringConsts.BSON_GUID_BUFFER_ERROR.Args(e.ToMessageWithType()), e); } }