我正在尝试将 XmlSchema 对象转换为字符串。
我正在构建一个简单的 XmlSchema,编译它,然后按如下方式转换它:
public string ConvertXmlSchemaToString(XmlSchema xmlSchema)
{
String schemaAsString = String.Empty;
// compile the schema
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add(xmlSchema);
schemaSet.ValidationEventHandler += new ValidationEventHandler(schemaSet_ValidationEventHandler);
schemaSet.Compile();
// allocate memory for string output
MemoryStream memStream = new MemoryStream(1024);
xmlSchema.Write(memStream);
memStream.Seek(0, SeekOrigin.Begin);
StreamReader reader = new StreamReader(memStream);
schemaAsString = reader.ReadToEnd();
return schemaAsString;
}
Run Code Online (Sandbox Code Playgroud)
作为控制台应用程序运行时,一切正常,但是从 Nunit 运行时,我在“xmlSchema.Write(memStream);”中遇到异常。线。
例外是:生成 XML 文档时出错。
内部异常是:公共语言运行时检测到无效程序。
有没有办法用CodeDom生成类约束.
因为当我使用类似的东西
var method = new CodeMemberMethod();
var genericParam = new CodeTypeParameter("InterfaceType");
genericParam.Constraints.Add("class");
method.TypeParameters.Add(genericParam);
Run Code Online (Sandbox Code Playgroud)
生成的代码就像
private InterfaceType GetImpl<InterfaceType>()
where InterfaceType : @class
{
}
Run Code Online (Sandbox Code Playgroud)
我发现最好的解决方法是在课前使用前导空格
genericParam.Constraints.Add(" class");
Run Code Online (Sandbox Code Playgroud)
但这似乎充其量只是一种解决方法.
我正在经历一些非常奇怪的事情!
我有一个div,我隐藏着JS(jQuery).像这样:
$('#myDiv').hide();
Run Code Online (Sandbox Code Playgroud)
然后,当我像这样做一个淡入淡出:
$("#myDiv").fadeIn('slow');
Run Code Online (Sandbox Code Playgroud)
然后文本在IE中丢失ClearType但在FF中丢失.如果我选择fadeIn的切换,那么一切都很好.
IE是什么,有什么解决方案,因为它看起来很糟糕. (我在这一点上可能已经理解了ClearType)
我有这个bash脚本将我的备份运行到外部硬盘驱动器...只有安装了该驱动器(OS X):
DIR=/Volumes/External;
if [ -e $DIR ];
then rsync -av ~/dir_to_backup $DIR;
else echo "$DIR does not exist";
fi
Run Code Online (Sandbox Code Playgroud)
这有效,但我感觉我误读了rsync手册页.如果顶级目标目录不存在,是否有内置rsync选项来中止运行?如果不测试/ Volumes/External是否存在,将使用该名称创建目录(如果尚未安装).
我有一个具有相同名称的函数,但在基类和派生类中具有不同的签名.当我尝试在继承自派生的另一个类中使用基类的函数时,我收到一个错误.请参阅以下代码:
class A
{
public:
void foo(string s){};
};
class B : public A
{
public:
int foo(int i){};
};
class C : public B
{
public:
void bar()
{
string s;
foo(s);
}
};
Run Code Online (Sandbox Code Playgroud)
我从gcc编译器收到以下错误:
In member function `void C::bar()': no matching function for call to `C::foo(std::string&)' candidates are: int B::foo(int)
Run Code Online (Sandbox Code Playgroud)
如果我int foo(int i){};从课堂上删除B,或者我将其重命名foo1,一切正常.
这有什么问题?
我以前认为成员函数只是普通函数的一个特例,其中成员函数在'this'指针的参数列表的开头有一个额外的参数,即成员函数所在的对象应该采取行动.我以前用这种方式使用了boost :: function,从未遇到过任何问题:
boost::function f<(void)(MyObject*, int, int)> = &MyObject::method_that_takes_two_ints;
Run Code Online (Sandbox Code Playgroud)
但我已经看到了成员函数指针的这种语法:
void (MyObject::*f)( int, int ) = &MyObject::method_that_takes_two_ints;
Run Code Online (Sandbox Code Playgroud)
在此语法中,'this'参数不可见.这让我想知道引擎盖指针到成员函数是否真的是一个单独的野兽,而且这种提升正在为我处理细节.
标准规定了'this'参数的位置是什么?也许只是在我的编译器上,额外的'this'参数首先出现,也许在其他编译器上它可能在最后?我很幸运,我的思维方式与我的编译器(GCC4,VS2005)如何处理它一致?指向成员函数的指针总是只是带有额外参数的指针到函数的特殊情况,或者编译器能够以不同的方式实现它们吗?
Rails大师:我刚刚发现named_scope感谢另一个SO用户.:)
我想得到一组行的计数 - 即a SELECT COUNT(*).另外,我希望仍然能够在调用中链接命名范围.
这是命名范围的合法(尽管是奇怪的)用法吗?
named_scope :count, :select => "COUNT(*) as count_all"
Run Code Online (Sandbox Code Playgroud)
那么我可以做(例如):
@foobar = Foobar.count.scope.scope.scope
Run Code Online (Sandbox Code Playgroud)
通过访问计数@foobar.first.count_all.
(编辑解决艾伦的评论)
你可以这样做:
@foobar = Foobar.scope.scope.scope.size
Run Code Online (Sandbox Code Playgroud)
但这会导致结果查询而不是更快的SELECT COUNT(*)查询.我在查询的数据库中有大量的行.
有一个更好的方法吗?
在Visual Studio(C++),有没有办法很容易地找到在.cpp文件中定义的重复标头?
我也试图找到检测这种情况的方法:
任何人都可以解释为什么:
function doAjax() {
var xmlHttpReq = false;
try { // Firefox, Opera 8.0+ and Safari
xmlHttpReq = new XMLHttpRequest();
}
catch (e) { // Internet Explorer
try {
xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Your browser does not support AJAX. Please use an AJAX compatible browser.");
return false;
}
}
}
xmlHttpReq.open('GET', 'handler.php', true);
xmlHttpReq.onreadystatechange = function() {
if (xmlHttpReq.readyState == 4) {
var response = xmlHttpReq.responseText; …Run Code Online (Sandbox Code Playgroud) 我在我的网站上使用URL重写来获取以下URL:
http://mysite.com/users/john
而不是
http://mysite.com/index.aspx?user=john
要使用IIS6实现这种无扩展的重写并且无法访问托管服务器,我使用"404-approach".当服务器找不到请求时,执行映射的404页面,因为这是一个aspx页面,可以执行重写(我可以使用托管服务上的控制面板设置404映射).
这是Global.asax中的代码:
protected void Application_BeginRequest(object sender, EventArgs e)
{
string url = HttpContext.Current.Request.Url.AbsolutePath;
if (url.Contains("404.aspx"))
{
string[] urlInfo404 = Request.Url.Query.ToString().Split(';');
if (urlInfo404.Length > 1)
{
string requestURL = urlInfo404[1];
if (requestURL.Contains("/users/"))
{
HttpContext.Current.RewritePath("~/index.aspx?user=" + GetPageID(requestURL));
StoreRequestURL(requestURL);
}
else if (requestURL.Contains("/picture/"))
{
HttpContext.Current.RewritePath("~/showPicture.aspx?pictureID=" + GetPageID(requestURL));
StoreRequestURL(requestURL);
}
}
}
}
private void StoreRequestURL(string url)
{
url = url.Replace("http://", "");
url = url.Substring(url.IndexOf("/"));
HttpContext.Current.Items["VirtualUrl"] = url;
}
private string GetPageID(string requestURL)
{
int idx = requestURL.LastIndexOf("/"); …Run Code Online (Sandbox Code Playgroud)