Merge pull request #36 from nventive/dev/cdb/stylecop-support
Added better support for StyleCop
This commit is contained in:
Коммит
807999f017
|
@ -121,8 +121,14 @@ namespace Uno.CodeGen.ClassLifecycle
|
|||
: null;
|
||||
|
||||
var code = new StringWriter();
|
||||
using (var writer = new IndentedTextWriter(code))
|
||||
using (var writer = new IndentedTextWriter(code, "\t"))
|
||||
{
|
||||
writer.WriteLine("// <auto-generated>");
|
||||
writer.WriteLine("// ***************************************************************************************************************************");
|
||||
writer.WriteLine("// This file has been generated by Uno.CodeGen (ClassLifecycleGenerator), available at https://github.com/nventive/Uno.CodeGen");
|
||||
writer.WriteLine("// ***************************************************************************************************************************");
|
||||
writer.WriteLine("// </auto-generated>");
|
||||
writer.WriteLine();
|
||||
writer.WriteLine("using global::System;");
|
||||
|
||||
using (writer.NameSpaceOf(methods.Owner))
|
||||
|
|
|
@ -27,7 +27,7 @@ using Uno.Extensions;
|
|||
namespace Uno.CodeGen.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public partial class Given_ClassLifecycle
|
||||
public partial class Given_ClassLifecycle
|
||||
{
|
||||
#region When_SimulateLifetimeOfObject_Then_AllMethodInvoked
|
||||
[TestMethod]
|
||||
|
@ -82,9 +82,14 @@ namespace Uno.CodeGen.Tests
|
|||
Initialize();
|
||||
}
|
||||
|
||||
[ConstructorMethod] public void BaseConstructor() => _counter.Constructed++;
|
||||
[DisposeMethod] public void BaseDispose() => _counter.Disposed++;
|
||||
[FinalizerMethod] public void BaseFinalizer() => _counter.Finalized++;
|
||||
[ConstructorMethod]
|
||||
public void BaseConstructor() => _counter.Constructed++;
|
||||
|
||||
[DisposeMethod]
|
||||
public void BaseDispose() => _counter.Disposed++;
|
||||
|
||||
[FinalizerMethod]
|
||||
public void BaseFinalizer() => _counter.Finalized++;
|
||||
}
|
||||
|
||||
private partial class When_InheritFromAnotherLifecycleObject_Then_AllMethodInvoked_Subject : When_InheritFromAnotherLifecycleObject_Then_AllMethodInvoked_Base
|
||||
|
@ -95,9 +100,14 @@ namespace Uno.CodeGen.Tests
|
|||
Initialize();
|
||||
}
|
||||
|
||||
[ConstructorMethod] public void ChildConstructor() => _counter.Constructed++;
|
||||
[DisposeMethod] public void ChildDispose() => _counter.Disposed++;
|
||||
[FinalizerMethod] public void ChildFinalizer() => _counter.Finalized++;
|
||||
[ConstructorMethod]
|
||||
public void ChildConstructor() => _counter.Constructed++;
|
||||
|
||||
[DisposeMethod]
|
||||
public void ChildDispose() => _counter.Disposed++;
|
||||
|
||||
[FinalizerMethod]
|
||||
public void ChildFinalizer() => _counter.Finalized++;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -107,11 +117,15 @@ namespace Uno.CodeGen.Tests
|
|||
{
|
||||
Assert.AreEqual(1, new When_RealConstructor_InvokesInitialize_Subject().Constructed);
|
||||
}
|
||||
|
||||
private partial class When_RealConstructor_InvokesInitialize_Subject
|
||||
{
|
||||
public int Constructed { get; set; }
|
||||
|
||||
public When_RealConstructor_InvokesInitialize_Subject() => Initialize();
|
||||
[ConstructorMethod] public void MyConstructor() => Constructed++;
|
||||
|
||||
[ConstructorMethod]
|
||||
public void MyConstructor() => Constructed++;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -155,13 +169,24 @@ namespace Uno.CodeGen.Tests
|
|||
Assert.AreEqual(1, new When_RealConstructor_InvokesParameterLessContructor_Subject("").Constructed);
|
||||
Assert.AreEqual(1, new When_RealConstructor_InvokesParameterLessContructor_Subject(0).Constructed);
|
||||
}
|
||||
|
||||
private partial class When_RealConstructor_InvokesParameterLessContructor_Subject
|
||||
{
|
||||
public int Constructed { get; private set; }
|
||||
public When_RealConstructor_InvokesParameterLessContructor_Subject(string test) : this() { }
|
||||
public When_RealConstructor_InvokesParameterLessContructor_Subject(int integer) : this(integer.ToString()) { }
|
||||
[ConstructorMethod] public void MyConstructor() => Constructed++;
|
||||
}
|
||||
|
||||
public When_RealConstructor_InvokesParameterLessContructor_Subject(string test)
|
||||
: this()
|
||||
{
|
||||
}
|
||||
|
||||
public When_RealConstructor_InvokesParameterLessContructor_Subject(int integer)
|
||||
: this(integer.ToString())
|
||||
{
|
||||
}
|
||||
|
||||
[ConstructorMethod]
|
||||
public void MyConstructor() => Constructed++;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region When_Constructor_With_NullableParameter
|
||||
|
@ -172,7 +197,7 @@ namespace Uno.CodeGen.Tests
|
|||
public void MyConstructor(int? value)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region When_Constructor_With_NullableOptionalParameter
|
||||
|
@ -183,7 +208,7 @@ namespace Uno.CodeGen.Tests
|
|||
public void MyConstructor(int? value = null)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region When_Constructor_With_OptionalParameter
|
||||
|
@ -194,7 +219,7 @@ namespace Uno.CodeGen.Tests
|
|||
public void MyConstructor(When_Constructor_With_OptionalParameter value = null)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region When_Constructor_With_OptionalParameter_And_DefaultValue_Then_DefaultValueCopied
|
||||
|
@ -213,7 +238,7 @@ namespace Uno.CodeGen.Tests
|
|||
}
|
||||
|
||||
public int? Value { get; set; }
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region When_Constructors_With_Parameters_Then_ParametersAggregatedOnInitialize
|
||||
|
@ -250,7 +275,7 @@ namespace Uno.CodeGen.Tests
|
|||
// public void MyConstructor2(int value)
|
||||
// {
|
||||
// }
|
||||
//}
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region When_Constructors_With_OptionalParameters_And_DefaultValueMismatch_Then_Fails
|
||||
|
@ -266,7 +291,7 @@ namespace Uno.CodeGen.Tests
|
|||
// public void MyConstructor2(int value = 6)
|
||||
// {
|
||||
// }
|
||||
//}
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region When_Dispose_With_Parameter_Then_Fails
|
||||
|
@ -300,19 +325,25 @@ namespace Uno.CodeGen.Tests
|
|||
|
||||
private class DisposablePatternBase : IDisposable
|
||||
{
|
||||
protected virtual void Dispose(bool disposing) { }
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
~DisposablePatternBase() => Dispose(false);
|
||||
}
|
||||
|
||||
private partial class When_Dispose_And_InheritFromDisposablePattern_Then_ChildGetDispose_Subject : DisposablePatternBase
|
||||
{
|
||||
public int Disposed { get; private set; }
|
||||
[DisposeMethod] public void ChildDispose() => Disposed++;
|
||||
|
||||
[DisposeMethod]
|
||||
public void ChildDispose() => Disposed++;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -326,11 +357,20 @@ namespace Uno.CodeGen.Tests
|
|||
|
||||
Assert.AreEqual(1, sut.Disposed);
|
||||
}
|
||||
private class SimpleVirtualDisposableBaseClass : IDisposable { public virtual void Dispose() { } }
|
||||
|
||||
private class SimpleVirtualDisposableBaseClass : IDisposable
|
||||
{
|
||||
public virtual void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private partial class When_Dispose_And_InheritFromSimpleDisposable_With_Override_Then_ChildGetDispose_Subject : SimpleVirtualDisposableBaseClass
|
||||
{
|
||||
public int Disposed { get; private set; }
|
||||
[DisposeMethod] public void ChildDispose() => Disposed++;
|
||||
|
||||
[DisposeMethod]
|
||||
public void ChildDispose() => Disposed++;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -354,17 +394,24 @@ namespace Uno.CodeGen.Tests
|
|||
|
||||
Assert.AreEqual(1, sut.Disposed);
|
||||
}
|
||||
|
||||
private class ExtensibleDisposable : IExtensibleDisposable
|
||||
{
|
||||
private readonly List<IDisposable> _extensions = new List<IDisposable>();
|
||||
|
||||
public void Dispose() => _extensions.DisposeAll();
|
||||
|
||||
public IReadOnlyCollection<object> Extensions => _extensions;
|
||||
|
||||
public IDisposable RegisterExtension<T>(T extension) where T : class, IDisposable => _extensions.DisposableAdd(extension);
|
||||
}
|
||||
|
||||
private partial class When_Dispose_And_InheritFromExtensibleDisposable_Then_ChildGetDispose_Subject : ExtensibleDisposable
|
||||
{
|
||||
public int Disposed { get; private set; }
|
||||
[DisposeMethod] public void ChildDispose() => Disposed++;
|
||||
|
||||
[DisposeMethod]
|
||||
public void ChildDispose() => Disposed++;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -378,17 +425,24 @@ namespace Uno.CodeGen.Tests
|
|||
|
||||
Assert.AreEqual(1, sut.Disposed);
|
||||
}
|
||||
|
||||
private class ExtensibleDisposableExplicit : IExtensibleDisposable
|
||||
{
|
||||
private readonly List<IDisposable> _extensions = new List<IDisposable>();
|
||||
|
||||
void IDisposable.Dispose() => _extensions.DisposeAll();
|
||||
|
||||
IReadOnlyCollection<object> IExtensibleDisposable.Extensions => _extensions;
|
||||
|
||||
IDisposable IExtensibleDisposable.RegisterExtension<T>(T extension) => _extensions.DisposableAdd(extension);
|
||||
}
|
||||
|
||||
private partial class When_Dispose_And_InheritFromExtensibleDisposable_With_ExplicitImplementation_Then_ChildGetDispose_Subject : ExtensibleDisposableExplicit
|
||||
{
|
||||
public int Disposed { get; private set; }
|
||||
[DisposeMethod] public void ChildDispose() => Disposed++;
|
||||
|
||||
[DisposeMethod]
|
||||
public void ChildDispose() => Disposed++;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -447,7 +501,9 @@ namespace Uno.CodeGen.Tests
|
|||
private class LifeTimeCounter
|
||||
{
|
||||
public int Constructed { get; set; }
|
||||
|
||||
public int Disposed { get; set; }
|
||||
|
||||
public int Finalized { get; set; }
|
||||
}
|
||||
#endregion
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace Uno.CodeGen.Tests
|
|||
new MyEntityForAllCollectionsAndDictionaryTypes(arrayUnsorted: new[] { "a", "b" })
|
||||
.Equals(new MyEntityForAllCollectionsAndDictionaryTypes(arrayUnsorted: new[] { "b", "a" })).Should().BeTrue();
|
||||
|
||||
new MyEntityForAllCollectionsAndDictionaryTypes(listSorted: new List<string>{"a", "b"})
|
||||
new MyEntityForAllCollectionsAndDictionaryTypes(listSorted: new List<string> {"a", "b"})
|
||||
.Equals(new MyEntityForAllCollectionsAndDictionaryTypes(listSorted: new List<string> { "a", "b" })).Should().BeTrue();
|
||||
|
||||
new MyEntityForAllCollectionsAndDictionaryTypes(listSorted: new List<string> { "a", "b" })
|
||||
|
@ -66,7 +66,7 @@ namespace Uno.CodeGen.Tests
|
|||
new MyEntityForAllCollectionsAndDictionaryTypes(readonlyCollectionUnsorted: ImmutableList.Create("a", "b"))
|
||||
.Equals(new MyEntityForAllCollectionsAndDictionaryTypes(readonlyCollectionUnsorted: ImmutableList.Create("b", "a"))).Should().BeTrue();
|
||||
|
||||
new MyEntityForAllCollectionsAndDictionaryTypes(dictionary: new Dictionary<string, string>{{"a", "a"}, {"b", "b"}})
|
||||
new MyEntityForAllCollectionsAndDictionaryTypes(dictionary: new Dictionary<string, string> {{"a", "a"}, {"b", "b"}})
|
||||
.Equals(new MyEntityForAllCollectionsAndDictionaryTypes(dictionary: new Dictionary<string, string> { { "a", "a" }, { "b", "b" } })).Should().BeTrue();
|
||||
|
||||
new MyEntityForAllCollectionsAndDictionaryTypes(dictionary: new Dictionary<string, string> { { "a", "a" }, { "b", "b" } })
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
// ******************************************************************
|
||||
namespace Uno.CodeGen.Tests
|
||||
{
|
||||
partial class Given_GeneratedEquality
|
||||
public partial class Given_GeneratedEquality
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ using Uno.Equality;
|
|||
|
||||
namespace Uno.CodeGen.Tests
|
||||
{
|
||||
partial class Given_GeneratedEquality
|
||||
public partial class Given_GeneratedEquality
|
||||
{
|
||||
[TestMethod]
|
||||
public void KeyEquality_WhenUsingKeyEqualityMode()
|
||||
|
|
|
@ -20,7 +20,7 @@ using Uno.Equality;
|
|||
|
||||
namespace Uno.CodeGen.Tests
|
||||
{
|
||||
partial class Given_GeneratedEquality
|
||||
public partial class Given_GeneratedEquality
|
||||
{
|
||||
[TestMethod]
|
||||
public void Equality_WhenUsingMyEntityForStringComparison()
|
||||
|
@ -28,45 +28,44 @@ namespace Uno.CodeGen.Tests
|
|||
new MyEntityForStringComparison.Builder {DefaultMode = "a"}.ToImmutable()
|
||||
.Equals(new MyEntityForStringComparison.Builder {DefaultMode = "a"}.ToImmutable()).Should().BeTrue();
|
||||
|
||||
new MyEntityForStringComparison.Builder { DefaultMode = "a" }.ToImmutable()
|
||||
.Equals(new MyEntityForStringComparison.Builder { DefaultMode = "A" }.ToImmutable()).Should().BeFalse();
|
||||
new MyEntityForStringComparison.Builder {DefaultMode = "a"}.ToImmutable()
|
||||
.Equals(new MyEntityForStringComparison.Builder {DefaultMode = "A"}.ToImmutable()).Should().BeFalse();
|
||||
|
||||
new MyEntityForStringComparison.Builder { DefaultMode = "" }.ToImmutable()
|
||||
new MyEntityForStringComparison.Builder {DefaultMode = ""}.ToImmutable()
|
||||
.Equals(MyEntityForStringComparison.Default).Should().BeFalse();
|
||||
|
||||
new MyEntityForStringComparison.Builder { IgnoreCase = "a" }.ToImmutable()
|
||||
.Equals(new MyEntityForStringComparison.Builder { IgnoreCase = "a" }.ToImmutable()).Should().BeTrue();
|
||||
new MyEntityForStringComparison.Builder {IgnoreCase = "a"}.ToImmutable()
|
||||
.Equals(new MyEntityForStringComparison.Builder {IgnoreCase = "a"}.ToImmutable()).Should().BeTrue();
|
||||
|
||||
new MyEntityForStringComparison.Builder { IgnoreCase = "a" }.ToImmutable()
|
||||
.Equals(new MyEntityForStringComparison.Builder { IgnoreCase = "A" }.ToImmutable()).Should().BeTrue();
|
||||
new MyEntityForStringComparison.Builder {IgnoreCase = "a"}.ToImmutable()
|
||||
.Equals(new MyEntityForStringComparison.Builder {IgnoreCase = "A"}.ToImmutable()).Should().BeTrue();
|
||||
|
||||
new MyEntityForStringComparison.Builder { IgnoreCase = "" }.ToImmutable()
|
||||
new MyEntityForStringComparison.Builder {IgnoreCase = ""}.ToImmutable()
|
||||
.Equals(MyEntityForStringComparison.Default).Should().BeFalse();
|
||||
|
||||
new MyEntityForStringComparison.Builder { EmptyEqualsNull = "a" }.ToImmutable()
|
||||
.Equals(new MyEntityForStringComparison.Builder { EmptyEqualsNull = "a" }.ToImmutable()).Should().BeTrue();
|
||||
new MyEntityForStringComparison.Builder {EmptyEqualsNull = "a"}.ToImmutable()
|
||||
.Equals(new MyEntityForStringComparison.Builder {EmptyEqualsNull = "a"}.ToImmutable()).Should().BeTrue();
|
||||
|
||||
new MyEntityForStringComparison.Builder { EmptyEqualsNull = "a" }.ToImmutable()
|
||||
.Equals(new MyEntityForStringComparison.Builder { EmptyEqualsNull = "A" }.ToImmutable()).Should().BeFalse();
|
||||
new MyEntityForStringComparison.Builder {EmptyEqualsNull = "a"}.ToImmutable()
|
||||
.Equals(new MyEntityForStringComparison.Builder {EmptyEqualsNull = "A"}.ToImmutable()).Should().BeFalse();
|
||||
|
||||
new MyEntityForStringComparison.Builder { EmptyEqualsNull = "" }.ToImmutable()
|
||||
new MyEntityForStringComparison.Builder {EmptyEqualsNull = ""}.ToImmutable()
|
||||
.Equals(MyEntityForStringComparison.Default).Should().BeTrue();
|
||||
|
||||
new MyEntityForStringComparison.Builder {EmptyEqualsNull = ""}.ToImmutable()
|
||||
.Should().BeSameAs(MyEntityForStringComparison.Default);
|
||||
|
||||
new MyEntityForStringComparison.Builder { EmptyEqualsNullIgnoreCase = "a" }.ToImmutable()
|
||||
.Equals(new MyEntityForStringComparison.Builder { EmptyEqualsNullIgnoreCase = "a" }.ToImmutable()).Should().BeTrue();
|
||||
new MyEntityForStringComparison.Builder {EmptyEqualsNullIgnoreCase = "a"}.ToImmutable()
|
||||
.Equals(new MyEntityForStringComparison.Builder {EmptyEqualsNullIgnoreCase = "a"}.ToImmutable()).Should().BeTrue();
|
||||
|
||||
new MyEntityForStringComparison.Builder { EmptyEqualsNullIgnoreCase = "a" }.ToImmutable()
|
||||
.Equals(new MyEntityForStringComparison.Builder { EmptyEqualsNullIgnoreCase = "A" }.ToImmutable()).Should().BeTrue();
|
||||
new MyEntityForStringComparison.Builder {EmptyEqualsNullIgnoreCase = "a"}.ToImmutable()
|
||||
.Equals(new MyEntityForStringComparison.Builder {EmptyEqualsNullIgnoreCase = "A"}.ToImmutable()).Should().BeTrue();
|
||||
|
||||
new MyEntityForStringComparison.Builder { EmptyEqualsNullIgnoreCase = "" }.ToImmutable()
|
||||
new MyEntityForStringComparison.Builder {EmptyEqualsNullIgnoreCase = ""}.ToImmutable()
|
||||
.Equals(MyEntityForStringComparison.Default).Should().BeTrue();
|
||||
|
||||
new MyEntityForStringComparison.Builder { EmptyEqualsNullIgnoreCase = "" }.ToImmutable()
|
||||
new MyEntityForStringComparison.Builder {EmptyEqualsNullIgnoreCase = ""}.ToImmutable()
|
||||
.Should().BeSameAs(MyEntityForStringComparison.Default);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ namespace Uno.CodeGen.Tests
|
|||
internal string A { get; set; }
|
||||
|
||||
private static int GetHash_A(string value) => -1;
|
||||
|
||||
private static IEqualityComparer<string> A_CustomComparer => StringComparer.OrdinalIgnoreCase;
|
||||
|
||||
[EqualityKey]
|
||||
|
@ -44,10 +45,12 @@ namespace Uno.CodeGen.Tests
|
|||
|
||||
[EqualityHash]
|
||||
internal string D { get; set; }
|
||||
|
||||
private static IEqualityComparer<string> D_CustomComparer => StringComparer.OrdinalIgnoreCase;
|
||||
|
||||
[EqualityHash]
|
||||
internal TSomething E { get; set; }
|
||||
|
||||
private static IEqualityComparer<TSomething> E_CustomComparer => EqualityComparer<TSomething>.Default;
|
||||
|
||||
[EqualityHash]
|
||||
|
@ -63,7 +66,6 @@ namespace Uno.CodeGen.Tests
|
|||
[GeneratedEquality]
|
||||
internal partial class DerivedEqualityClass : MyEqualityClass<int>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[GeneratedEquality]
|
||||
|
@ -71,8 +73,8 @@ namespace Uno.CodeGen.Tests
|
|||
{
|
||||
[EqualityKey]
|
||||
internal string A { get; }
|
||||
|
||||
[Key]
|
||||
internal string B { get; }
|
||||
}
|
||||
|
||||
}
|
|
@ -19,7 +19,7 @@ using System.ComponentModel.DataAnnotations;
|
|||
|
||||
namespace Uno.CodeGen.Tests
|
||||
{
|
||||
partial class Given_ImmutableEntity
|
||||
public partial class Given_ImmutableEntity
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -53,16 +53,22 @@ namespace Uno.CodeGen.Tests
|
|||
|
||||
[Required(AllowEmptyStrings = true, ErrorMessage = "Entity1 is required!")]
|
||||
public T1 Entity1 { get; }
|
||||
|
||||
[EqualityIgnore]
|
||||
public T2 Entity2 { get; }
|
||||
|
||||
[EqualityIgnore]
|
||||
public T3 Entity3 { get; }
|
||||
|
||||
[EqualityIgnore]
|
||||
public T4 Entity4 { get; }
|
||||
|
||||
[EqualityIgnore]
|
||||
public T5 Entity5 { get; }
|
||||
|
||||
[EqualityHash]
|
||||
public T6 Entity6 { get; }
|
||||
|
||||
public (T1, T2, T3, T4, T5, T6) Values { get; }
|
||||
|
||||
private static int GetHash_Entity6(T6 value) => 50;
|
||||
|
|
|
@ -21,7 +21,7 @@ using AbstractExternalClass = Uno.CodeGen.Tests.ExternalClasses.AbstractExternal
|
|||
|
||||
namespace Uno.CodeGen.Tests
|
||||
{
|
||||
partial class Given_ImmutableEntity
|
||||
public partial class Given_ImmutableEntity
|
||||
{
|
||||
[TestMethod]
|
||||
public void Immutable_When_Abstracted_Base_Class()
|
||||
|
@ -61,11 +61,9 @@ namespace Uno.CodeGen.Tests
|
|||
|
||||
public partial class InheritanceDerivedClassFromExternal : AbstractExternalClass
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public partial class InheritanceDerivedClassFromExternalGeneric : ExternalClasses.AbstractExternalGenericClass<string>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ using Newtonsoft.Json;
|
|||
|
||||
namespace Uno.CodeGen.Tests
|
||||
{
|
||||
partial class Given_ImmutableEntity
|
||||
public partial class Given_ImmutableEntity
|
||||
{
|
||||
[TestMethod]
|
||||
public void Immutable_When_Serializing_A_Using_JsonNet()
|
||||
|
|
|
@ -20,7 +20,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|||
|
||||
namespace Uno.CodeGen.Tests
|
||||
{
|
||||
partial class Given_ImmutableEntity
|
||||
public partial class Given_ImmutableEntity
|
||||
{
|
||||
[TestMethod]
|
||||
public void Immutable_When_Using_Options()
|
||||
|
|
|
@ -19,6 +19,7 @@ using System.Collections.Generic;
|
|||
using System.Collections.Immutable;
|
||||
using FluentAssertions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Uno.Equality;
|
||||
|
||||
[assembly: Uno.ImmutableGenerationOptions(TreatArrayAsImmutable = true, GenerateEqualityByDefault = true)]
|
||||
|
||||
|
@ -72,7 +73,6 @@ namespace Uno.CodeGen.Tests
|
|||
MyField1 = 42
|
||||
};
|
||||
|
||||
|
||||
var builder = new MyImmutableEntity.Builder(original);
|
||||
var newInstance = builder.ToImmutable();
|
||||
|
||||
|
@ -120,6 +120,23 @@ namespace Uno.CodeGen.Tests
|
|||
var attributes = idProperty.GetCustomAttributes(false);
|
||||
attributes.Should().HaveCount(3);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Immutable_When_Assigning_EquivalentParameters()
|
||||
{
|
||||
ImmutableForTypeEquality original = ImmutableForTypeEquality.Default
|
||||
.WithString("str")
|
||||
.WithSortedBytes(new byte[] {1, 2, 3})
|
||||
.WithUnsortedBytes(new byte[] {1, 2, 3});
|
||||
|
||||
ImmutableForTypeEquality modified = original
|
||||
.WithString("str")
|
||||
.WithSortedBytes(new byte[] { 1, 2, 3 })
|
||||
.WithUnsortedBytes(new byte[] { 1, 2, 3 });
|
||||
|
||||
original.Should().BeEquivalentTo(modified);
|
||||
original.Should().BeSameAs(modified);
|
||||
}
|
||||
}
|
||||
|
||||
[GeneratedImmutable]
|
||||
|
@ -137,11 +154,17 @@ namespace Uno.CodeGen.Tests
|
|||
public partial class B : A
|
||||
{
|
||||
public Uri FirstField { get; }
|
||||
|
||||
public string SecondField { get; }
|
||||
|
||||
public long ThirdField { get; }
|
||||
|
||||
public TimeSpan TimeSpan { get; }
|
||||
|
||||
public bool Boolean { get; }
|
||||
|
||||
public DateTimeKind Enum { get; }
|
||||
|
||||
public new bool IsSomething { get; }
|
||||
}
|
||||
|
||||
|
@ -179,8 +202,12 @@ namespace Uno.CodeGen.Tests
|
|||
}
|
||||
|
||||
public string A { get; }
|
||||
|
||||
public string B { get; }
|
||||
|
||||
#pragma warning disable SA1401 // Fields must be private
|
||||
public readonly int I;
|
||||
#pragma warning restore SA1401 // Fields must be private
|
||||
}
|
||||
|
||||
public struct ImplicitlyImmutableStruct
|
||||
|
@ -193,8 +220,21 @@ namespace Uno.CodeGen.Tests
|
|||
}
|
||||
|
||||
public string A { get; }
|
||||
|
||||
public string B { get; }
|
||||
|
||||
public readonly int I;
|
||||
}
|
||||
|
||||
[GeneratedImmutable]
|
||||
public partial class ImmutableForTypeEquality
|
||||
{
|
||||
public string String { get; }
|
||||
|
||||
[EqualityComparerOptions(CollectionMode = CollectionComparerMode.Sorted)]
|
||||
public byte[] SortedBytes { get; }
|
||||
|
||||
[EqualityComparerOptions(CollectionMode = CollectionComparerMode.Unsorted)]
|
||||
public byte[] UnsortedBytes { get; }
|
||||
}
|
||||
}
|
|
@ -4,17 +4,13 @@
|
|||
<TargetFramework>net46</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<NoWarn>1701;1702;1705;NU1701</NoWarn>
|
||||
<CodeAnalysisRuleSet>Uno.CodeGen.Tests.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<SourceGenerator Include="..\Uno.CodeGen\bin\$(Configuration)\net46\Uno.CodeGen.dll" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\Uno.CodeGen\build\Uno.CodeGen.props" />
|
||||
<Import Project="..\Uno.CodeGen.ClassLifecycle\Build\Uno.CodeGen.ClassLifecycle.props" />
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="5.1.2" />
|
||||
|
@ -22,11 +18,15 @@
|
|||
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
|
||||
<PackageReference Include="System.ComponentModel.Annotations" Version="4.4.1" />
|
||||
<PackageReference Include="Uno.Core" Version="1.20.2" />
|
||||
<PackageReference Include="Uno.SourceGenerationTasks" Version="1.20.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\Uno.CodeGen\build\Uno.CodeGen.props" />
|
||||
<Import Project="..\Uno.CodeGen.ClassLifecycle\Build\Uno.CodeGen.ClassLifecycle.props" />
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Uno.ClassLifecycle\Uno.ClassLifecycle.csproj" />
|
||||
<ProjectReference Include="..\Uno.CodeGen.Tests.ExternalClasses\Uno.CodeGen.Tests.ExternalClasses.csproj" />
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RuleSet Name="Microsoft Managed Recommended Rules" Description="These rules focus on the most critical problems in your code, including potential security holes, application crashes, and other important logic and design errors. It is recommended to include this rule set in any custom rule set you create for your projects." ToolsVersion="10.0">
|
||||
<Localization ResourceAssembly="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.dll" ResourceBaseName="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.Localized">
|
||||
<Name Resource="MinimumRecommendedRules_Name" />
|
||||
<Description Resource="MinimumRecommendedRules_Description" />
|
||||
</Localization>
|
||||
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
|
||||
<Rule Id="CA1001" Action="Warning" />
|
||||
<Rule Id="CA1009" Action="Warning" />
|
||||
<Rule Id="CA1016" Action="Warning" />
|
||||
<Rule Id="CA1033" Action="Warning" />
|
||||
<Rule Id="CA1049" Action="Warning" />
|
||||
<Rule Id="CA1060" Action="Warning" />
|
||||
<Rule Id="CA1061" Action="Warning" />
|
||||
<Rule Id="CA1063" Action="Warning" />
|
||||
<Rule Id="CA1065" Action="Warning" />
|
||||
<Rule Id="CA1301" Action="Warning" />
|
||||
<Rule Id="CA1400" Action="Warning" />
|
||||
<Rule Id="CA1401" Action="Warning" />
|
||||
<Rule Id="CA1403" Action="Warning" />
|
||||
<Rule Id="CA1404" Action="Warning" />
|
||||
<Rule Id="CA1405" Action="Warning" />
|
||||
<Rule Id="CA1410" Action="Warning" />
|
||||
<Rule Id="CA1415" Action="Warning" />
|
||||
<Rule Id="CA1821" Action="Warning" />
|
||||
<Rule Id="CA1900" Action="Warning" />
|
||||
<Rule Id="CA1901" Action="Warning" />
|
||||
<Rule Id="CA2002" Action="Warning" />
|
||||
<Rule Id="CA2100" Action="Warning" />
|
||||
<Rule Id="CA2101" Action="Warning" />
|
||||
<Rule Id="CA2108" Action="Warning" />
|
||||
<Rule Id="CA2111" Action="Warning" />
|
||||
<Rule Id="CA2112" Action="Warning" />
|
||||
<Rule Id="CA2114" Action="Warning" />
|
||||
<Rule Id="CA2116" Action="Warning" />
|
||||
<Rule Id="CA2117" Action="Warning" />
|
||||
<Rule Id="CA2122" Action="Warning" />
|
||||
<Rule Id="CA2123" Action="Warning" />
|
||||
<Rule Id="CA2124" Action="Warning" />
|
||||
<Rule Id="CA2126" Action="Warning" />
|
||||
<Rule Id="CA2131" Action="Warning" />
|
||||
<Rule Id="CA2132" Action="Warning" />
|
||||
<Rule Id="CA2133" Action="Warning" />
|
||||
<Rule Id="CA2134" Action="Warning" />
|
||||
<Rule Id="CA2137" Action="Warning" />
|
||||
<Rule Id="CA2138" Action="Warning" />
|
||||
<Rule Id="CA2140" Action="Warning" />
|
||||
<Rule Id="CA2141" Action="Warning" />
|
||||
<Rule Id="CA2146" Action="Warning" />
|
||||
<Rule Id="CA2147" Action="Warning" />
|
||||
<Rule Id="CA2149" Action="Warning" />
|
||||
<Rule Id="CA2200" Action="Warning" />
|
||||
<Rule Id="CA2202" Action="Warning" />
|
||||
<Rule Id="CA2207" Action="Warning" />
|
||||
<Rule Id="CA2212" Action="Warning" />
|
||||
<Rule Id="CA2213" Action="Warning" />
|
||||
<Rule Id="CA2214" Action="Warning" />
|
||||
<Rule Id="CA2216" Action="Warning" />
|
||||
<Rule Id="CA2220" Action="Warning" />
|
||||
<Rule Id="CA2229" Action="Warning" />
|
||||
<Rule Id="CA2231" Action="Warning" />
|
||||
<Rule Id="CA2232" Action="Warning" />
|
||||
<Rule Id="CA2235" Action="Warning" />
|
||||
<Rule Id="CA2236" Action="Warning" />
|
||||
<Rule Id="CA2237" Action="Warning" />
|
||||
<Rule Id="CA2238" Action="Warning" />
|
||||
<Rule Id="CA2240" Action="Warning" />
|
||||
<Rule Id="CA2241" Action="Warning" />
|
||||
<Rule Id="CA2242" Action="Warning" />
|
||||
</Rules>
|
||||
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
|
||||
<!-- Some errors known to fail in generated code. Should be ignored since it's generated code. -->
|
||||
<Rule Id="SA1005" Action="None" />
|
||||
<Rule Id="SA1012" Action="None" />
|
||||
<Rule Id="SA1013" Action="None" />
|
||||
<Rule Id="SA1027" Action="None" />
|
||||
<Rule Id="SA1028" Action="Error" />
|
||||
<Rule Id="SA1101" Action="None" />
|
||||
<Rule Id="SA1122" Action="None" />
|
||||
<Rule Id="SA1124" Action="None" />
|
||||
<Rule Id="SA1127" Action="None" />
|
||||
<Rule Id="SA1200" Action="None" />
|
||||
<Rule Id="SA1201" Action="None" />
|
||||
<Rule Id="SA1202" Action="None" />
|
||||
<Rule Id="SA1205" Action="None" />
|
||||
<Rule Id="SA1309" Action="None" />
|
||||
<Rule Id="SA1401" Action="None" />
|
||||
<Rule Id="SA1402" Action="None" />
|
||||
<Rule Id="SA1507" Action="Error" />
|
||||
<Rule Id="SA1513" Action="None" />
|
||||
<Rule Id="SA1515" Action="None" />
|
||||
<Rule Id="SA1616" Action="Error" />
|
||||
<Rule Id="SA1611" Action="None" />
|
||||
<Rule Id="SA1633" Action="None" />
|
||||
<Rule Id="SA1652" Action="None" />
|
||||
</Rules>
|
||||
</RuleSet>
|
|
@ -45,6 +45,20 @@ namespace Uno
|
|||
output.AppendLine(string.Join(Environment.NewLine, lines));
|
||||
|
||||
context.AddCompilationUnit(nameof(CompilationReferencesListingGenerator), output.ToString());
|
||||
|
||||
var projectReferences = context
|
||||
.GetProjectInstance()
|
||||
.Items
|
||||
.Where(i => i.ItemType.Equals("PackageReference", StringComparison.OrdinalIgnoreCase))
|
||||
.ToArray();
|
||||
|
||||
var projectDependencies = context
|
||||
.GetProjectInstance()
|
||||
.Items
|
||||
.Where(i => i.ItemType.Equals("PackageDependencies", StringComparison.OrdinalIgnoreCase))
|
||||
.ToArray();
|
||||
|
||||
projectReferences.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,14 +136,14 @@ namespace Uno
|
|||
var baseTypeInfo = GetBaseTypeInfo(typeSymbol);
|
||||
var generateKeyEquals = baseTypeInfo.baseImplementsKeyEquals || baseTypeInfo.baseImplementsKeyEqualsT || keyEqualityMembers.Any();
|
||||
|
||||
builder.AppendLine("using System;");
|
||||
builder.AppendLine();
|
||||
builder.AppendLineInvariant("// <auto-generated>");
|
||||
builder.AppendLineInvariant("// ****************************************************************************************************************");
|
||||
builder.AppendLineInvariant("// This has been generated by Uno.CodeGen (EqualityGenerator), available at https://github.com/nventive/Uno.CodeGen");
|
||||
builder.AppendLineInvariant("// ****************************************************************************************************************");
|
||||
builder.AppendLineInvariant("// **********************************************************************************************************************");
|
||||
builder.AppendLineInvariant("// This file has been generated by Uno.CodeGen (ImmutableGenerator), available at https://github.com/nventive/Uno.CodeGen");
|
||||
builder.AppendLineInvariant("// **********************************************************************************************************************");
|
||||
builder.AppendLineInvariant("// </auto-generated>");
|
||||
builder.AppendLine();
|
||||
builder.AppendLine("using System;");
|
||||
builder.AppendLine();
|
||||
|
||||
using (builder.BlockInvariant($"namespace {typeSymbol.ContainingNamespace}"))
|
||||
{
|
||||
|
|
|
@ -231,14 +231,14 @@ namespace Uno
|
|||
|
||||
var newModifier = baseTypeInfo.isBaseTypePresent ? "new " : "";
|
||||
|
||||
builder.AppendLineInvariant("using System;");
|
||||
builder.AppendLine();
|
||||
builder.AppendLineInvariant("// <auto-generated>");
|
||||
builder.AppendLineInvariant("// **********************************************************************************************************************");
|
||||
builder.AppendLineInvariant("// This file has been generated by Uno.CodeGen (ImmutableGenerator), available at https://github.com/nventive/Uno.CodeGen");
|
||||
builder.AppendLineInvariant("// **********************************************************************************************************************");
|
||||
builder.AppendLineInvariant("// </auto-generated>");
|
||||
builder.AppendLine();
|
||||
builder.AppendLineInvariant("using System;");
|
||||
builder.AppendLine();
|
||||
|
||||
using (builder.BlockInvariant($"namespace {typeSymbol.ContainingNamespace}"))
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче