Ejemplo n.º 1
0
        public bool InterfaceImplementationAsClass()
        {
            var  equalityComparer = new UInt64EqualityComparer();
            bool result           = true;

            for (int i = 0; i < _n; i++)
            {
                result = equalityComparer.Equals(_x, _y);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public bool EqualsMethodReference()
        {
            var equalityComparer = new UInt64EqualityComparer();
            Func <ulong, ulong, bool> equalsReference = equalityComparer.Equals;
            bool result = true;

            for (int i = 0; i < _n; i++)
            {
                result = equalsReference(_x, _y);
            }
            return(result);
        }
Ejemplo n.º 3
0
    List <TMaster> GenerateObjects(Table table)
    {
        IEqualityComparer <object> comparer;
        var columnType = table.ColumnTypeMap[m_MasterKeyColumn];

        if (columnType == typeof(short))
        {
            comparer = new Int16EqualityComparer();
        }
        else if (columnType == typeof(int))
        {
            comparer = new Int32EqualityComparer();
        }
        else if (columnType == typeof(long))
        {
            comparer = new Int64EqualityComparer();
        }
        else if (columnType == typeof(Guid))
        {
            comparer = new GuidEqualityComparer();
        }
        else if (columnType == typeof(string))
        {
            comparer = new StringEqualityComparer();
        }
        else if (columnType == typeof(DateTime))
        {
            comparer = new DateTimeEqualityComparer();
        }
        else if (columnType == typeof(DateTimeOffset))
        {
            comparer = new DateTimeOffsetEqualityComparer();
        }
        else if (columnType == typeof(ulong))
        {
            comparer = new UInt64EqualityComparer();
        }
        else
        {
            throw new NotSupportedException($"Key column of type '{columnType.Name}' is not supported for Master/Detail collections.");
        }

        var groups = new Dictionary <object, List <Row> >(comparer);

        foreach (var row in table.Rows)
        {
            var key = row[m_MasterKeyColumn];
            if (key == null)
            {
                throw new MissingDataException($"A null was found in the master key column '{m_MasterKeyColumn}'");
            }

            if (!groups.TryGetValue(key, out var group))
            {
                group = new();
                groups.Add(key, group);
            }
            group.Add(row);
        }

        var result = new List <TMaster>();

        foreach (var group in groups.Values)
        {
            var master = MaterializerUtilities.ConstructObject <TMaster>(group[0], m_MasterConstructor, Converter);
            var target = m_Map(master);
            foreach (var row in group)
            {
                target.Add(MaterializerUtilities.ConstructObject <TDetail>(row, m_DetailConstructor, Converter));
            }
            result.Add(master);
        }

        return(result);
    }