我有一个像这样的抽象类;
public abstract PropertyBase
{
public static System.Type GetMyType()
{
return !!!SOME MAGIC HERE!!!
}
}
Run Code Online (Sandbox Code Playgroud)
我想将它子类化,当我调用静态GetMyType()时,我想返回子类的类型.所以,如果我宣布一个子类型;
public class ConcreteProperty: PropertyBase {}
Run Code Online (Sandbox Code Playgroud)
然后我打电话的时候
var typeName = ConcreteProperty.GetMyType().Name;
Run Code Online (Sandbox Code Playgroud)
我希望'typeName'设置为"ConcreteProperty".我怀疑没有办法做到这一点,但我很感兴趣,如果有人知道如何获得这些信息.
(我试图解决的特殊问题是WPF中依赖属性的冗长;我希望能够做到这样的事情;
class NamedObject : DependencyObject
{
// declare a name property as a type, not an instance.
private class NameProperty : PropertyBase<string, NamedObject> { }
// call static methods on the class to read the property
public string Name
{
get { return NameProperty.Get(this); }
set { NameProperty.Set(this, value); }
}
} …Run Code Online (Sandbox Code Playgroud) 如果我把控件放在像这样的.aspx文件中;
<asp:TextBox ID="protectedTextBox" runat="server">Some info</asp:TextBox>
Run Code Online (Sandbox Code Playgroud)
我在页面的.aspx.designer.cs文件中获得了一个声明的控件;
protected global::System.Web.UI.WebControls.TextBox protectedTextBox;
Run Code Online (Sandbox Code Playgroud)
但是我想将控件的访问修饰符更改为public.我可以设置任何属性或类似物来更改访问修饰符吗?
这就是我想要做的原因.我试图让跨页回发工作很好,整洁.我有两页:
FirstPage.aspx
MyTextBox : textbox
MyButton : button, @PostbackUrl=Secondpage
SecondPage.aspx
MyLabel : label
Run Code Online (Sandbox Code Playgroud)
当用户单击FirstPage.MyButton时,我想写入FirstPage.MyTextBox.Textinto 的值SecondPage.MyLabel.Text.我可以使用Page.FindControl来做到这一点,但这似乎是将上一页作为FirstPage对象进行转换并直接引用其上的MyTextBox控件的不良替代品.像这样的东西;
// on the page_load of SecondPage.aspx;
var previousPage = this.PreviousPage as FirstPage;
this.MyLabel.Text = previousPage.MyTextBox.Text;
Run Code Online (Sandbox Code Playgroud)
有没有办法更改访问修饰符?
我正在尝试在程序中使用TMP环境变量.当我要求
tmp = os.path.expandvars("$TMP")
Run Code Online (Sandbox Code Playgroud)
我明白了
C:\Users\STEVE~1.COO\AppData\Local\Temp
Run Code Online (Sandbox Code Playgroud)
其中包含老派,波浪形式.我无法控制返回路径的函数
C:\Users\steve.cooper\AppData\Local\Temp\file.txt
Run Code Online (Sandbox Code Playgroud)
我的问题是这个; 我想检查文件是否在我的临时驱动器中,但我找不到比较它们的方法.你怎么知道这两个Windows目录;
C:\Users\STEVE~1.COO\AppData\Local\Temp
C:\Users\steve.cooper\AppData\Local\Temp
Run Code Online (Sandbox Code Playgroud)
是相同的?
我想.js使用ASP.NET MVC 5 自动生成一些JavaScript文件,其URL中有适当的扩展名.
这是我的问题;
我在我的网站上使用require.js并且它运行良好.但是,并非所有JavaScript文件都是磁盘上的真实文件.其中一些必须在运行时生成.所以我编写了一个生成动态JavaScript文件的控制器,并在使用默认路由时为它们提供服务;
// ~/Resource/CommonRes -- from ResourceController.CommonRes()
define([], function() {
return {
"menuItemConfiguration":"Configuration",
"menuItemAdmin":"Admin",
"manageAccount":"Manage Account",
"logOff":"Log off"
...
};
});
Run Code Online (Sandbox Code Playgroud)
但是,我需要将路由作为~/Scripts/Resources/CommonRes.js- .js扩展是至关重要的,因为我实际上正在返回一个require.js模块,要像这样调用;
require(['Resources/CommonRes'], function(commonRes) {
// code the uses the resource file
});
Run Code Online (Sandbox Code Playgroud)
在这种情况下,Resources/CommonRes将始终查找名为的模块~/Scripts/Resources/CommonRes.js.因此需要使用该扩展来提供服务.
我似乎无法使路由正确.我尝试过以下但无济于事;
routes.MapRoute(
name: "Resource Scripts",
url: "Scripts/Resource/{action}",
defaults: new { controller = "Resource" },
namespaces: new string[] { "AITrackRecord.Controllers" }
);
Run Code Online (Sandbox Code Playgroud) javascript asp.net-mvc url-routing asp.net-mvc-routing requirejs
使用<customErrors>web.config文件中的旧标记,可以编写;
<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorPage/">
<error statusCode="500" redirect="~/ErrorPage/E500" />
</customErrors>
Run Code Online (Sandbox Code Playgroud)
并且~in redirect="~/ErrorPage/E500"由网站的根替换.
然而,在使用中<httpErrors>,我发现波浪线不受尊重;
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" path="~/ErrorPage/E500" responseMode="ExecuteURL" />
</httpErrors>
Run Code Online (Sandbox Code Playgroud)
"修复"它的唯一方法是让我从我的网站的根目录放一个绝对路径;
<error statusCode="500" path="/MySites/SiteRoot/ErrorPage/E500" responseMode="ExecuteURL" />
Run Code Online (Sandbox Code Playgroud)
哪种感觉真的错了.有没有办法解决这个问题,或者以URL相对于站点根目录的方式引用它?
我正在使用OleDb从excel电子表格中选择数据.每个电子表格都可以包含许多小表,也可能包含标题和标签等家具.所以它可能看起来像这样,我们有两个表和一些标题;
A B C D
1 . . . .
2 . . . .
3 Table1 . . .
4 Header1 HEADER2 . .
5 h huey . .
6 d dewey . .
7 l loius . .
8 s scrooge . .
9 . . . .
10 . . . .
11 . . . .
12 . . . .
13 . Table 2 . .
14 . HEADER1 HEADER2 HEADER3
15 . 1 foo … 我正在写一段代码只是一堆JavaScript和JSON文件 - 它是一个咕噜的插件,而不是一个网站 - 我想通过Visual Studio编辑文件和管理源代码控制.
我正在尝试构建一个'vanilla'msbuild项目文件 - 而不是C#,而不是VB等,因为这些文件在这种文件中无效.我可以编写一个带有.msbuildproj扩展名的非常简单的MSBuild文件,但无法将其加载到VS2013中,并且无法在任何地方找到示例.
任何人都知道如何组建一个空的,独立于语言的项目,仅用于文件管理?
我正在寻找编写一个JsonConverter在字符串中转义 HTML 的代码,除非[AllowHtml]已应用该属性;
private class ObjectWithStrings
{
// will be HTML-escaped
public string Name { get; set; }
// won't be escaped
[AllowHtml]
public string Unsafe { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
所以我试图用自定义的 ReadJson 属性编写一个 JsonConverter;
public override bool CanConvert(Type objectType)
{
return objectType == typeof(string);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var s = (string)reader.Value;
if (s == null)
{
return null;
}
// here I need to get …Run Code Online (Sandbox Code Playgroud) 使用Visual Studio时,我希望它能够持续构建我的项目.也就是说,在每次保存之后,启动构建.我倾向于处理大型(35+项目)解决方案,因此让所有内容都保持最新可以节省我启动应用程序的时间.
Roslyn在您键入时为您提供编译器错误,但它实际上并不运行完整的构建过程,这意味着您仍需要告诉VS构建并等待它在调试或运行测试之前完成.
Redgate的.Net恶魔用于进行这种后台编译,它确实很有用,但它已经停止使用,因为"Visual Studio 2015将引入微软的新Roslyn编译器,我们认为这些改进使.NET恶魔变得多余."
是否有选项或扩展可让Visual Studio 2015在保存文件或在IDE中修改项目后自动启动构建?
我正在尝试记录一些SQL,并希望得到正确的术语.如果你这样写SQL;
select child.ID, parent.ID
from hierarchy child
inner join hierarchy parent
on child.parentId = parent.ID
Run Code Online (Sandbox Code Playgroud)
然后你有一个实际的表('hierarchy')你给了两个名字('parent'和'child')我的问题是关于你如何引用一个带有名字的表的逻辑实体.
你会在这里写下这个名字的空白吗?
"此查询使用一个表(层次结构),但两个_(子和父)"
[编辑]在问题中留下了先前的草稿.现在纠正了.
我正在使用python以编程方式从Web服务器下载zip文件.使用网络浏览器,没关系.我写过这个(部分)脚本;
response = urllib2.urlopen(url, data, 10)
the_page = response.read()
f = open(filename, 'w')
f.write(the_page)
f.close()
Run Code Online (Sandbox Code Playgroud)
请求成功,我获取数据.问题是我正在下载的文件 - 一个zip文件 - 不起作用; 该文件似乎已损坏.它似乎是正确的长度,并在文本编辑器中看起来看起来像一个zip文件的内容.以下是下载的标题;
内容长度:9891内容 - 处置:内容 - 处置:附件; filename ="TrunkBackup_20101230.zip"日期:2009年12月30日星期三12:22:08 GMT Accept-Ranges:bytes
当我检查响应的长度,它是正确的,在9891.我怀疑发生了什么事是,当我打电话response.read()的结果是与运输字符串返回"有益"标准化(比如,\r到\n).当我写文件时,二进制数据略有错误,并且zip文件已损坏.
我的问题是(A)我不确定我是否正确,(B)如果我是对的,如何保存二进制数据本身?
我正在写第一篇jQuery,我遇到了问题jQuery.get().我在说这个;
$.get(url, updateList);
Run Code Online (Sandbox Code Playgroud)
其中updateList的定义如下;
function updateList(data)
{
if (data)
{
$('#contentlist').html(data);
}
else
{
$('#contentlist').html('<li><a href="#" id="synclink">Nothing found. Try again</a></li>');
}
}
Run Code Online (Sandbox Code Playgroud)
该函数运行,并被updateList调用.它在Internet Explorer中工作正常.但是,在Firefox中,data参数始终为空.我希望它会填充我作为URL传入的网页内容.我用错了吗?
笔记;
200 OK.该Headers标签看起来不错,而Response和HTML面板都为空.