我有一个WebApi返回一个简单的对象,但当我强制它返回XML(Accept: application/xml)时,它忽略了[XmlAttribute]我在对象上设置的属性.
这是我的目标:
public class Foo
{
[XmlAttribute]
public string Bar { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我在代码中将其返回:
[RoutePrefix("api/mytest")]
public class MyTestController : System.Web.Http.ApiController
{
[HttpGet]
[Route("gettest")]
public Foo GetTest()
{
return new Foo() { Bar = "foobar" };
}
}
Run Code Online (Sandbox Code Playgroud)
生成的XML是:
<Foo>
<Bar>foobar</Bar>
</Foo>
Run Code Online (Sandbox Code Playgroud)
而我希望它会像这样返回:
<Foo Bar="foobar">
</Foo>
Run Code Online (Sandbox Code Playgroud)
为什么WebApi使用的XmlSerializer会忽略该[XmlAttribute]属性,如何让它像我想的那样工作?
我正在尝试使用lightGallery jQuery插件(http://sachinchoolur.github.io/lightGallery/index.html)与AngularJS一起使用.
我发现一些答案表明我需要一个指令,所以我创建了以下内容:
.directive('lightGallery', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
jQuery(element).lightGallery();
}
};
})
Run Code Online (Sandbox Code Playgroud)
然后在我看来我这样做:
<ul lightGallery>
<li ng-repeat="photo in album.photos" data-src="{{photo.fullres}}">
<img ng-src="{{photo.thumbnail}}" />
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
(我也试过<ul light-gallery>)当我运行页面时,当我点击任何缩略图时没有任何反应.不过,我可以alert()在链接功能中添加一个,然后显示.
如何让AngularJS与jQuery和这个插件一起玩?
更新:
经过一些调试后,似乎jQuery(element).lightGallery()在模型绑定到视图之前执行.那么接下来的问题是,当一切都被约束而不是之前,我如何获得一个被调用的指令.
我有一个自定义属性,我希望它具有一个属性名称作为输入。因为名称是一个字符串,所以它是一种有效的输入类型(因为属性对于其作为构造函数的输入的限制非常有限)。但是我该怎么做呢?
请看以下示例代码:
public class MyCustomAttribute : Attribute {
public MyCustomAttribute(string propertyName) {}
}
public class Foo {
public bool MyCustomProperty { get; set; }
[MyCustom(SomeMagicAppliedToMyCustomProperty)] // I want the attribute to receive something along the lines of "Foo.MyCustomProperty"
public void Bar();
}
Run Code Online (Sandbox Code Playgroud)
如何限制属性可以在其构造函数中接收的内容来完成此操作?
我正在根据其他一些数据构建一系列Actions.每个操作都应该调用方法,并且应该并行执行操作列表.我有以下代码适用于无参数方法:
private void Execute() {
List<Action> actions = new List<Action>();
for (int i = 0; i < 5; i++) {
actions.Add(new Action(DoSomething));
}
Parallel.Invoke(actions.ToArray());
}
private void DoSomething() {
Console.WriteLine("Did something");
}
Run Code Online (Sandbox Code Playgroud)
但是,如果方法有参数,我怎么能做类似的事呢?以下不起作用:
private void Execute() {
List<Action<int>> actions = new List<Action<int>>();
for (int i = 0; i < 5; i++) {
actions.Add(new Action(DoSomething(i))); // This fails because I can't input the value to the action like this
}
Parallel.Invoke(actions.ToArray()); // This also fails because Invoke() expects Action[], not Action<T>[] …Run Code Online (Sandbox Code Playgroud) 在 DevOps 中,您可以创建一个dotnet build任务,其中可以设置“项目路径”**/*.csproj来构建所有项目。
这工作得很好,但它(显然)也构建了我的*.Test.csproj项目。
我发现一些帖子提到了排除模式,因此我尝试执行与这些帖子中相同的操作,并尝试了以下组合:
**/*.csproj;-**/*.Test.csproj
**/*.csproj;!**/*.Test.csproj
**/*.csproj;-:**/*.Test.csproj
**/*.csproj;!:**/*.Test.csproj
Run Code Online (Sandbox Code Playgroud)
对于所有尝试,我都会在 DevOps 日志中收到以下错误:
未找到与指定模式匹配的项目文件。
那么,如何创建一个dotnet build任务来构建除项目之外的所有项目呢*.Test.csproj?
.net-core azure-devops azure-pipelines-build-task azure-pipelines
我发现WpfMediaKit似乎是一个很好的选择<MediaElement>.但是,我似乎无法让它发挥作用.
在Visual Studio中,我创建了一个新的WPF项目,然后我下载了NuGet包.我添加了xmlns一个和一个播放器元素,并为元素分配了一个源并启动了应用程序...但没有任何反应.没有显示任何内容,没有错误.
<Window x:Class="MainApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MainApp"
xmlns:wpfmediakit="clr-namespace:WPFMediaKit.DirectShow.Controls;assembly=WPFMediaKit"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<wpfmediakit:MediaUriElement Source="https://domain/path/video.mp4" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
通过将源更改为下载文件并使用本地副本,file://C:/Temp/File.mp4对此没有帮助.
我觉得我必须错过一些必不可少的东西,但是什么?
我有一个使用MEF加载插件的应用程序.所有这些插件都符合以下界面:
public interface IPlugin {
Task Start();
}
Run Code Online (Sandbox Code Playgroud)
所有方法都实现为async:public async Task Start()
当应用程序运行时,我有一个IEnumerable<IPlugin>可用于所有插件的属性.问题基本上是我如何Start()并行运行所有方法并等待所有方法完成?
我知道Parallel.ForEach(plugins, plugin => plugin.Start()),但这是不可能的,并且在所有插件启动之前执行仍在继续.
最有希望的解决方案似乎是Task.WhenAll(),但我不知道如何在不添加一些脚手架(这似乎是开销)的情况下将未知的方法列表发送到此.
我怎么能做到这一点?
c# ×5
.net-core ×2
.net ×1
action ×1
angularjs ×1
async-await ×1
azure-devops ×1
javascript ×1
jquery ×1
lightgallery ×1
task ×1
wpf ×1
wpf-mediakit ×1