Created
August 17, 2022 09:16
-
-
Save trnktms/0b2508afd6ad7a30ed3e9c417ac102a1 to your computer and use it in GitHub Desktop.
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