问题列表 - 第38844页

通过动态方法解析IL中发现的令牌

感谢Hans Passant在这里回答我的问题: 如何从DynamicMethod获取IL bytearray?

我能够起床和跑步.我现在正在尝试解决在IL发出的元数据令牌,以查看正在调用哪些方法,或者什么不是.我能够解决方法体中的下一个标记是一个调用.我正在使用来自Mono.ReflectionMethodBodyReader的一些代码.

static byte[] GetILByteArray(Delegate @delegate){
   // does stuff mentioned in other thread
}
...
Expression<Action> foo = () => Console.WriteLine(0);
var compiled = foo.Compile();
var bytes = GetILByteArray(compiled);
int index =Array.FindIndex(bytes,b=>GetOpCode(b).OperandType == OperandType.InlineMethod);
var token = BitConverter.ToInt32(bytes,index+1);
compiled.Method.Module.ResolveMember(token);
Run Code Online (Sandbox Code Playgroud)

引发异常,说明该域中的令牌是不可解析的.这里有人有诀窍吗?我应该尝试传递代理通用参数还是完全没用?

我现在正在考虑为表达式树的代表编写一个反编译器的想法,我真的希望能够使用我自己编译为测试用例的表达式树,因为我总是可以回到原始版本并进行比较.

c# dynamicmethod

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

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

绑定到数组支持的属性

我正在尝试为Windows Phone 7平台构建自定义控件.到目前为止,我已经定义了属性,如果它是一个简单类型(如字符串),它可以正常工作,但这最终需要是一个数组.所以我这样定义我的属性:

    #region Keywords

    public string[] Keywords
    {
        get { return (string[])GetValue(KeywordsProperty); }
        set { SetValue(KeywordsProperty, value); }
    }

    public static readonly DependencyProperty KeywordsProperty =
        DependencyProperty.Register(
            "Keywords",
            typeof(string[]),
            typeof(MyType),
            new PropertyMetadata(null));

    #endregion Keywords
Run Code Online (Sandbox Code Playgroud)

现在我想要顶级支持绑定和XAML,但我无法弄清楚如何通过XAML设置属性.有一个更好的方法吗?

c# wpf xaml

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

JFormattedTextField未正确清除

我正在做这个任务,制作一个解决数独的程序.我有一个带有SudokuTextBox网格的面板,扩展了JFormattedTextField.我有一个MaskFormatter,因此每个文本框只接受一个整数.然后在我的面板中,当密钥被释放时,我有这个代码.

 public void keyReleased(KeyEvent e) {
  SudokuTextBox tb = (SudokuTextBox) e.getSource();
  int row = tb.getRow();
  int col = tb.getCol();
  int value = toInteger(tb.getText());
  //System.out.println(value);
  if(sudoku.isValid(row, col, value)) {
   sudoku.set(row, col, value);
  }
  else {
   sudoku.set(row, col, 0);
   tb.setText(null);
  }
  tb.setCaretPosition(0);
  sudoku.print();
 }
Run Code Online (Sandbox Code Playgroud)

问题是,如果我在文本框中放一个有效的值,然后我回去(由数独的规则),输入无效值的文本框被清除.但是当我向前选项卡时,前一个有效值显示在文本框中.我sudokumatrix包含所有已inputed不明确的价值像它应该这样,只有在相应的文本框中的数字.

当我将"SudokuTextBox扩展JFormattedTextField"更改为"SudokuTextBox extends JTextField"时,它更加令人困惑,它就像一个魅力.但我不能设置JTextField的大小,以便它是正方形,我不能强制每个文本框只有一个整数.

我错过了一些非常明显的东西吗

java keyevent sudoku jtextfield jformattedtextfield

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

MVC Razor 3 RC语法:错误或用户错误?

我想这很明显,但在我提交错误报告之前,我想知道我做错了.我使用ASP.NET MVC3 RC和Razor有这个视图:

<div class="miniProfile">
    Joined: @FormatTime(Model.Joined)<br />
    @if (!String.IsNullOrWhiteSpace(Model.Location)) {
        Location: @Model.Location<br />
    }
    Posts: @Model.PostCount<br />
    @Html.ActionLink("Full Profile", "ViewProfile", new { id = Model.UserID }, new { target = "_blank" }) | 
    @Html.ActionLink("Send Private Message", "SendNew", "PrivateMessages", new { id = Model.UserID }) | 
    @Html.ActionLink("Send E-mail", "Send", "Email", new { id = Model.UserID })
    @if (!String.IsNullOrWhiteSpace(Model.Web)) {
        | <a href="@Model.Web" target="_blank">Visit user Web site: @Model.Web</a>
    }
