首页 \ 问答 \ 目标C的协议代表等同于xamarin(Protocol delegates of Objective C equivalent in xamarin)

目标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
更新时间:2023-09-20 14:09

最满意答案

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容器创建,当你需要它只是放入你的控制器方法的参数,它将被注入。 用户登录示例 @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 ...
  • 是的,您可以安全地将其存储在会话中。 您应该确保验证方法是安全的。 (存储在会话中之前使用的方法)。 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 ...
  • 免责声明:我刚刚提出这个实现,因为我认为这是一个有趣的 - 可解决的 - 问题。 因此,我可能会忽略一些问题或细节。 不过,如果您使用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 ...
  • 这对于基于默认文件的PHP会话非常困难。 默认情况下,PHP只将会话信息存储在文件系统文件中的不透明blob中,文件名为会话ID。 您无法直接访问这些文件中的数据,而无需逐个打开它们并对其进行评估。 您需要的是将该信息移动到数据库中。 要么只存储数据库中的并发登录数,要保持其他会话不变,但这很难保持同步。 最好切换到会话的完整数据库后端来代替基于文件的存储。 这允许您透明地查询会话中的任何数据,包括轻松获取有关用户拥有的会话数的统计信息。 This is very difficult to do with ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)