Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
1.36/5 (4 votes)
See more:
Does anyone know how to make a Friend System in VB or C#. Specifically, I need the ability in C# to make friend classes.
Posted
Updated 3-Oct-11 14:26pm
v2
Comments
Sergey Alexandrovich Kryukov 3-Oct-11 18:25pm    
???
AspDotNetDev 3-Oct-11 18:32pm    
I think the OP is referring to the ability in C++ to make friend classes. But that is a wild guess and I could be wrong. The OP should clarify.
Sergey Alexandrovich Kryukov 3-Oct-11 21:16pm    
If so (OP confirmed), I answered, crediting Wonde.
--SA
mw2adrian 3-Oct-11 18:44pm    
Yes that's what i need help on

If you are referring to a Friend assembly, then here is how you can do so Friend Assemblies (C# and Visual Basic)[^]. The basic concept is to decorate you class with InternalsVisibleToAttribute[^] attribute and to declare your class as internal(C#)[^] and Friend(VB.NET)[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Oct-11 20:26pm    
I provided more detailed answer but forgot to mentioned friend assemblies. So I voted 5 and credited your solution in mine, please see it.
--SA
Wonde Tadesse 3-Oct-11 21:32pm    
Thanks --SA
I think the OP is referring to the ability in C++ to make friend classes. But that is a wild guess and I could be wrong. The OP should clarify.

mw2adrian wrote:
Yes that's what I need help on.


Well, if so, the answer is pretty simple. VB.NET, C# and .NET have different, somewhat simplified approach. There are no "friends" in the sense of C++. The difference is that .NET introduces the concept of assembly and provides additional distinction in access specifier. Instead of just one public specifier, there is one more, internal. Likewise, C++ protected splits in two: protected and internal protected. The keyword internal means "same as "public" but only in the same assembly" and protected internal means: "same as "protected" but only in the same assembly".

Back to internal: this specifiers makes all types friends to all other code in the same assembly, but inaccessible from external assemblies. This is certainly less fine-grain approach than that of C++, but in practice is only should encourage the developers to use assemblies properly. From the other hand, using C++ "friend" feature is not trivial and not always help developing really tight access control.

It should be noted that access specifiers do not present any security protection, as all types and methods can be accessed using Reflection, even private and protected ones. The access specifiers are designed to guard discipline of programming, not to protect again malicious activity.

On top of all this, there are also friend assemblies mentioned by Wonde. Please see his solution for more detail.

—SA
 
Share this answer
 
v2
Comments
Wonde Tadesse 3-Oct-11 21:11pm    
5+ for your detail explanation.
Sergey Alexandrovich Kryukov 3-Oct-11 21:15pm    
Thank you, Wonde.
--SA
So you can maybe use a treeview if you want your users to group their friends. You could have the user's friends names/information stored in an sql table if you want....

If you need to learn some SQL, theres a relativly quick and painless starter course here(SQL is relatively simple in comparison to Visual basic), it took me less than an hour to run through the entire thing...

http://www.sqlcourse.com

It is even possible that you could use sql to relay the chat data from a table, im not exactly sure how you intend on generating a unique new table name for that chat session, but I could see the benefit, being as long as you never delete the table storing the chat information, you would have every conversation that ever took place stored.

I imagine, if you did use an sql table for chat relay, that it may affect the performance of your server, depending on how many users will be using the application.

When users open your application, you could change their status online/away/offline with some settings you store in an sql table as well...

Depending on how many users you expect, you may have to create unique guids for each user.

The friends list would store their name, but when you query that name, your application would use the guid. This would allow for multiple people with the same first and last name, even the same screen name.

First, You need to create a summary, checklist.



1.) Determine the format of how account information will be stored and why this will support your ultimate goal best.

2.) Identify potential problems

3.) Determine how stored data will be accessed, by guid? by username?



Private Function GenerateGUID() As String
GenerateGUID = System.Guid.NewGuid.ToString()
End Function




At first glance, this question seems to be relatively simple, but if you want the best possible answer, I really suggest that you consider disclosing more supporting information about your application, what it does, how it stores data, and how you access it
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900