Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Sep 22, 2023
1 parent a09e703 commit 8cf969e
Show file tree
Hide file tree
Showing 92 changed files with 618 additions and 707 deletions.
42 changes: 22 additions & 20 deletions PropertyChanged.Fody.Analyzer.Tests/CodeGeneratorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,29 +500,31 @@ public partial class Class2a : INotifyPropertyChanged
[Fact]
public async Task CodeIsGeneratedForNestedPartialClasses()
{
var source = @"
using System.ComponentModel;
using PropertyChanged;
var source = """

[AddINotifyPropertyChangedInterface]
public partial class Class1
{
public int Property1 { get; set; }
public int Property2 { get; set; }
using System.ComponentModel;
using PropertyChanged;

public partial class Class2
{
public int Property1 { get; set; }
public int Property2 { get; set; }
[AddINotifyPropertyChangedInterface]
public partial class Class1
{
public int Property1 { get; set; }
public int Property2 { get; set; }

public partial class Class2
{
public int Property1 { get; set; }
public int Property2 { get; set; }

public partial class Class3 : INotifyPropertyChanged
{
public int Property1 { get; set; }
public int Property2 { get; set; }
}
}
}

public partial class Class3 : INotifyPropertyChanged
{
public int Property1 { get; set; }
public int Property2 { get; set; }
}
}
}
";
""";
var generated = await new Test(source).RunAsync();

await Verify(generated);
Expand Down
3 changes: 1 addition & 2 deletions PropertyChanged.Fody/OnChangedWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ bool PropertyWillBeNotified(PropertyDefinition p)
}
}


string GetMethodWarning(TypeNode notifyNode, OnChangedMethod onChangedMethod)
static string GetMethodWarning(TypeNode notifyNode, OnChangedMethod onChangedMethod)
{
var method = onChangedMethod.MethodDefinition;
var methodRef = onChangedMethod.MethodReference;
Expand Down
2 changes: 1 addition & 1 deletion PropertyChanged.Fody/PropertyDataWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void GetPropertyData(PropertyDefinition propertyDefinition, TypeNode node)
});
}

List<PropertyDefinition> GetFullDependencies(PropertyDefinition propertyDefinition, IEnumerable<PropertyDefinition> dependenciesForProperty, TypeNode node)
static List<PropertyDefinition> GetFullDependencies(PropertyDefinition propertyDefinition, IEnumerable<PropertyDefinition> dependenciesForProperty, TypeNode node)
{
// Create an HashSet to contain all dependent properties (direct or transitive)
// Add the initial Property to stop the recursion if this property is a dependency of another property
Expand Down
32 changes: 18 additions & 14 deletions PropertyChanged.Fody/SupportsCeqChecker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using Mono.Cecil;

Expand All @@ -10,19 +9,19 @@ static SupportsCeqChecker()
{
ceqStructNames = new()
{
typeof (int).Name,
typeof (uint).Name,
typeof (long).Name,
typeof (ulong).Name,
typeof (float).Name,
typeof (double).Name,
typeof (bool).Name,
typeof (short).Name,
typeof (ushort).Name,
typeof (byte).Name,
typeof (sbyte).Name,
typeof (char).Name,
};
typeof(int).Name,
typeof(uint).Name,
typeof(long).Name,
typeof(ulong).Name,
typeof(float).Name,
typeof(double).Name,
typeof(bool).Name,
typeof(short).Name,
typeof(ushort).Name,
typeof(byte).Name,
typeof(sbyte).Name,
typeof(char).Name,
};
}

public static bool SupportsCeq(this TypeReference typeReference)
Expand All @@ -31,23 +30,28 @@ public static bool SupportsCeq(this TypeReference typeReference)
{
return true;
}

if (typeReference.IsArray)
{
return false;
}

if (typeReference.ContainsGenericParameter)
{
return false;
}

var typeDefinition = typeReference.Resolve();
if (typeDefinition == null)
{
throw new($"Could not resolve '{typeReference.FullName}'.");
}

if (typeDefinition.IsEnum)
{
return true;
}

return !typeDefinition.IsValueType;
}
}
16 changes: 4 additions & 12 deletions PropertyChanged.Fody/TypeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@

public class TypeNode
{
public TypeNode()
{
Nodes = new();
PropertyDependencies = new List<PropertyDependency>();
Mappings = new List<MemberMapping>();
PropertyDatas = new List<PropertyData>();
}

public TypeDefinition TypeDefinition;
public List<TypeNode> Nodes;
public List<PropertyDependency> PropertyDependencies;
public List<MemberMapping> Mappings;
public List<TypeNode> Nodes = new();
public List<PropertyDependency> PropertyDependencies = new();
public List<MemberMapping> Mappings = new();
public EventInvokerMethod EventInvoker;
public MethodReference IsChangedInvoker;
public List<PropertyData> PropertyDatas;
public List<PropertyData> PropertyDatas = new();
public List<PropertyDefinition> AllProperties;
public ICollection<OnChangedMethod> OnChangedMethods;
public IEnumerable<PropertyDefinition> DeclaredProperties => AllProperties.Where(prop => prop.DeclaringType == TypeDefinition);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;
using System.ComponentModel;
using PropertyChanged;

public class ClassWithBeforeAfterImplementation :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ClassWithOnChangedBeforeAfterGeneric :
public void OnPropertyChanged<T>(string propertyName, T before, T after)
{
GenericOnPropertyChangedCalled = true;
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
PropertyChanged(this, new(propertyName));
}

public event PropertyChangedEventHandler PropertyChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ public void OnProperty1Changed(T before, T after)
public event PropertyChangedEventHandler PropertyChanged;
}

