Ejemplo n.º 1
0
        private void _DoPrecedenceHack(FieldInfo fieldInfo, OutputAttribute outputAttribute)
        {
            const char dash         = '-';
            const char score        = '_';
            const char dashReplace  = '0';
            const char scoreReplace = '9';

            // back it up, these changes can't be undone
            if (fieldInfo.FieldType == typeof(String))
            {
                if (_backupRows == null) // back it up, these changes can't be undone
                {
                    _backupRows = Rows.DeepClone();
                }

                foreach (Object row in Rows)
                {
                    fieldInfo.SetValue(row, ((String)fieldInfo.GetValue(row)).Replace(dash, dashReplace).Replace(score, scoreReplace));
                }
            }

            if (outputAttribute.IsStringOffset)
            {
                if (_backupStringBuffer == null) // back it up, these changes can't be undone
                {
                    _backupStringBuffer = new byte[_stringBuffer.Length];
                    Buffer.BlockCopy(_stringBuffer, 0, _backupStringBuffer, 0, _stringBuffer.Length);
                }

                for (int i = 0; i < _stringBuffer.Length; i++)
                {
                    switch (_stringBuffer[i])
                    {
                    case (byte)dash:
                        _stringBuffer[i] = (byte)dashReplace;
                        break;

                    case (byte)score:
                        _stringBuffer[i] = (byte)scoreReplace;
                        break;
                    }
                }
            }

            if (String.IsNullOrEmpty(outputAttribute.SecondarySortColumn))
            {
                return;
            }

            FieldInfo fieldInfo2 = DataType.GetField(outputAttribute.SecondarySortColumn);

            if (fieldInfo2.FieldType != typeof(string))
            {
                return;
            }

            foreach (object row in Rows)
            {
                if (_backupRows == null) // back it up, these changes can't be undone
                {
                    _backupRows = Rows.DeepClone();
                }

                fieldInfo.SetValue(row, ((string)fieldInfo.GetValue(row)).Replace(dash, dashReplace).Replace(score, scoreReplace));
            }
        }