SafeBuffer IFirewallEnumTemplate <FirewallFilter> .ToTemplateBuffer(DisposableList list) { FirewallActionType action_type = ActionType; switch (action_type) { case FirewallActionType.Permit: case FirewallActionType.Block: action_type &= ~FirewallActionType.Terminating; break; } var template = new FWPM_FILTER_ENUM_TEMPLATE0 { layerKey = LayerKey, flags = Flags, providerKey = ProviderKey.HasValue ? list.AddResource(ProviderKey.Value.ToBuffer()).DangerousGetHandle() : IntPtr.Zero, actionMask = action_type }; var valid_conditions = Conditions.Where(c => !FirewallConditionGuids.IsUserId(c.FieldKey)); int count = valid_conditions.Count(); if (count > 0) { template.numFilterConditions = count; template.filterCondition = list.AddList(valid_conditions.Select(c => c.ToStruct(list))).DangerousGetHandle(); } return(list.AddStructure(template)); }