目标C的协议代表等同于xamarin(Protocol delegates of Objective C equivalent in xamarin)
我想使用委托设计模式将一些任务分配给子对象,一旦完成它必须让我知道,以便我可以采取相应的行动。
但是在Objective c中,可以使用Protocols轻松完成。
我知道Protocol等价是C#中的接口,但我找不到任何关于如何在c#中进行委托的例子我知道我们必须将子对象声明为弱,否则将发生循环引用。
如果有任何其他替代方法可以实现这一目的,那么在c#中不可能进行AFAIK授权
使用代码片段进行解释将是一个好主意
I would like to use delegation design pattern to assign some tasks to child object and once its done it has to let me know so that I can act accordingly.
But in Objective c it can be done easily using Protocols.
I know Protocol equivalent is interface in C# but I couldn't find any examples on how to proceed delegation in c# I know we have to declare child object as weak or else cyclic reference will occur.
AFAIK delegation is not possible in c# if there are any other alternatives to achieve this thing
Explaining with a code snippet would be a good idea
原文:https://stackoverflow.com/questions/42736888
最满意答案
if((!isset($_SESSION['admin'])) || (!isset($_SESSION['super_admin']))) // redirect
这意味着你同时拒绝任何不是“admin” 和 “super_admin”的人! 您可能打算使用
&&
拒绝“任何不是管理员而非超级管理员的人”。
我不确定为什么你会得到重定向错误,我的猜测是
home.php
确定你已经登录并重定向回到再次拒绝你的管理页面等等所以你可能有两个要修复的错误 - 条件和重定向周期。if((!isset($_SESSION['admin'])) || (!isset($_SESSION['super_admin']))) // redirect
This means you're refusing anyone that is not "admin" and "super_admin" at the same time! You probably meant to use
&&
to refuse "anyone who's not an admin and not a super admin either".
I'm not sure why you're getting the redirect error out of this, my guess would be that
home.php
determines you're logged in and redirects you back to the admin page that refuses you again etc. So you probably have two errors to fix - the condition and the redirect cycle.
相关问答
更多-
Spring MVC中的会话(Sessions in Spring MVC)[2023-03-03]
会话已经由spring容器创建,当你需要它只是放入你的控制器方法的参数,它将被注入。 用户登录示例 @RequestMapping(value=("login"),method=RequestMethod.POST) public String login(@RequestParam("name")String name,@RequestParam("pass")String pass,@RequestParam("gName")String gName,HttpSession session ... -
我不认为那是罕见的。 一种可能的解决方案是将会话超时设置为最小值。 例如5分钟。 此外,如果用户已存在会话,您可以编写过滤器以增加会话超时。 因此,普通用户将具有30分钟的会话超时,并且仅访问一方的用户具有5分钟的超时。 这是一个过滤器,可以解决这个问题: public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletEx ...
-
将新列添加到users表。 设opened_once:boolean ,DEFAULT为false 然后在你的users_controller def edit @user = User.find( params[:id], :conditions => ['opened_once => ?', false] ) rescue ActiveRecord::RecordNotFound @user.update_attribute :opened_once, true ... end 所以现在只 ...
-
行(!string.IsNullOrEmpty(Session["User"].ToString()))是不正确的方式,并且肯定会引发异常,因为你没有设置会话变量。 因为在这种情况下,Session [“User”]将返回null值,因此您应该检查它。 即 if (null != Session["User"]) { 要么 user = Session["User"]; if (null != user && user.ToString().Length > 0) { // user logged ...
-
ServerSide会话安全吗?(ServerSide Sessions safe?)[2024-02-17]
是的,您可以安全地将其存储在会话中。 您应该确保验证方法是安全的。 (存储在会话中之前使用的方法)。 Yes you can store it in the session safely. You should make sure that the Validation method is safe. (the method you use before storing in the session). -
不,因为它正在检查Session是否为空字符串,但在此处, Session为空,即不是空字符串。 因此条件失败。 您应该检查Session是否为空而不是空字符串。 if(Session["RoleCheck"] == null) { // redirect } No, because it is checking whether Session is blank string, but here, Session is null, i.e not a blank string. Hence cond ...
-
if((!isset($_SESSION['admin'])) || (!isset($_SESSION['super_admin']))) // redirect 这意味着你同时拒绝任何不是“admin” 和 “super_admin”的人! 您可能打算使用&&拒绝“任何不是管理员而非超级管理员的人”。 我不确定为什么你会得到重定向错误,我的猜测是home.php确定你已经登录并重定向回到再次拒绝你的管理页面等等所以你可能有两个要修复的错误 - 条件和重定向周期。 if((!isset($_SE ...
-
如何查看所有活动会话的会话状态中的所有内容?(How can I view everything in Session State for all active Sessions?)[2022-03-16]
免责声明:我刚刚提出这个实现,因为我认为这是一个有趣的 - 可解决的 - 问题。 因此,我可能会忽略一些问题或细节。 不过,如果您使用InProc会话状态,这是一个解决方案。 简介:创建存储在Application_Start事件期间创建的Application状态的应用程序级对象(例如List),并在每个Session_Start事件上,将对会话的引用添加到列表中。 在Session_End ,删除它。 要检索所有活动会话和值,请遍历会话列表,然后遍历每个会话和会话密钥。 Global.asax中 voi ... -
如果你想让jQuery知道它是什么,你需要设置一个带有用户名的cookie。 或者,您可以为php页面设置ajax请求,该页面返回活动会话ID的用户名。 您也可以在Javascript之前输出PHP,如下所示: You need to set a cookie with the ...
-
是否可以从其他会话访问$ _SESSION变量?(Is it possible to access $_SESSION variables from other sessions?)[2022-03-22]
这对于基于默认文件的PHP会话非常困难。 默认情况下,PHP只将会话信息存储在文件系统文件中的不透明blob中,文件名为会话ID。 您无法直接访问这些文件中的数据,而无需逐个打开它们并对其进行评估。 您需要的是将该信息移动到数据库中。 要么只存储数据库中的并发登录数,要保持其他会话不变,但这很难保持同步。 最好切换到会话的完整数据库后端来代替基于文件的存储。 这允许您透明地查询会话中的任何数据,包括轻松获取有关用户拥有的会话数的统计信息。 This is very difficult to do with ...