我为WinForm UserControl创建了一个通用基类:
public partial class BaseUserControl<T> : UserControl
{
public virtual void MyMethod<T>()
{
// some base stuff here
}
}
Run Code Online (Sandbox Code Playgroud)
以及基于以下内容的UserControl:
public partial class MyControl : BaseUserControl<SomeClass>
{
public override void MyMethod<SomeClass>()
{
// some specific stuff here
base.MyMethod<SomeClass>();
}
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,但MyControl无法在VisualStudio Designer中进行编辑,因为它表示无法加载基类.我试图定义另一个类BaseUserControl,非泛型,希望它会加载它,但这个技巧似乎不起作用.
我已经有一个解决方法:定义一个接口,IMyInterface <T>,然后创建我的控件
public partial class MyControl : UserControl, IMyInterface<SomeClass>
Run Code Online (Sandbox Code Playgroud)
但是我失去了我的基本虚拟方法(不是很重要,但仍然......).
有没有办法为UserControl创建基础泛型类,有可能在VisualStudio Designer中编辑它?
我在一个有很多字段的类上调用一个简单的XmlSerializer.Deserizlize()时遇到了巨大的性能损失.
注意:我在家里没有Visual Studio编写代码,因此可能会有一些错误.
我的可序列化类是扁平的,有数百个字段:
[Serializable]
class Foo
{
public Foo() { }
[XmlElement(ElementName = "Field1")]
public string Field1;
// [...] 500 Fields defined in the same way
[XmlElement(ElementName = "Field500")]
public string Field500;
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序反序列化输入字符串(甚至很小):
StringReader sr = new StringReader(@"<Foo><Field1>foo</Field1></Foo>");
XmlSerializer serializer = new XmlSerializer(typeof(Foo));
object o = serializer.Deserialize(sr);
Run Code Online (Sandbox Code Playgroud)
运行在32位系统中的应用(或32位被迫corflags.exe),代码需要大约一秒钟的第一次(临时序列化类的生成,和所有的...),那么它的接近0.
在64位系统中运行应用程序,代码第一次占用一分钟,然后接近0.
在第一次执行XmlSerializer期间,对于大型类,在64位系统中,可能会将系统挂起这么长时间?
现在我不确定是否必须责怪临时类生成/删除,xml名称表初始化,CAS,Windows搜索,AntiVirus或圣诞老人......
破坏者
以下是我的测试,如果您不想被我(可能的)analysys错误所牵制,请不要阅读此内容.
为了进一步解释最后一点,如果我有一个班级:
[Serializable]
class Bar
{ …Run Code Online (Sandbox Code Playgroud) 我试图在XPathExpression对象中使用Microsoft XPath扩展函数(例如ms:string-compare http://msdn.microsoft.com/en-us/library/ms256114.aspx).
这些函数是MSXML库中的扩展,如果我在XslCompiledTransform中使用它们(只是添加"ms"命名空间),它们就像一个魅力:
var xsl =
@"
<?xml version=""1.0"" encoding=""UTF-8""?>
<xsl:stylesheet version=""2.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform""
xmlns:xs=""http://www.w3.org/2001/XMLSchema""
xmlns:fn=""http://www.w3.org/2005/xpath-functions""
xmlns:ms=""urn:schemas-microsoft-com:xslt"">
<xsl:output method=""xml"" version=""1.0"" encoding=""UTF-8"" indent=""yes""/>
<xsl:template match=""/Data"">
<xsl:element name=""Result"">
<xsl:value-of select=""ms:string-compare(@timeout1, @timeout2)""/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>";
var xslDocument = new XmlDocument();
xslDocument.LoadXml(xsl);
var transform = new XslCompiledTransform();
transform.Load(xslDocument);
Run Code Online (Sandbox Code Playgroud)
然后我尝试在XPathExpression中使用它们:
XPathNavigator nav = document.DocumentElement.CreateNavigator();
XPathExpression expr = nav.Compile("ms:string-compare(/Data/@timeout1, /Data/@timeout2)");
XmlNamespaceManager manager = new XmlNamespaceManager(document.NameTable);
manager.AddNamespace("ms", "urn:schemas-microsoft-com:xslt");
expr.SetContext(manager);
nav.Evaluate(expr);
Run Code Online (Sandbox Code Playgroud)
但是我得到一个例外"由于函数未知,此查询需要XsltContext".
XsltContext是一个特定的XmlNamespaceManager,但我不知道是否可以在没有实际的XslCompiledTransform(它是抽象的)的情况下实例化它并将其用作我的表达式上下文.
有没有办法做到这一点(或任何其他方式使用ms:XPathExpression内的扩展)?
我想在ASP.Net 2.0中做这样的事情:
<asp:Repeater id="myRepeater" runat="server">
<ItemTemplate>
<% if (DataBinder.Eval(Container.DataItem, "MyProperty").Equals("SomeValue")) { %>
<%#DataBinder.Eval(Container.DataItem, "MyProperty")%>
<% } %>
</ItemTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)
但我不能像这样测试DataBinder.Eval(Container.DataItem,"MyProperty").
注意:我无法访问源代码,我只能更改内联的aspx.
NOTE2:我知道我可以用这个:
<%#DataBinder.Eval(Container.DataItem, "MyProperty").Equals("SomeValue")?"<!--":""%>
Run Code Online (Sandbox Code Playgroud)
但我一直在寻找一种更清洁的方式.
有没有办法在Repeater中使用内联代码测试Container.DataItem?
我现在已经调用了使用Angular 4 Http服务制作的Bing Maps,它正常工作:
this.http.get("{absolute URL of Bing Maps REST Locations, with options and key}")
Run Code Online (Sandbox Code Playgroud)
我正在尝试更改调用以使用Angular 4.3中引入的HttpClient服务,但在尝试相同的代码时:
this.httpClient.get("{absolute URL of Bing Maps REST Locations, with options and key}")
Run Code Online (Sandbox Code Playgroud)
然后请求与预检OPTIONS请求一起发送,而bing map显然拒绝它.
我试图观察请求而不是正文,请求文本响应,并强制Accept标头文本,但没有成功.
Http请求的标头(工作):
Accept: application/json, text/plain, */*
Origin: http://localhost:4200
Referer: http://localhost:4200/
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
Run Code Online (Sandbox Code Playgroud)
HttpClient请求的标头(不工作):
Access-Control-Request-Headers: authorization
Access-Control-Request-Method: GET
Origin: http://localhost:4200
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
Run Code Online (Sandbox Code Playgroud)
有关为什么HttpClient请求与Http请求如此不同的任何想法?如何强制HttpClient跳过预检OPTIONS请求?我错过了什么吗?
在此先感谢您的帮助