Can I Inherit from this class?
I am trying to create a class that inherits from SPListItem. When I try to compile it throws the error:
The type 'Microsoft.SharePoint.SPListItem' has no constructors defined
H开发者_运维技巧ere is my code:
public class MySPListItem : SPListItem
{
public string ItemUrl {get;set;}
}
Is there anyway I can inherit from SPListItem?
According to the documentation, the class doesn't have any public or protected constructors. That means you can't inherit from it.
As svick has pointed out, the documentation states that there are no public or protected constructors which means you won't be able to inherit from this class.
I do wonder though, if you're inheriting so that you can extend this class, you might be best off writing some extension methods.
This might be a viable option if that's what you're intending to do, extend the class.
try defining a constructor:
public class MySPListItem : SPListItem
{
public string ItemUrl {get;set;}
public MySPListItem():base()
{
}
}
updated
I agree with @svick!
精彩评论