diff --git a/Esiur/Resource/Template/TypeTemplate.cs b/Esiur/Resource/Template/TypeTemplate.cs index d30961b..2c1294e 100644 --- a/Esiur/Resource/Template/TypeTemplate.cs +++ b/Esiur/Resource/Template/TypeTemplate.cs @@ -398,6 +398,9 @@ public class TypeTemplate public TypeTemplate(Type type, bool addToWarehouse = false) { + //if (!type.IsPublic) + // throw new Exception("Not public"); + if (Codec.ImplementsInterface(type, typeof(IResource))) templateType = TemplateType.Resource; else if (Codec.ImplementsInterface(type, typeof(IRecord))) @@ -481,7 +484,7 @@ public class TypeTemplate } // add attributes - var attrs = type.GetProperties(BindingFlags.Public | BindingFlags.Instance) + var attrs = type.GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(x => x.GetCustomAttribute() != null); foreach (var attr in attrs) @@ -592,6 +595,7 @@ public class TypeTemplate if (classIsPublic) { + // get public instance members only. var mis = type.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Static) .Where(x => x.MemberType == MemberTypes.Property || x.MemberType == MemberTypes.Field @@ -618,7 +622,8 @@ public class TypeTemplate } else { - var mis = type.GetMembers(BindingFlags.Public | BindingFlags.Instance + // allow private and public members that are marked with [Export] attribute. + var mis = type.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Static) .Where(x => x.MemberType == MemberTypes.Property || x.MemberType == MemberTypes.Field || x.MemberType == MemberTypes.Event || x.MemberType == MemberTypes.Method) diff --git a/Test/MyService.cs b/Test/MyService.cs index c1ecc58..c5aed4c 100644 --- a/Test/MyService.cs +++ b/Test/MyService.cs @@ -135,7 +135,7 @@ public partial class MyService [Export] public MyResource? Resource { get; set; } [Export] public MyChildResource? ChildResource { get; set; } - [Export] public MyChildRecord ChildRecord { get; set; } = new MyChildRecord() { ChildName = "Child", Id = 12, Name = "Parent", Score = 12.2 }; + [Export] MyChildRecord ChildRecord { get; set; } = new MyChildRecord() { ChildName = "Child", Id = 12, Name = "Parent", Score = 12.2 }; [Export] public IResource[]? Resources { get; set; } @@ -194,4 +194,6 @@ public partial class MyService [Export] public const double PI = Math.PI; [Export] public MyService Me => this; + + [Export] int PrivateInt32 { get; set; } = 99; }