TypeConverter and arrays

G

Guest

Using asp.net1.1, I have a property on a control that is an enum. I use an
accessor and set it in HTML view. So:

public enum Permission
{
None = 0,
Admin = 1,
Member = 2, ...
}
....
public class Lock : System.Web.UI.Control
{
private Permission perm;

[Bindable(true),
Category("Security"),
DefaultValue("1")]
public Permission RequiredPermission
{
get
{
return perm;
}
set
{
perm = value;
}
}

Then in html view:
<cc1:Lock ... RequiredPermission="Admin" ... >

Now, I want to make the Permission property an array of permissions:

private Permission[] perm;

My question is, how can I implement this to allow me to still specify the
list of permissions in html view, like:
<cc1:Lock ... RequiredPermission="Admin,Member" ... >

I need to convert this list into an array, is there any way to do this
within an accessor? If I try something like this, I get a parser error,
saying it can't create an object of type Permission[] from its string
representation.

public Camelot.Permission[] RequiredPermission
{
get
{
return perm;
}
set
{
// break up comma delimited string in value, create an array of
permissions, assign it to perm
}
}

Thanks!
 
G

Guest

You would have to use a separate setter method to turn your string into a
Permission[].

I almost sent code to do it in an implicit cast but then I remembered you
can't create an implicit cast from an object to an array of another object -
only to an instance of the other object.

Alternatively, you may make your Permission[] property into an Object[]
property instead. That would require casting each time you access it but
then you could pass the string as the value, convert it to an array of
Permissions, and set your private Permission[] variable to hold that array.

HTH

Dale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top