我使用 Json.Net 序列化字典类型的字典,当我向字典添加整数或布尔值时,反序列化时我会得到整数和布尔值。现在我试图将我的代码更改为使用 ServiceStack.Text,因为代码的其他部分存在日期序列化的问题,但现在我在反序列化后将布尔值和整数作为字符串。有没有办法与 Json.Net 具有相同的行为?
这是重现它的代码:https: //gist.github.com/1608951 Test_JsonNet 通过,但 Test_ServiceStack_Text_TypeSerializer 和 Test_ServiceStack_Text_JsonSerializer 都失败
我有一个带有垂直滚动条的外部列表框,在每个项目上我都有一个可能有水平滚动条的滚动查看器。问题是当我使用鼠标时,事件不会到达外部列表框,因此滚动不起作用。我已经在滚动查看器上设置了 Focusable=false,但这只会阻止它们处理键盘事件,而不是鼠标事件。如何阻止内部滚动查看器捕获鼠标滚轮事件并让它冒泡到外部列表框?
我有一组这样的 F# 记录类型:
type Course =
{ Id : int
Title : string
Instructor : string
Duration : string
StartDate : string
IconUrl : string
Url : string
LectureSections : LectureSection list }
and LectureSection =
{ Title : string
Completed : bool
Lectures : Lecture list }
and Lecture =
{ Title : string
VideoUrl : string }
Run Code Online (Sandbox Code Playgroud)
在某些时候我打电话
sprintf "%A" course
Run Code Online (Sandbox Code Playgroud)
其中 course 是 Course 记录的一个实例
在常规 .NET 项目中,这工作正常,但在 Windows Phone 7.1/Silverlight 4 F# 项目(我使用的是 Daniel Mohl 的模板)上,我收到此错误: …
有什么影响
<AllowCrossTargeting>true</AllowCrossTargeting>
Run Code Online (Sandbox Code Playgroud)
在fsproj文件中?我找不到任何关于它的文档
我正在做这样一个经过身份验证的请求:
let url = "https://datafeeds.networkrail.co.uk/ntrod/CifFileAuthenticate?type=CIF_ALL_FULL_DAILY&day=toc-full"
let auth = "Basic " + (username + ":" + password |> Encoding.UTF8.GetBytes |> Convert.ToBase64String)
Http.Request(url, headers=["Authorization", auth])
Run Code Online (Sandbox Code Playgroud)
Http.Request来自FSharp.Data
在已编译的F#应用程序上,它工作正常,但在F#interactive上运行时,发送的请求稍有不同,我收到此错误:
System.Net.WebException: The remote server returned an error: (403) Forbidden.
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
Run Code Online (Sandbox Code Playgroud)
在fiddler下查看,该url返回302重定向到https://nr-datafeed-cif.s3.amazonaws.com/CIF_ALL_FULL_DAILY%2Ftoc-full.json?...
但是在fsi下,后续请求转到https: //nr-datafeed-cif.s3.amazonaws.com/CIF_ALL_FULL_DAILY/toc-full.json ?....
我正在使用MediaLauncher播放视频,如下所示:
var launcher = new MediaPlayerLauncher();
launcher.Location = MediaLocationType.Data;
launcher.Media = new Uri("shared/transfers/video.mp4", UriKind.Relative);
launcher.Show();
Run Code Online (Sandbox Code Playgroud)
但这有一个问题,当你切换到另一个应用程序或锁定屏幕时它关闭,所以我想在应用程序中创建一个页面来播放视频,所以我可以保持状态.
我尝试使用MediaElement和Microsoft Player Framework这样:
var file = IsolatedStorageFile.GetUserStoreForApplication())
var stream = file.OpenFile("shared/transfers/video.mp4", FileMode.Open, FileAccess.Read))
mediaPlayer.SetSource(stream);
mediaPlayer.Play();
Run Code Online (Sandbox Code Playgroud)
和这样:
mediaPlayer.Source = new Uri("ms-appdata:///local/shared/transfers/video.mp4", UriKind.RelativeOrAbsolute);
mediaPlayer.Play();
Run Code Online (Sandbox Code Playgroud)
但在所有4个案例中,我都收到了3123 An error has occurred.
关于该MediaFailed
事件的非常有用的错误消息
我在C#中完成了一个手写的CSS解析器,这个解析器变得难以管理,并且正在尝试使用FParsec来使其更具可持续性.这是一个解析用regexes制作的css选择器元素的片段:
var tagRegex = @"(?<Tag>(?:[a-zA-Z][_\-0-9a-zA-Z]*|\*))";
var idRegex = @"(?:#(?<Id>[a-zA-Z][_\-0-9a-zA-Z]*))";
var classesRegex = @"(?<Classes>(?:\.[a-zA-Z][_\-0-9a-zA-Z]*)+)";
var pseudoClassRegex = @"(?::(?<PseudoClass>link|visited|hover|active|before|after|first-line|first-letter))";
var selectorRegex = new Regex("(?:(?:" + tagRegex + "?" + idRegex + ")|" +
"(?:" + tagRegex + "?" + classesRegex + ")|" +
tagRegex + ")" +
pseudoClassRegex + "?");
var m = selectorRegex.Match(str);
if (m.Length != str.Length) {
cssParserTraceSwitch.WriteLine("Unrecognized selector: " + str);
return null;
}
string tagName = m.Groups["Tag"].Value;
string pseudoClassString = m.Groups["PseudoClass"].Value;
CssPseudoClass pseudoClass;
if (pseudoClassString.IsEmpty()) {
pseudoClass = …
Run Code Online (Sandbox Code Playgroud) 有一个类型提供程序,它有三个属性'a','b'和'c',分别是'string','string option'和'int option'.
当我在这些属性中有"","无"和"1"的实例时,会失败:
(row1.a, row1.b, row1.c) |> should equal ("", None, Some 1)
Run Code Online (Sandbox Code Playgroud)
但所有这些工作都很好:
row1.a |> should equal ""
row1.b |> should equal None
row1.c |> should equal (Some 1)
("", None, Some 1) |> should equal ("", None, Some 1)
Run Code Online (Sandbox Code Playgroud)
这怎么可能?什么可以使b中的None与其他None不同?编译后,None只是一个null,在.Net中两个空值是否可以不同?
与大多数F#类型一样,元组具有结构相等性,因此它应该可以工作.我得到一个带有Message的NUnit.Framework.AssertionException:
Expected: <(, , Some(1))>
But was: <(, , Some(1))>
Run Code Online (Sandbox Code Playgroud)
NUnit只调用.Equals,这就是问题所在.
这也失败了:
(row1.a, row1.b, row1.c).Equals(("", None, Some 1)) |> should equal true
Run Code Online (Sandbox Code Playgroud)
运行时类型row1
是System.Tuple<string,Microsoft.FSharp.Core.FSharpOption<string>,Microsoft.FSharp.Core.FSharpOption<int>>
,所以即使这应该在理论上工作:
row1 |> should equal ("", None, Some 1)
Run Code Online (Sandbox Code Playgroud)
事实上,当None …
我需要将刷子设置为红色或橙色,具体取决于某些条件,如果没有满足任何条件,则需要回退到默认刷子.
如果Windows手机有样式触发器,这将是微不足道的,但事实并非如此,我必须为每个场景创建一个特殊用途的转换器,如下所示:
public class StatusToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var status = (Status)value;
if (status.IsCancelled)
{
return new SolidColorBrush(Colors.Red);
}
else if (status.IsDelayed)
{
return new SolidColorBrush(Colors.Orange);
}
else
{
return parameter;
}
}
}
Run Code Online (Sandbox Code Playgroud)
并像这样使用它:
<TextBlock Foreground="{Binding Status,
Converter={StaticResource statusToColorConverter},
ConverterParameter={StaticResource PhoneForegroundBrush}}" />
Run Code Online (Sandbox Code Playgroud)
但现在我需要一个返回PhoneForegroundBrush
或PhoneDisabledBrush
根据条件返回的转换器.
我无法传递两个参数,Windows Phone也不支持MultiBindings.我虽然这样:
<TextBlock Foreground="{Binding Status,
Converter={StaticResource statusToColorConverter},
ConverterParameter={Binding RelativeSource={RelativeSource Self}}
Run Code Online (Sandbox Code Playgroud)
所以我可以在参数中获取文本块,然后使用它来查找资源,但它也不起作用.
有任何想法吗?
我想使用FSharp.Data.CsvProvider(v1.1.10)创建一个类型来处理带有";"的CSV文件 分隔符和预定义的模式.
以下行报告错误:
type CsvType1 = CsvProvider<Sample="1;2;3", Separator=";", Schema="category (string), id (string), timestamp (string)">
Run Code Online (Sandbox Code Playgroud)
错误是:
指定的参数既不是文件,也不是格式良好的CSV:无法找到文件'...\1; 2; 3'.
将Sample设置为"",null或不设置它会产生其他错误.
使用","的分隔符和"1,2,3"的样本工作正常..但是无法读取我的csv文件.
我究竟做错了什么?
我有一个 ObservableCollection 和一个 ListCollectionView 并带有过滤谓词集。当我更改全局条件时,比如说搜索文本,我可以调用.Refresh()
视图以强制它刷新。但是当集合中的一个项目改变了一个属性时,是否可以只刷新该元素的可见性?假设通过声明过滤器取决于属性?
f# ×6
f#-data ×2
wpf ×2
c# ×1
data-binding ×1
fparsec ×1
fsi ×1
listbox ×1
mousewheel ×1
parsing ×1
servicestack ×1
silverlight ×1
xaml ×1