</div>
Run Code Online (Sandbox Code Playgroud)

它在"位置"和最后一个条件的管道中窒息.如果我插入一些<text>标签,它的工作原理如下:

<div class="miniProfile">
    Joined: @FormatTime(Model.Joined)<br />
    @if (!String.IsNullOrWhiteSpace(Model.Location)) {
        <text>Location: </text>@Model.Location<br …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc razor

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

asp.net mvc身份验证操作没有获得returnUrl

在asp.net/mvc身份验证的经典示例中,LogOn操作获取LogOnViewModel和returnUrl字符串以进行身份​​验证并重定向到以前的Url.

[HttpPost]
public ActionResult LogOn(LogOnViewModel model, string returnUrl)
{
if (ModelState.IsValid)
    if (!FormsAuthentication.Authenticate(model.UserName, model.Password))                                              
        ModelState.AddModelError("", "Incorrect user name or password."); 

    if (ModelState.IsValid)
    {
        FormsAuthentication.SetAuthCookie(model.UserName, false);
        return Redirect(returnUrl ?? "Bookings");
    }
    else
        return View();
}
Run Code Online (Sandbox Code Playgroud)

但是当通过动作处理请求时,returnUrl参数为null,但是应该有作者所说的值.有人可以解释一下吗?

我发送请求的表单如下所示:Views/Admin/LogOn.aspx

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
  <div id="login">
    <% Html.EnableClientValidation(); %>
    <% using (Html.BeginForm("LogOn", "Admin")) { %>
      <%= Html.ValidationSummary(true) %>
      <div><label>Username:</label><input name="userName" type="text" /></div>
      <div><label>Password:</label><input name="password" type="password" /></div>
      <div><input type="submit" value="Login" /></div>
    <% } %>
  </div>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)

表单上没有生成隐藏字段.

验证:

<authentication mode="Forms">
  <forms loginUrl="~/Admin/LogOn" timeout="2880">
    <credentials passwordFormat="SHA1"> …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-2

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

这是C++'move'语义的正确用法吗?

今晚我一直在看一些我过去几天一直在研究的代码,并开始阅读移动语义,特别是std :: move.我有几个问题要求专业人士确保我走正确的道路而不做任何愚蠢的假设!

首先:

1)最初,我的代码有一个返回大向量的函数:

template<class T> class MyObject
{
public:
    std::vector<T> doSomething() const;
    {
        std::vector<T> theVector;

        // produce/work with a vector right here

        return(theVector);
    }; // eo doSomething
};  // eo class MyObject
Run Code Online (Sandbox Code Playgroud)

鉴于"theVector"在这个和"扔掉"中是暂时的,我将该函数修改为:

    std::vector<T>&& doSomething() const;
    {
        std::vector<T> theVector;

        // produce/work with a vector right here

        return(static_cast<std::vector<T>&&>(theVector));
    }; // eo doSomething
Run Code Online (Sandbox Code Playgroud)

它是否正确?这样做有什么陷阱吗?

2)我在一个函数中注意到它返回std::string它自动调用移动构造函数.调试返回字符串(thankyou,Aragorn),我注意到它称为显式移动构造函数.为什么有一个字符串类而不是矢量?

我没有必要对此函数进行任何修改以利用移动语义:

// below, no need for std::string&& return value?
std::string AnyConverter::toString(const boost::any& _val) const
{
    string ret;
    // convert here
    return(ret); // No …
Run Code Online (Sandbox Code Playgroud)

c++ c++-standard-library move-semantics c++11

33
推荐指数
4
解决办法
1万
查看次数


F#中的递归映射引用

我正在尝试在F#中创建一个递归映射.

type RecMap = Map<string, RecMap>

因为循环引用而无法工作RecMap.但为什么不这样呢

type RecMap = Map<string, RecMap ref>

也不

type RecMap = (Map<string, RecMap>) ref

作品?我认为将地图的值类型设为a RecMap ref应该已经完成​​了.

通过重写RecMap为一个成员记录类型来解决问题,

type RecMap = { r : Map<string, RecMap> }

记录就像引用类型一样ref,但是为什么不在引用的情况下引用递归定义?

f#

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

在python中是否存在等效于'map'的位置?

我有一个需要消毒的字符串列表.我有一种消毒方法,所以我可以这样做:

new_list = map(Sanitize, old_list)
Run Code Online (Sandbox Code Playgroud)

但我不需要保留旧列表.这让我想知道是否有一个相当于地图的就地.很容易为它编写for循环(或自定义就地映射方法),但是内置了什么?

python dictionary in-place

13
推荐指数
3
解决办法
7375
查看次数