Utils/DataUtil.cs

(开头部分) 14KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Passwords.Models;
using System.Collections.ObjectModel;
using Passwords.ViewModels;
using Passwords.DAL;

namespace Passwords.Utils
{
    public static class DataUtil
    {

        /// <summary>
        /// Finds a category in a list by it's id.
        /// </summary>
        /// <param name="list">list of categories.</param>
        /// <param name="id">id of the category to find</param>
        /// <returns>category with the specified id, otherwise null.</returns>
        public static CategoryContract FindCategory(this IList<CategoryContract> list, string id)
        {
            return list.FirstOrDefault(c => c.Id == id);
        }

        /// <summary>
        /// Reorders a password in a given collection of PasswordContract.
        /// </summary>
        /// <param name="collection">observable collection wich contains the specified password.</param>
        /// <param name="password">PasswordContract in the collection to reindex in order of it's name.</param>
        /// <param name="originalName">The original name of the password when it was sorted into the collection.</param>
        public static void Reorder(this ObservableCollection<PasswordContract> collection, PasswordContract password, string originalName)
        {
            if (password == null) throw new ArgumentNullException("password");
            if (collection == null) throw new ArgumentNullException("collection");

            if (originalName != password.Name)
            {
                int origIndex = collection.IndexOf(password);

                PasswordComparer comparer = new PasswordComparer { Password = password, CompareName = originalName ?? string.Empty };

                int index = collection.BinarySearch(password, comparer);
                if (index < 0) index = ~index;

                if (index > 0 && index > origIndex) index--;
                if (origIndex != index)
                {
                    collection.Move(origIndex, index);
                }
            }
        }


        /// <summary>
        /// Sorts a password into a list of passwords alphabetically sorted by name.
        /// </summary>
        /// <param name="list">the list of passwords to add.</param>
        /// <param name="password">password to add.</param>
        public static void SortInto(this IList<PasswordContract> list, PasswordContract password)
后面还有 315 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。