This project has moved and is read-only. For the latest updates, please go here.

can you extend a linqtotwitter object and add your own propterties to it?

Apr 27, 2013 at 1:10 AM
I am returning a list of User objects
and I was wondering if I could loop through the list of User objects and add a custom Property to each user object?

for example I have a string property called "totalretweets" and I wanted to add this property to each "User" object

is this possible?

any help is awesome! and you are awesome if you or anyone an shed light on my dark corner over here..

Code On...

May 1, 2013 at 12:30 AM
Edited May 1, 2013 at 12:35 AM
Apart from grabbing the source and making the modifications directly, the only thing I can think you might be able to do is to add this through an extension method.

A pretty good example/explanation of an extension methods is available here:

Also, while this may "work", it's not a good idea performance-wise, but the basic idea would be to have the extension method do what you need it to and would look something like this:

using LinqToTwitter;

namespace YOUR_APPLICATION_NAMESPACE.ExtensionMethods
    public static class TwitterUserExtensions
        public static int TotalRetweets(this User user)
            int retweets = 0;

            // code to open a new twitter context and count retweets

            return retweets;
Now, as to the question of whether you can get the information you're looking for out of Linq to Twitter, that is for someone else to answer because I just started looking at this today...

Edit: Wups, forgot a quick example of what that would look like in use. In the file where you need to get at this new method, import the namespace that you gave it in the above step, and then your new method will be available to use:
var myRewteetCount = myUserObject.TotalRetweets()