mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-05-06 11:32:59 +00:00
null check
This commit is contained in:
parent
05964ebe4c
commit
6afea08b08
@ -398,6 +398,9 @@ public class TypeTemplate
|
|||||||
public TypeTemplate(Type type, bool addToWarehouse = false)
|
public TypeTemplate(Type type, bool addToWarehouse = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//if (!type.IsPublic)
|
||||||
|
// throw new Exception("Not public");
|
||||||
|
|
||||||
if (Codec.ImplementsInterface(type, typeof(IResource)))
|
if (Codec.ImplementsInterface(type, typeof(IResource)))
|
||||||
templateType = TemplateType.Resource;
|
templateType = TemplateType.Resource;
|
||||||
else if (Codec.ImplementsInterface(type, typeof(IRecord)))
|
else if (Codec.ImplementsInterface(type, typeof(IRecord)))
|
||||||
@ -592,6 +595,7 @@ public class TypeTemplate
|
|||||||
|
|
||||||
if (classIsPublic)
|
if (classIsPublic)
|
||||||
{
|
{
|
||||||
|
// get public instance members only.
|
||||||
var mis = type.GetMembers(BindingFlags.Public | BindingFlags.Instance
|
var mis = type.GetMembers(BindingFlags.Public | BindingFlags.Instance
|
||||||
| BindingFlags.DeclaredOnly | BindingFlags.Static)
|
| BindingFlags.DeclaredOnly | BindingFlags.Static)
|
||||||
.Where(x => x.MemberType == MemberTypes.Property || x.MemberType == MemberTypes.Field
|
.Where(x => x.MemberType == MemberTypes.Property || x.MemberType == MemberTypes.Field
|
||||||
@ -618,7 +622,8 @@ public class TypeTemplate
|
|||||||
}
|
}
|
||||||
else
|
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)
|
| BindingFlags.DeclaredOnly | BindingFlags.Static)
|
||||||
.Where(x => x.MemberType == MemberTypes.Property || x.MemberType == MemberTypes.Field
|
.Where(x => x.MemberType == MemberTypes.Property || x.MemberType == MemberTypes.Field
|
||||||
|| x.MemberType == MemberTypes.Event || x.MemberType == MemberTypes.Method)
|
|| x.MemberType == MemberTypes.Event || x.MemberType == MemberTypes.Method)
|
||||||
|
@ -135,7 +135,7 @@ public partial class MyService
|
|||||||
[Export] public MyResource? Resource { get; set; }
|
[Export] public MyResource? Resource { get; set; }
|
||||||
[Export] public MyChildResource? ChildResource { 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; }
|
[Export] public IResource[]? Resources { get; set; }
|
||||||
|
|
||||||
@ -194,4 +194,6 @@ public partial class MyService
|
|||||||
[Export] public const double PI = Math.PI;
|
[Export] public const double PI = Math.PI;
|
||||||
|
|
||||||
[Export] public MyService Me => this;
|
[Export] public MyService Me => this;
|
||||||
|
|
||||||
|
[Export] int PrivateInt32 { get; set; } = 99;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user