Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public interface ICustomItemSerializer : IItemSerializer
{
}
public class CustomItemSerializer : DefaultItemSerializer, ICustomItemSerializer
{
/// <summary>
/// TemplateId - FieldIds to exclude
/// </summary>
private static readonly IDictionary<ID, ID[]> _fieldsToExclude = new Dictionary<ID, ID[]>()
{
{
new ID(Constants.Template1.TemplateId),
new ID[]
{
Constants.Template1.Fields.Field1,
Constants.Template1.Fields.Field2,
}
}
};
public CustomItemSerializer(IGetFieldSerializerPipeline getFieldSerializerPipeline) : base(getFieldSerializerPipeline)
{
}
protected override IEnumerable<Field> GetItemFields(Item item)
{
if (!_fieldsToExclude.TryGetValue(item.TemplateID, out var fields))
{
return base.GetItemFields(item);
}
return base.GetItemFields(item).Where(f => !fields.Contains(f.ID));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment