Skip to content

Commit

Permalink
Finish fixing those pesky generics bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kswoll committed Apr 7, 2015
1 parent aae9e2e commit ec958df
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Nuget/ReactiveUIFody.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 2,12 @@
<package >
<metadata>
<id>ReactiveUI.Fody</id>
<version>1.0.33</version>
<version>1.0.36</version>
<authors>kirk</authors>
<owners>kirk</owners>
<projectUrl>https://github.com/kswoll/ReactiveUI.Fody</projectUrl>
<licenseUrl>http://www.opensource.org/licenses/mit-license.php</licenseUrl>
<releaseNotes>Fix bug when using auto property initializers on reactive properties.</releaseNotes>
<releaseNotes>Fix some other bugs around properties in generic types.</releaseNotes>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Fody extension to generate RaisePropertyChange notifications for properties and ObservableAsPropertyHelper properties.</description>
<copyright>Copyright 2015</copyright>
Expand Down
4 changes: 2 additions & 2 deletions ReactiveUI.Fody/CecilExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 66,7 @@ public static MethodReference Bind(this MethodReference method, GenericInstanceT

return reference;
}

/*
public static MethodReference BindDefinition(this MethodReference method, TypeReference genericTypeDefinition)
{
if (!genericTypeDefinition.HasGenericParameters)
Expand All @@ -87,7 87,7 @@ public static MethodReference BindDefinition(this MethodReference method, TypeRe
return reference;
}

*/
public static FieldReference BindDefinition(this FieldReference field, TypeReference genericTypeDefinition)
{
if (!genericTypeDefinition.HasGenericParameters)
Expand Down
14 changes: 12 additions & 2 deletions ReactiveUI.Fody/ReactiveUIPropertyWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 75,20 @@ public void Execute()
il.Emit(OpCodes.Ret); // Return the field value that is lying on the stack
});

var genericRaiseAndSetIfChangedMethod = raiseAndSetIfChangedMethod.MakeGenericMethod(targetType, property.PropertyType);
TypeReference genericTargetType = targetType;
if (targetType.HasGenericParameters)
{
var genericDeclaration = new GenericInstanceType(targetType);
foreach (var parameter in targetType.GenericParameters)
{
genericDeclaration.GenericArguments.Add(parameter);
}
genericTargetType = genericDeclaration;
}

var methodReference = raiseAndSetIfChangedMethod.MakeGenericMethod(genericTargetType, property.PropertyType);

// Build out the setter which fires the RaiseAndSetIfChanged method
var methodReference = genericRaiseAndSetIfChangedMethod.BindDefinition(targetType);
property.SetMethod.Body = new MethodBody(property.SetMethod);
property.SetMethod.Body.Emit(il =>
{
Expand Down

0 comments on commit ec958df

Please sign in to comment.