第一:
public class ClassePrincipal
{
[Key] public long IdPrinc { get; set; }
public string NomePrinc { get; set; }
public string Princ { get; set; }
public override string ToString()
{
return "ID: " + IdPrinc + " NomePrinc: " + NomePrinc + " Princ: " + Princ;
}
}
第二:
public class Classe_Secundaria
{
[Key] public long IdSec { get; set; }
public string NomeSec { get; set; }
public string Sec { get; set; }
[Primary] public ClassePrincipal ClassePrincipal { get; set; }
public override string ToString()
{
return "ID Sec: " + IdSec + " NomeSec: " + NomeSec + " Sec: " + Sec + (ClassePrincipal != null ? " ClassePrincipal: " + ClassePrincipal.ToString() : "");
}
}
我用这个:
Classe_Secundaria x = null;
我需要从x获取类型,但是x为空,如何使用反射从x获取类型?我没有反射:
Type type = TypedReference.GetTargetType(__makeref(x));
在反思中使用此代码时,他只有对象类型,而没有Classe_Secundaria类型