Сохранение и загрузка значений переключателей не работает c #

Вот как это работает:

export function getFunctionCallerName (){
  // gets the text between whitespace for second part of stacktrace
  return (new Error()).stack.match(/at (\S+)/g)[1].slice(3);
}

Затем в ваших тестах:

import { expect } from 'chai';
import { getFunctionCallerName } from '../../../lib/util/functions';

describe('Testing caller name', () => {

    it('should return the name of the function', () => {
      function getThisName(){
        return getFunctionCallerName();
      }

      const functionName = getThisName();

      expect(functionName).to.equal('getThisName');
    });

  it('should work with an anonymous function', () => {


    const anonymousFn = function (){
      return getFunctionCallerName();
    };

    const functionName = anonymousFn();

    expect(functionName).to.equal('anonymousFn');
  });

  it('should work with an anonymous function', () => {
    const fnName = (function (){
      return getFunctionCallerName();
    })();

    expect(/\/util\/functions\.js/.test(fnName)).to.eql(true);
  });

});

Обратите внимание, что третий тест будет работать, только если тест находится в / UTIL / функции

0
задан Aziks 13 July 2018 в 06:17
поделиться

1 ответ

Я думаю, проблема в следующем коде -

radioButton1.Checked = bool.TryParse(temp[0], out tempBool);
radioButton2.Checked = bool.TryParse(temp[1], out tempBool);

bool.TryParse всегда будет возвращать true, если он сможет успешно разобрать первый параметр в значение bool. Что вам нужно сделать.

bool tempBool_1 = false, tempBool_2 = false;
if(bool.TryParse(temp[0], out tempBool_1))
{
      radioButton1.Checked = tempBool_1;
}
else
{
    // handle parsing error.
}
if(bool.TryParse(temp[0], out tempBool_2))
{
      radioButton2.Checked = bool.TryParse(temp[1], out tempBool_2);
}
else
{
    // handle parsing error.
}
1
ответ дан Kedar Rudre 17 August 2018 в 13:35
поделиться
  • 1
    Я только что заменил radioButton1.Checked = bool.TryParse(temp[0], out tempBool); на radioButton1.Checked = Convert.ToBoolean(temp[0]);, и он работает – Aziks 13 July 2018 в 06:46
  • 2
    Да, это тоже должно работать. Но если по какой-то причине вы ожидаете, что значения в реестре могут быть повреждены, тогда Convert.ToBoolean() будет генерировать исключение, если он не сможет проанализировать значение. – Kedar Rudre 13 July 2018 в 06:48
  • 3
    Если я поймаю исключение, значения будут установлены по умолчанию, поэтому проблем не будет. – Aziks 13 July 2018 в 07:02
Другие вопросы по тегам:

Похожие вопросы: