views:

48

answers:

1

I need to define something like this using reflection Emit:

public class Foo {
    public Bar Bar { get; set; }
}

public class Bar {
    public Foo Foo { get; set; }
}

The difficulty is that when calling TypeBuilder.DefineProperty(), I need to pass the System.Type of the property's return value, which doesn't exist yet. If the reference only went one way, it would be easy, but going both ways causes a chicken and egg problem.

I was hoping to find an overload that takes a TypeBuilder instead of a Type, which would let me define both classes at the same time and then call TypeBuilder.CreateType() on both at then end. But I'm not seeing such thing.

What is the right way to solve this?

+2  A: 

TypeBuilder is a subclass of Type: MSDN

You can pass it in to DefineProperty.

Kennet Belenky
Wow, I totally didn't realize that, thanks!
David Ebbo