小编ama*_*ers的帖子

C#编译器是否计算常量的数学?

给出以下代码:

const int constA = 10;
const int constB = 10;

function GetX(int input) {
    int x = constA * constB * input;
    ...
    return x;
}
Run Code Online (Sandbox Code Playgroud)

.Net编译器会'替换'表达式并放置1000,所以计算不会一遍又一遍地重复吗?

在什么时候代码运行得最快:

  1. int x = constA * constB * input;
    
    Run Code Online (Sandbox Code Playgroud)
  2. int x = 10 * 10 * input;
    
    Run Code Online (Sandbox Code Playgroud)
  3. int x = 100 * input;
    
    Run Code Online (Sandbox Code Playgroud)

我猜选项3将比2更快,但有时不是最可读的选项.编译器是否识别这样的模式并相应地对其进行优化?

c# performance constants compiler-optimization

10
推荐指数
2
解决办法
1956
查看次数

在浏览器中编辑html

很多人都知道人们可以使用大多数浏览器上提供的inspect元素功能编辑网站的html源代码.这是非常无害的,因为编辑只是在本地机器上进行,而不是在实际的网站上进行.我担心它可能会遇到一个安全问题,我想知道是否有人知道它的答案.

这个函数如何影响提交的表单.通常可以隐藏字段并存储运行特定查询所必需的值.我想知道人们是否在隐藏字段上改变了这个值会损害网站的安全性吗?是否存在与此相关的安全威胁?我有办法轻松捍卫它,但我只是想知道这是否是一个值得防守的缺陷.

谢谢您的帮助.

html css php security

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

流畅的NHibernate Automapping与抽象基类

鉴于以下类别:

public class Address : Place
{
    public virtual string Street { get; set; }
    public virtual int Number  { get; set; }


    public override string WhereAmI
    {
        get { string.Format("{0} {1}", Street , Number); }
    }
}
public abstract class Place : DomainEntity
{
    public abstract string WhereAmI { get; }
}
Run Code Online (Sandbox Code Playgroud)

当我使用此映射时:

var autoMap = AutoMap.AssemblyOf<Party>()
            .Override<Place>(map => map.IgnoreProperty(p => p.WhereAmI))
            .Override<Address>(map => map.IgnoreProperty(p => p.WhereAmI))
            .Where(type => type.Namespace != null && type.Namespace.Contains("Models"));
Run Code Online (Sandbox Code Playgroud)

我仍然得到错误:无法在"地址"类中找到属性'WhereAmI'的setter

我做的事情:

  • 当我从基类"地址"中删除属性时,它的工作原理.
  • 当我使用.OverrideAll(map …

nhibernate configuration abstract-class fluent automapping

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

如何使用Query_Match进行Soap UI

我在Soap UI中使用MockOperation编辑器时遇到问题.

我有这个要求:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <methodName xmlns="http://tempuri.org/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
      <dataAreaId>error</dataAreaId>
      <pInvoiceList>
      <dataAreaId>NOTTHESAME</dataAreaId>
        ...
      </pInvoiceList>
    </methodName>
  </s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)

我几乎尝试了每个XPATH表达式,但我总是得到"请求中缺少匹配"

在Xpath框中填写什么?

我试过了:

  • // dataAreaId /文本()
  • // dataAreaId /
  • // dataAreaId
  • / dataAreaId /文本()
  • / dataAreaId
  • /方法名/ dataAreaId /文本()
  • /方法名/ dataAreaId /
  • /方法名/ dataAreaId

xpath mocking soapui

7
推荐指数
2
解决办法
9524
查看次数

如何使用soap UI传递流

我在使用接受 Stream 对象的soap UI 测试WCF 服务方法时遇到问题。这是服务方法作为输入参数的对象:

[DataContract(Namespace = Constants.NAMESPACE)]
public class RemoteFileInfo : IDisposable
{
    [DataMember(IsRequired = true, Order = 1)]
    public string FileName { get; set; }

    [DataMember(IsRequired = true, Order = 2)]
    public long Length { get; set; }

    [DataMember(IsRequired = true, Order = 3)]
    public System.IO.Stream FileByteStream { get; set; }

    public void Dispose()
    {
        if (FileByteStream != null)
        {
            FileByteStream.Close();
            FileByteStream = null;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在soap UI 中生成的请求:

...
<ws:File>
  <ws:FileName>?</ws:FileName>
  <ws:Length>?</ws:Length>
  <ws:FileByteStream>
    <sys:__identity>?</sys:__identity>
  </ws:FileByteStream> …
Run Code Online (Sandbox Code Playgroud)

c# testing wcf soapui

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

对用户未输入的数据进行模型验证

我有这个ViewModel(简化):

public class ResponseViewModel {

    public QuestionViewModel Question { get; set; }
    public string Answer { get; set; }
}

public class QuestionViewModel {

    public string Text { get; set; }
    public string Description { get; set; }
    public bool IsRequired { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

QuestionViewModel是从我的DAL实体Question映射的,这是一个简单的映射:

public class Question {

    public int Id { get; set; }
    public string Text { get; set; }
    public string Description { get; set; }
    public bool IsRequired { get; set; }
} …
Run Code Online (Sandbox Code Playgroud)

c# validation asp.net-mvc automapper

5
推荐指数
2
解决办法
234
查看次数