T
tshad
I am trying to understand why I would use interfaces.
In the following example for IPrinciple, I have the following code:
************************************************************
using System;
using System.Collections;
using System.Security;
using System.Security.Principal;
namespace CustomSecurity
{
[Serializable]
public class CustomPrincipal: IPrincipal
{
private IIdentity identity;
private ArrayList roles;
public CustomPrincipal(IIdentity id, ArrayList rolesArray)
{
identity = id;
roles = rolesArray;
}
public bool IsInRole(string role)
{
return roles.Contains( role );
}
public IIdentity Identity
{
get { return identity; }
set { identity = value; }
}
}
}
*****************************************************
I understand that IPrincipal (and IIdentity) is defined as:
*********************************************************
namespace System.Security.Principal {
interface IIdentity {
bool IsAuthenticated { get; }
string AuthenticationType { get; }
string Name { get; }
}
interface IPrincipal {
IIdentity Identity { get; }
bool IsInRole(string role);
}
}
**********************************************************
What would be the difference if I just wrote the code as (I understand that
I also would have the IIdentity class also).:
**********************************************************
using System;
using System.Collections;
using System.Security;
namespace CustomSecurity
{
[Serializable]
public class CustomPrincipal
{
private IIdentity identity;
private ArrayList roles;
public CustomPrincipal(IIdentity id, ArrayList rolesArray)
{
identity = id;
roles = rolesArray;
}
public bool IsInRole(string role)
{
return roles.Contains( role );
}
public IIdentity Identity
{
get { return identity; }
set { identity = value; }
}
}
}
*****************************************************
Does the system handle it any different?
Thanks,
Tom
In the following example for IPrinciple, I have the following code:
************************************************************
using System;
using System.Collections;
using System.Security;
using System.Security.Principal;
namespace CustomSecurity
{
[Serializable]
public class CustomPrincipal: IPrincipal
{
private IIdentity identity;
private ArrayList roles;
public CustomPrincipal(IIdentity id, ArrayList rolesArray)
{
identity = id;
roles = rolesArray;
}
public bool IsInRole(string role)
{
return roles.Contains( role );
}
public IIdentity Identity
{
get { return identity; }
set { identity = value; }
}
}
}
*****************************************************
I understand that IPrincipal (and IIdentity) is defined as:
*********************************************************
namespace System.Security.Principal {
interface IIdentity {
bool IsAuthenticated { get; }
string AuthenticationType { get; }
string Name { get; }
}
interface IPrincipal {
IIdentity Identity { get; }
bool IsInRole(string role);
}
}
**********************************************************
What would be the difference if I just wrote the code as (I understand that
I also would have the IIdentity class also).:
**********************************************************
using System;
using System.Collections;
using System.Security;
namespace CustomSecurity
{
[Serializable]
public class CustomPrincipal
{
private IIdentity identity;
private ArrayList roles;
public CustomPrincipal(IIdentity id, ArrayList rolesArray)
{
identity = id;
roles = rolesArray;
}
public bool IsInRole(string role)
{
return roles.Contains( role );
}
public IIdentity Identity
{
get { return identity; }
set { identity = value; }
}
}
}
*****************************************************
Does the system handle it any different?
Thanks,
Tom