problem with reflection

  • Thread starter Thread starter Marco V
  • Start date Start date
M

Marco V

Hi all,

I'm using reflection and want to know how this piece of code can be
realized with reflection.

Code:
(SomeInterface) myObject = (SomeInterface)SomeObject

With kind regards,

Marco
 
If you meen with CodeDom, that this would be the code:

Notes:
the left-hand-value of an assign-expression don't have to be casted ->
myObject = (SomeInterface)SomeObject.

CodeAssignStatement s = new CodeAssignStatement(
new CodeVariableReferenceExpression("myObject"), //i asume that
'myObject' is a variable
new CodeCastExpression(
typeof(SomeInterface),
new CodeVariableReferenceExpression("SomeObject") //SomeObject
also a variable?
)
);

hope it helps,

Günter Prossliner


| Hi all,
|
| I'm using reflection and want to know how this piece of code can be
| realized with reflection.
|
| Code:
| (SomeInterface) myObject = (SomeInterface)SomeObject
|
| With kind regards,
|
| Marco
 
Marco,
I'm using reflection and want to know how this piece of code can be
realized with reflection.

If you want to check if you can cast an object to a certain interface,
use Type.IsAssignableFrom(). The actual cast can't be done with
reflection.



Mattias
 

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

Back
Top