System.Func.Invoke(VoteModel)

Here are the examples of the csharp api System.Func.Invoke(VoteModel) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

19 Source : VoteLookup.cs
with GNU General Public License v3.0
from Sebazzz

internal void Initialize(List<VoteModel> source) {
            foreach (VoteModel voteModel in source) {
                int? key = this._keySelector.Invoke(voteModel);
                if (key == null) {
                    continue;
                }

                if (!this._dictionary.TryGetValue(key.Value, out List<VoteModel>? votes)) {
                    this._dictionary[key.Value] = votes = new List<VoteModel>(0);
                }
                votes.Add(voteModel);
            }

            foreach (List<VoteModel> list in this._dictionary.Values) {
                list.Sort(this._sorter);
            }
        }

19 Source : VoteLookup.cs
with GNU General Public License v3.0
from Sebazzz

public void Add(VoteModel notificationVote) {
            int? key = this._keySelector.Invoke(notificationVote);
            if (key == null) {
                return;
            }

            if (!this._dictionary.TryGetValue(key.Value, out List<VoteModel>? votes)) {
                this._dictionary[key.Value] = votes = new List<VoteModel>(0);
            }

            votes.Add(notificationVote);

            // Remove artificial uncast vote
            int uncastVoteIdx = votes.FindIndex(x => x.IsCast == false);
            if (uncastVoteIdx != -1) {
                votes.RemoveAt(uncastVoteIdx);
            }

            votes.Sort(this._sorter);
        }

19 Source : VoteLookup.cs
with GNU General Public License v3.0
from Sebazzz

public void Remove(VoteModel notificationVote) {
            int? key = this._keySelector.Invoke(notificationVote);
            if (key == null) {
                return;
            }

            if (!this._dictionary.TryGetValue(key.Value, out List<VoteModel>? votes)) {
                return;
            }

            votes.RemoveAll(x => x.Id == notificationVote.Id);

            // Add artificial uncast vote
            VoteModel artificialVote = VoteModel.CreateEmptyFrom(notificationVote);
            if (this._keySelector.Invoke(artificialVote) != null) {
                votes.Add(artificialVote);
            }
        }