This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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