VB或C#中的Friend系统 [英] Friend System In VB Or C#

查看:117
本文介绍了VB或C#中的Friend系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何在VB或C#中建立朋友系统吗?具体来说,我需要C#中的能力来创建朋友类.

解决方案

如果您引用的是Friend程序集,那么您可以按照以下方法进行操作朋友程序集(C#和Visual Basic) [ InternalsVisibleToAttribute [ ^ ]属性并声明您的课程为内部(C#) [朋友(VB.NET) [ ^ ].


是的,这是我需要帮助的地方.



好吧,如果是这样,答案很简单. VB.NET,C#和.NET具有不同的简化方法.在C ++的意义上没有朋友".区别在于.NET引入了汇编的概念,并在访问说明符中提供了其他区别.不仅仅是一个public说明符,还有一个internal.同样,C ++ protected分为两部分:protectedinternal protected.关键字internal的意思是与公共"相同,但仅在同一程序集中",而protected internal的含义是:与受保护"相同,但仅在同一程序集中".

返回到internal:此说明符使所有类型的朋友成为同一程序集中的所有其他代码的朋友,但无法从外部程序集访问.当然,这比C ++的细粒度方法要少,但是在实践中仅应鼓励开发人员正确使用程序集.另一方面,使用C ++的朋友"功能并非易事,并不总是有助于开发真正严格的访问控制.

应当注意,访问说明符不提供任何安全保护,因为可以使用反射来访问所有类型和方法,甚至可以使用privateprotected进行访问.访问说明符旨在保护编程纪律,而不是再次保护恶意活动.

最重要的是,Wonde还提到了 friend Assembly .请查看他的解决方案以获取更多详细信息.

-SA


因此,如果希望用户将其朋友分组,则可以使用树形视图.如果需要,可以将用户的朋友名称/信息存储在sql表中.
如果您需要学习一些SQL,这里有一个相对快速而轻松的入门课程(与Visual Basic相比,SQL相对简单),花了不到一个小时的时间来完成整个过程...

http://www.sqlcourse.com

甚至有可能您可以使用sql来中继来自表的聊天数据,而不完全确定您打算如何为该聊天会话生成唯一的新表名,但是只要您从不这样做,我就可以看到好处.删除存储聊天信息的表,您将存储曾经发生的所有对话.

我想,如果您确实使用sql表进行聊天中继,则可能会影响服务器的性能,具体取决于将使用该应用程序的用户数量.

当用户打开您的应用程序时,您还可以使用存储在sql表中的某些设置来在线/离线/离线更改其状态...

根据您期望的用户数量,您可能必须为每个用户创建唯一的向导.

朋友列表将存储他们的名字,但是当您查询该名字时,您的应用程序将使用guid.这样可以允许多个人使用相同的名字和姓氏,甚至使用相同的屏幕名称.

首先,您需要创建摘要清单.



1.)确定如何存储帐户信息的格式以及为什么这将最好地支持您的最终目标.

2.)找出潜在的问题

3.)确定guid将如何访问存储的数据?通过用户名?



私有函数GenerateGUID()作为字符串
GenerateGUID = System.Guid.NewGuid.ToString()
最终功能




乍一看,这个问题似乎相对简单,但是如果您想获得最佳答案,我真的建议您考虑公开有关应用程序,它的功能,如何存储数据以及如何访问它的更多支持信息. /blockquote>

Does anyone know how to make a Friend System in VB or C#. Specifically, I need the ability in C# to make friend classes.

解决方案

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)[^].


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


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


这篇关于VB或C#中的Friend系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