IceChat Forums

IceChat 9 => IceChat 9 Coding => Topic started by: ElementAlchemist on July 04, 2009, 04:36:50 PM

Title: C# classes and instances
Post by: ElementAlchemist on July 04, 2009, 04:36:50 PM
So, not knowing or really expecting Snerf to do it eventually (you know what happens when you assume), I have started working on a numeric 005 PREFIX parser in Ice 2009.  (I know, this is a great time to be learning C#, right?)

Well, anyway, I'm almost done.  Well, I think I am.  I've gotten most of the hardcoded symbols replaced.  However, I do have one C#-related question that I can't figure out but I need to solve.

How do I call a certain instance of a class when there are no calls to instances of a class in the class I'm trying to call it from?

Translation, because it sounds confusing now that I've typed it. :P  I need to call the right instance of IRCConnection but some files/classes don't have references to this.  My workaround was to use the server number as an element of the array but not all classes have instances of ServerSetting, either.

Note: I'm in Kubuntu Linux so all suggestions should also compile under Mono.  If you don't know if it works, suggest it and I'll try it.
Title: Re: C# classes and instances
Post by: ElementAlchemist on July 12, 2009, 07:29:47 PM
For anyone who is following this, the only place I probably need this now is User.cs.
Title: Re: C# classes and instances
Post by: Snerf on July 13, 2009, 11:59:21 AM
What I would do is change the constructor for the User Class, to also pass the IRCConnection.

Code: [Select]
public User(string nick)That is the current constructor, change it to also pass the IRCConnection
Code: [Select]
public User(string nick, IRCConnection connection)
Now, when you create the User class, which is in AddNick method in TabWindow class, add the connection variable. What you can then do is have a private variable for the User class that saves this value, and then you can use it in all the methods inside the User class.
Code: [Select]
internal void AddNick(string nick, bool refresh)
   User u = new User(nick, this.connection);  

You will also need to change the UpdateNick method in the TabWindow class to show the proper user modes.

Pretty straight forward, you can easily pass extra variables to classes.