For a bitwise type like AnchorStyles the .NET runtime provides an easy way
to convert this to a string (like "Top, Left"), but is there an easy way to
convert it back again ? I've written my own method (see below) to do it but
it strikes me that there may be a much simpler way !

protected static AnchorStyles DeserializeAnchor(string a)
{
AnchorStyles retval = AnchorStyles.None;
if (a != "None")
{
if (a.IndexOf("Top") > -1) retval = retval | AnchorStyles.Top;
if (a.IndexOf("Bottom") > -1) retval = retval | AnchorStyles.Bottom;
if (a.IndexOf("Left") > -1) retval = retval | AnchorStyles.Left;
if (a.IndexOf("Right") > -1) retval = retval | AnchorStyles.Right;
}
return retval;
}

Re: AnchorStyles conversion by hirf-spam-me-here

hirf-spam-me-here
Wed Jan 07 11:17:38 CST 2004

* "JezB" <jeremy.bradshaw@blueyonder.co.yk> scripsit:
> For a bitwise type like AnchorStyles the .NET runtime provides an easy way
> to convert this to a string (like "Top, Left"), but is there an easy way to
> convert it back again ? I've written my own method (see below) to do it but
> it strikes me that there may be a much simpler way !

Have a look at 'Enum.Parse'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Re: AnchorStyles conversion by JezB

JezB
Wed Jan 07 11:30:46 CST 2004

Thanks very much !!

"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:bthf5t$7fscl$4@ID-208219.news.uni-berlin.de...
> * "JezB" <jeremy.bradshaw@blueyonder.co.yk> scripsit:
> > For a bitwise type like AnchorStyles the .NET runtime provides an easy
way
> > to convert this to a string (like "Top, Left"), but is there an easy way
to
> > convert it back again ? I've written my own method (see below) to do it
but
> > it strikes me that there may be a much simpler way !
>
> Have a look at 'Enum.Parse'.
>
> --
> Herfried K. Wagner [MVP]
> <http://www.mvps.org/dotnet>



Re: AnchorStyles conversion by JezB

JezB
Wed Jan 07 11:38:56 CST 2004

How about serializing and deserializing types like Point and Size ?
Currently I split these into pairs of digits separated by a comma and when
deserializing I parse the string into two Ints to reconstruct the Point or
Size, but as for Enums I suspect there is a neater way (having serialized
just by using the ToString() method).


"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:bthf5t$7fscl$4@ID-208219.news.uni-berlin.de...
> * "JezB" <jeremy.bradshaw@blueyonder.co.yk> scripsit:
> > For a bitwise type like AnchorStyles the .NET runtime provides an easy
way
> > to convert this to a string (like "Top, Left"), but is there an easy way
to
> > convert it back again ? I've written my own method (see below) to do it
but
> > it strikes me that there may be a much simpler way !
>
> Have a look at 'Enum.Parse'.
>
> --
> Herfried K. Wagner [MVP]
> <http://www.mvps.org/dotnet>