Re: Type conversions question
- From: "Madhu Gopinathan" <madhugops@xxxxxxxxxxxxxx>
- Date: Thu, 28 Jul 2005 11:30:58 +0530
Hi Mattias,
> Well how you store it internally is irrelevant as long asn you can
> convert all items to the type expected by the client.
>
> You could first convert strings (and for example store in a string
> array) and then return an enumerator to that instead.
That is exactly what I wish to achieve. Conversion of the types to what the
client expects. However, I do not wish to handle this using separate
enumerators
> No, any conversion you do must happen before the item is returned by
> the enumerator. You can't detect the type of the enumeration variable
> the client uses, and type converters or conversion operators will not
> help you here since the enumerator returns a reference of type Object.
Well, not necessarily. Rightly said by you, IEnumerator returns a reference
of a type "Object". However, the client would perform a conversion of type
in the for loop for accepting that return into some type.
In normal cases, I would return a string from IEnumerator as a ref to type
Object and the loop would re-convert the type back to string without
hassles. In my particular case, the types do not match, which would cause
the CLR to fail in conversion. Is there a way I can register a handler for
custom type conversion here before or after CLR attempts the conversion to
the type asked by the client?
I am asking this because I am aware of the existence of handlers that help
in resolution of assemblies when LoadWithPartialName() fails etc.? Is there
something on those lines for type conversions?
Thanks,
Madhu
"Mattias Sjögren" <mattias.dont.want.spam@xxxxxxxx> wrote in message
news:uweLT5rkFHA.576@xxxxxxxxxxxxxxxxxxxxxxx
> > I understand what you are trying to point. However, what I would like
to
> >achieve is to make the client unaware of the fact that the collection
stores
> >the data using a type that is not what the user expected, i.e. in this
case,
> >IMyObject instead of string.
>
> Well how you store it internally is irrelevant as long asn you can
> convert all items to the type expected by the client.
>
> You could first convert strings (and for example store in a string
> array) and then return an enumerator to that instead.
>
>
>
> > Here, the IEnumerator will return an object of type IMyObject. The CLR
> >will attempt to convert this type to a string. This is where I would like
to
> >apply my conversion. Is this possible?
>
> No, any conversion you do must happen before the item is returned by
> the enumerator. You can't detect the type of the enumeration variable
> the client uses, and type converters or conversion operators will not
> help you here since the enumerator returns a reference of type Object.
>
>
>
> Mattias
>
> --
> Mattias Sjögren [MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
.
- References:
- Type conversions question
- From: Madhu Gopinathan
- Re: Type conversions question
- From: Mattias Sjögren
- Re: Type conversions question
- From: Madhu Gopinathan
- Re: Type conversions question
- From: Mattias Sjögren
- Type conversions question
- Prev by Date: Re: SHA1 Hash question with large Files
- Next by Date: Re: need help understanding this code snippet
- Previous by thread: Re: Type conversions question
- Next by thread: Re: Type conversions question
- Index(es):
Relevant Pages
|