InjectableGenerator: Add support for generic types
This commit is contained in:
Родитель
282f225fbd
Коммит
fc214b0145
|
@ -15,6 +15,7 @@
|
|||
//
|
||||
// ******************************************************************
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Uno.CodeGen.Tests.ExternalClasses
|
||||
{
|
||||
|
@ -27,6 +28,7 @@ namespace Uno.CodeGen.Tests.ExternalClasses
|
|||
[Inject] public DateTime MyDateTimeProperty { get; private set; }
|
||||
[Inject("name")] public object MyObjectProperty { get; private set; }
|
||||
[Inject] public Func<string> MyFuncStringProperty { get; private set; }
|
||||
[Inject] public List<string> MyListStringProperty { get; private set; }
|
||||
|
||||
// Fields
|
||||
[Inject] public string MyStringField;
|
||||
|
@ -35,5 +37,6 @@ namespace Uno.CodeGen.Tests.ExternalClasses
|
|||
[Inject] public DateTime MyDateTimeField;
|
||||
[Inject("name")] public object MyObjectField;
|
||||
[Inject] public Func<string> MyFuncStringField;
|
||||
[Inject] public List<string> MyListStringField;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace Uno.CodeGen.Tests
|
|||
var @string = "Hello world!";
|
||||
var dateTime = DateTime.Now;
|
||||
var providedName = default(string);
|
||||
var strings = new List<string> { "A", "B", "C" };
|
||||
|
||||
var vm = new MyViewModel();
|
||||
|
||||
|
@ -59,6 +60,10 @@ namespace Uno.CodeGen.Tests
|
|||
providedName = name;
|
||||
return name;
|
||||
}
|
||||
if (type == typeof(List<string>))
|
||||
{
|
||||
return strings;
|
||||
}
|
||||
|
||||
throw new NotSupportedException();
|
||||
});
|
||||
|
@ -70,6 +75,7 @@ namespace Uno.CodeGen.Tests
|
|||
Assert.AreEqual(dateTime, vm.MyDateTimeProperty);
|
||||
Assert.AreEqual(providedName, vm.MyObjectProperty);
|
||||
Assert.AreEqual(@string, vm.MyFuncStringProperty());
|
||||
Assert.AreEqual(strings, vm.MyListStringProperty);
|
||||
|
||||
// Fields
|
||||
Assert.AreEqual(boolean, vm.MyBooleanField);
|
||||
|
@ -78,6 +84,7 @@ namespace Uno.CodeGen.Tests
|
|||
Assert.AreEqual(dateTime, vm.MyDateTimeField);
|
||||
Assert.AreEqual(providedName, vm.MyObjectField);
|
||||
Assert.AreEqual(@string, vm.MyFuncStringField());
|
||||
Assert.AreEqual(strings, vm.MyListStringField);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,13 +83,13 @@ namespace Uno
|
|||
{
|
||||
var memberName = attribute.member.Name;
|
||||
var memberType = GetMemberType(attribute.member);
|
||||
var memberTypeName = memberType?.GetFullMetadataName();
|
||||
var memberTypeName = memberType?.ToDisplayString();
|
||||
var name = attribute.attribute.ConstructorArguments.Select(x => x.Value?.ToString()).FirstOrDefault();
|
||||
var nameLiteral = name != null ? $"\"{name}\"" : "null";
|
||||
|
||||
if (memberType.IsFunc(out ITypeSymbol funcResultType)) // Resolve lazily
|
||||
{
|
||||
var funcResultTypeName = funcResultType?.GetFullMetadataName();
|
||||
var funcResultTypeName = funcResultType?.ToDisplayString();
|
||||
builder.AppendLineInvariant($"{memberName} = () => ({funcResultTypeName})resolver(typeof({funcResultTypeName}), {nameLiteral});");
|
||||
}
|
||||
else
|
||||
|
@ -117,4 +117,4 @@ namespace Uno
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче