在运行时,我不知道变量v1是什么类型.出于这个原因,我写了很多if else陈述:
if (v1 is ShellProperty<int?>)
{
v2 = (v1 as ShellProperty<int?>).Value;
}
else if (v1 is ShellProperty<uint?>)
{
v2 = (v1 as ShellProperty<uint?>).Value;
}
else if (v1 is ShellProperty<string>)
{
v2 = (v1 as ShellProperty<string>).Value;
}
else if (v1 is ShellProperty<object>)
{
v2 = (v1 as ShellProperty<object>).Value;
}
Run Code Online (Sandbox Code Playgroud)
唯一的区别在于ShellProperty<AnyType>.
因此if else,我决定使用反射来在运行时获取属性类型,而不是使用大量语句编写它:
Type t1 = v1.GetType().GetProperty("Value").PropertyType;
dynamic v2 = (v1 as ShellProperty<t1>).Value;
Run Code Online (Sandbox Code Playgroud)
此代码获取PropertyType的v1,并将其分配给本地变量t1,但在那之后,我的编译器说:
t1是一个变量但是像一个类型一样使用
所以它不允许我在t1 …
Web Api中[FromRoute]和[FromBody]有什么区别?
[Route("api/Settings")]
public class BandwidthController : Controller
{
// GET: api/Settings
[HttpGet]
public IEnumerable<Setting> GetSettings()
{
return _settingRespository.GetAllSettings();
}
// GET: api/Settings/1
[HttpGet("{facilityId}", Name = "GetTotalBandwidth")]
public IActionResult GetTotalBandwidth([FromRoute] int facilityId)
{
if (!ModelState.IsValid)
{
return HttpBadRequest(ModelState);
}
}
}
Run Code Online (Sandbox Code Playgroud)
也是为了[FromRoute].
// PUT: api/Setting/163/10
[HttpPut]
public void UpdateBandwidthChangeHangup([FromRoute] int facilityId, int bandwidthChange)
{
_settingRespository.UpdateBandwidthHangup(facilityId, bandwidthChange);
}
Run Code Online (Sandbox Code Playgroud)
我可以用[FromBody]吗?
我有一个可以按原样运行的SSIS项目,但是当我尝试编辑它时,我收到一个错误:
"zipfile"这个名称在当前上下文中不存在
没有编辑,它工作正常.
产生错误的代码:
public void Main()
{
// TODO: Add your code here
string moduleName = Dts.Variables["User::ModuleName"].Value.ToString();
string s = Dts.Variables["User::ZipFileLocation"].Value.ToString().TrimEnd('\\') + "\\" + moduleName + "\\" + moduleName + "_" + DateTime.Now.ToString("ddMMyyyy");
// TODO: Add your code here
string startPath = s;
string zipPath = s + ".zip";
try
{
File.Delete(zipPath);
ZipFile.CreateFromDirectory(startPath, zipPath);
}
catch (Exception e)
{
}
Dts.TaskResult = (int)ScriptResults.Success;
}
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?
{props.stories.map((story) =>
<div key={story.id}>
{story = story.story}
<SliderItem story={story} />
</div>
)}
Run Code Online (Sandbox Code Playgroud)
上面的代码抛出一个错误说:
Uncaught (in promise) Error: Objects is not valid as a React child (found: object with keys
因为story第 3 行是一个对象。
我可以直接将该条件移动为<SliderItem story={story.story} />,但我想知道是否有任何方法可以将我的计算值分配给一个变量并在 JSX 中使用它?
我想应用一些逻辑,例如:
{ let storyObj = story.type === 'story' && story.story ? story.story : story }
Run Code Online (Sandbox Code Playgroud) 我将Visual Studio 2017更新为版本15.8.2。
在此更新之后,我开始在调试时遇到以下错误:
这是错误消息:
Visual Studio调试错误:为了防止在评估函数* .toString允许运行的所有线程时发生不安全中止。这可能已更改了进程的状态,并且遇到的任何断点都已被跳过。
此错误经常出现,并且一段时间后Visual Studio崩溃。
我尝试再次卸载并安装Visual Studio并重置首选项,但是我没有运气。
当我禁用选项:“启用属性评估和其他隐式函数调用”时,当我尝试通过将鼠标移到某些属性上来评估某些属性时,会遇到相同的错误。没有它,调试起来很困难,在此构建之前我没有任何问题。
问题与C#和Visual Basic(.NET)相同。
这个问题有解决办法吗?我的团队使用Visual Studio 2017版本15.7.4在同一个项目上工作没有问题
每次循环迭代,我都想直观地更新文本块的文本.我的问题是WPF窗口或控件在循环完成之前不会直观刷新.
for (int i = 0; i < 50; i++)
{
System.Threading.Thread.Sleep(100);
myTextBlock.Text = i.ToString();
}
Run Code Online (Sandbox Code Playgroud)
在VB6中,我会打电话DoEvents()或control.Refresh.目前我只是喜欢类似的快速和肮脏的解决方案DoEvents(),但我也想了解替代方案或"正确"的方法来做到这一点.我可以添加一个简单的绑定语句吗?语法是什么?提前致谢.
我正在使用最新的(2017年12月)依赖项堆栈。当我尝试使用Jest进行同构反应测试时,测试服不断失败并显示以下错误:
* Test suite failed to run
[BABEL] /__tests__/router.test.js: Plugin/Preset files are not allowed to
export objects, only functions.
Run Code Online (Sandbox Code Playgroud)
这是我的依赖项:
"dependencies": {
"axios": "^0.17.1",
"babel-polyfill": "^6.26.0",
"cors": "^2.8.4",
"express": "^4.16.2",
"react": "^16.1.1",
"react-dom": "^16.1.1",
"react-router-dom": "^4.2.2"
},
"devDependencies": {
"@babel/core": "^7.0.0-beta.35",
"babel-cli": "^6.26.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^8.0.2",
"babel-jest": "^22.0.1",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"enzyme": "^3.2.0",
"enzyme-adapter-react-16": "^1.1.0",
"enzyme-to-json": "^3.2.2",
"eslint": "^4.11.0",
"eslint-plugin-react": "^7.5.1",
"html-webpack-plugin": "^2.30.1",
"jest": "^21.2.1",
"nodemon": "^1.11.0",
"parallelshell": "^3.0.2",
"react-test-renderer": "^16.2.0",
"regenerator-runtime": "^0.11.1",
"supertest": …Run Code Online (Sandbox Code Playgroud) 我有一个.NET Core 2应用程序模板,该模板已配置为可以直接使用Azure AD。
配置为:
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "lautaroarinolive.onmicrosoft.com",
"TenantId": "67cb2dfd-ebd5-40d8-829b-378340981a17",
"ClientId": "50819a7a-e018-4c1d-bf0a-18c8fce5c600",
"CallbackPath": "/signin-oidc"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的门户中,我有一个Azure应用注册,其ID与相同ClientId。它具有回复URL [APP-URL]/signin-oidc。
仅在将回复URL设置为的情况下,localhost应用程序才有效[LocalhostURL]/signin-oidc,即使我了解到配置不会影响在localhost上的登录。
Azure应用程序在任何情况下均不起作用。
在两个应用程序中都无法正常工作时,出现此错误:
AADSTS50011:请求中指定的回复URL与为应用程序配置的回复URL不匹配:'50819a7a-e018-4c1d-bf0a-18c8fce5c600'
本地主机应用程序不需要配置的回复URL是否正确?
为什么会出现“未配置答复网址”错误?
<Employees>
<Employee>
<EmpId>1</EmpId>
<Name>Sam</Name>
<Sex>Male</Sex>
<Phone Type="Home">423-555-0124</Phone>
<Phone Type="Work">424-555-0545</Phone>
</Employee>
</Employees>
Run Code Online (Sandbox Code Playgroud)
private void Window_Loaded(object sender, RoutedEventArgs e)
{
emplyeeDetails = XDocument.Load(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\LinqToXml\\Xmls\\" + "Employees.xml");
var emplyees = from emp in emplyeeDetails.Descendants("Employee").Take(10)
orderby emp.Element("EmpId").Value ascending
select new
{
Id = emp.Element("EmpId").Value,
Name = emp.Element("Name").Value,
Sex = emp.Element("Sex").Value,
WorkPhone=emp.Element("Phone").Attribute("Type").Value,
HomePhone = emp.Element("Phone").Attribute("Type").Value,
};
DgrdEmployeeDetails.ItemsSource = emplyees.ToList();
}
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,我可以得到以下结果:

但我需要列WorkPhone的值424-555-0545而不是Home列HomePhone的值423-555-0124而不是列的值Home.
我该怎么办?
我使用的反应,并与组件Negotiation,frontend以及food来自其它组件传递的元素.
我如何设置这个样式,以便每个元素(Negotiation,Frontend和food)彼此分开,但仍然在同一列中,旁边有新闻排列?
我的JavaScript:
class Course extends React.Component {
render() {
return (
<div>
<div className="coursecontent">
<h3>{this.props.coursename}</h3>
<h4> {this.props.status} {this.props.progress}</h4>
</div>
<button className="coursecontent">Start exercise</button>
</div>
);
}
}
class Welcomebox extends React.Component {
render() {
return <h1>Welcome Naomi</h1>;
}
}
ReactDOM.render(<Welcomebox />, document.getElementById('welcomebox'));
class Coursebox extends React.Component {
render() {
return (
<div className="box-field">
<Course coursename="Negotiation" progress= "20%" status="Progress"/>
<Course coursename="Frontend" progress="56%" status="Progress"/>
<Course coursename="Food" status="Progress" progress="43%"/>
</div> …Run Code Online (Sandbox Code Playgroud)