我正在尝试编写以下内容:我想编写一个方法"A",它将另一个方法"B"作为参数,并为此方法B提供未知数量的参数.(params object [] args).现在,在方法A中,我想用参数args调用B. B现在将返回一个我希望A返回的对象.
这听起来有点奇怪,因此我将添加一些示例代码:
public object A(Func<object> B, params object[] args)
{
object x = B.Method.Invoke(args);
return x;
}
Run Code Online (Sandbox Code Playgroud)
问题是,Func不能那样工作.有谁知道这样做的方法?
此致,基督徒
我的情况是我的C#WPF应用程序包含一个ListView,其元素是Expanders.每个扩展器都包含一个带有ListViewItems的ListView.这是一张图片:

在右侧,您可以看到滚动条.那个ScrollBar是我的问题.它有两个问题:
在扩展列表上使用MouseWheel时,ScrollBar不起作用.我指的是从"Controller"到"FullInstallation"的区域.如果将鼠标悬停在标题上("所有测试"),ScrollBar会滚动.我认为Expander中的ListView默认有一个ScrollBar,它"窃取"了MouseWheel事件.但是,我不知道该怎么办.
ScrollBar滚动扩展器项目,而不是扩展器的内容.我的意思是,不可能向下滚动一点,而是总是向下滚动至少1个Expander项目.我希望滚动条滚动,以便可以看到例如"All Tests"Expander的一半.
该图显示了禁用的滚动条,但通过缩小窗口,滚动条将启用.
到目前为止我尝试了什么:
外部ListView外部的ScrollViewer:这解决了问题1,但这意味着MouseWheel根本不起作用!这是因为外部ListView生成了自己的ScrollViewer(使用Snoop来查找它),它"窃取"了MouseWheel事件.
将所有控件(ListView,Expander,ListViewItem)的所有MouseWheel事件重定向到ScrollViewer:我再次使用外部ListView外部的ScrollViewer,这次我使用MouseWheel事件为我的所有控件调用外部的MouseWheel事件ScrollViewer中.这确实有效,但是对于鼠标指针的某些位置它没有.例如,在两个ListViewItem之间有一个小的1毫米空间,其中没有捕获MouseWheel事件.或者在最后一个Expander("Short Tests")之后的底部.在那里,我没有得到任何事件.
我尝试了更多的东西,但没有进一步.有谁知道如何解决这个问题?
祝愿,基督徒
我目前正在编写一个单元测试框架,它最终将运行用Visual Studio编写的标准单元测试.框架目前无法正常使用访问者.请考虑以下测试方法:
[TestMethod()]
public void TestMethod()
{
ExampleMethods_Accessor target = null;
target = new ExampleMethods_Accessor();
target.SomeMethod();
}
Run Code Online (Sandbox Code Playgroud)
在此示例中,访问者已由Visual Studio生成.使用Visual Studio的单元测试环境运行时,单元测试工作正常.但是,我想从我的框架内调用TestMethod().在"target = new ExampleMethods_Accessor()"行中,抛出以下异常:
"Proband.ExampleMethods_Accessor"的类型初始化程序引发了一个例外.
内部异常:
无法加载文件或程序集:Proband,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null ...
有谁知道微软单元测试框架如何调用单元测试?我在想它可能是由于缺少TestContext对象.在我的情况下,这是"空".在Visual Studio中启动单元测试时,TestContext对象包含大量信息.可能是,我需要正确地初始化它吗?怎么需要初始化?
谢谢你的帮助,克里斯蒂安
编辑:
我一直在试验访问者的工作方式.我使用ILSpy来查看Proband_Accessor.dll中生成了什么代码.事实证明导致异常的指令是:
SomeClass_Accessor.m_privateType = new PrivateType("Probant, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "Probant.SomeClass");
Run Code Online (Sandbox Code Playgroud)
我将我的单元测试代码修改为这样(仅用于测试):
[TestMethod()]
[DeploymentItem("Proband.dll")]
public void SomeMethodTest()
{
ExampleMethods_Accessor target = null;
ExampleMethods c = null;
try
{
Assembly.Load("Proband, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"); // this works fine
PrivateType tx = new PrivateType(typeof(ExampleMethods)); // this works fine …Run Code Online (Sandbox Code Playgroud) 给定一个变更集c并且假设c包含合并操作,我想获得已合并并导致c的所有变更集的列表.
例如:
现在我想从变更集3中获取变更集1 + 2,变更集合并包含它.
我想使用TFS API执行此操作.我遇到了versionControlServer.TrackMerges方法,但是我不明白该方法应该是什么ItemIdentifiers.不幸的是,我找不到如何使用此方法的示例.此外,我不确定这是否真的是正确的.
我正在虚拟机上运行TFS 2012安装(在Windows Azure中).一切正常,但大于5MB的文件无法签入.在客户端,它说:"请求被中止:请求被取消.".
在服务器端,事件日志包含错误说:
- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
<Provider Name="TFS Services" />
<EventID Qualifiers="0">4000</EventID>
<Level>2</Level>
<Task>0</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2013-07-02T15:57:04.000000000Z" />
<EventRecordID>1832</EventRecordID>
<Channel>Application</Channel>
<Computer>gm-tfsserver</Computer>
<Security />
</System>
- <EventData>
<Data>TF53010: The following error has occurred in a Team Foundation component or extension: Date (UTC): 02/07/2013 15:57:04 Machine: GM-TFSSERVER Application Domain: /LM/W3SVC/2/ROOT/tfs-2-130172535704544600 Assembly: Microsoft.TeamFoundation.Framework.Server, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a; v4.0.30319 Service Host: 7e62b8c5-5065-4b32-9734-fc37fac35a8c (GM) Process Details: Process Name: w3wp Process Id: 3636 Thread Id: 3232 Account name: GM-TFSSERVER\Christian Detailed Message: TF30065: An unhandled …Run Code Online (Sandbox Code Playgroud) 我试图获得单个blob的共享访问签名,然后使用REST api下载blob.但是,我总是得到一个禁止的403错误消息.存储模拟器和云都有.这是我的代码:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("myConnectionStringHere...");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("containerName");
CloudBlob blob = container.GetBlobReference("blobName");
string sasToken = blob.GetSharedAccessSignature(new SharedAccessPolicy()
{
Permissions = SharedAccessPermission.Read,
SharedAccessExpiryTime = DateTime.UtcNow + TimeSpan.FromHours(24)
}
);
string completeUri = string.Format(CultureInfo.InvariantCulture, "{0}{1}", blob.Uri, sasToken);
// now use the uri to make the rest call and download
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(completeUri);
request.Method = "GET";
using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
{
using (Stream s = resp.GetResponseStream())
{
using (FileStream fs = new FileStream("test.jpg", FileMode.Create, FileAccess.Write)) …Run Code Online (Sandbox Code Playgroud) 我有一个表单,我使用jQuery .serialize();获取表单的值,例如获取表单数据我使用以下.
var formData = $('form').serialize();
Run Code Online (Sandbox Code Playgroud)
现在变量formData保存以下值.
subcategoryname=aaaa&prefix=AA&categoryid=1
Run Code Online (Sandbox Code Playgroud)
从上面的字符串我想在categoryid这里只获取ie 1 的值,我如何使用jQuery?