@@ -12,7 +12,7 @@ public class ModuleWeaver
12
12
13
13
public void Execute ( )
14
14
{
15
- var markerDll = Check ( ( ) => ModuleDefinition . AssemblyReferences . SingleOrDefault ( a => a . Name . ToLowerInvariant ( ) == "FodyDependencyPropertyMarker " . ToLowerInvariant ( ) ) , "find FodyDependencyPropertyMarker reference" ) ;
15
+ var markerDll = Check ( ( ) => ModuleDefinition . AssemblyReferences . SingleOrDefault ( a => a . Name . ToLowerInvariant ( ) == "AutoDependencyPropertyMarker " . ToLowerInvariant ( ) ) , "find AutoDependencyPropertyMarker reference" ) ;
16
16
if ( markerDll == null )
17
17
return ;
18
18
var windowsBase = CheckAssembly ( "WindowsBase" ) ;
@@ -27,11 +27,6 @@ public void Execute()
27
27
var registerMeta = CheckImport ( ( ) => depProperty . Methods . Single ( m => m . Name == "Register" && m . Parameters . Count == 4 ) , "Register" ) ;
28
28
var presentationDllRef = Check ( ( ) => ModuleDefinition . AssemblyReferences . SingleOrDefault ( a => a . Name . ToLowerInvariant ( ) == "PresentationFramework" . ToLowerInvariant ( ) ) , "check for PresentationFramework reference" ) ;
29
29
MethodReference metadataCtor = null ;
30
- if ( presentationDllRef != null )
31
- {
32
- var presentationDll = CheckAssembly ( "PresentationFramework" ) ;
33
- metadataCtor = CheckImport ( ( ) => presentationDll . GetType ( "System.Windows.FrameworkPropertyMetadata" ) . GetConstructors ( ) . Single ( c => c . Parameters . Count == 2 && c . Parameters [ 1 ] . ParameterType . Name == "FrameworkPropertyMetadataOptions" ) , "FrameworkPropertyMetadata constructor" ) ;
34
- }
35
30
foreach ( var type in ModuleDefinition . Types )
36
31
if ( ! type . IsSpecialName && type . GenericParameters . Count == 0 && Inherits ( type , "System.Windows.DependencyObject" ) )
37
32
{
@@ -41,7 +36,7 @@ public void Execute()
41
36
if ( ! property . IsSpecialName && property . HasThis && property . GetMethod != null && property . SetMethod != null && property . GetMethod . IsPublic && property . SetMethod . IsPublic )
42
37
{
43
38
var attribute = property . CustomAttributes . Concat ( type . CustomAttributes ) . FirstOrDefault (
44
- a => a . AttributeType . FullName == "FodyDependencyPropertyMarker.DependencyPropertyAttribute " ) ;
39
+ a => a . AttributeType . FullName == "AutoDependencyPropertyMarker.AutoDependencyPropertyAttribute " ) ;
45
40
if ( attribute == null )
46
41
continue ;
47
42
if ( type . Fields . Any ( f => f . Name == property . Name + "Property" ) )
@@ -67,10 +62,23 @@ public void Execute()
67
62
instructions . Add ( Instruction . Create ( OpCodes . Call , registerSimple ) ) ;
68
63
else
69
64
{
65
+ if ( metadataCtor == null )
66
+ {
67
+ if ( presentationDllRef == null )
68
+ {
69
+ metadataCtor = Check ( ( ) => ModuleDefinition . Import ( typeof ( FrameworkPropertyMetadata ) . GetConstructor ( new [ ] { typeof ( object ) , typeof ( FrameworkPropertyMetadataOptions ) } ) ) , "directly import FrameworkPropertyMetadata constructor" ) ;
70
+ }
71
+ else
72
+ {
73
+ var presentationDll = CheckAssembly ( "PresentationFramework" ) ;
74
+ metadataCtor = CheckImport ( ( ) => presentationDll . GetType ( "System.Windows.FrameworkPropertyMetadata" ) . GetConstructors ( ) . Single ( c => c . Parameters . Count == 2 && c . Parameters [ 1 ] . ParameterType . Name == "FrameworkPropertyMetadataOptions" ) , "FrameworkPropertyMetadata constructor" ) ;
75
+ }
76
+ }
70
77
if ( ! property . PropertyType . IsValueType )
71
78
instructions . Add ( Instruction . Create ( OpCodes . Ldnull ) ) ;
72
79
else
73
80
{
81
+ cctor . Body . InitLocals = true ;
74
82
var constVar = new VariableDefinition ( property . PropertyType ) ;
75
83
cctor . Body . Variables . Add ( constVar ) ;
76
84
instructions . Add ( Instruction . Create ( OpCodes . Ldloca_S , constVar ) ) ;
@@ -107,7 +115,7 @@ public void Execute()
107
115
instructions . Reverse ( ) ;
108
116
foreach ( var instruction in instructions )
109
117
cctor . Body . Instructions . Insert ( 0 , instruction ) ;
110
- foreach ( var attribute in type . CustomAttributes . Where ( a => a . AttributeType . FullName == "FodyDependencyPropertyMarker.DependencyPropertyAttribute " ) . ToList ( ) )
118
+ foreach ( var attribute in type . CustomAttributes . Where ( a => a . AttributeType . FullName == "AutoDependencyPropertyMarker.AutoDependencyPropertyAttribute " ) . ToList ( ) )
111
119
type . CustomAttributes . Remove ( attribute ) ;
112
120
}
113
121
ModuleDefinition . AssemblyReferences . Remove ( markerDll ) ;
0 commit comments