Reputation: 4130
public class Access
{
public Entity eeee { get; set; }
public Permission<eeee.GetType()> pppp { get; set; }
}
public class Entity
{
}
public class Permission<T>
{
public bool CanView {get;set;}
public bool CanEdit {get;set;}
public bool CanDelete {get;set;}
}
public class Photo:Entity
{
}
public class PhotoPermission:Permission<Photo>
{
public bool CanTag {get;set;}
}
public class Video:Entity
{
}
public class VideoPermission:Permission<Video>
{
public bool CanFastForward {get;set;}
}
So, If eeee
is of type Photo
, then the "type" of pppp
should be Permission<Photo>
Is there something like eeee.GetType()
Upvotes: 0
Views: 349
Reputation: 894
The idea behind generics is that the generic type is known at runtime; therefore, your code would not compile. I suggest you to use Reflection to accomplish your task.
Upvotes: 0
Reputation: 109017
Looks like you can very easily change your Access
class to
public class Access<T>
{
public T eeee { get; set; }
public Permission<T> pppp { get; set; }
}
Upvotes: 1