我使用以下定义运行XML Schema:
<xs:simpleType name="ClassRankType">
<xs:restriction base="xs:integer">
<xs:totalDigits value="4"/>
<xs:minInclusive value="1"/>
<xs:maxInclusive value="9999"/>
</xs:restriction>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud)
但是,在我看来,这totalDigits是多余的.我对XML Schema有些新意,并希望确保我没有错过任何东西.
什么是实际行为totalDigits与maxInclusive?
可以totalDigits始终与的组合来表示minInclusive和MaxInclusive?
如何totalDigits影响负数?
首先,我知道Mercurial:Windows和Linux之间的文件名中的非ascii字母问题以及DVCS支持的Unicode文件名是什么?.但它们已经陈旧,并不适用于最新版本的mercurial.
他们都提到FixUtf8扩展 -这确实不是与善变的最新版本(2.3.1写这篇文章的)工作,显然是因为善变2.0没有奏效.事实上,启用该扩展将阻止您添加任何文件,甚至是简单的"vanilla"ascii文件名.FixUtf8Extension似乎已被放弃 - 它的最后一次提交是在2010年.
到目前为止,我一直是一个快乐的善变用户,但我现在正处于一个国际项目中,对非ascii文件名的支持至关重要.如果无法在mercurial中解决这个问题,我将不得不考虑备用版本控制系统.
在Windows上最新版本的mercurial是否支持unicode文件名?
假设我有三个班级.实例化A是有效的,但也有特殊情况B和D,它们是A的子类,添加了额外的信息.
我如何在(流畅的)NHibernate中为此创建映射文件?
public class A
{
public int ID { get; set;}
public string CommonProperty1 { get; set; }
public string CommonProperty2 { get; set; }
}
public class B : A
{
public string BSpecificProperty1 { get; set; } //not null
public string BSpecificProperty2 { get; set; } //not null
}
public class D : A
{
public string DSpecificProperty { get; set; } //not null
}
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法,但它根本不起作用:
public class AMap : ClassMap<A>
{
public AMap()
{
Id(x => …Run Code Online (Sandbox Code Playgroud) 我意识到在其他地方已经很好地建立了序列化你的NHibernate域对象通常是一个坏主意.我在这里的问题是试图理解如何BinaryFormatter工作,以及为什么下面的场景产生了InvalidCastException.
类结构大致如下所示:
[Serializable]
public class Parent
{
public virtual Child child{get; set;}
}
[Serializable]
public class Child
{
public virtual ICollection<GrandChild> GrandChildren { get; set; }
}
[Serializable]
public class GrandChild
{
public virtual Pet pet{get; set;}
}
[Serializable]
public class Pet
{
public virtual IList<Toy> Toys { get; set; }
}
[Serializable]
public class Toy
{
public string ToyName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
序列化方法如下所示:
public static byte[] Serialize(this object t)
{
using (var ms …Run Code Online (Sandbox Code Playgroud) 假设你有一个这样的模型:
class Foo
{
public int A {get; set;}
public int B {get; set;}
}
class SomeModel
{
public List<Foo> Foos { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在ASP.NET mvc框架的剃刀视图中,您可以执行以下操作:
@model SomeModel
@for(int i = 0; i < Model.Foos.Count; ++i)
{
Html.EditorFor(x => x.Foos[i]);
}
Run Code Online (Sandbox Code Playgroud)
并且剃刀引擎将愉快地吐出包含索引的正确html,并将使用正确的索引实例调用编辑器模板.
该EditorFor方法是具有签名的静态扩展方法
public static MvcHtmlString EditorFor<TModel, TValue>(
this HtmlHelper<TModel> html,
Expression<Func<TModel, TValue>> expression
)
Run Code Online (Sandbox Code Playgroud)
从签名中可以看出,它只是表达式,唯一的上下文来自HtmlHelper实例.
我已经完成了非常有限的Expression树处理,但是从我所看到的,我看不出这种静态方法可以知道它以某种方式神奇地获得的信息.
该EditorFor方法如何找出生成html名称的索引并获取传递给编辑器模板的正确实例?
我最近在我的网站上遭到了一些攻击,其中一个是用户代理NV32ts.
它们都是针对查询字符串变量的以下注入攻击的一些变体(其中99999表示有效的查询字符串值,攻击附加到值):
(为方便起见,我已经对以下攻击进行了解码)
999999 And char(124)+(Select Cast(Count(1) as varchar(8000))+char(124) From [sysobjects] Where 1=1)>0
Run Code Online (Sandbox Code Playgroud)
要么
999999' And char(124)+(Select Cast(Count(1) as varchar(8000))+char(124) From [sysobjects] Where 1=1)>0 and ''='
Run Code Online (Sandbox Code Playgroud)
要么
999999' And char(124)+(Select Cast(Count(1) as varchar(8000))+char(124) From [sysobjects] Where 1=1)>0 and ''='
Run Code Online (Sandbox Code Playgroud)
我相信sysobjects与Sql Server主数据库有关,但我无法弄清楚他们想要完成什么.
编辑: 我现在已经看到两个不同的用户代理相同的事情:
我在配置文件中定义了带有"假"域名的端点.我们的想法是,这样可以简化部署,因为我们只需在环境的hosts文件中设置"假"域名的IP地址,而不是修改配置文件.例如,在我的本地开发盒中,我将在hosts文件中有一个条目
127.0.0.1 fake.domain
Run Code Online (Sandbox Code Playgroud)
以及我可能拥有的用户接受环境
192.45.34.31 fake.domain
Run Code Online (Sandbox Code Playgroud)
但在我的配置文件中,我只有端点
<endpoint address="http://fake.domain/someServiceBase/SomeService.svc" ... />
Run Code Online (Sandbox Code Playgroud)
但是,WCF似乎完全忽略了hosts文件.我可以将地址复制到浏览器中,它会立即生效,但是WCF客户端(位于本地开发盒上)会出现"找不到主机"错误.
为什么WCF会忽略hosts文件?
编辑: 附加注释,如果我替换端点地址以直接在配置文件中使用实际IP地址,例如,
<endpoint address="http://127.0.0.1/someServiceBase/SomeService.svc" ... />
Run Code Online (Sandbox Code Playgroud) 取一个Expression树并将其转换为其他形式(例如字符串表示形式)是很常见的(例如,这个问题和这个问题,我怀疑Linq2Sql做类似的事情)。
在很多情况下,即使在大多数情况下,表达式树的转换也总是相同的,即如果我有一个函数
public string GenerateSomeSql(Expression<Func<TResult, TProperty>> expression)
Run Code Online (Sandbox Code Playgroud)
那么具有相同参数的任何调用将始终返回相同的结果,例如:
GenerateSomeSql(x => x.Age) //suppose this will always return "select Age from Person"
GenerateSomeSql(x => x.Ssn) //suppose this will always return "select Ssn from Person"
Run Code Online (Sandbox Code Playgroud)
因此,从本质上讲,带有特定参数的函数调用实际上只是一个常量,除了在运行时不断地重新计算时间而浪费时间之外。
出于争论的原因,假定转换足够复杂以至于引起明显的性能下降,是否有任何方法可以将函数调用预编译为实际常量?
编辑 似乎没有办法在C#本身中完全做到这一点。您可能会在c#中找到最接近的一个答案(当然,尽管您要确保缓存本身不比重新生成慢)。要真正转换为真正的常数,我怀疑经过一些工作,您可以在编译后使用诸如mono-cecil之类的方法来修改字节码。
我正在使用Visual Studio C++ 2008(Express).当我运行下面的代码时,wostream(both std::wcout和std::wfstream)在遇到第一个非ASCII字符(在这种情况下是中文)时停止输出.纯ASCII字符打印正常.但是,在调试器中,我可以看到wstrings实际上已正确填充了中文字符,并且output << ...实际上正在执行.
Visual Studio解决方案中的项目设置设置为"使用Unicode字符集".为什么std::wostream无法输出ASCII范围之外的Unicode字符?
void PrintTable(const std::vector<std::vector<std::wstring>> &table, std::wostream& output) {
for (unsigned int i=0; i < table.size(); ++i) {
for (unsigned int j=0; j < table[i].size(); ++j) {
output << table[i][j] << L"\t";
}
//output << std::endl;
}
}
void TestUnicodeSingleTableChinesePronouns() {
FileProcessor p("SingleTableChinesePronouns.docx");
FileProcessor::iterator fileIterator;
std::wofstream myFile("data.bin", std::ios::out | std::ios::binary);
for(fileIterator = p.begin(); fileIterator != p.end(); ++fileIterator) {
PrintTable(*fileIterator, myFile);
PrintTable(*fileIterator, std::wcout);
std::cout<<std::endl<<"---------------------------------------"<<std::endl;
} …Run Code Online (Sandbox Code Playgroud) 编辑
这似乎发生在任何沿一个方向引用另一个实体的实体属性上。换句话说,对于下面的示例,Bar覆盖 Equality 的事实似乎是无关紧要的。
假设我有以下课程:
public class Foo
{
public int? Id { get; set; }
public virtual Bar { get; set; }
}
public class Bar : IEquatable<Bar>
{
public int Id { get; set; }
public override bool Equals(object obj)
{
var other = obj as Bar;
return Equals(other);
}
public bool Equals(Bar other)
{
if (object.Equals(other, null))
return false;
return this.Id == other.Id;
}
public static bool operator ==(Bar left, Bar right)
{ …Run Code Online (Sandbox Code Playgroud)