小编Bra*_*ner的帖子

在unicode类中是char吗?

在.Net中,给定一个char,有没有办法判断该字符是否属于特定的Unicode类别?我感兴趣的类别在这里定义http://www.fileformat.info/info/unicode/category/index.htm

例如,是否有一个函数执行此类操作?:

bool isCharInClass(Char c, String class)
Run Code Online (Sandbox Code Playgroud)

这可以被称为:

SomeClass.isCharInClass("a", "Lo");
Run Code Online (Sandbox Code Playgroud)

.net c# vb.net unicode

3
推荐指数
1
解决办法
485
查看次数

await this.ShowMessageAsync在WPF C#中不起作用

我有一个小问题,等待this.ShowMessageAsync()方法.我搜索了很多我的问题,但还没有成功.

对于下面的代码我收到错误";期望"

private void removeGameButton_Click(object sender, RoutedEventArgs e)
{
     Task<MessageDialogResult> result = await this.ShowMessageAsync("Hi", "Message", MessageDialogStyle.AffirmativeAndNegative);
     if(result.Result == MessageDialogResult.Negative)
     {
         Console.WriteLine("No");
     }
     else
     {
         Console.WriteLine("yes");
     }
}
Run Code Online (Sandbox Code Playgroud)

我对"这个"感到错误.如果我没有使用await那么它工作正常,但后来我不知道从Message Dialogue获得结果.

我从https://www.nuget.org/packages/Microsoft.Bcl.Async安装了2次3次Microsoft.Bcl.Async

我真的很困惑.所以请帮我找到解决方案.提前致谢

c# wpf asynchronous

2
推荐指数
1
解决办法
2136
查看次数

框架 4.7.2 中使用的 C#8 功能不会在 Visual Studio 中导致生成错误,但在 TFS 上会导致生成错误

我有一个适用于 .NET Framework 4.7.2 的 C# 类库。我的一位开发人员添加了一个接口,并将一些成员标记为public,仅使用 C# 8 支持。他的计算机和我的计算机都没有给出有关此问题的任何错误或警告,这使其无法通过代码审查。然而我们的 TFS 服务器抛出了正确的错误。

界面:

public interface IHintManager
{
    public void AddJoinHint(string leftTable, string rightTable, JoinHint hint);
    public void AddQueryHint(QueryHint hint);
    public void AddTableHint(string table, TableHint hint);
    void InjectHints(DbContext context, DbCommand command, DbInterceptionContext interceptionContext);
}
Run Code Online (Sandbox Code Playgroud)

.csproj 设置为 4.7.2:

<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
Run Code Online (Sandbox Code Playgroud)

TFS 错误:

在此输入图像描述

本地构建输出:

在此输入图像描述

为什么我们不会在本地看到此错误?为了将来在本地开发人员和 TFS 之间获得一致的构建结果,我们需要更改哪些内容?

c# tfs

2
推荐指数
1
解决办法
556
查看次数

根据所选项目的类型显示 XAML 元素

在我的 WPF 应用程序中,我有一个抽象基类的 Observable 集合Test,它实际上充满了它的派生类SqlTestConfigTest

我有一个组合框,允许用户从可观察集合中选择一个项目,并且根据所选测试的类型需要不同的控件。

我尝试过使用 DataTemplates,但没有设法让它们适用于列表以外的任何内容。

测试.cs

public abstract class Test
{
    public string Number { get; set; } // A string as test numbers can contain multiple decimal points depending on the section

    public string Description { get; set; }

    public string Condition { get; set; }

