public override object CreateItem(Type itemType, Guid id)
{
if (itemType == null)
{
throw new ArgumentNullException("itemType");
}
if (itemType == typeof(ProductItem))
{
return this.CreateProduct(id);
}
throw GetInvalidItemTypeException(itemType, this.GetKnownTypes());
}
public override object GetItem(Type itemType, Guid id)
{
if (itemType == typeof(Comment))
{
return this.GetComment(id);
}
if (itemType == typeof(ProductItem) || itemType == null)
{
return this.GetProduct(id);
}
return base.GetItem(itemType, id);
}
public override object GetItemOrDefault(Type itemType, Guid id)
{
if (itemType == typeof(Comment))
{
return this.GetComments().Where(c => c.Id == id).FirstOrDefault();
}
if (itemType == typeof(ProductItem))
{
return this.GetProducts().Where(n => n.Id == id).FirstOrDefault();
}
return base.GetItemOrDefault(itemType, id);
}
public override IEnumerable GetItems(Type itemType, string filterExpression, string orderExpression, int skip, int take, ref int? totalCount)
{
if (itemType == null)
{
throw new ArgumentNullException("itemType");
}
if (itemType == typeof(Comment))
{
return SetExpressions(this.GetComments(), filterExpression, orderExpression, skip, take, ref totalCount);
}
if (itemType == typeof(ProductItem))
{
return SetExpressions(this.GetProducts(), filterExpression, orderExpression, skip, take, ref totalCount);
}
throw GetInvalidItemTypeException(itemType, this.GetKnownTypes());
}
public override void DeleteItem(object item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
var itemType = item.GetType();
this.providerDecorator.DeletePermissions(item);
if (itemType == typeof(Comment))
{
this.Delete((Comment)item);
return;
}
if (itemType == typeof(ProductItem))
{
this.DeleteProduct((ProductItem)item);
return;
}
throw GetInvalidItemTypeException(item.GetType(), this.GetKnownTypes());
}
In the code above, when overriding the methods, you must check whether the item type is Comment.