From 4074a5fba5b1f0cb3b425a95ffedab4638e32ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igr=20Alex=C3=A1nder=20Fern=C3=A1ndez=20Sa=C3=BAco?= Date: Mon, 10 Apr 2017 16:45:30 -0400 Subject: [PATCH 1/3] (*) NoWeavingAttribute can be use in order to disable computed properties weaving --- src/Catel.Fody/Core/Models/CatelType.cs | 25 +++++++------------ .../AutoProperties/OnPropertyChangedWeaver.cs | 7 +++++- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Catel.Fody/Core/Models/CatelType.cs b/src/Catel.Fody/Core/Models/CatelType.cs index 172a52dd..2ef1b704 100644 --- a/src/Catel.Fody/Core/Models/CatelType.cs +++ b/src/Catel.Fody/Core/Models/CatelType.cs @@ -54,7 +54,7 @@ public CatelType(TypeDefinition typeDefinition) return; } - Properties = DetermineProperties(); + DetermineProperties(); DetermineMappings(); Ignore = false; @@ -89,6 +89,8 @@ public CatelType(TypeDefinition typeDefinition) public List Properties { get; private set; } + public List NoWeavingProperties { get; private set; } + private void DetermineCatelType() { if (TypeDefinition.ImplementsViewModelBase()) @@ -161,9 +163,10 @@ private bool DetermineMethods() return true; } - private List DetermineProperties() + private void DetermineProperties() { - var properties = new List(); + Properties = new List(); + NoWeavingProperties = new List(); var typeProperties = TypeDefinition.Properties; foreach (var typeProperty in typeProperties) @@ -171,23 +174,13 @@ private List DetermineProperties() if (typeProperty.IsDecoratedWithAttribute("NoWeavingAttribute")) { typeProperty.RemoveAttribute("NoWeavingAttribute"); - continue; - } - - if (typeProperty.SetMethod == null) - { - continue; + NoWeavingProperties.Add(typeProperty); } - - if (typeProperty.SetMethod.IsStatic) + else if (typeProperty.SetMethod != null && !typeProperty.SetMethod.IsStatic) { - continue; + Properties.Add(new CatelTypeProperty(TypeDefinition, typeProperty)); } - - properties.Add(new CatelTypeProperty(TypeDefinition, typeProperty)); } - - return properties; } private void DetermineMappings() diff --git a/src/Catel.Fody/Weaving/AutoProperties/OnPropertyChangedWeaver.cs b/src/Catel.Fody/Weaving/AutoProperties/OnPropertyChangedWeaver.cs index 5f9befbc..1b6837f7 100644 --- a/src/Catel.Fody/Weaving/AutoProperties/OnPropertyChangedWeaver.cs +++ b/src/Catel.Fody/Weaving/AutoProperties/OnPropertyChangedWeaver.cs @@ -46,7 +46,7 @@ private bool AddOrUpdateOnPropertyChangedMethod(PropertyDefinition property) var stringEqualsMethodReference = _catelType.TypeDefinition.Module.Import(GetSystemObjectEqualsMethodReference(_catelType.TypeDefinition.Module)); var dependentProperties = _catelType.GetDependentPropertiesFrom(property).ToList(); - if (dependentProperties.Count > 0) + if (dependentProperties.Count > 0 && !dependentProperties.All(definition => _catelType.NoWeavingProperties.Contains(definition))) { var onPropertyChangedMethod = EnsureOnPropertyChangedMethod(); if (onPropertyChangedMethod == null) @@ -67,6 +67,11 @@ private bool AddOrUpdateOnPropertyChangedMethod(PropertyDefinition property) foreach (var propertyDefinition in dependentProperties) { + if (_catelType.NoWeavingProperties.Contains(propertyDefinition)) + { + continue; + } + onPropertyChangedMethod.Body.Instructions.Insert(idx++, Instruction.Create(OpCodes.Ldarg_1)); onPropertyChangedMethod.Body.Instructions.Insert(idx++, Instruction.Create(OpCodes.Callvirt, getMethodReference)); onPropertyChangedMethod.Body.Instructions.Insert(idx++, Instruction.Create(OpCodes.Ldstr, property.Name)); From fdfa70f810ced92060a3d16bd12a6cce72db0ce9 Mon Sep 17 00:00:00 2001 From: Geert van Horrik Date: Mon, 24 Apr 2017 22:58:07 +0200 Subject: [PATCH 2/3] Update to Fody 2.0 and improve weaving of special cases for argument checks --- .../template/Catel.Fody/Catel.Fody.nuspec | 2 +- src/Catel.Fody.TestAssembly/CTL908.cs | 8 + .../Catel.Fody.TestAssembly.csproj | 12 +- src/Catel.Fody.TestAssembly/packages.config | 4 +- ...atel.Fody.TestExternalTypesAssembly.csproj | 5 +- .../packages.config | 2 +- .../ArgumentExpressionFacts.cs | 102 ++++---- src/Catel.Fody.Tests/ArgumentFacts.cs | 96 +++---- src/Catel.Fody.Tests/AssemblyWeaver.cs | 67 +++-- src/Catel.Fody.Tests/CSharp6Facts.cs | 4 +- src/Catel.Fody.Tests/CTL504.cs | 2 +- src/Catel.Fody.Tests/CTL569.cs | 2 +- src/Catel.Fody.Tests/CTL768.cs | 2 +- src/Catel.Fody.Tests/CTL908.cs | 4 +- src/Catel.Fody.Tests/Catel.Fody.Tests.csproj | 39 ++- src/Catel.Fody.Tests/DefaultValueFacts.cs | 22 +- .../DependentPropertyFacts.cs | 2 +- src/Catel.Fody.Tests/ExposeFacts.cs | 10 +- src/Catel.Fody.Tests/GenericModelFacts.cs | 2 +- src/Catel.Fody.Tests/InheritanceFacts.cs | 2 +- src/Catel.Fody.Tests/LoggingFacts.cs | 2 +- src/Catel.Fody.Tests/MockAssemblyResolver.cs | 48 ++-- src/Catel.Fody.Tests/ModelBaseFacts.cs | 22 +- .../ModelWithDoubleValuesFacts.cs | 2 +- src/Catel.Fody.Tests/NoWeavingFacts.cs | 4 +- src/Catel.Fody.Tests/PeVerifyFacts.cs | 23 ++ src/Catel.Fody.Tests/Verifier.cs | 44 ++++ src/Catel.Fody.Tests/ViewModelBaseFacts.cs | 4 +- src/Catel.Fody.Tests/app.config | 8 + src/Catel.Fody.Tests/packages.config | 6 +- src/Catel.Fody.sln.DotSettings | 238 ++++++++---------- src/Catel.Fody/Catel.Fody.csproj | 25 +- .../Extensions/CecilCatelExtensions.cs | 1 + .../Extensions/CecilExtensions.assembly.cs | 19 ++ src/Catel.Fody/Extensions/CecilExtensions.cs | 9 +- .../Extensions/CecilExtensions.methods.cs | 8 +- .../Extensions/InstructionListExtensions.cs | 25 -- .../Extensions/TypeReferenceExtensions.cs | 18 +- .../Argument/ArgumentMethodCallWeaverBase.cs | 2 +- .../Weaving/Argument/ArgumentWeaver.cs | 12 +- .../Argument/ArgumentWeaver.expressions.cs | 26 +- .../Weaving/Logging/LoggingWeaver.cs | 2 +- .../Weaving/XmlSchemas/XmlSchemasWeaver.cs | 2 +- src/Catel.Fody/packages.config | 2 +- 44 files changed, 522 insertions(+), 419 deletions(-) create mode 100644 src/Catel.Fody.Tests/PeVerifyFacts.cs create mode 100644 src/Catel.Fody.Tests/Verifier.cs create mode 100644 src/Catel.Fody/Extensions/CecilExtensions.assembly.cs diff --git a/deployment/NuGet/template/Catel.Fody/Catel.Fody.nuspec b/deployment/NuGet/template/Catel.Fody/Catel.Fody.nuspec index a88904f6..7b109322 100644 --- a/deployment/NuGet/template/Catel.Fody/Catel.Fody.nuspec +++ b/deployment/NuGet/template/Catel.Fody/Catel.Fody.nuspec @@ -24,7 +24,7 @@ http://www.catenalogic.com/catel.png - + diff --git a/src/Catel.Fody.TestAssembly/CTL908.cs b/src/Catel.Fody.TestAssembly/CTL908.cs index ea92a421..1a398939 100644 --- a/src/Catel.Fody.TestAssembly/CTL908.cs +++ b/src/Catel.Fody.TestAssembly/CTL908.cs @@ -16,4 +16,12 @@ public CTL908(object obj) Argument.IsNotNull(() => obj); } } + + public class CTL908_Expected + { + public CTL908_Expected(object obj) + { + Argument.IsNotNull("obj", obj); + } + } } \ No newline at end of file diff --git a/src/Catel.Fody.TestAssembly/Catel.Fody.TestAssembly.csproj b/src/Catel.Fody.TestAssembly/Catel.Fody.TestAssembly.csproj index 407fa18c..b44b6e90 100644 --- a/src/Catel.Fody.TestAssembly/Catel.Fody.TestAssembly.csproj +++ b/src/Catel.Fody.TestAssembly/Catel.Fody.TestAssembly.csproj @@ -32,13 +32,11 @@ 4 - - ..\..\lib\Catel.Core.4.5.3\lib\net40\Catel.Core.dll - True + + ..\..\lib\Catel.Core.4.5.4\lib\net40\Catel.Core.dll - - ..\..\lib\Catel.MVVM.4.5.3\lib\net40\Catel.MVVM.dll - True + + ..\..\lib\Catel.MVVM.4.5.4\lib\net40\Catel.MVVM.dll ..\..\lib\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll @@ -67,7 +65,7 @@ True - ..\..\lib\Catel.MVVM.4.5.3\lib\net40\System.Windows.Interactivity.dll + ..\..\lib\Catel.MVVM.4.5.4\lib\net40\System.Windows.Interactivity.dll True diff --git a/src/Catel.Fody.TestAssembly/packages.config b/src/Catel.Fody.TestAssembly/packages.config index d8cfc234..19b408e6 100644 --- a/src/Catel.Fody.TestAssembly/packages.config +++ b/src/Catel.Fody.TestAssembly/packages.config @@ -1,7 +1,7 @@  - - + + diff --git a/src/Catel.Fody.TestExternalTypesAssembly/Catel.Fody.TestExternalTypesAssembly.csproj b/src/Catel.Fody.TestExternalTypesAssembly/Catel.Fody.TestExternalTypesAssembly.csproj index aa60bff0..4e8ac01f 100644 --- a/src/Catel.Fody.TestExternalTypesAssembly/Catel.Fody.TestExternalTypesAssembly.csproj +++ b/src/Catel.Fody.TestExternalTypesAssembly/Catel.Fody.TestExternalTypesAssembly.csproj @@ -31,9 +31,8 @@ 4 - - ..\..\lib\Catel.Core.4.5.3\lib\net40\Catel.Core.dll - True + + ..\..\lib\Catel.Core.4.5.4\lib\net40\Catel.Core.dll ..\..\lib\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll diff --git a/src/Catel.Fody.TestExternalTypesAssembly/packages.config b/src/Catel.Fody.TestExternalTypesAssembly/packages.config index cbeece02..eb0f25b0 100644 --- a/src/Catel.Fody.TestExternalTypesAssembly/packages.config +++ b/src/Catel.Fody.TestExternalTypesAssembly/packages.config @@ -1,6 +1,6 @@  - + diff --git a/src/Catel.Fody.Tests/ArgumentExpressionFacts.cs b/src/Catel.Fody.Tests/ArgumentExpressionFacts.cs index 5b2f8e01..9228ec4c 100644 --- a/src/Catel.Fody.Tests/ArgumentExpressionFacts.cs +++ b/src/Catel.Fody.Tests/ArgumentExpressionFacts.cs @@ -19,7 +19,7 @@ public class SupportedExpressions public void CorrectlyCompilesGenericArgumentChecks() { // Note: do NOT instantiate the type, then you will get the "unweaved" types. You need to use this helper during unit tests - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); // Instantiate to have properties registered var instance = Activator.CreateInstance(type); @@ -34,7 +34,7 @@ public void CorrectlyCompilesGenericArgumentChecks() public void CorrectlyCompilesGenericArgumentWithPredicateChecks() { // Note: do NOT instantiate the type, then you will get the "unweaved" types. You need to use this helper during unit tests - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); // Instantiate to have properties registered var instance = Activator.CreateInstance(type); @@ -49,7 +49,7 @@ public void CorrectlyCompilesGenericArgumentWithPredicateChecks() public void CheckForNullForGenericArgumentWithPredicateAndInstantiation() { // Note: do NOT instantiate the type, then you will get the "unweaved" types. You need to use this helper during unit tests - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); // Instantiate to have properties registered var instance = Activator.CreateInstance(type); @@ -64,7 +64,7 @@ public void CheckForNullForGenericArgumentWithPredicateAndInstantiation() public void CorrectlyThrowsArgumentNullExceptionForNullTypes() { // Note: do NOT instantiate the type, then you will get the "unweaved" types. You need to use this helper during unit tests - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); // Instantiate to have properties registered var instance = Activator.CreateInstance(type); @@ -78,7 +78,7 @@ public void CorrectlyThrowsArgumentNullExceptionForNullTypes() public void CorrectlyThrowsArgumentNullExceptionForMultipleNullTypes() { // Note: do NOT instantiate the type, then you will get the "unweaved" types. You need to use this helper during unit tests - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); // Instantiate to have properties registered var instance = Activator.CreateInstance(type); @@ -91,7 +91,7 @@ public void CorrectlyThrowsArgumentNullExceptionForMultipleNullTypes() [TestCase] public void CorrectlyThrowsNoArgumentNullExceptionForNotNullTypes() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -102,7 +102,7 @@ public void CorrectlyThrowsNoArgumentNullExceptionForNotNullTypes() [TestCase] public void CorrectlyThrowsArgumentExceptionForNullString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -114,7 +114,7 @@ public void CorrectlyThrowsArgumentExceptionForNullString() [TestCase] public void CorrectlyThrowsArgumentExceptionForEmptyString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -126,7 +126,7 @@ public void CorrectlyThrowsArgumentExceptionForEmptyString() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForNoNullOrEmptyString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -138,7 +138,7 @@ public void CorrectlyThrowsNoArgumentExceptionForNoNullOrEmptyString() [TestCase] public void CorrectlyThrowsArgumentExceptionForNullString2() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -150,7 +150,7 @@ public void CorrectlyThrowsArgumentExceptionForNullString2() [TestCase] public void CorrectlyThrowsArgumentExceptionForWhitespaceString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -162,7 +162,7 @@ public void CorrectlyThrowsArgumentExceptionForWhitespaceString() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForNoNullOrWhitespaceString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -178,7 +178,7 @@ public class UnsupportedExpressions [TestCase] public void CorrectlyThrowsArgumentExceptionForNullArray() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -190,7 +190,7 @@ public void CorrectlyThrowsArgumentExceptionForNullArray() [TestCase] public void CorrectlyThrowsArgumentExceptionForEmptyArray() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -202,7 +202,7 @@ public void CorrectlyThrowsArgumentExceptionForEmptyArray() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForNoNullOrEmptyArray() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -214,7 +214,7 @@ public void CorrectlyThrowsNoArgumentExceptionForNoNullOrEmptyArray() [TestCase] public void CorrectlyThrowsArgumentExceptionForNotMatchString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -226,7 +226,7 @@ public void CorrectlyThrowsArgumentExceptionForNotMatchString() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForMatchString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -238,7 +238,7 @@ public void CorrectlyThrowsNoArgumentExceptionForMatchString() [TestCase] public void CorrectlyThrowsArgumentExceptionForMatchString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -250,7 +250,7 @@ public void CorrectlyThrowsArgumentExceptionForMatchString() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForNotMatchString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -263,7 +263,7 @@ public void CorrectlyThrowsNoArgumentExceptionForNotMatchString() [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMinimalInt() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -275,7 +275,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMinimalInt() [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMinimalInt() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -287,7 +287,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMinimalInt() [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMinimalDouble() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -299,7 +299,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMinimalDouble( [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMinimalDouble() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -311,7 +311,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMinimalDoubl [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMinimalFloat() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -323,7 +323,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMinimalFloat() [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMinimalFloat() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -335,7 +335,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMinimalFloat [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMaximalInt() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -347,7 +347,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMaximalInt() [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMaximalInt() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -359,7 +359,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMaximalInt() [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMaximalDouble() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -371,7 +371,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMaximalDouble( [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMaximalDouble() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -383,7 +383,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMaximalDoubl [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMaximalFloat() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -395,7 +395,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMaximalFloat() [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMaximalFloat() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -407,7 +407,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMaximalFloat [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeInt() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -419,7 +419,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeInt( [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeInt() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -431,7 +431,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeIn [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeDouble() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -443,7 +443,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeDoub [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeDouble() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -455,7 +455,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeDo [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeFloat() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -467,7 +467,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeFloa [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeFloat() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -480,7 +480,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeFl [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -492,7 +492,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeStri [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -505,7 +505,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeSt //[TestCase] //public void CorrectlyThrowsArgumentExceptionForNotInheritsFrom() //{ - // var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + // var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); // var instance = Activator.CreateInstance(type); @@ -517,7 +517,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeSt //[TestCase] //public void CorrectlyThrowsNoArgumentExceptionForInheritsFrom() //{ - // var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + // var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); // var instance = Activator.CreateInstance(type); @@ -529,7 +529,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeSt //[TestCase] //public void CorrectlyThrowsArgumentExceptionForNotInheritsFrom2() //{ - // var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + // var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); // var instance = Activator.CreateInstance(type); @@ -541,7 +541,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeSt //[TestCase] //public void CorrectlyThrowsNoArgumentExceptionForInheritsFrom2() //{ - // var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + // var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); // var instance = Activator.CreateInstance(type); @@ -553,7 +553,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeSt [TestCase] public void CorrectlyThrowsArgumentExceptionForNotTypeOf() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -565,7 +565,7 @@ public void CorrectlyThrowsArgumentExceptionForNotTypeOf() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForTypeOf() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -577,7 +577,7 @@ public void CorrectlyThrowsNoArgumentExceptionForTypeOf() [TestCase] public void CorrectlyThrowsArgumentExceptionForNotTypeOf2() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -589,7 +589,7 @@ public void CorrectlyThrowsArgumentExceptionForNotTypeOf2() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForTypeOf2() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -601,7 +601,7 @@ public void CorrectlyThrowsNoArgumentExceptionForTypeOf2() [TestCase] public void CorrectlyThrowsArgumentExceptionForNotInterfaceImplemented() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -613,7 +613,7 @@ public void CorrectlyThrowsArgumentExceptionForNotInterfaceImplemented() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForNotInterfaceImplemented() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -625,7 +625,7 @@ public void CorrectlyThrowsNoArgumentExceptionForNotInterfaceImplemented() [TestCase] public void CorrectlyThrowsArgumentExceptionForNotInterfaceImplemented2() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); @@ -637,7 +637,7 @@ public void CorrectlyThrowsArgumentExceptionForNotInterfaceImplemented2() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForNotInterfaceImplemented2() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksAsExpressionsClass"); var instance = Activator.CreateInstance(type); diff --git a/src/Catel.Fody.Tests/ArgumentFacts.cs b/src/Catel.Fody.Tests/ArgumentFacts.cs index 3db5417f..b2ff5c05 100644 --- a/src/Catel.Fody.Tests/ArgumentFacts.cs +++ b/src/Catel.Fody.Tests/ArgumentFacts.cs @@ -18,7 +18,7 @@ public class ArgumentFacts public void CorrectlyThrowsArgumentNullExceptionForNullTypes() { // Note: do NOT instantiate the type, then you will get the "unweaved" types. You need to use this helper during unit tests - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); // Instantiate to have properties registered var instance = Activator.CreateInstance(type); @@ -31,7 +31,7 @@ public void CorrectlyThrowsArgumentNullExceptionForNullTypes() [TestCase] public void CorrectlyThrowsNoArgumentNullExceptionForNotNullTypes() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -42,7 +42,7 @@ public void CorrectlyThrowsNoArgumentNullExceptionForNotNullTypes() [TestCase] public void CorrectlyThrowsArgumentExceptionForNullString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -54,7 +54,7 @@ public void CorrectlyThrowsArgumentExceptionForNullString() [TestCase] public void CorrectlyThrowsArgumentExceptionForEmptyString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -66,7 +66,7 @@ public void CorrectlyThrowsArgumentExceptionForEmptyString() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForNotNullOrEmptyString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -78,7 +78,7 @@ public void CorrectlyThrowsNoArgumentExceptionForNotNullOrEmptyString() [TestCase] public void CorrectlyThrowsArgumentExceptionForNullArray() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -90,7 +90,7 @@ public void CorrectlyThrowsArgumentExceptionForNullArray() [TestCase] public void CorrectlyThrowsArgumentExceptionForEmptyArray() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -102,7 +102,7 @@ public void CorrectlyThrowsArgumentExceptionForEmptyArray() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForNoNullOrEmptyArray() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -114,7 +114,7 @@ public void CorrectlyThrowsNoArgumentExceptionForNoNullOrEmptyArray() [TestCase] public void CorrectlyThrowsArgumentExceptionForNullString2() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -126,7 +126,7 @@ public void CorrectlyThrowsArgumentExceptionForNullString2() [TestCase] public void CorrectlyThrowsArgumentExceptionForWhitespaceString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -138,7 +138,7 @@ public void CorrectlyThrowsArgumentExceptionForWhitespaceString() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForNoNullOrWhitespaceString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -150,7 +150,7 @@ public void CorrectlyThrowsNoArgumentExceptionForNoNullOrWhitespaceString() [TestCase] public void CorrectlyThrowsArgumentExceptionForNotMatchString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -162,7 +162,7 @@ public void CorrectlyThrowsArgumentExceptionForNotMatchString() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForMatchString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -174,7 +174,7 @@ public void CorrectlyThrowsNoArgumentExceptionForMatchString() [TestCase] public void CorrectlyThrowsArgumentExceptionForMatchString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -186,7 +186,7 @@ public void CorrectlyThrowsArgumentExceptionForMatchString() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForNotMatchString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -199,7 +199,7 @@ public void CorrectlyThrowsNoArgumentExceptionForNotMatchString() [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMinimalInt() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -212,7 +212,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMinimalInt() [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMinimalInt() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -224,7 +224,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMinimalInt() [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMinimalDouble() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -237,7 +237,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMinimalDouble( [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMinimalDouble() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -249,7 +249,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMinimalDoubl [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMinimalFloat() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -262,7 +262,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMinimalFloat() [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMinimalFloat() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -274,7 +274,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMinimalFloat [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMaximalInt() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -287,7 +287,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMaximalInt() [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMaximalInt() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -299,7 +299,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMaximalInt() [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMaximalDouble() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -312,7 +312,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMaximalDouble( [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMaximalDouble() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -324,7 +324,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMaximalDoubl [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMaximalFloat() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -337,7 +337,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForMaximalFloat() [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMaximalFloat() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -349,7 +349,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForMaximalFloat [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeInt() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -362,7 +362,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeInt( [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeInt() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -374,7 +374,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeIn [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeDouble() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -386,7 +386,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeDoub [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeDouble() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -398,7 +398,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeDo [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeFloat() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -410,7 +410,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeFloa [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeFloat() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -423,7 +423,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeFl [TestCase] public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -435,7 +435,7 @@ public void CorrectlyThrowsArgumentOutOfRangeExceptionExceptionForOutOfRangeStri [TestCase] public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -448,7 +448,7 @@ public void CorrectlyThrowsNoArgumentOutOfRangeExceptionExceptionForOutOfRangeSt [TestCase] public void CorrectlyThrowsArgumentExceptionForNotInheritsFrom() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -460,7 +460,7 @@ public void CorrectlyThrowsArgumentExceptionForNotInheritsFrom() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForInheritsFrom() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -472,7 +472,7 @@ public void CorrectlyThrowsNoArgumentExceptionForInheritsFrom() [TestCase] public void CorrectlyThrowsArgumentExceptionForNotInheritsFrom2() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -484,7 +484,7 @@ public void CorrectlyThrowsArgumentExceptionForNotInheritsFrom2() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForInheritsFrom2() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -497,7 +497,7 @@ public void CorrectlyThrowsNoArgumentExceptionForInheritsFrom2() [TestCase] public void CorrectlyThrowsArgumentExceptionForNotTypeOf() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -509,7 +509,7 @@ public void CorrectlyThrowsArgumentExceptionForNotTypeOf() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForTypeOf() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -521,7 +521,7 @@ public void CorrectlyThrowsNoArgumentExceptionForTypeOf() [TestCase] public void CorrectlyThrowsArgumentExceptionForNotTypeOf2() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -533,7 +533,7 @@ public void CorrectlyThrowsArgumentExceptionForNotTypeOf2() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForTypeOf2() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -545,7 +545,7 @@ public void CorrectlyThrowsNoArgumentExceptionForTypeOf2() [TestCase] public void CorrectlyThrowsArgumentExceptionForNotInterfaceImplemented() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -557,7 +557,7 @@ public void CorrectlyThrowsArgumentExceptionForNotInterfaceImplemented() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForNotInterfaceImplemented() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -569,7 +569,7 @@ public void CorrectlyThrowsNoArgumentExceptionForNotInterfaceImplemented() [TestCase] public void CorrectlyThrowsArgumentExceptionForNotInterfaceImplemented2() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -581,7 +581,7 @@ public void CorrectlyThrowsArgumentExceptionForNotInterfaceImplemented2() [TestCase] public void CorrectlyThrowsNoArgumentExceptionForNotInterfaceImplemented2() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ArgumentChecksClass"); var instance = Activator.CreateInstance(type); @@ -600,7 +600,7 @@ private static void CallMethodAndExpectException(Action action) } catch (Exception ex) { - Type exceptionType = ex.GetType(); + var exceptionType = ex.GetType(); if (exceptionType == typeof(TException)) { diff --git a/src/Catel.Fody.Tests/AssemblyWeaver.cs b/src/Catel.Fody.Tests/AssemblyWeaver.cs index 9d06d07b..01c6d89b 100644 --- a/src/Catel.Fody.Tests/AssemblyWeaver.cs +++ b/src/Catel.Fody.Tests/AssemblyWeaver.cs @@ -15,43 +15,70 @@ using Catel.Reflection; using Mono.Cecil; -public static class AssemblyWeaver +public class AssemblyWeaver { #region Constants - public static Assembly Assembly; + public Assembly Assembly; + public string BeforeAssemblyPath; + public string AfterAssemblyPath; - public static string BeforeAssemblyPath; - public static string AfterAssemblyPath; - - public static List Errors = new List(); + public List Errors = new List(); #endregion #region Constructors static AssemblyWeaver() { + Instance = new AssemblyWeaver(); + } + + public AssemblyWeaver(List referenceAssemblyPaths = null) + { + if (referenceAssemblyPaths == null) + { + referenceAssemblyPaths = new List(); + } + //Force ref since MSTest is a POS - var type = typeof (ViewModelBaseTest); + var type = typeof(ViewModelBaseTest); BeforeAssemblyPath = type.GetAssemblyEx().Location; //BeforeAssemblyPath = Path.GetFullPath("Catel.Fody.TestAssembly.dll"); AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll"); - Debug.WriteLine("Weaving assembly on-demand from '{0}' to '{1}'", BeforeAssemblyPath, AfterAssemblyPath); + var oldPdb = Path.ChangeExtension(BeforeAssemblyPath, "pdb"); + var newPdb = Path.ChangeExtension(AfterAssemblyPath, "pdb"); + if (File.Exists(oldPdb)) + { + File.Copy(oldPdb, newPdb, true); + } - File.Copy(BeforeAssemblyPath, AfterAssemblyPath, true); + Debug.WriteLine("Weaving assembly on-demand from '{0}' to '{1}'", BeforeAssemblyPath, AfterAssemblyPath); var assemblyResolver = new MockAssemblyResolver(); - var moduleDefinition = ModuleDefinition.ReadModule(AfterAssemblyPath); + foreach (var referenceAssemblyPath in referenceAssemblyPaths) + { + //var directoryName = Path.GetDirectoryName(referenceAssemblyPath); + //assemblyResolver.AddSearchDirectory(directoryName); + } - var weavingTask = new ModuleWeaver + var readerParameters = new ReaderParameters { - ModuleDefinition = moduleDefinition, AssemblyResolver = assemblyResolver, - LogError = LogError, + ReadSymbols = File.Exists(oldPdb), }; - weavingTask.Execute(); - moduleDefinition.Write(AfterAssemblyPath); + using (var moduleDefinition = ModuleDefinition.ReadModule(BeforeAssemblyPath, readerParameters)) + { + var weavingTask = new ModuleWeaver + { + ModuleDefinition = moduleDefinition, + AssemblyResolver = assemblyResolver, + LogError = LogError, + }; + + weavingTask.Execute(); + moduleDefinition.Write(AfterAssemblyPath); + } if (Debugger.IsAttached) { @@ -69,12 +96,14 @@ static AssemblyWeaver() Assembly = Assembly.LoadFile(AfterAssemblyPath); } -#endregion + #endregion -#region Methods - private static void LogError(string error) + public static AssemblyWeaver Instance { get; private set; } + + #region Methods + private void LogError(string error) { Errors.Add(error); } -#endregion + #endregion } \ No newline at end of file diff --git a/src/Catel.Fody.Tests/CSharp6Facts.cs b/src/Catel.Fody.Tests/CSharp6Facts.cs index 60f7b8ca..8c1e551c 100644 --- a/src/Catel.Fody.Tests/CSharp6Facts.cs +++ b/src/Catel.Fody.Tests/CSharp6Facts.cs @@ -9,7 +9,7 @@ public class CSharp6Facts [TestCase] public void AutoPropertyInitializer() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.CSharp6_AutoPropertyInitializer"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.CSharp6_AutoPropertyInitializer"); var obj = (dynamic)Activator.CreateInstance(type); Assert.IsNotNull(obj.SimpleModels); @@ -18,7 +18,7 @@ public void AutoPropertyInitializer() [TestCase] public void AutoPropertyInitializer_Generic() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.CSharp6_AutoPropertyInitializer_Generic"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.CSharp6_AutoPropertyInitializer_Generic"); var obj = (dynamic)Activator.CreateInstance(type); Assert.IsNotNull(obj.SimpleModels); diff --git a/src/Catel.Fody.Tests/CTL504.cs b/src/Catel.Fody.Tests/CTL504.cs index 437cfdce..c5609258 100644 --- a/src/Catel.Fody.Tests/CTL504.cs +++ b/src/Catel.Fody.Tests/CTL504.cs @@ -16,7 +16,7 @@ public class CTL504 [TestCase] public void PropertyWeavingDoesNotThrowException() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.CTL504_Model"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.CTL504_Model"); var model = Activator.CreateInstance(type); } diff --git a/src/Catel.Fody.Tests/CTL569.cs b/src/Catel.Fody.Tests/CTL569.cs index 19e99816..bc0792e7 100644 --- a/src/Catel.Fody.Tests/CTL569.cs +++ b/src/Catel.Fody.Tests/CTL569.cs @@ -18,7 +18,7 @@ public class CTL569 [TestCase] public void WeavingCalculatedPropertiesWithExistingOverride() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.CTL569_ViewModel"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.CTL569_ViewModel"); var vm = (INotifyPropertyChanged)Activator.CreateInstance(type); diff --git a/src/Catel.Fody.Tests/CTL768.cs b/src/Catel.Fody.Tests/CTL768.cs index 7a857d0c..7e52ad19 100644 --- a/src/Catel.Fody.Tests/CTL768.cs +++ b/src/Catel.Fody.Tests/CTL768.cs @@ -17,7 +17,7 @@ public class CTL768 [TestCase] public void WeavingConstructors() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.CTL768_Model"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.CTL768_Model"); var model = (INotifyPropertyChanged) Activator.CreateInstance(type, new [] { "test" }); diff --git a/src/Catel.Fody.Tests/CTL908.cs b/src/Catel.Fody.Tests/CTL908.cs index 58c44143..d0f0b27c 100644 --- a/src/Catel.Fody.Tests/CTL908.cs +++ b/src/Catel.Fody.Tests/CTL908.cs @@ -17,7 +17,7 @@ public class CTL908TestFixture [TestCase] public void WeavingConstructorWithString() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.CTL908"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.CTL908"); var model = Activator.CreateInstance(type, new[] {"test"}); @@ -27,7 +27,7 @@ public void WeavingConstructorWithString() [TestCase] public void WeavingConstructorWithObject() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.CTL908"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.CTL908"); var model = Activator.CreateInstance(type, new[] { new object() }); diff --git a/src/Catel.Fody.Tests/Catel.Fody.Tests.csproj b/src/Catel.Fody.Tests/Catel.Fody.Tests.csproj index e90560ef..9d55052b 100644 --- a/src/Catel.Fody.Tests/Catel.Fody.Tests.csproj +++ b/src/Catel.Fody.Tests/Catel.Fody.Tests.csproj @@ -36,35 +36,26 @@ false - - ..\..\lib\Catel.Core.4.5.3\lib\net45\Catel.Core.dll - True + + ..\..\lib\Catel.Core.4.5.4\lib\net45\Catel.Core.dll - - ..\..\lib\Catel.MVVM.4.5.3\lib\net45\Catel.MVVM.dll - True + + ..\..\lib\Catel.MVVM.4.5.4\lib\net45\Catel.MVVM.dll + - - False - ..\..\lib\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll - True + + ..\..\lib\FodyCecil.2.0.2\lib\net40\Mono.Cecil.dll - - False - ..\..\lib\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll - True + + ..\..\lib\FodyCecil.2.0.2\lib\net40\Mono.Cecil.Mdb.dll - - False - ..\..\lib\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll - True + + ..\..\lib\FodyCecil.2.0.2\lib\net40\Mono.Cecil.Pdb.dll - - False - ..\..\lib\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll - True + + ..\..\lib\FodyCecil.2.0.2\lib\net40\Mono.Cecil.Rocks.dll ..\..\lib\NUnit.2.6.4\lib\nunit.framework.dll @@ -74,7 +65,7 @@ - ..\..\lib\Catel.MVVM.4.5.3\lib\net45\System.Windows.Interactivity.dll + ..\..\lib\Catel.MVVM.4.5.4\lib\net45\System.Windows.Interactivity.dll True @@ -105,7 +96,9 @@ + + diff --git a/src/Catel.Fody.Tests/DefaultValueFacts.cs b/src/Catel.Fody.Tests/DefaultValueFacts.cs index 1d1d500c..dd373f92 100644 --- a/src/Catel.Fody.Tests/DefaultValueFacts.cs +++ b/src/Catel.Fody.Tests/DefaultValueFacts.cs @@ -18,7 +18,7 @@ public class DefaultValueFacts [TestCase] public void SetsNullAsDefaultValueWhenNoAttributeDefined() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); // Instantiate to have properties registered Activator.CreateInstance(type); @@ -30,7 +30,7 @@ public void SetsNullAsDefaultValueWhenNoAttributeDefined() [TestCase] public void SetsDefaultValueForStringWhenAttributeDefined() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); // Instantiate to have properties registered Activator.CreateInstance(type); @@ -42,7 +42,7 @@ public void SetsDefaultValueForStringWhenAttributeDefined() [TestCase] public void SetsDefaultValueForBoolWhenAttributeDefined() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); // Instantiate to have properties registered Activator.CreateInstance(type); @@ -54,7 +54,7 @@ public void SetsDefaultValueForBoolWhenAttributeDefined() [TestCase] public void SetsDefaultValueForNullableBoolWhenNullAttributeDefined() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); // Instantiate to have properties registered Activator.CreateInstance(type); @@ -66,7 +66,7 @@ public void SetsDefaultValueForNullableBoolWhenNullAttributeDefined() [TestCase] public void SetsDefaultValueForNullableBoolWhenTrueAttributeDefined() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); // Instantiate to have properties registered Activator.CreateInstance(type); @@ -78,7 +78,7 @@ public void SetsDefaultValueForNullableBoolWhenTrueAttributeDefined() [TestCase] public void SetsDefaultValueForNullableBoolWhenFalseAttributeDefined() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); // Instantiate to have properties registered Activator.CreateInstance(type); @@ -90,7 +90,7 @@ public void SetsDefaultValueForNullableBoolWhenFalseAttributeDefined() [TestCase] public void SetsDefaultValueForIntWhenAttributeDefined() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); // Instantiate to have properties registered Activator.CreateInstance(type); @@ -102,7 +102,7 @@ public void SetsDefaultValueForIntWhenAttributeDefined() [TestCase] public void SetsDefaultValueForLongWhenAttributeDefined() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); // Instantiate to have properties registered Activator.CreateInstance(type); @@ -114,7 +114,7 @@ public void SetsDefaultValueForLongWhenAttributeDefined() [TestCase] public void SetsDefaultValueForDoubleWhenAttributeDefined() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); // Instantiate to have properties registered Activator.CreateInstance(type); @@ -126,7 +126,7 @@ public void SetsDefaultValueForDoubleWhenAttributeDefined() [TestCase] public void SetsDefaultValueForFloatWhenAttributeDefined() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); // Instantiate to have properties registered Activator.CreateInstance(type); @@ -138,7 +138,7 @@ public void SetsDefaultValueForFloatWhenAttributeDefined() [TestCase] public void SetsDefaultValueForEnumWhenAttributeDefined() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.DefaultValueModel"); // Instantiate to have properties registered Activator.CreateInstance(type); diff --git a/src/Catel.Fody.Tests/DependentPropertyFacts.cs b/src/Catel.Fody.Tests/DependentPropertyFacts.cs index 8b06167b..ef6cfe6d 100644 --- a/src/Catel.Fody.Tests/DependentPropertyFacts.cs +++ b/src/Catel.Fody.Tests/DependentPropertyFacts.cs @@ -24,7 +24,7 @@ public class DependentPropertyFacts //[TestCase("Catel.Fody.TestAssembly.DependentPropertyModelWithExistingOnPropertyChanged", "LastName", "Fernández Saúco", "Profile")] public void NotifiesPropertyChangedOfDepedentProperties(string modelType, string propertyName, string newValue, string expectedPropertyName) { - var type = AssemblyWeaver.Assembly.GetType(modelType); + var type = AssemblyWeaver.Instance.Assembly.GetType(modelType); var instance = Activator.CreateInstance(type); var changedProperties = new List(); diff --git a/src/Catel.Fody.Tests/ExposeFacts.cs b/src/Catel.Fody.Tests/ExposeFacts.cs index be035242..7546d5a4 100644 --- a/src/Catel.Fody.Tests/ExposeFacts.cs +++ b/src/Catel.Fody.Tests/ExposeFacts.cs @@ -19,8 +19,8 @@ public class ExposeFacts [TestCase] public void CreatesExposedProperties() { - var modelType = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ExposingDerivedModel"); - var viewModelType = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ExposingViewModel"); + var modelType = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ExposingDerivedModel"); + var viewModelType = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ExposingViewModel"); var model = Activator.CreateInstance(modelType); var viewModel = Activator.CreateInstance(viewModelType, new [] {model}); @@ -38,8 +38,8 @@ public void CreatesExposedProperties() [TestCase] public void CreatesExposedPropertiesFromExternalTypes() { - var modelType = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ExposingDerivedModel"); - var viewModelType = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ExposingViewModel"); + var modelType = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ExposingDerivedModel"); + var viewModelType = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ExposingViewModel"); var model = Activator.CreateInstance(modelType); var viewModel = Activator.CreateInstance(viewModelType, new [] { model }); @@ -53,7 +53,7 @@ public void CreatesExposedPropertiesFromExternalTypes() [TestCase] public void CanCreateReadOnlyExposedProperties() { - var viewModelType = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ExposingViewModel"); + var viewModelType = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ExposingViewModel"); var propertyInfo = viewModelType.GetPropertyEx("ReadOnlyProperty"); diff --git a/src/Catel.Fody.Tests/GenericModelFacts.cs b/src/Catel.Fody.Tests/GenericModelFacts.cs index cd6e7d85..39aac7da 100644 --- a/src/Catel.Fody.Tests/GenericModelFacts.cs +++ b/src/Catel.Fody.Tests/GenericModelFacts.cs @@ -10,7 +10,7 @@ public class GenericModelFacts [TestCase] public void ImportedGenericTypeFromExternalAssemblyWorks() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.GenericModel"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.GenericModel"); var obj = (dynamic)Activator.CreateInstance(type); Assert.IsNull(obj.GenericProperty); diff --git a/src/Catel.Fody.Tests/InheritanceFacts.cs b/src/Catel.Fody.Tests/InheritanceFacts.cs index 5d5e82dc..99dcb4e8 100644 --- a/src/Catel.Fody.Tests/InheritanceFacts.cs +++ b/src/Catel.Fody.Tests/InheritanceFacts.cs @@ -17,7 +17,7 @@ public class Inheritance [TestCase] public void InheritanceWorks() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.InheritedClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.InheritedClass"); var obj = (dynamic) Activator.CreateInstance(type); obj.PropertyOnBase = "base prop"; diff --git a/src/Catel.Fody.Tests/LoggingFacts.cs b/src/Catel.Fody.Tests/LoggingFacts.cs index a45fa772..346098dd 100644 --- a/src/Catel.Fody.Tests/LoggingFacts.cs +++ b/src/Catel.Fody.Tests/LoggingFacts.cs @@ -17,7 +17,7 @@ public class LoggingFacts public void InheritanceWorks() { // Instantiating is sufficient - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.LoggingClass"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.LoggingClass"); var obj = (dynamic)Activator.CreateInstance(type); } } diff --git a/src/Catel.Fody.Tests/MockAssemblyResolver.cs b/src/Catel.Fody.Tests/MockAssemblyResolver.cs index 70827071..ed7471f4 100644 --- a/src/Catel.Fody.Tests/MockAssemblyResolver.cs +++ b/src/Catel.Fody.Tests/MockAssemblyResolver.cs @@ -8,37 +8,35 @@ using System; using System.Diagnostics; using Mono.Cecil; +using System.Collections.Generic; -public class MockAssemblyResolver : IAssemblyResolver +public class MockAssemblyResolver : DefaultAssemblyResolver { - #region IAssemblyResolver Members - public AssemblyDefinition Resolve(AssemblyNameReference name) - { - return AssemblyDefinition.ReadAssembly(name.Name + ".dll"); - } + private readonly Dictionary _cache = new Dictionary(); - public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) + public override AssemblyDefinition Resolve(AssemblyNameReference name) { - throw new NotImplementedException(); - } + var fullName = name.FullName; - public AssemblyDefinition Resolve(string fullName) - { - if (fullName == "System") - { - var codeBase = typeof (Debug).Assembly.CodeBase.Replace("file:///", ""); - return AssemblyDefinition.ReadAssembly(codeBase); - } - else + lock (_cache) { - var codeBase = typeof (string).Assembly.CodeBase.Replace("file:///", ""); - return AssemblyDefinition.ReadAssembly(codeBase); - } - } + AssemblyDefinition definition = null; + if (!_cache.TryGetValue(fullName, out definition)) + { + if (name.Name == "System") + { + var codeBase = typeof(Debug).Assembly.CodeBase.Replace("file:///", ""); + definition = AssemblyDefinition.ReadAssembly(codeBase); + } + else + { + definition = base.Resolve(name); + } - public AssemblyDefinition Resolve(string fullName, ReaderParameters parameters) - { - throw new NotImplementedException(); + _cache[fullName] = definition; + } + + return definition; + } } - #endregion } \ No newline at end of file diff --git a/src/Catel.Fody.Tests/ModelBaseFacts.cs b/src/Catel.Fody.Tests/ModelBaseFacts.cs index 9a216c24..48996a27 100644 --- a/src/Catel.Fody.Tests/ModelBaseFacts.cs +++ b/src/Catel.Fody.Tests/ModelBaseFacts.cs @@ -20,7 +20,7 @@ public class ModelBaseFacts [TestCase] public void StringsCanBeUsedAfterWeaving() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); var obj = (dynamic) Activator.CreateInstance(type); obj.Name = "hi there"; Assert.AreEqual("hi there", obj.Name); @@ -29,7 +29,7 @@ public void StringsCanBeUsedAfterWeaving() [TestCase] public void BooleansCanBeUsedAfterWeaving() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); var obj = (dynamic) Activator.CreateInstance(type); Assert.IsFalse(obj.BoolValue); @@ -40,7 +40,7 @@ public void BooleansCanBeUsedAfterWeaving() [TestCase] public void IntegersCanBeUsedAfterWeaving() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); var obj = (dynamic) Activator.CreateInstance(type); Assert.AreEqual(0, obj.IntValue); @@ -51,7 +51,7 @@ public void IntegersCanBeUsedAfterWeaving() [TestCase] public void GuidsCanBeUsedAfterWeaving() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); var obj = (dynamic) Activator.CreateInstance(type); Assert.AreEqual(Guid.Empty, obj.GuidValue); @@ -62,7 +62,7 @@ public void GuidsCanBeUsedAfterWeaving() [TestCase] public void CollectionsCanBeUsedAfterWeaving() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); var obj = (dynamic) Activator.CreateInstance(type); obj.CollectionProperty.Add(1); @@ -74,7 +74,7 @@ public void CollectionsCanBeUsedAfterWeaving() [TestCase] public void DoesNotWeaveExistingProperties() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); var obj = (dynamic) Activator.CreateInstance(type); obj.FullName = "hi there"; @@ -91,7 +91,7 @@ public void IgnoresPropertiesWithoutBackingField() [TestCase] public void HandlesChangeNotificationsMethodsCorrectly() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); var modelBase = (dynamic) Activator.CreateInstance(type); Assert.IsFalse(modelBase.OnFullNameWithChangeCallbackChangedCalled); @@ -110,7 +110,7 @@ public void HandlesChangeNotificationsMethodsCorrectly() [TestCase] public void IgnoresChangeNotificationsWithoutRightSignature() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ModelBaseTest"); var modelBase = (dynamic)Activator.CreateInstance(type); Assert.IsFalse(modelBase.OnLastNameChangedCalled); @@ -121,7 +121,7 @@ public void IgnoresChangeNotificationsWithoutRightSignature() [TestCase] public void CorrectlyWorksOnGenericClasses() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.GenericModelBaseTest"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.GenericModelBaseTest"); var model = (dynamic)Activator.CreateInstance(type); Assert.IsTrue(PropertyDataManager.Default.IsPropertyRegistered(type, "Operations")); @@ -134,7 +134,7 @@ public void CorrectlyWorksOnGenericClasses() [TestCase] public void CorrectlyWorksOnClassesWithGenericModelsWithValueTypes() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.GenericPropertyModelAsInt"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.GenericPropertyModelAsInt"); var model = Activator.CreateInstance(type); string propertyNameToCheck = "MyModel"; @@ -149,7 +149,7 @@ public void CorrectlyWorksOnClassesWithGenericModelsWithValueTypes() [TestCase] public void CorrectlyWorksOnClassesWithGenericModelsWithReferenceTypes() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.GenericPropertyModelAsObject"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.GenericPropertyModelAsObject"); var model = Activator.CreateInstance(type); string propertyNameToCheck = "MyModel"; diff --git a/src/Catel.Fody.Tests/ModelWithDoubleValuesFacts.cs b/src/Catel.Fody.Tests/ModelWithDoubleValuesFacts.cs index 355eb6ea..16b53d18 100644 --- a/src/Catel.Fody.Tests/ModelWithDoubleValuesFacts.cs +++ b/src/Catel.Fody.Tests/ModelWithDoubleValuesFacts.cs @@ -19,7 +19,7 @@ public class ModelWithDoubleValuesFacts [TestCase] public void CorrectlyDefaultsToDefaultDoubleValues() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ModelWithDoubleValues"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ModelWithDoubleValues"); var obj = (dynamic)Activator.CreateInstance(type); Assert.AreEqual(0.0d, obj.Top); diff --git a/src/Catel.Fody.Tests/NoWeavingFacts.cs b/src/Catel.Fody.Tests/NoWeavingFacts.cs index 424727e1..c29eb52a 100644 --- a/src/Catel.Fody.Tests/NoWeavingFacts.cs +++ b/src/Catel.Fody.Tests/NoWeavingFacts.cs @@ -16,7 +16,7 @@ public class NoWeavingFacts [TestCase] public void IgnoresTypesWithNoWeavingAttribute() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.NoWeavingModelTest"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.NoWeavingModelTest"); Assert.IsFalse(PropertyDataManager.Default.IsPropertyRegistered(type, "FirstName")); } @@ -24,7 +24,7 @@ public void IgnoresTypesWithNoWeavingAttribute() [TestCase] public void IgnoresPropertiesWithNoWeavingAttribute() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.NoPropertyWeavingModelTest"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.NoPropertyWeavingModelTest"); Assert.IsFalse(PropertyDataManager.Default.IsPropertyRegistered(type, "FirstName")); } diff --git a/src/Catel.Fody.Tests/PeVerifyFacts.cs b/src/Catel.Fody.Tests/PeVerifyFacts.cs new file mode 100644 index 00000000..6bd9ebe7 --- /dev/null +++ b/src/Catel.Fody.Tests/PeVerifyFacts.cs @@ -0,0 +1,23 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2008 - 2017 Catel development team. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace Catel.Fody.TestAssembly +{ + using NUnit.Framework; + + [TestFixture] + public class PeVerifyFacts + { + [Test] + public void PeVerify() + { + var weaver = AssemblyWeaver.Instance; + + Verifier.Verify(weaver.BeforeAssemblyPath, weaver.AfterAssemblyPath); + } + } +} \ No newline at end of file diff --git a/src/Catel.Fody.Tests/Verifier.cs b/src/Catel.Fody.Tests/Verifier.cs new file mode 100644 index 00000000..0084762a --- /dev/null +++ b/src/Catel.Fody.Tests/Verifier.cs @@ -0,0 +1,44 @@ +using System.Diagnostics; +using System.IO; +using System.Text.RegularExpressions; +using Microsoft.Build.Utilities; +using NUnit.Framework; + +public static class Verifier +{ + public static void Verify(string beforeAssemblyPath, string afterAssemblyPath) + { + var before = Validate(beforeAssemblyPath); + var after = Validate(afterAssemblyPath); + var message = $"Failed processing {Path.GetFileName(afterAssemblyPath)}\r\n{after}"; + Assert.AreEqual(TrimLineNumbers(before), TrimLineNumbers(after), message); + } + + static string Validate(string assemblyPath2) + { + var exePath = GetPathToPeVerify(); + if (!File.Exists(exePath)) + { + return string.Empty; + } + var process = Process.Start(new ProcessStartInfo(exePath, "\"" + assemblyPath2 + "\"") + { + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true + }); + + process.WaitForExit(10000); + return process.StandardOutput.ReadToEnd().Trim().Replace(assemblyPath2, ""); + } + + static string GetPathToPeVerify() + { + return ToolLocationHelper.GetPathToDotNetFrameworkFile("peverify.exe", TargetDotNetFrameworkVersion.VersionLatest); + } + + static string TrimLineNumbers(string foo) + { + return Regex.Replace(foo, @"0x.*]", ""); + } +} \ No newline at end of file diff --git a/src/Catel.Fody.Tests/ViewModelBaseFacts.cs b/src/Catel.Fody.Tests/ViewModelBaseFacts.cs index 9e7f9c4f..965de58b 100644 --- a/src/Catel.Fody.Tests/ViewModelBaseFacts.cs +++ b/src/Catel.Fody.Tests/ViewModelBaseFacts.cs @@ -17,7 +17,7 @@ public class ViewModelBaseFacts [TestCase] public void StringsCanBeUsedAfterWeaving() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ViewModelBaseTest"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ViewModelBaseTest"); var vm = (dynamic) Activator.CreateInstance(type); vm.Name = "hi there"; @@ -28,7 +28,7 @@ public void StringsCanBeUsedAfterWeaving() [TestCase] public void IgnoresICommandProperties() { - var type = AssemblyWeaver.Assembly.GetType("Catel.Fody.TestAssembly.ViewModelBaseTest"); + var type = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.ViewModelBaseTest"); var vm = (dynamic) Activator.CreateInstance(type); // TODO: Test command by setting it and check if property changed is invoked diff --git a/src/Catel.Fody.Tests/app.config b/src/Catel.Fody.Tests/app.config index 7dfd088b..00cdcce6 100644 --- a/src/Catel.Fody.Tests/app.config +++ b/src/Catel.Fody.Tests/app.config @@ -6,6 +6,14 @@ + + + + + + + + \ No newline at end of file diff --git a/src/Catel.Fody.Tests/packages.config b/src/Catel.Fody.Tests/packages.config index 3f3e2b4d..e454c0a7 100644 --- a/src/Catel.Fody.Tests/packages.config +++ b/src/Catel.Fody.Tests/packages.config @@ -1,7 +1,7 @@  - - - + + + \ No newline at end of file diff --git a/src/Catel.Fody.sln.DotSettings b/src/Catel.Fody.sln.DotSettings index 756a427d..1030088f 100644 --- a/src/Catel.Fody.sln.DotSettings +++ b/src/Catel.Fody.sln.DotSettings @@ -1,6 +1,7 @@  SOLUTION - <?xml version="1.0" encoding="utf-16"?><Profile name="Code cleanup"><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSUpdateFileHeader>True</CSUpdateFileHeader><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSReformatCode>True</CSReformatCode><CSReorderTypeMembers>True</CSReorderTypeMembers><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><HtmlReformatCode>True</HtmlReformatCode><CSharpFormatDocComments>False</CSharpFormatDocComments></Profile> + + <?xml version="1.0" encoding="utf-16"?><Profile name="Code cleanup"><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSUpdateFileHeader>True</CSUpdateFileHeader><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSReformatCode>True</CSReformatCode><CSReorderTypeMembers>True</CSReorderTypeMembers><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><HtmlReformatCode>True</HtmlReformatCode><CSharpFormatDocComments>False</CSharpFormatDocComments></Profile> Code cleanup 2 @@ -22,6 +23,7 @@ False False False + False 20 False @@ -29,9 +31,10 @@ 1 OnSingleLine FirstAttributeOnSingleLine + False <?xml version="1.0" encoding="utf-16"?> <Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns"> - <TypePattern Priority="100" DisplayName="Type Pattern"> + <TypePattern DisplayName="COM interfaces or structs"> <TypePattern.Match> <Or> <And> @@ -41,34 +44,33 @@ <HasAttribute Name="System.Runtime.InteropServices.ComImport" /> </Or> </And> - <HasAttribute Name="System.Runtime.InteropServices.StructLayoutAttribute" /> + <Kind Is="Struct" /> </Or> </TypePattern.Match> </TypePattern> - <TypePattern Priority="100" DisplayName="Type Pattern"> + <TypePattern DisplayName="NUnit Test Fixtures" RemoveRegions="All"> <TypePattern.Match> <And> <Kind Is="Class" /> <HasAttribute Name="NUnit.Framework.TestFixtureAttribute" Inherited="True" /> + <HasAttribute Name="NUnit.Framework.TestCaseFixtureAttribute" Inherited="True" /> </And> </TypePattern.Match> - <Region Name="Setup/Teardown"> - <Entry DisplayName="Entry"> - <Entry.Match> - <And> - <Kind Is="Method" /> - <Or> - <HasAttribute Name="NUnit.Framework.SetUpAttribute" Inherited="True" /> - <HasAttribute Name="NUnit.Framework.TearDownAttribute" Inherited="True" /> - <HasAttribute Name="NUnit.Framework.FixtureSetUpAttribute" Inherited="True" /> - <HasAttribute Name="NUnit.Framework.FixtureTearDownAttribute" Inherited="True" /> - </Or> - </And> - </Entry.Match> - </Entry> - </Region> - <Entry DisplayName="Entry" /> - <Entry Priority="100" DisplayName="Entry"> + <Entry DisplayName="Setup/Teardown Methods"> + <Entry.Match> + <And> + <Kind Is="Method" /> + <Or> + <HasAttribute Name="NUnit.Framework.SetUpAttribute" Inherited="True" /> + <HasAttribute Name="NUnit.Framework.TearDownAttribute" Inherited="True" /> + <HasAttribute Name="NUnit.Framework.FixtureSetUpAttribute" Inherited="True" /> + <HasAttribute Name="NUnit.Framework.FixtureTearDownAttribute" Inherited="True" /> + </Or> + </And> + </Entry.Match> + </Entry> + <Entry DisplayName="All other members" /> + <Entry Priority="100" DisplayName="Test Methods"> <Entry.Match> <And> <Kind Is="Method" /> @@ -80,125 +82,90 @@ </Entry.SortBy> </Entry> </TypePattern> - <TypePattern DisplayName="Type Pattern"> - <Region Name="Delegates"> - <Entry Priority="100" DisplayName="Entry"> - <Entry.Match> - <And> - <Access Is="Public" /> - <Kind Is="Delegate" /> - </And> - </Entry.Match> - <Entry.SortBy> - <Name /> - </Entry.SortBy> - </Entry> - </Region> - <Region Name="${0} enum"> - <Region.GroupBy> + <TypePattern DisplayName="Default Pattern"> + <Entry Priority="100" DisplayName="Public Delegates"> + <Entry.Match> + <And> + <Access Is="Public" /> + <Kind Is="Delegate" /> + </And> + </Entry.Match> + <Entry.SortBy> <Name /> - </Region.GroupBy> - <Entry Priority="100" DisplayName="Entry"> - <Entry.Match> - <And> - <Access Is="Public" /> - <Kind Is="Enum" /> - </And> - </Entry.Match> - <Entry.SortBy> - <Name /> - </Entry.SortBy> - </Entry> - </Region> - <Region Name="Constants"> - <Entry DisplayName="Entry"> - <Entry.Match> - <Or> - <Kind Is="Constant" /> - <And> - <Kind Is="Field" /> - <Static /> - </And> - </Or> - </Entry.Match> - <Entry.SortBy> - <Kind Order="Constant Field" /> - </Entry.SortBy> - </Entry> - </Region> - <Region Name="Fields"> - <Entry DisplayName="Entry"> - <Entry.Match> + </Entry.SortBy> + </Entry> + <Entry Priority="100" DisplayName="Public Enums"> + <Entry.Match> + <And> + <Access Is="Public" /> + <Kind Is="Enum" /> + </And> + </Entry.Match> + <Entry.SortBy> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Static Fields and Constants"> + <Entry.Match> + <Or> + <Kind Is="Constant" /> <And> <Kind Is="Field" /> - <Not> - <Static /> - </Not> + <Static /> </And> - </Entry.Match> - <Entry.SortBy> - <Readonly /> - <Name /> - </Entry.SortBy> - </Entry> - </Region> - <Region Name="Constructors"> - <Entry DisplayName="Entry"> - <Entry.Match> - <Kind Is="Constructor" /> - </Entry.Match> - <Entry.SortBy> - <Static /> - </Entry.SortBy> - </Entry> - </Region> - <Region Name="Properties"> - <Entry DisplayName="Entry"> - <Entry.Match> - <Or> - <Kind Is="Property" /> - <Kind Is="Indexer" /> - </Or> - </Entry.Match> - </Entry> - </Region> - <Region Name="${0} Members"> - <Region.GroupBy> - <ImplementsInterface Immediate="True" /> - </Region.GroupBy> - <Entry Priority="100" DisplayName="Entry"> - <Entry.Match> - <And> - <Kind Is="Member" /> - <ImplementsInterface /> - </And> - </Entry.Match> - <Entry.SortBy> - <ImplementsInterface Immediate="True" /> - </Entry.SortBy> - </Entry> - </Region> - <Region Name="Methods"> - <Entry DisplayName="Entry"> - <Entry.Match> - <Kind Is="Method" /> - </Entry.Match> - </Entry> - </Region> - <Entry DisplayName="Entry" /> - <Region Name="Nested type: ${0}"> - <Region.GroupBy> + </Or> + </Entry.Match> + <Entry.SortBy> + <Kind Order="Constant Field" /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Fields"> + <Entry.Match> + <And> + <Kind Is="Field" /> + <Not> + <Static /> + </Not> + </And> + </Entry.Match> + <Entry.SortBy> + <Readonly /> <Name /> - </Region.GroupBy> - <Entry DisplayName="Entry"> - <Entry.Match> - <Kind Is="Type" /> - </Entry.Match> - <Entry.SortBy> - <Name /> - </Entry.SortBy> - </Entry> - </Region> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Constructors"> + <Entry.Match> + <Kind Is="Constructor" /> + </Entry.Match> + <Entry.SortBy> + <Static /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Properties, Indexers"> + <Entry.Match> + <Or> + <Kind Is="Property" /> + <Kind Is="Indexer" /> + </Or> + </Entry.Match> + </Entry> + <Entry Priority="100" DisplayName="Interface Implementations"> + <Entry.Match> + <And> + <Kind Is="Member" /> + <ImplementsInterface /> + </And> + </Entry.Match> + <Entry.SortBy> + <ImplementsInterface Immediate="True" /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="All other members" /> + <Entry DisplayName="Nested Types"> + <Entry.Match> + <Kind Is="Type" /> + </Entry.Match> + </Entry> </TypePattern> </Patterns> <?xml version="1.0" encoding="utf-8" ?> @@ -440,6 +407,7 @@ II.2.12 <HandlesEvent /> True True True + True None <data /> <data><IncludeFilters /><ExcludeFilters /></data> \ No newline at end of file diff --git a/src/Catel.Fody/Catel.Fody.csproj b/src/Catel.Fody/Catel.Fody.csproj index 16475092..71d5821e 100644 --- a/src/Catel.Fody/Catel.Fody.csproj +++ b/src/Catel.Fody/Catel.Fody.csproj @@ -38,25 +38,17 @@ false - - False - ..\..\lib\Mono.Cecil.0.9.6.1\lib\net40\Mono.Cecil.dll - True + + ..\..\lib\FodyCecil.2.0.2\lib\net40\Mono.Cecil.dll - - False - ..\..\lib\Mono.Cecil.0.9.6.1\lib\net40\Mono.Cecil.Mdb.dll - True + + ..\..\lib\FodyCecil.2.0.2\lib\net40\Mono.Cecil.Mdb.dll - - False - ..\..\lib\Mono.Cecil.0.9.6.1\lib\net40\Mono.Cecil.Pdb.dll - True + + ..\..\lib\FodyCecil.2.0.2\lib\net40\Mono.Cecil.Pdb.dll - - False - ..\..\lib\Mono.Cecil.0.9.6.1\lib\net40\Mono.Cecil.Rocks.dll - True + + ..\..\lib\FodyCecil.2.0.2\lib\net40\Mono.Cecil.Rocks.dll @@ -72,6 +64,7 @@ + diff --git a/src/Catel.Fody/Extensions/CecilCatelExtensions.cs b/src/Catel.Fody/Extensions/CecilCatelExtensions.cs index 26149636..68a1d843 100644 --- a/src/Catel.Fody/Extensions/CecilCatelExtensions.cs +++ b/src/Catel.Fody/Extensions/CecilCatelExtensions.cs @@ -3,6 +3,7 @@ // Copyright (c) 2008 - 2013 Catel development team. All rights reserved. // // -------------------------------------------------------------------------------------------------------------------- + namespace Catel.Fody { using System.Collections.Generic; diff --git a/src/Catel.Fody/Extensions/CecilExtensions.assembly.cs b/src/Catel.Fody/Extensions/CecilExtensions.assembly.cs new file mode 100644 index 00000000..d6014d12 --- /dev/null +++ b/src/Catel.Fody/Extensions/CecilExtensions.assembly.cs @@ -0,0 +1,19 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2008 - 2017 Catel development team. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace Catel.Fody +{ + using Mono.Cecil; + + public static partial class CecilExtensions + { + public static AssemblyDefinition Resolve(this IAssemblyResolver assemblyResolver, string name) + { + return assemblyResolver.Resolve(new AssemblyNameReference(name, null)); + } + } +} \ No newline at end of file diff --git a/src/Catel.Fody/Extensions/CecilExtensions.cs b/src/Catel.Fody/Extensions/CecilExtensions.cs index 392afde0..09a0a204 100644 --- a/src/Catel.Fody/Extensions/CecilExtensions.cs +++ b/src/Catel.Fody/Extensions/CecilExtensions.cs @@ -405,15 +405,16 @@ private static IEnumerable BuildIFaces(TypeDefinition type, IDict foreach (var iface in type.Interfaces) { - var result = iface; + var result = iface.InterfaceType; - if (iface is GenericInstanceType) + var genericIface = iface.InterfaceType as GenericInstanceType; + if (genericIface != null) { - var map = GetGenericArgsMap(iface, genericArgsMap, mappedFromSuperType); + var map = GetGenericArgsMap(genericIface, genericArgsMap, mappedFromSuperType); if (mappedFromSuperType.Any()) { - result = ((GenericInstanceType)iface).ElementType.MakeGenericInstanceType(map.Select(x => x.Value).ToArray()); + result = genericIface.ElementType.MakeGenericInstanceType(map.Select(x => x.Value).ToArray()).Import(); } } diff --git a/src/Catel.Fody/Extensions/CecilExtensions.methods.cs b/src/Catel.Fody/Extensions/CecilExtensions.methods.cs index 2c9b5646..0d9e2a0f 100644 --- a/src/Catel.Fody/Extensions/CecilExtensions.methods.cs +++ b/src/Catel.Fody/Extensions/CecilExtensions.methods.cs @@ -16,7 +16,13 @@ public static partial class CecilExtensions { public static SequencePoint GetFirstSequencePoint(this MethodDefinition method) { - return method.Body.Instructions.GetFirstSequencePoint(); + return method.DebugInformation.SequencePoints.FirstOrDefault(); + } + + public static SequencePoint GetSequencePoint(this MethodDefinition method, Instruction instruction) + { + var debugInfo = method.DebugInformation; + return debugInfo.GetSequencePoint(instruction); } public static MethodReference MakeGeneric(this MethodReference method, TypeReference declaringType) diff --git a/src/Catel.Fody/Extensions/InstructionListExtensions.cs b/src/Catel.Fody/Extensions/InstructionListExtensions.cs index 21e1ab89..9a96dc1f 100644 --- a/src/Catel.Fody/Extensions/InstructionListExtensions.cs +++ b/src/Catel.Fody/Extensions/InstructionListExtensions.cs @@ -26,31 +26,6 @@ public static void MoveInstructionsToEnd(this IList instructions, i Insert(instructions, instructions.Count - 1, instructionsToMove); } - public static SequencePoint GetFirstSequencePoint(this IEnumerable instructions) - { - return instructions.Select(x => x.SequencePoint).FirstOrDefault(y => y != null); - } - - public static SequencePoint GetSequencePoint(this IList instructions, Instruction instruction) - { - var index = instructions.IndexOf(instruction); - if (index < 0) - { - return null; - } - - for (int i = index; i >= 0; i--) - { - var ix = instructions[i]; - if (ix.SequencePoint != null) - { - return ix.SequencePoint; - } - } - - return null; - } - public static Instruction GetPreviousInstruction(this IList instructions, Instruction instruction) { var currentIndex = instructions.IndexOf(instruction); diff --git a/src/Catel.Fody/Extensions/TypeReferenceExtensions.cs b/src/Catel.Fody/Extensions/TypeReferenceExtensions.cs index 71da303a..7fc9b944 100644 --- a/src/Catel.Fody/Extensions/TypeReferenceExtensions.cs +++ b/src/Catel.Fody/Extensions/TypeReferenceExtensions.cs @@ -1,6 +1,7 @@ namespace Catel.Fody { using Mono.Cecil; + using System.Linq; public static class TypeReferenceExtensions { @@ -9,15 +10,24 @@ public static bool IsAssignableFrom(this TypeReference target, TypeReference typ { target = type.Module.Import(target).Resolve(); - for (var typeDefinition = type.Resolve(); !typeDefinition.Equals(target) && !typeDefinition.Interfaces.Contains(target); typeDefinition = typeDefinition.BaseType.Resolve()) + var typeDefinition = type.Resolve(); + + while (typeDefinition != null) { - if (typeDefinition.BaseType == null) + if (typeDefinition.Equals(target)) { - return false; + return true; } + + if (typeDefinition.Interfaces.Any(x => x.InterfaceType.Equals(target))) + { + return true; + } + + typeDefinition = typeDefinition.BaseType?.Resolve(); } - return true; + return false; } #endregion } diff --git a/src/Catel.Fody/Weaving/Argument/ArgumentMethodCallWeaverBase.cs b/src/Catel.Fody/Weaving/Argument/ArgumentMethodCallWeaverBase.cs index a7551d7e..ac93b12d 100644 --- a/src/Catel.Fody/Weaving/Argument/ArgumentMethodCallWeaverBase.cs +++ b/src/Catel.Fody/Weaving/Argument/ArgumentMethodCallWeaverBase.cs @@ -49,7 +49,7 @@ public bool Execute(TypeDefinition type, MethodDefinition methodDefinition, { var error = $"[{type.FullName}.{methodDefinition.Name}] {ex.Message}"; - var sequencePoint = methodDefinition.Body.Instructions[instructionIndex].SequencePoint; + var sequencePoint = methodDefinition.GetFirstSequencePoint(); if (sequencePoint != null) { FodyEnvironment.LogErrorPoint(error, sequencePoint); diff --git a/src/Catel.Fody/Weaving/Argument/ArgumentWeaver.cs b/src/Catel.Fody/Weaving/Argument/ArgumentWeaver.cs index 18393100..a63434e1 100644 --- a/src/Catel.Fody/Weaving/Argument/ArgumentWeaver.cs +++ b/src/Catel.Fody/Weaving/Argument/ArgumentWeaver.cs @@ -122,7 +122,7 @@ private void ProcessMethod(MethodDefinition method) var customAttribute = ExpressionChecksToAttributeMappings[fullKey](method, instructions, instruction); if (customAttribute == null) { - FodyEnvironment.LogWarningPoint($"Expression argument method transformation in '{method.GetFullName()}' to '{fullKey}' is not (yet) supported. To ensure the best performance, either rewrite this into a non-expression argument check or create a PR for Catel.Fody to enable support :-)", method.Body.Instructions.GetSequencePoint(instruction)); + FodyEnvironment.LogWarningPoint($"Expression argument method transformation in '{method.GetFullName()}' to '{fullKey}' is not (yet) supported. To ensure the best performance, either rewrite this into a non-expression argument check or create a PR for Catel.Fody to enable support :-)", method.GetSequencePoint(instruction)); continue; } @@ -153,6 +153,16 @@ private void ProcessMethod(MethodDefinition method) RemoveObsoleteCodeForArgumentExpression(method, instructions, displayClass); } } + + // Step 4) Remove double nop commands, start at 1 + // Note: disabled because there might be jump codes to different Nop instructions + //for (int i = 1; i < instructions.Count; i++) + //{ + // if (instructions[i].IsOpCode(OpCodes.Nop) && instructions[i - 1].IsOpCode(OpCodes.Nop)) + // { + // instructions.RemoveAt(i--); + // } + //} } if (instructions != null) diff --git a/src/Catel.Fody/Weaving/Argument/ArgumentWeaver.expressions.cs b/src/Catel.Fody/Weaving/Argument/ArgumentWeaver.expressions.cs index 3f6880db..e502e604 100644 --- a/src/Catel.Fody/Weaving/Argument/ArgumentWeaver.expressions.cs +++ b/src/Catel.Fody/Weaving/Argument/ArgumentWeaver.expressions.cs @@ -51,7 +51,7 @@ private bool IsSupportedExpressionArgumentCheck(MethodDefinition method, Instruc var finalKey = methodBeingCalled.GetFullName(); if (!ExpressionChecksToAttributeMappings.ContainsKey(finalKey)) { - FodyEnvironment.LogWarningPoint($"Expression argument method transformation in '{method.GetFullName()}' to '{methodBeingCalled.GetFullName()}' is not (yet) supported. To ensure the best performance, either rewrite this into a non-expression argument check or create a PR for Catel.Fody to enable support :-)", method.Body.Instructions.GetSequencePoint(instruction)); + FodyEnvironment.LogWarningPoint($"Expression argument method transformation in '{method.GetFullName()}' to '{methodBeingCalled.GetFullName()}' is not (yet) supported. To ensure the best performance, either rewrite this into a non-expression argument check or create a PR for Catel.Fody to enable support :-)", method.GetSequencePoint(instruction)); return false; } @@ -163,11 +163,31 @@ private void RemoveObsoleteCodeForArgumentExpression(MethodDefinition method, Co instructions.RemoveAt(i - 1); } - if (i > 2) + // Special case, we only need to remove when i - 2 is ldlock.s + var additionalIndex = i - 2; + if (additionalIndex >= 0) { - instructions.RemoveAt(i - 2); + var instruction = instructions[additionalIndex]; + if (instruction.IsOpCode(OpCodes.Ldloc_S, OpCodes.Ldloc)) + { + var operand = instruction.Operand as VariableReference; + if (operand != null) + { + var variableType = operand.VariableType; + if (variableType.IsGenericInstance) + { + variableType = variableType.GetElementType(); + } + + if (variableType == displayClassType) + { + instructions.RemoveAt(additionalIndex); + } + } + } } + // Reset index & start over i -= 3; if (i < 0) diff --git a/src/Catel.Fody/Weaving/Logging/LoggingWeaver.cs b/src/Catel.Fody/Weaving/Logging/LoggingWeaver.cs index a05af5e3..c233db08 100644 --- a/src/Catel.Fody/Weaving/Logging/LoggingWeaver.cs +++ b/src/Catel.Fody/Weaving/Logging/LoggingWeaver.cs @@ -89,7 +89,7 @@ private void UpdateCallsToGetCurrentClassLogger(MethodBody ctorBody) var getLoggerMethod = GetGetLoggerMethod(methodReference.DeclaringType); if (getLoggerMethod == null) { - var point = instruction.SequencePoint; + var point = methodReference.Resolve().GetSequencePoint(instruction); var message = $"Cannot change method call for log '{type.FullName}', the GetLogger(type) method does not exist on the calling type (try to use LogManager.GetCurrentClassLogger())"; diff --git a/src/Catel.Fody/Weaving/XmlSchemas/XmlSchemasWeaver.cs b/src/Catel.Fody/Weaving/XmlSchemas/XmlSchemasWeaver.cs index 0ad96954..f93ac9fb 100644 --- a/src/Catel.Fody/Weaving/XmlSchemas/XmlSchemasWeaver.cs +++ b/src/Catel.Fody/Weaving/XmlSchemas/XmlSchemasWeaver.cs @@ -130,7 +130,7 @@ private void AddGetXmlSchemaMethod(CatelType catelType) Instruction.Create(OpCodes.Ret)); getXmlSchemaMethod.Body.InitLocals = true; - getXmlSchemaMethod.Body.Variables.Add(new VariableDefinition("callingType", catelTypeDefinition.Module.Import(catelTypeDefinition.Module.FindType("mscorlib", "System.Type")))); + getXmlSchemaMethod.Body.Variables.Add(new VariableDefinition(catelTypeDefinition.Module.Import(catelTypeDefinition.Module.FindType("mscorlib", "System.Type")))); getXmlSchemaMethod.Body.Variables.Add(new VariableDefinition(catelTypeDefinition.Module.Import(_msCoreReferenceFinder.XmlQualifiedName))); catelTypeDefinition.Methods.Add(getXmlSchemaMethod); diff --git a/src/Catel.Fody/packages.config b/src/Catel.Fody/packages.config index 546c289a..51607be6 100644 --- a/src/Catel.Fody/packages.config +++ b/src/Catel.Fody/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file From 85e1a9e1037b97e8c948e49932c6f7e5338f1d99 Mon Sep 17 00:00:00 2001 From: Geert van Horrik Date: Tue, 25 Apr 2017 10:59:25 +0200 Subject: [PATCH 3/3] Treat warnings as errors --- src/Catel.Fody/Catel.Fody.csproj | 2 + src/Catel.Fody/Core/CatelPropertyWeaver.cs | 20 +- src/Catel.Fody/Core/Models/CatelType.cs | 16 +- src/Catel.Fody/Extensions/CecilExtensions.cs | 6 +- .../Extensions/CecilExtensions.members.cs | 4 +- .../Extensions/CecilExtensions.methods.cs | 2 +- .../Extensions/TypeReferenceExtensions.cs | 2 +- .../Services/XmlSchemasWeaverService.cs | 2 +- .../ArgumentInstructionSequenceBuilder.cs | 292 +++++++++--------- .../Argument/ArgumentMethodCallWeaverBase.cs | 2 +- .../AutoProperties/OnPropertyChangedWeaver.cs | 12 +- .../ExposedPropertiesWeaver.cs | 6 +- .../Weaving/Logging/LoggingWeaver.cs | 2 +- .../Weaving/XmlSchemas/XmlSchemasWeaver.cs | 14 +- src/SolutionAssemblyInfo.cs | 7 +- 15 files changed, 193 insertions(+), 196 deletions(-) diff --git a/src/Catel.Fody/Catel.Fody.csproj b/src/Catel.Fody/Catel.Fody.csproj index 71d5821e..40dbe7f7 100644 --- a/src/Catel.Fody/Catel.Fody.csproj +++ b/src/Catel.Fody/Catel.Fody.csproj @@ -25,6 +25,7 @@ false + true pdbonly @@ -36,6 +37,7 @@ false + true diff --git a/src/Catel.Fody/Core/CatelPropertyWeaver.cs b/src/Catel.Fody/Core/CatelPropertyWeaver.cs index 9c731ae4..df96b390 100644 --- a/src/Catel.Fody/Core/CatelPropertyWeaver.cs +++ b/src/Catel.Fody/Core/CatelPropertyWeaver.cs @@ -144,7 +144,7 @@ private void EnsureStaticConstructor(TypeDefinition type) var voidType = _msCoreReferenceFinder.GetCoreTypeReference("Void"); staticConstructor = new MethodDefinition(".cctor", MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.Static | MethodAttributes.RTSpecialName, - type.Module.Import(voidType)); + type.Module.ImportReference(voidType)); var body = staticConstructor.Body; body.SimplifyMacros(); @@ -176,7 +176,7 @@ private void AddChangeNotificationHandlerField(PropertyDefinition property, Cate //.field private static class [mscorlib]System.EventHandler`1 CS$<>9__CachedAnonymousMethodDelegate1 - var field = new FieldDefinition(fieldName, FieldAttributes.Private | FieldAttributes.Static, declaringType.Module.Import(handlerType)); + var field = new FieldDefinition(fieldName, FieldAttributes.Private | FieldAttributes.Static, declaringType.Module.ImportReference(handlerType)); declaringType.Fields.Add(field); @@ -198,10 +198,10 @@ private void AddChangeNotificationHandlerField(PropertyDefinition property, Cate string initializationMethodName = GetChangeNotificationHandlerConstructorName(property); var initializationMethod = new MethodDefinition(initializationMethodName, - MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static, declaringType.Module.Import(voidType)); + MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static, declaringType.Module.ImportReference(voidType)); - initializationMethod.Parameters.Add(new ParameterDefinition("s", ParameterAttributes.None, declaringType.Module.Import(objectType))); - initializationMethod.Parameters.Add(new ParameterDefinition("e", ParameterAttributes.None, declaringType.Module.Import(advancedPropertyChangedEventArgsType))); + initializationMethod.Parameters.Add(new ParameterDefinition("s", ParameterAttributes.None, declaringType.Module.ImportReference(objectType))); + initializationMethod.Parameters.Add(new ParameterDefinition("e", ParameterAttributes.None, declaringType.Module.ImportReference(advancedPropertyChangedEventArgsType))); var body = initializationMethod.Body; body.Instructions.Insert(0, @@ -345,8 +345,8 @@ private bool AddPropertyRegistration(PropertyDefinition property, CatelTypePrope var importedHandlerType = handlerType.Resolve(); var advancedPropertyChangedEventArgsType = property.Module.FindType("Catel.Core", "Catel.Data.AdvancedPropertyChangedEventArgs"); - var handlerTypeConstructor = declaringType.Module.Import(importedHandlerType.Constructor(false)); - var genericConstructor = handlerTypeConstructor.MakeHostInstanceGeneric(declaringType.Module.Import(advancedPropertyChangedEventArgsType)); + var handlerTypeConstructor = declaringType.Module.ImportReference(importedHandlerType.Constructor(false)); + var genericConstructor = handlerTypeConstructor.MakeHostInstanceGeneric(declaringType.Module.ImportReference(advancedPropertyChangedEventArgsType)); var finalInstruction = Instruction.Create(OpCodes.Ldsfld, handlerField); @@ -468,7 +468,7 @@ private int AddSetValueCall(PropertyDefinition property, FieldReference fieldRef { var voidType = _msCoreReferenceFinder.GetCoreTypeReference("Void"); - var setMethod = new MethodDefinition($"set_{property.Name}", MethodAttributes.Public, property.DeclaringType.Module.Import(voidType)); + var setMethod = new MethodDefinition($"set_{property.Name}", MethodAttributes.Public, property.DeclaringType.Module.ImportReference(voidType)); setMethod.Parameters.Add(new ParameterDefinition(property.PropertyType.Import())); property.DeclaringType.Methods.Add(setMethod); @@ -617,7 +617,7 @@ private void RemoveBackingField(PropertyDefinition property) setter = setter.MakeHostInstanceGeneric(genericInstanceType.GenericArguments.ToArray()); } - instruction.Operand = declaringType.Module.Import(setter); + instruction.Operand = declaringType.Module.ImportReference(setter); // Now move this to the end of the method (we need to call the base ctor first to have the property bag ready) instructions.MoveInstructionsToEnd(i - 2, 3); @@ -635,7 +635,7 @@ private void RemoveBackingField(PropertyDefinition property) getter = getter.MakeHostInstanceGeneric(genericInstanceType.GenericArguments.ToArray()); } - instruction.Operand = declaringType.Module.Import(getter); + instruction.Operand = declaringType.Module.ImportReference(getter); // Now move this to the end of the method (we need to call the base ctor first to have the property bag ready) instructions.MoveInstructionsToEnd(i - 2, 3); diff --git a/src/Catel.Fody/Core/Models/CatelType.cs b/src/Catel.Fody/Core/Models/CatelType.cs index 2ef1b704..e84b9664 100644 --- a/src/Catel.Fody/Core/Models/CatelType.cs +++ b/src/Catel.Fody/Core/Models/CatelType.cs @@ -111,8 +111,8 @@ private void DetermineTypes() { var module = TypeDefinition.Module; - PropertyDataType = module.Import(TypeDefinition.Module.FindType("Catel.Core", "PropertyData")); - AdvancedPropertyChangedEventArgsType = module.Import(TypeDefinition.Module.FindType("Catel.Core", "AdvancedPropertyChangedEventArgs")); + PropertyDataType = module.ImportReference(TypeDefinition.Module.FindType("Catel.Core", "PropertyData")); + AdvancedPropertyChangedEventArgsType = module.ImportReference(TypeDefinition.Module.FindType("Catel.Core", "AdvancedPropertyChangedEventArgs")); } public TypeReference AdvancedPropertyChangedEventArgsType { get; private set; } @@ -124,7 +124,7 @@ public MethodReference BaseOnPropertyChangedInvoker var typeDefinition = TypeDefinition; var baseTypeDefinition = TypeDefinition.BaseType.Resolve(); - return typeDefinition.Module.Import(RecursiveFindMethod(baseTypeDefinition, "OnPropertyChanged")); + return typeDefinition.Module.ImportReference(RecursiveFindMethod(baseTypeDefinition, "OnPropertyChanged")); } } @@ -154,11 +154,11 @@ private bool DetermineMethods() return false; } - RegisterPropertyWithDefaultValueInvoker = module.Import(registerPropertyWithDefaultValueInvokerMethod); - RegisterPropertyWithoutDefaultValueInvoker = module.Import(FindRegisterPropertyMethod(TypeDefinition, false)); - GetValueInvoker = module.Import(RecursiveFindMethod(TypeDefinition, "GetValue", new[] { "property" }, true)); - SetValueInvoker = module.Import(RecursiveFindMethod(TypeDefinition, "SetValue", new[] { "property", "value" })); - RaisePropertyChangedInvoker = module.Import(RecursiveFindMethod(TypeDefinition, "RaisePropertyChanged", new[] { "propertyName" })); + RegisterPropertyWithDefaultValueInvoker = module.ImportReference(registerPropertyWithDefaultValueInvokerMethod); + RegisterPropertyWithoutDefaultValueInvoker = module.ImportReference(FindRegisterPropertyMethod(TypeDefinition, false)); + GetValueInvoker = module.ImportReference(RecursiveFindMethod(TypeDefinition, "GetValue", new[] { "property" }, true)); + SetValueInvoker = module.ImportReference(RecursiveFindMethod(TypeDefinition, "SetValue", new[] { "property", "value" })); + RaisePropertyChangedInvoker = module.ImportReference(RecursiveFindMethod(TypeDefinition, "RaisePropertyChanged", new[] { "propertyName" })); return true; } diff --git a/src/Catel.Fody/Extensions/CecilExtensions.cs b/src/Catel.Fody/Extensions/CecilExtensions.cs index 09a0a204..49f8c362 100644 --- a/src/Catel.Fody/Extensions/CecilExtensions.cs +++ b/src/Catel.Fody/Extensions/CecilExtensions.cs @@ -41,11 +41,11 @@ public static TypeReference Import(this TypeReference typeReference, bool checkF var nullableValueType = typeReference.GetNullableValueType(); if (nullableValueType != null) { - return module.Import(nullableValueType); + return module.ImportReference(nullableValueType); } } - return module.Import(typeReference); + return module.ImportReference(typeReference); } public static MethodReference FindConstructor(this TypeDefinition typeReference, List types) @@ -241,7 +241,7 @@ public static MethodReference GetMethodAndImport(this ModuleDefinition module, s return method; } - return module.Import(method); + return module.ImportReference(method); } public static MethodReference GetMethod(this ModuleDefinition module, string methodName) diff --git a/src/Catel.Fody/Extensions/CecilExtensions.members.cs b/src/Catel.Fody/Extensions/CecilExtensions.members.cs index 6a20144f..c66511a0 100644 --- a/src/Catel.Fody/Extensions/CecilExtensions.members.cs +++ b/src/Catel.Fody/Extensions/CecilExtensions.members.cs @@ -138,7 +138,7 @@ private static CustomAttribute CreateGeneratedCodeAttribute(MsCoreReferenceFinde var version = typeof(ModuleWeaver).Assembly.GetName().Version.ToString(); var name = typeof(ModuleWeaver).Assembly.GetName().Name; - var generatedAttribute = new CustomAttribute(importingModule.Import(constructor)); + var generatedAttribute = new CustomAttribute(importingModule.ImportReference(constructor)); generatedAttribute.ConstructorArguments.Add(new CustomAttributeArgument(stringType, name)); generatedAttribute.ConstructorArguments.Add(new CustomAttributeArgument(stringType, version)); @@ -153,7 +153,7 @@ private static CustomAttribute CreateDebuggerNonUserCodeAttribute(MsCoreReferenc return null; } - var attribute = new CustomAttribute(importingModule.Import(attributeType.Resolve().Constructor(false))); + var attribute = new CustomAttribute(importingModule.ImportReference(attributeType.Resolve().Constructor(false))); return attribute; } } diff --git a/src/Catel.Fody/Extensions/CecilExtensions.methods.cs b/src/Catel.Fody/Extensions/CecilExtensions.methods.cs index 0d9e2a0f..7a8ec2d9 100644 --- a/src/Catel.Fody/Extensions/CecilExtensions.methods.cs +++ b/src/Catel.Fody/Extensions/CecilExtensions.methods.cs @@ -45,7 +45,7 @@ public static MethodReference MakeGeneric(this MethodReference method, TypeRefer public static MethodReference GetMethodReference(this MethodDefinition methodDefinition, Stack typeDefinitions) { - var methodReference = FodyEnvironment.ModuleDefinition.Import(methodDefinition).GetGeneric(); + var methodReference = FodyEnvironment.ModuleDefinition.ImportReference(methodDefinition).GetGeneric(); if (methodDefinition.IsStatic) { diff --git a/src/Catel.Fody/Extensions/TypeReferenceExtensions.cs b/src/Catel.Fody/Extensions/TypeReferenceExtensions.cs index 7fc9b944..92396352 100644 --- a/src/Catel.Fody/Extensions/TypeReferenceExtensions.cs +++ b/src/Catel.Fody/Extensions/TypeReferenceExtensions.cs @@ -8,7 +8,7 @@ public static class TypeReferenceExtensions #region Methods public static bool IsAssignableFrom(this TypeReference target, TypeReference type) { - target = type.Module.Import(target).Resolve(); + target = type.Module.ImportReference(target).Resolve(); var typeDefinition = type.Resolve(); diff --git a/src/Catel.Fody/Services/XmlSchemasWeaverService.cs b/src/Catel.Fody/Services/XmlSchemasWeaverService.cs index bc53f9b1..f420c1a5 100644 --- a/src/Catel.Fody/Services/XmlSchemasWeaverService.cs +++ b/src/Catel.Fody/Services/XmlSchemasWeaverService.cs @@ -38,7 +38,7 @@ public void Execute() xmlSchemaWeaver.Execute(catelTypeNode); } - catch (Exception ex) + catch (Exception) { #if DEBUG System.Diagnostics.Debugger.Launch(); diff --git a/src/Catel.Fody/Weaving/Argument/ArgumentInstructionSequenceBuilder.cs b/src/Catel.Fody/Weaving/Argument/ArgumentInstructionSequenceBuilder.cs index 634c0a07..6d1856a8 100644 --- a/src/Catel.Fody/Weaving/Argument/ArgumentInstructionSequenceBuilder.cs +++ b/src/Catel.Fody/Weaving/Argument/ArgumentInstructionSequenceBuilder.cs @@ -1,147 +1,147 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2008 - 2013 Catel development team. All rights reserved. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace Catel.Fody.Weaving.Argument -{ - using System.Collections.Generic; - using System.Text.RegularExpressions; - - using Mono.Cecil; - using Mono.Cecil.Cil; - - internal static class ArgumentInstructionSequenceBuilder - { - #region Methods - public static IEnumerable BuildRegexRelatedInstructions(ParameterDefinition parameter, CustomAttribute attribute) - { - return BuildRegexRelatedInstructionsInternal(parameter, attribute); - } - - public static IEnumerable BuildRegexRelatedInstructions(FieldDefinition field, CustomAttribute attribute) - { - return BuildRegexRelatedInstructionsInternal(field, attribute); - } - - private static IEnumerable BuildRegexRelatedInstructionsInternal(object parameterDefinitionOrFieldDefinition, CustomAttribute attribute) - { - var pattern = (string)attribute.ConstructorArguments[0].Value; - var regexOptions = (RegexOptions)attribute.ConstructorArguments[1].Value; - - foreach (var instruction in BuildDefaultInstructionsInternal(parameterDefinitionOrFieldDefinition)) - { - yield return instruction; - } - - yield return Instruction.Create(OpCodes.Ldstr, pattern); - yield return Instruction.Create(OpCodes.Ldc_I4, (int)regexOptions); - } - - public static IEnumerable BuildDefaultInstructions(ParameterDefinition parameter) - { - yield return Instruction.Create(OpCodes.Ldstr, parameter.Name); - yield return Instruction.Create(OpCodes.Ldarg_S, parameter); - - if (parameter.ParameterType.IsBoxingRequired(parameter.ParameterType)) - { - yield return Instruction.Create(OpCodes.Box, parameter.ParameterType.Import()); - } - } - - public static IEnumerable BuildDefaultInstructions(FieldDefinition field) - { - yield return Instruction.Create(OpCodes.Ldstr, field.Name); - yield return Instruction.Create(OpCodes.Ldarg_0); - yield return Instruction.Create(OpCodes.Ldfld, field); - - if (field.FieldType.IsBoxingRequired(field.FieldType)) - { - yield return Instruction.Create(OpCodes.Box, field.FieldType.Import()); - } - } - - private static IEnumerable BuildDefaultInstructionsInternal(object parameterDefinitionOrFieldDefinition) - { - var fieldDefinition = parameterDefinitionOrFieldDefinition as FieldDefinition; - if (fieldDefinition != null) - { - return BuildDefaultInstructions(fieldDefinition); - } - - var parameterDefinition = parameterDefinitionOrFieldDefinition as ParameterDefinition; - if (parameterDefinitionOrFieldDefinition != null) - { - return BuildDefaultInstructions(parameterDefinition); - } - - return null; - } - - public static IEnumerable BuildTypeCheckRelatedInstructions(ModuleDefinition module, object parameterDefinitionOrFieldDefinition, CustomAttribute attribute) - { - var typeReference = (TypeReference)attribute.ConstructorArguments[0].Value; - foreach (var instruction in BuildDefaultInstructionsInternal(parameterDefinitionOrFieldDefinition)) - { - yield return instruction; - } - - var importedGetTypeFromHandle = module.Import(module.GetMethod("GetTypeFromHandle")); - - yield return Instruction.Create(OpCodes.Ldtoken, typeReference); - yield return Instruction.Create(OpCodes.Call, importedGetTypeFromHandle); - } - - public static IEnumerable BuildBoundariesCheckInstructions(object parameterDefinitionOrFieldDefinition, CustomAttribute attribute) - { - foreach (var instruction in BuildDefaultInstructionsInternal(parameterDefinitionOrFieldDefinition)) - { - yield return instruction; - } - - foreach (var argument in attribute.ConstructorArguments) - { - object value = argument.Value; - if (value is string) - { - yield return Instruction.Create(OpCodes.Ldstr, (string)value); - } - else if (value is int) - { - yield return Instruction.Create(OpCodes.Ldc_I4, (int)value); - } - else if (value is long) - { - foreach (var instruction in BuildLongInstructions(value)) - { - yield return instruction; - } - } - else if (value is float) - { - yield return Instruction.Create(OpCodes.Ldc_R4, (float)value); - } - else if (value is double) - { - yield return Instruction.Create(OpCodes.Ldc_R8, (double)value); - } - } - } - - private static IEnumerable BuildLongInstructions(object minValue) - { - if ((long)minValue <= int.MaxValue) - { - // Note: don't use Ldc_I8 here, although it is a long - yield return Instruction.Create(OpCodes.Ldc_I4, (int)(long)minValue); - yield return Instruction.Create(OpCodes.Conv_I8); - } - else - { - yield return Instruction.Create(OpCodes.Ldc_I8, (long)minValue); - } - } - #endregion - } +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2008 - 2013 Catel development team. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace Catel.Fody.Weaving.Argument +{ + using System.Collections.Generic; + using System.Text.RegularExpressions; + + using Mono.Cecil; + using Mono.Cecil.Cil; + + internal static class ArgumentInstructionSequenceBuilder + { + #region Methods + public static IEnumerable BuildRegexRelatedInstructions(ParameterDefinition parameter, CustomAttribute attribute) + { + return BuildRegexRelatedInstructionsInternal(parameter, attribute); + } + + public static IEnumerable BuildRegexRelatedInstructions(FieldDefinition field, CustomAttribute attribute) + { + return BuildRegexRelatedInstructionsInternal(field, attribute); + } + + private static IEnumerable BuildRegexRelatedInstructionsInternal(object parameterDefinitionOrFieldDefinition, CustomAttribute attribute) + { + var pattern = (string)attribute.ConstructorArguments[0].Value; + var regexOptions = (RegexOptions)attribute.ConstructorArguments[1].Value; + + foreach (var instruction in BuildDefaultInstructionsInternal(parameterDefinitionOrFieldDefinition)) + { + yield return instruction; + } + + yield return Instruction.Create(OpCodes.Ldstr, pattern); + yield return Instruction.Create(OpCodes.Ldc_I4, (int)regexOptions); + } + + public static IEnumerable BuildDefaultInstructions(ParameterDefinition parameter) + { + yield return Instruction.Create(OpCodes.Ldstr, parameter.Name); + yield return Instruction.Create(OpCodes.Ldarg_S, parameter); + + if (parameter.ParameterType.IsBoxingRequired(parameter.ParameterType)) + { + yield return Instruction.Create(OpCodes.Box, parameter.ParameterType.Import()); + } + } + + public static IEnumerable BuildDefaultInstructions(FieldDefinition field) + { + yield return Instruction.Create(OpCodes.Ldstr, field.Name); + yield return Instruction.Create(OpCodes.Ldarg_0); + yield return Instruction.Create(OpCodes.Ldfld, field); + + if (field.FieldType.IsBoxingRequired(field.FieldType)) + { + yield return Instruction.Create(OpCodes.Box, field.FieldType.Import()); + } + } + + private static IEnumerable BuildDefaultInstructionsInternal(object parameterDefinitionOrFieldDefinition) + { + var fieldDefinition = parameterDefinitionOrFieldDefinition as FieldDefinition; + if (fieldDefinition != null) + { + return BuildDefaultInstructions(fieldDefinition); + } + + var parameterDefinition = parameterDefinitionOrFieldDefinition as ParameterDefinition; + if (parameterDefinitionOrFieldDefinition != null) + { + return BuildDefaultInstructions(parameterDefinition); + } + + return null; + } + + public static IEnumerable BuildTypeCheckRelatedInstructions(ModuleDefinition module, object parameterDefinitionOrFieldDefinition, CustomAttribute attribute) + { + var typeReference = (TypeReference)attribute.ConstructorArguments[0].Value; + foreach (var instruction in BuildDefaultInstructionsInternal(parameterDefinitionOrFieldDefinition)) + { + yield return instruction; + } + + var importedGetTypeFromHandle = module.ImportReference(module.GetMethod("GetTypeFromHandle")); + + yield return Instruction.Create(OpCodes.Ldtoken, typeReference); + yield return Instruction.Create(OpCodes.Call, importedGetTypeFromHandle); + } + + public static IEnumerable BuildBoundariesCheckInstructions(object parameterDefinitionOrFieldDefinition, CustomAttribute attribute) + { + foreach (var instruction in BuildDefaultInstructionsInternal(parameterDefinitionOrFieldDefinition)) + { + yield return instruction; + } + + foreach (var argument in attribute.ConstructorArguments) + { + object value = argument.Value; + if (value is string) + { + yield return Instruction.Create(OpCodes.Ldstr, (string)value); + } + else if (value is int) + { + yield return Instruction.Create(OpCodes.Ldc_I4, (int)value); + } + else if (value is long) + { + foreach (var instruction in BuildLongInstructions(value)) + { + yield return instruction; + } + } + else if (value is float) + { + yield return Instruction.Create(OpCodes.Ldc_R4, (float)value); + } + else if (value is double) + { + yield return Instruction.Create(OpCodes.Ldc_R8, (double)value); + } + } + } + + private static IEnumerable BuildLongInstructions(object minValue) + { + if ((long)minValue <= int.MaxValue) + { + // Note: don't use Ldc_I8 here, although it is a long + yield return Instruction.Create(OpCodes.Ldc_I4, (int)(long)minValue); + yield return Instruction.Create(OpCodes.Conv_I8); + } + else + { + yield return Instruction.Create(OpCodes.Ldc_I8, (long)minValue); + } + } + #endregion + } } \ No newline at end of file diff --git a/src/Catel.Fody/Weaving/Argument/ArgumentMethodCallWeaverBase.cs b/src/Catel.Fody/Weaving/Argument/ArgumentMethodCallWeaverBase.cs index ac93b12d..08c2fd33 100644 --- a/src/Catel.Fody/Weaving/Argument/ArgumentMethodCallWeaverBase.cs +++ b/src/Catel.Fody/Weaving/Argument/ArgumentMethodCallWeaverBase.cs @@ -69,7 +69,7 @@ public bool Execute(TypeDefinition type, MethodDefinition methodDefinition, } var moduleDefinition = type.Module; - var importedMethod = moduleDefinition.Import(selectedMethod); + var importedMethod = moduleDefinition.ImportReference(selectedMethod); var instructions = new List(); diff --git a/src/Catel.Fody/Weaving/AutoProperties/OnPropertyChangedWeaver.cs b/src/Catel.Fody/Weaving/AutoProperties/OnPropertyChangedWeaver.cs index 1b6837f7..e315c4d4 100644 --- a/src/Catel.Fody/Weaving/AutoProperties/OnPropertyChangedWeaver.cs +++ b/src/Catel.Fody/Weaving/AutoProperties/OnPropertyChangedWeaver.cs @@ -42,8 +42,8 @@ public void Execute() private bool AddOrUpdateOnPropertyChangedMethod(PropertyDefinition property) { - var getMethodReference = _catelType.TypeDefinition.Module.Import(_catelType.AdvancedPropertyChangedEventArgsType.GetProperty("PropertyName").Resolve().GetMethod); - var stringEqualsMethodReference = _catelType.TypeDefinition.Module.Import(GetSystemObjectEqualsMethodReference(_catelType.TypeDefinition.Module)); + var getMethodReference = _catelType.TypeDefinition.Module.ImportReference(_catelType.AdvancedPropertyChangedEventArgsType.GetProperty("PropertyName").Resolve().GetMethod); + var stringEqualsMethodReference = _catelType.TypeDefinition.Module.ImportReference(GetSystemObjectEqualsMethodReference(_catelType.TypeDefinition.Module)); var dependentProperties = _catelType.GetDependentPropertiesFrom(property).ToList(); if (dependentProperties.Count > 0 && !dependentProperties.All(definition => _catelType.NoWeavingProperties.Contains(definition))) @@ -58,7 +58,7 @@ private bool AddOrUpdateOnPropertyChangedMethod(PropertyDefinition property) var idx = onPropertyChangedMethod.Body.Instructions.ToList().FindLastIndex(instruction => instruction.OpCode == OpCodes.Ret); if (idx > -1) { - var booleanTypeReference = _catelType.TypeDefinition.Module.Import(_msCoreReferenceFinder.GetCoreTypeReference("Boolean")); + var booleanTypeReference = _catelType.TypeDefinition.Module.ImportReference(_msCoreReferenceFinder.GetCoreTypeReference("Boolean")); if (onPropertyChangedMethod.Body.Variables.ToList().FirstOrDefault(definition => definition.VariableType != booleanTypeReference) == null) { onPropertyChangedMethod.Body.Variables.Add(new VariableDefinition(booleanTypeReference)); @@ -131,7 +131,7 @@ private MethodDefinition EnsureOnPropertyChangedMethod() { var voidType = _msCoreReferenceFinder.GetCoreTypeReference("Void"); - methodDefinition = new MethodDefinition("OnPropertyChanged", MethodAttributes.Family | MethodAttributes.HideBySig | MethodAttributes.Virtual, type.Module.Import(voidType)); + methodDefinition = new MethodDefinition("OnPropertyChanged", MethodAttributes.Family | MethodAttributes.HideBySig | MethodAttributes.Virtual, type.Module.ImportReference(voidType)); methodDefinition.Parameters.Add(new ParameterDefinition("e", ParameterAttributes.None, _catelType.AdvancedPropertyChangedEventArgsType)); var body = methodDefinition.Body; @@ -155,7 +155,7 @@ private MethodDefinition EnsureOnPropertyChangedMethod() { // Note: need to replace call to base, otherwise it might skip a call to a just generated base member var body = methodDefinition.Body; - var hasReplaced = false; + //var hasReplaced = false; body.SimplifyMacros(); @@ -167,7 +167,7 @@ private MethodDefinition EnsureOnPropertyChangedMethod() if ((methodReference != null) && string.Equals(methodReference.Name, baseOnPropertyChangedInvoker.Name)) { instruction.Operand = baseOnPropertyChangedInvoker; - hasReplaced = true; + //hasReplaced = true; } } } diff --git a/src/Catel.Fody/Weaving/ExposedProperties/ExposedPropertiesWeaver.cs b/src/Catel.Fody/Weaving/ExposedProperties/ExposedPropertiesWeaver.cs index 57ec4c61..9a889f9c 100644 --- a/src/Catel.Fody/Weaving/ExposedProperties/ExposedPropertiesWeaver.cs +++ b/src/Catel.Fody/Weaving/ExposedProperties/ExposedPropertiesWeaver.cs @@ -86,7 +86,7 @@ where string.Equals(property.Name, "IsReadOnly") var modelPropertyType = modelPropertyToMap.PropertyType; - var viewModelPropertyDefinition = new PropertyDefinition(viewModelPropertyName, PropertyAttributes.None, FodyEnvironment.ModuleDefinition.Import(modelPropertyType)); + var viewModelPropertyDefinition = new PropertyDefinition(viewModelPropertyName, PropertyAttributes.None, FodyEnvironment.ModuleDefinition.ImportReference(modelPropertyType)); viewModelPropertyDefinition.DeclaringType = catelType.TypeDefinition; catelType.TypeDefinition.Properties.Add(viewModelPropertyDefinition); @@ -100,9 +100,9 @@ where string.Equals(property.Name, "IsReadOnly") catelPropertyWeaver.Execute(true); var stringType = _msCoreReferenceFinder.GetCoreTypeReference("String"); - var stringTypeDefinition = catelType.TypeDefinition.Module.Import(stringType); + var stringTypeDefinition = catelType.TypeDefinition.Module.ImportReference(stringType); - var attributeConstructor = catelType.TypeDefinition.Module.Import(ViewModelToModelAttributeTypeDefinition.Constructor(false)); + var attributeConstructor = catelType.TypeDefinition.Module.ImportReference(ViewModelToModelAttributeTypeDefinition.Constructor(false)); var viewModelToModelAttribute = new CustomAttribute(attributeConstructor); viewModelToModelAttribute.ConstructorArguments.Add(new CustomAttributeArgument(stringTypeDefinition, modelName)); viewModelToModelAttribute.ConstructorArguments.Add(new CustomAttributeArgument(stringTypeDefinition, modelPropertyName)); diff --git a/src/Catel.Fody/Weaving/Logging/LoggingWeaver.cs b/src/Catel.Fody/Weaving/Logging/LoggingWeaver.cs index c233db08..fd05f541 100644 --- a/src/Catel.Fody/Weaving/Logging/LoggingWeaver.cs +++ b/src/Catel.Fody/Weaving/Logging/LoggingWeaver.cs @@ -111,7 +111,7 @@ private void UpdateCallsToGetCurrentClassLogger(MethodBody ctorBody) instructions.Insert(i, Instruction.Create(OpCodes.Ldtoken, type), Instruction.Create(OpCodes.Call, getTypeFromHandle), - Instruction.Create(OpCodes.Call, type.Module.Import(getLoggerMethod))); + Instruction.Create(OpCodes.Call, type.Module.ImportReference(getLoggerMethod))); } } } diff --git a/src/Catel.Fody/Weaving/XmlSchemas/XmlSchemasWeaver.cs b/src/Catel.Fody/Weaving/XmlSchemas/XmlSchemasWeaver.cs index f93ac9fb..ef8ebebd 100644 --- a/src/Catel.Fody/Weaving/XmlSchemas/XmlSchemasWeaver.cs +++ b/src/Catel.Fody/Weaving/XmlSchemas/XmlSchemasWeaver.cs @@ -69,7 +69,7 @@ where string.Equals(attribute.AttributeType.Name, "XmlSchemaProviderAttribute") var xmlSchemaProviderAttribute = catelTypeDefinition.Module.FindType("System.Xml", "System.Xml.Serialization.XmlSchemaProviderAttribute"); - var attributeConstructor = catelTypeDefinition.Module.Import(xmlSchemaProviderAttribute.Resolve().Constructor(false)); + var attributeConstructor = catelTypeDefinition.Module.ImportReference(xmlSchemaProviderAttribute.Resolve().Constructor(false)); var customAttribute = new CustomAttribute(attributeConstructor); customAttribute.ConstructorArguments.Add(new CustomAttributeArgument(catelTypeDefinition.Module.TypeSystem.String, methodName)); @@ -93,7 +93,7 @@ private void AddGetXmlSchemaMethod(CatelType catelType) } var getTypeFromHandle = catelTypeDefinition.Module.GetMethod("GetTypeFromHandle"); - var importedGetTypeFromHandle = catelTypeDefinition.Module.Import(getTypeFromHandle); + var importedGetTypeFromHandle = catelTypeDefinition.Module.ImportReference(getTypeFromHandle); var xmlSchemaManager = (TypeDefinition)catelTypeDefinition.Module.FindType("Catel.Core", "Catel.Runtime.Serialization.Xml.XmlSchemaManager"); if (xmlSchemaManager == null) @@ -102,7 +102,7 @@ private void AddGetXmlSchemaMethod(CatelType catelType) xmlSchemaManager = (TypeDefinition)catelTypeDefinition.Module.FindType("Catel.Core", "Catel.Runtime.Serialization.XmlSchemaManager"); } - var getXmlSchemaMethodOnXmlSchemaManager = catelTypeDefinition.Module.Import(xmlSchemaManager.Methods.First(x => x.IsStatic && x.Name == "GetXmlSchema")); + var getXmlSchemaMethodOnXmlSchemaManager = catelTypeDefinition.Module.ImportReference(xmlSchemaManager.Methods.First(x => x.IsStatic && x.Name == "GetXmlSchema")); //public static XmlQualifiedName GetXmlSchema(XmlSchemaSet schemas) //{ @@ -110,9 +110,9 @@ private void AddGetXmlSchemaMethod(CatelType catelType) // return XmlSchemaManager.GetXmlSchema(callingType, schemas); //} - var getXmlSchemaMethod = new MethodDefinition(methodName, MethodAttributes.Public | MethodAttributes.Static, catelTypeDefinition.Module.Import(_msCoreReferenceFinder.XmlQualifiedName)); + var getXmlSchemaMethod = new MethodDefinition(methodName, MethodAttributes.Public | MethodAttributes.Static, catelTypeDefinition.Module.ImportReference(_msCoreReferenceFinder.XmlQualifiedName)); - getXmlSchemaMethod.Parameters.Add(new ParameterDefinition("xmlSchemaSet", ParameterAttributes.None, catelTypeDefinition.Module.Import(_msCoreReferenceFinder.XmlSchemaSet))); + getXmlSchemaMethod.Parameters.Add(new ParameterDefinition("xmlSchemaSet", ParameterAttributes.None, catelTypeDefinition.Module.ImportReference(_msCoreReferenceFinder.XmlSchemaSet))); var ldloc1Instruction = Instruction.Create(OpCodes.Ldloc_1); @@ -130,8 +130,8 @@ private void AddGetXmlSchemaMethod(CatelType catelType) Instruction.Create(OpCodes.Ret)); getXmlSchemaMethod.Body.InitLocals = true; - getXmlSchemaMethod.Body.Variables.Add(new VariableDefinition(catelTypeDefinition.Module.Import(catelTypeDefinition.Module.FindType("mscorlib", "System.Type")))); - getXmlSchemaMethod.Body.Variables.Add(new VariableDefinition(catelTypeDefinition.Module.Import(_msCoreReferenceFinder.XmlQualifiedName))); + getXmlSchemaMethod.Body.Variables.Add(new VariableDefinition(catelTypeDefinition.Module.ImportReference(catelTypeDefinition.Module.FindType("mscorlib", "System.Type")))); + getXmlSchemaMethod.Body.Variables.Add(new VariableDefinition(catelTypeDefinition.Module.ImportReference(_msCoreReferenceFinder.XmlQualifiedName))); catelTypeDefinition.Methods.Add(getXmlSchemaMethod); diff --git a/src/SolutionAssemblyInfo.cs b/src/SolutionAssemblyInfo.cs index ca3e7fc4..0c21bcd9 100644 --- a/src/SolutionAssemblyInfo.cs +++ b/src/SolutionAssemblyInfo.cs @@ -33,9 +33,4 @@ // by using the '*' as shown below: [assembly: AssemblyVersion("1.5.4")] -[assembly: AssemblyInformationalVersion("1.5.4, manual release in Visual Studio")] - -// CLS compliant -#if !NETFX_CORE -[assembly: CLSCompliant(true)] -#endif \ No newline at end of file +[assembly: AssemblyInformationalVersion("1.5.4, manual release in Visual Studio")] \ No newline at end of file