public class ClassWithOnChangedBeforeAfterTypedGenericString : ClassWithOnChangedBeforeAfterTypedGeneric<string>
{
}
public class ClassWithOnChangedBeforeAfterTypedGenericString : ClassWithOnChangedBeforeAfterTypedGeneric<string>;

public class ClassWithOnChangedBeforeAfterTypedGenericInteger : ClassWithOnChangedBeforeAfterTypedGeneric<int>
{
}
public class ClassWithOnChangedBeforeAfterTypedGenericInteger : ClassWithOnChangedBeforeAfterTypedGeneric<int>;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ClassWithOnChangedCalculatedProperty :
public string Property1 { get; set; }
public string Property2 => $"{Property1}!";
public string Property3 => $"{Property2}!";

public void OnProperty2Changed()
{
OnProperty2ChangedCalled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public class ClassWithOwnImplementation :
public virtual void OnPropertyChanged(string propertyName)
{
BaseNotifyCalled = true;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
PropertyChanged?.Invoke(this, new(propertyName));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace ComplexHierarchy
namespace ComplexHierarchy;

public class ClassChild1 : ClassParent
{
public class ClassChild1 : ClassParent
{
public string Property1 { get; set; }
}
public string Property1 { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace ComplexHierarchy
namespace ComplexHierarchy;

public class ClassChild2 : ClassParent
{
public class ClassChild2 : ClassParent
{
public string Property1 { get; set; }
}
public string Property1 { get; set; }
}
10 changes: 4 additions & 6 deletions TestAssemblies/AssemblyToProcess/ComplexHierarchy/ClassChild3.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

namespace ComplexHierarchy
namespace ComplexHierarchy;

public class ClassChild3 : ClassChild2
{
public class ClassChild3 : ClassChild2
{
public string Property2 { get; set; }
}
public string Property2 { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.ComponentModel;

namespace ComplexHierarchy
namespace ComplexHierarchy;

public class ClassParent: INotifyPropertyChanged
{
public class ClassParent: INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
}
public event PropertyChangedEventHandler PropertyChanged;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
public class ClassWithFieldFromOtherClass :
INotifyPropertyChanged
{
OtherClass otherClass;

public ClassWithFieldFromOtherClass()
{
otherClass = new OtherClass();
}
OtherClass otherClass = new();

public string Property1
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
public class ClassWithGenericChild : ClassWithGenericParent<string>
{
}
public class ClassWithGenericChild : ClassWithGenericParent<string>;
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.ComponentModel;

namespace GenericBaseWithProperty
{
public class ClassWithGenericPropertyParent<T> :
namespace GenericBaseWithProperty;

public class ClassWithGenericPropertyParent<T> :
INotifyPropertyChanged {
public T Property1 { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
}
public T Property1 { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
namespace GenericBaseWithProperty
{
public class ClassWithGenericPropertyChild : ClassWithGenericPropertyParent<string>
{
}
namespace GenericBaseWithProperty;

public class ClassWithGenericPropertyDouble : ClassWithGenericPropertyParent<double>
{
}
}
public class ClassWithGenericPropertyChild : ClassWithGenericPropertyParent<string>;

public class ClassWithGenericPropertyDouble : ClassWithGenericPropertyParent<double>;
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System.ComponentModel;

namespace GenericBaseWithPropertyBeforeAfter
{
public class ClassWithGenericPropertyParent<T> :
namespace GenericBaseWithPropertyBeforeAfter;

public class ClassWithGenericPropertyParent<T> :
INotifyPropertyChanged {
public T Property1 { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName, object before, object after)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public T Property1 { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName, object before, object after)
{
PropertyChanged?.Invoke(this, new(propertyName));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
namespace GenericBaseWithPropertyBeforeAfter
{
public class ClassWithGenericPropertyChild : ClassWithGenericPropertyParent<string>
{
}
}
namespace GenericBaseWithPropertyBeforeAfter;

public class ClassWithGenericPropertyChild : ClassWithGenericPropertyParent<string>;
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
using System.ComponentModel;

namespace GenericBaseWithPropertyOnChanged
{
public class ClassWithGenericPropertyParent<T> :
INotifyPropertyChanged {
public bool OnProperty1ChangedCalled;
public bool OnProperty2ChangedCalled;
namespace GenericBaseWithPropertyOnChanged;

public T Property1 { get; set; }
public void OnProperty1Changed()
{
OnProperty1ChangedCalled = true;
}
public class ClassWithGenericPropertyParent<T> :
INotifyPropertyChanged {
public bool OnProperty1ChangedCalled;
public bool OnProperty2ChangedCalled;

public T Property2 { get; set; }
public void OnProperty2Changed()
{
OnProperty2ChangedCalled = true;
}
public T Property1 { get; set; }
public void OnProperty1Changed()
{
OnProperty1ChangedCalled = true;
}

public event PropertyChangedEventHandler PropertyChanged;
public T Property2 { get; set; }
public void OnProperty2Changed()
{
OnProperty2ChangedCalled = true;
}

public event PropertyChangedEventHandler PropertyChanged;
}
Loading

0 comments on commit 8cf969e

Please sign in to comment.