This project is read-only.
1

Closed

Wrong type in Dependency Property of type enum after CodeModel roundtrip

description

When the PeToPeViaCodeModel example targets a dll containg a class that has a Dependency Property of type enum, the result produces a runtime error because the PropertyMetaData are initialized with an int instead of the enum value.
 
Example:
 
public enum Foo{ X, Y, Z}
 
Before executing PeToPeViaCodeModel:
 
public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register("MyProperty", typeof(Foo), typeof(Class1), new UIPropertyMetadata(Foo.Y));
 
After executing PeToPeViaCodeModel:
 
public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register("MyProperty", typeof(Foo), typeof(Class1), new UIPropertyMetadata(1));
 
The exception is: "The type of the default value does not match the type of the property"
 
Hint:
When the default value is specified via a method like this:
new UIPropertyMetadata(DefaultValue())
the result adds a cast to int:
new UIPropertyMetadata((int) DefaultValue())
Closed Jan 5, 2013 at 2:06 AM by hermanv

comments

hermanv wrote May 31, 2012 at 9:38 PM

Fixed, see revision: 69203