switch-statement

Switch based on generic argument type

一笑奈何 提交于 2020-08-24 08:34:17
问题 In C# 7.1 the below is valid code: object o = new object(); switch (o) { case CustomerRequestBase c: //do something break; } However, I want to use the pattern switch statement in the following scenario: public T Process<T>(object message, IMessageFormatter messageFormatter) where T : class, IStandardMessageModel, new() { switch (T) { case CustomerRequestBase c: //do something break; } } The IDE gives me the error "'T' is a type, which is not valid in the given context" Is there an elegant

Switch based on generic argument type

安稳与你 提交于 2020-08-24 08:31:32
问题 In C# 7.1 the below is valid code: object o = new object(); switch (o) { case CustomerRequestBase c: //do something break; } However, I want to use the pattern switch statement in the following scenario: public T Process<T>(object message, IMessageFormatter messageFormatter) where T : class, IStandardMessageModel, new() { switch (T) { case CustomerRequestBase c: //do something break; } } The IDE gives me the error "'T' is a type, which is not valid in the given context" Is there an elegant

Add text to Switch formcontrol and change it in toggle using material ui

拜拜、爱过 提交于 2020-08-09 09:01:33
问题 I am using Material UI's Switch component and I want to add text inside it. Also I need to make it square in shape. How to I add text inside the Switch component. It should say on when selected and off when default. I am using Material UI's Switch inside Formcontrol in reactjs form. <FormControlLabel label="Private ? " labelPlacement="start" control={ <Switch checked={this.state.checked} onChange={this.handleChange} color='primary' /> } /> 回答1: Here is an example of how to change the text

Add text to Switch formcontrol and change it in toggle using material ui

孤人 提交于 2020-08-09 09:01:07
问题 I am using Material UI's Switch component and I want to add text inside it. Also I need to make it square in shape. How to I add text inside the Switch component. It should say on when selected and off when default. I am using Material UI's Switch inside Formcontrol in reactjs form. <FormControlLabel label="Private ? " labelPlacement="start" control={ <Switch checked={this.state.checked} onChange={this.handleChange} color='primary' /> } /> 回答1: Here is an example of how to change the text

Is there a way to simplify if..else statements in Java [duplicate]

不想你离开。 提交于 2020-08-09 08:51:12
问题 This question already has answers here : How to remove large if-else-if chain [duplicate] (6 answers) Closed yesterday . I have this if statements that check the ID of a sport and set an Image according to the sport. but I am curious if there is a more simple and shorter way to implement this. Thank you for the time and answers! if (sport.equals("1")) { sportImg.setImageResource(R.drawable.fudbal); } else if (sport.equals("2")) { sportImg.setImageResource(R.drawable.hokej); } else if (sport

Is there a way to simplify if..else statements in Java [duplicate]

痴心易碎 提交于 2020-08-09 08:50:05
问题 This question already has answers here : How to remove large if-else-if chain [duplicate] (6 answers) Closed yesterday . I have this if statements that check the ID of a sport and set an Image according to the sport. but I am curious if there is a more simple and shorter way to implement this. Thank you for the time and answers! if (sport.equals("1")) { sportImg.setImageResource(R.drawable.fudbal); } else if (sport.equals("2")) { sportImg.setImageResource(R.drawable.hokej); } else if (sport