Re: Type conversions question



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.


.



Relevant Pages

  • Re: Type conversions question
    ... 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. ... any conversion you do must happen before the item is returned by ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: java Date problem
    ... sent to the server and stored in the DB. ... in any location can look at the deals in their own client and I want to ... I want to store the dates as midnight GMT in the DB. ... It's the conversion to this number of seconds ...
    (comp.lang.java.programmer)
  • Re: Text terminal rendering design
    ... The client wants to later change the color and provides ... If the client is doing a multiple part conversion then the client ... On separating concerns of instantiation and data acquisition: ... A SymbolFactory always produces a Symbol of the same subclass. ...
    (comp.object)
  • Re: Text terminal rendering design
    ... this would only be appropriate for a symbol that was instantiated purely for display compatibility. ... The only way I see is to have some separate notion of symbol identity that the client provides. ... available when each Icon is being constructed. ... What I thought you were representing was the fact that if a conversion is necessary, then there will be two Symbol instances in your UI software and you will provide both handles to the client to map to the relevant Icon. ...
    (comp.object)
  • Re: WCF Contract Design Best Practices Question
    ... I had this thought that I could host my WFC client proxies in this library ... separate from the server code. ... even though I've embedded functions for the conversion of my objects ... my WCF object I'm still going to have to ...
    (microsoft.public.dotnet.framework.webservices)