This project is read-only.

Can I safely use the same instance of IThisReference everywhere?

Topics: Metadata Model
Jan 2, 2011 at 2:20 AM

Often I use a factory with convenience methods and properties for building metadata expressions.

In this factory class I have, among the other things, a property This that will return always the same IThisReference and a Null property that will return always the same ICompileTimeConstant with value null.

Is this safe in general?

Thanks.

Jan 2, 2011 at 4:44 AM

Yes, since the object model is immutable and object identity has no semantic significance, it is safe in general.

Jan 2, 2011 at 5:25 AM
hermanv wrote:

Yes, since the object model is immutable

 

My question came from the fact that I saw code in your type inferencer that actually attempts to cast interfaces to mutable expressions and set the Type property.

While I was adapting it I wondered what could happen if it was used on expression trees sharing subtrees.

 

 

Jan 2, 2011 at 7:20 AM

The type inferencer is an implementation detail of the decompiler and is specific to the mutable code model. General clients of the immutable object model should not assume that object identity is meaningful or that the interfaces are implemented by specific implementations.