    public string Result { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

查看模型

public class MainWindowViewModel : INotifyPropertyChanged
{
    public ObservableCollection<Test> Tests { get; set; } = new …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

1
推荐指数
1
解决办法
2680
查看次数

MVC默认路由不适用于控制器

我刚刚开始一个新的MVC项目,默认路由似乎没有像我期望的那样工作.

路由配置:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}
Run Code Online (Sandbox Code Playgroud)

ActionLink在"Scripts"控制器上进行了"索引"操作@Html.ActionLink("Scripts", "Index", "Scripts").

public class ScriptsController : Controller
{
    public ActionResult Index()
    {
        var model = new IndexModel();
        .......
        return View(model);
    }
}
Run Code Online (Sandbox Code Playgroud)

单击此链接时,浏览器会尝试导航到" http:// localhost:1733/Scripts / ",浏览器会显示"目录列表被拒绝"错误.当我手动将URL更改为" http:// localhost:1733/Scripts/Index "时,它可以正常工作.

默认路由不应自动推断"索引"操作吗?它似乎适用ManageController于作为默认MVC站点模板一部分的类(" http:// localhost:1733/Manage "会调出IndexActionResult ManageController)

我究竟做错了什么?

c# asp.net-mvc asp.net-mvc-routing

1
推荐指数
1
解决办法
3003
查看次数

如何从我的带参数的控制器返回不同的ActionResult?

我有Controller一些行动,如下:

[HttpPost]
public ActionResult Create(CreateModel model)
{
    if (model.SelectedCustomers.Count > 0 &&
        model.SelectedVersions.Count > 0 &&
        !string.IsNullOrWhiteSpace(model.ScriptName) &&
        !string.IsNullOrWhiteSpace(model.ScriptText))
    {

        Script script;
        ...save to database...
        return Edit(script.Id);   //<---------Return other view here
    }
    else
    {
        ...
    }
}

[HttpGet]
public ActionResult Edit(int? scriptId)
{
    return View();
}
Run Code Online (Sandbox Code Playgroud)

在以后Create的行动中运行,并节省了我的模型到数据库成功,我想给用户发送到Edit新创建的脚本视图.当我使用上面的代码时,特别是return Edit(script.Id);它只是将用户发送回Create视图而不是Edit视图.当用户Edit直接导航到操作时,或通过Html.ActionLink指向Edit一切正常的结果.

我究竟做错了什么?

c# asp.net-mvc

1
推荐指数
1
解决办法
4909
查看次数

主窗口 DataContext StackOverflowException

我知道这听起来可能有点疯狂,但我理解的目的,你会如何解释设置Window.DataContextMainWindow这个错误的结果:

“抛出了‘System.StackOverflowException’类型的异常。”

<Window>
  <Window.DataContext>
    <local:MainWindow />
  </Window.DataContext>
</Window>
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

1
推荐指数
1
解决办法
541
查看次数

隐式转换不能分配给接口

我有一个隐式转换的类string定义为:

class TestClass : ITestInterface
{
    public static implicit operator TestClass(string value)
    {
        return new TestClass(value);
    }

    public TestClass(string value)
    {
        Value = value;
    }
    public string Value { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

它实现了一个标记界面:

public interface ITestInterface { }
Run Code Online (Sandbox Code Playgroud)

我有另一个类的方法定义为:

public void DoSomething(ITestInterface thing) { }
Run Code Online (Sandbox Code Playgroud)

我试图调用该方法时遇到错误:

public void Test()
{
    TestClass a = "This works fine.";
    DoSomething("Why doesn't this work?");
}
Run Code Online (Sandbox Code Playgroud)

无法从'string'转换为'Tests.ITestInterface'

所有代码都大大简化了; 我的实际需求要复杂得多,但这似乎是阻碍我想实现的模式的核心.

什么阻止这种工作?(C#规范中的东西?)
我可以对我的代码进行任何更改以允许这种类型的转换工作吗?

c# implicit-conversion

1
推荐指数
1
解决办法
66
查看次数

平铺对象层将位置绘制到错误的位置

我知道这个问题对那些熟悉平铺和单一游戏的人来说非常具体,所以我会尽量做到尽可能彻底.我已经在这个问题上工作了15个多小时,我很绝望.

我正在尝试使用Tiled的对象层将精灵绘制到屏幕上.我已经创建了一个新的对象图层,为它绘制了一些矩形,并添加了一个我在LoadContent方法中引用的自定义属性.

这是绘制到对象图层

这是我的LoadContent方法:

protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);

        mymap = Content.Load<TiledMap>("Misc/newmap");
        enemyShip = Content.Load<Texture2D>("Enemies/enemyship");

        //TiledMapObject[] islands = mymap.GetLayer<TiledMapObjectLayer>("Islands").Objects;
        ship_sprite = Content.Load<Texture2D>("character/wooden_ship");

        Texture2D texture = Content.Load<Texture2D>("character/anima2");
        animatedSprite = new AnimatedSprite(texture, 1, 2);

        font = Content.Load<SpriteFont>("Misc/londrinasolid");

        Song song = Content.Load<Song>("Music/Chad_Crouch_-_Stellars_Jay");
        MediaPlayer.Volume = 0.7F;
        MediaPlayer.Play(song);

        TiledMapObject[] littleBoats = mymap.GetLayer<TiledMapObjectLayer>("SmallBoats").Objects;
        foreach (var en in littleBoats)
        {
         string type;
            en.Properties.TryGetValue("type", out type);
            if (type == "smallboat")
            {                    
                Enemy.enemies.Add(new SmallBoat(en.Position)); …
Run Code Online (Sandbox Code Playgroud)

c# xna monogame tiled

0
推荐指数
1
解决办法
174
查看次数

如何在C#中的类中动态设置变量的值?

我正在尝试做这样的事情:

public class MyClass()
{
  private void SetAValiable(int boolNumber)
  {
    bool b1 = false;
    bool b2 = false;

    ("b" + boolNumber) = true;
  }
}
Run Code Online (Sandbox Code Playgroud)

我试过这个但是不断从GetProperty调用中得到一个null:

Type myType = typeof(MyClass);
PropertyInfo pinfo = myType.GetProperty("b" + boolNumber);
pinfo.SetValue(myType, true, null);
Run Code Online (Sandbox Code Playgroud)

任何人都有任何想法如何让这个工作?

谢谢!

c# reflection

-2
推荐指数
1
解决办法
82
查看次数