Can MEF expose the public properties

May 19, 2010 at 10:23 AM

of a class and when only the Class is exported.

[Export(typeof(UserControl))]

public class DemoUserControl : UserControl

{

private int x;

public int X

{

get { return x; }

set { x = value; }

Here goes private member variables and its properties

.

.

.

}

 

When imported of this type, can MEF expose the public properties?

 

 

 

 

May 19, 2010 at 1:31 PM

You could try doing an interface marked as an [InheritedExport()].  Excuse the pseudocode I mainly use VB.

<InheritedExport>
Public Interface IDemoUserControl

    Property X As Integer

End Interface

public class DemoUserControl : UserControl
Implements IDemoUserControl

{

private int x;

public Property X As Integer Implements IDemoUserControl.X

{

get { return x; }

set { x = value; }

Here goes private member variables and its properties

.

.

.

}

 Then when you import and compose the parts you can declare the import like this:
<Import>
Public Property DemoUserControl as IDemoUserControl