访问属性内的属性 [英] Accessing property within a property

查看:56
本文介绍了访问属性内的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在asp.net安全中,当我们编写以下内容时:httpcontext.user.identity.isauthenticated()

这里的httpcontext是一个命名空间
用户是属性
身份是财产.
isauthenicated是一种方法...

我对"USER"和"IDENTITY"属性感到困惑...为什么我们可以在一个属性内访问属性?

In asp.net security, when we write : httpcontext.user.identity.isauthenticated()

here httpcontext is a namespace
user is a property
identity is a property.
isauthenicated is a method...

i am confused about ''USER'' and ''IDENTITY'' properties...how come we can access a property WITHIN A PROPERTY ???

推荐答案

错误:

HttpContext-这是一个静态类.
用户-是属性,但继承IPrincipal.
身份-IPrinciple界面中的属性.
IsAthenticated-这是一种方法,如果当前用户已被削弱,则返回该方法.

http://msdn.microsoft.com/en-us/library/system.web. httpcontext.aspx [ ^ ]
Wrong:

HttpContext - This is a static class.
User - Is a property but inherits IPrincipal.
Identity - Is a property in the the IPrinciple interface.
IsAthenticated - This is a method that returns if the current user is athenticated.

http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx[^]


您可以访问属性内的属性,因为实现IPrincipal的属性User具有方法Identity,该方法返回实现对象的属性. IIdentity界面.因此,每次您对该属性的返回值进行操作时.从技术上讲,是否使用属性或方法返回对象实例都无关紧要.如果User.Identity.isAuthenticated()将是User.GetIdentity().isAuthenticated(),则它也可以正常工作,尽管阅读起来会有些奇怪.

因此,由于该属性属于某个类,因此您可以在访问属性和方法时立即开始调用它们.像httpcontext.User.Identity.isAuthenticated()返回一个布尔值一样,但是要将其存储为字符串,您也可以执行此httpcontext.User.Identity.isAuthenticated().toString()而没有任何问题.

祝你好运!
You can access a property within a property because that property User, that implements IPrincipal, has a method Identity that returns an object that implements the IIdentity interface. So each time you operate on the return value of that property. It would technically not matter whether a property or method was used to return the object instance. If User.Identity.isAuthenticated() would be User.GetIdentity().isAuthenticated() it could also work fine, although it would be somewhat more strange to read.

So, because the property is of a certain class you can immediately start calling properties and methods when you access them. Like httpcontext.User.Identity.isAuthenticated() returns a boolean, but to store it as a string you can also do this httpcontext.User.Identity.isAuthenticated().toString() without any problems.

Good luck!


很简单:将每个类都看作一个盒子.

每个盒子都可以打开,并包含各种抽屉-每个图纸都是盒子的属性.

如果将一个盒子(SmallBox)放在另一个盒子(BigBox)的抽屉中:
It''s simple: think of each class as a box.

Each box can be opened, and contains various drawers - each draw is a property of the box.

If you put a box (SmallBox) inside the drawer of another box (BigBox):
BigBox myBigBox = new BigBox();
myBigBox.DrawerSeven.Box = new SmallBox(nameOfSmallBox);

然后您将以以下方式访问它的抽屉:

Then you would access it''s drawers as:

SmallBox mySmallBox = myBigBox.DrawerSeven.Box;
string s = mySmallBox.DrawerFour.Name;

您可以将这些结合起来并说:

You could combine these and say:

string s = myBigBox.DrawerSeven.Box.DrawerFour.Name;

并获得相同的结果.

Box是DrawerSeven的属性,而DrawerSeven是BigBox的属性.
名称是DrawerFour的属性,而DrawerFour是SmallBox的属性.

and get the same result.

Box is a property of DrawerSeven, which is a property of BigBox.
Name is a property of DrawerFour, which is a property of SmallBox.


这篇关于访问属性内的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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