How to create an IAttachmentID using Trello.Net?

499 views Asked by At

I'm using dillenmeister's Trello.Net API wrapper, and I see that removing an attachment from a card was added a couple months ago, but the call that I'm using (Trello.Cards.RemoveAttachment()) calls for a CardId and an IAttachmentId. I've figured out how to create a CardId (new CardID(Card.ID)), but I'm not seeing how to create the IAttachmentID that it's looking for.

I have the attachment object, and can get the ID from there, but that is of type string.

1

There are 1 answers

3
dillenmeister On BEST ANSWER

The Attachment class itself implements IAttachmentId.

// Example: Remove all attachments with the name "DevSupport" from a card 
var card = trello.Cards.WithId("a card id");
foreach (var attachment in card.Attachments.Where(a => a.Name == "DevSupport"))
    trello.Cards.RemoveAttachment(card, attachment);

It's similar for many other objects, for example the Card class implements ICardId. You do not need to create a CardId object if you have a Card. Just use the actual Card.

// Example: Fetch all members assigned to a card
var card = trello.Cards.WithId("a card id");
var members = trello.Members.ForCard(card);

There might be a need for an AttachmentId class anyway though. What is your use case?