Re: Type conversions question

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



> 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
    ... > Well how you store it internally is irrelevant as long asn you can ... > convert all items to the type expected by the client. ... > array) and then return an enumerator to that instead. ... Conversion of the types to what the ...
    (microsoft.public.dotnet.languages.csharp)
  • 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)
  • Previously Functioning Date Interpreter Now Failing
    ... Dim Entry As String ... Dim Result As String ... Dim ClientElement As Variant 'Holds the extracted Client Number ... ElseIf IsNumeric= False _ ...
    (microsoft.public.excel.programming)
  • RE: Previously Functioning Date Interpreter Now Failing
    ... Dim Entry As String ... Dim Result As String ... Dim ClientElement As Variant 'Holds the extracted Client Number ... ElseIf IsNumeric= False _ ...
    (microsoft.public.excel.programming)
  • 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)