我正在尝试创建一个方法,该方法接受testdelegate或delegate并将参数传递给委托对象.这是因为我正在为控制器中的方法创建测试,这些方法都采用相同的参数(id),并且我不想为所有控制器方法创建测试.
我有以下代码:
protected void AssertThrows_NullReference_Og_InvalidOperation(TestDelegate delegateMethod)
{
Assert.Throws<NullReferenceException>(delegateMethod);
Assert.Throws<InvalidOperationException>(delegateMethod);
Assert.Throws<InvalidOperationException>(delegateMethod);
}
Run Code Online (Sandbox Code Playgroud)
我想做什么:
protected void AssertThrows_NullReference_Og_InvalidOperation(TestDelegate delegateMethod)
{
Assert.Throws<NullReferenceException>(delegateMethod(null));
Assert.Throws<InvalidOperationException>(delegateMethod(string.Empty));
Assert.Throws<InvalidOperationException>(delegateMethod(" "));
}
Run Code Online (Sandbox Code Playgroud)
编辑:我忘了提到控制器有一个返回值.因此不能使用Action.
我想要转发内容,好像我将内容复制粘贴到我写的文件中<div data-ng-transclude="">.我该怎么做呢?
我知道我可以使用ng-include包含模板,我可以使用脚本标签来定义模板.但这会使模板缓存变得混乱并污染模板命名空间.
我想这样做,以便我可以有一个(或更多!这就是整点)文件,我在其中定义我想要显示我的项目的方式,
<!-- list directive to show the items -->
<div data-item-list="" data-values="vm.items">
<!-- content to include to display list items -->
<div class="form-relation-picker-value" ng-bind="item.value.title"></div>
<div class="form-relation-picker-subtitle" ng-bind="item.value.subTitle"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
和一个文件,我在其中定义列表结构的工作方式.
<div class="list-container">
<div class="list-item"
data-ng-click="vm.select(item)"
data-ng-repeat="item in vm.items | orderBy : vm.orderBy"
data-selected="{{vm.isSelected(item)}}">
<div class="flex">
<div ng-transclude=""></div><!-- item display via transclude -->
<div class="grid-col flex-icon form-relation-picker-chrome-height-fix">
<div data-ng-show="vm.isSelected(item)" class="icon check"></div>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
如果我做这样的事情,这是有效的:
<div data-item-list="" data-values="vm.items" data-template-to-use="randomhash">
<script type="text/ng-template" id="randomhash">
<div class="form-relation-picker-value" …Run Code Online (Sandbox Code Playgroud) 为什么来自angularjs $ http帖子的有效负载没有绑定到输入模型?
调用该操作时,模型为null,request.params和request.forms不显示发送表单的任何迹象.但是小提琴请求表明有效载荷是用JSON发送的.
AngularJS:
$http({
method: "POST",
url: "price/add",
data: {
Id: $scope.id,
StoreId: $scope.storeid,
Name: $scope.name,
Manufacturer: $scope.manufacturer,
Price: $scope.price
}
})
Run Code Online (Sandbox Code Playgroud)
模型:
public class PriceModel
{
public int? Id { get; set; }
public int? StoreId { get; set; }
public string Barcode { get; set; }
public string Name { get; set; }
public string Manufacturer { get; set; }
public DateTime Created { get; set; }
public double? Price { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
控制器和动作方法描述 …
我有一点问题.
我想这样做:
Type[] classes = new Type[]{ Class1, Class2 };
foreach(Type t in classes){
List<t> list = new List<t>();
}
Run Code Online (Sandbox Code Playgroud)
有办法做到这一点吗?
这不是一个真正的问题,因为我已经找到了这个问题的原因
使用此代码检索后代。
using System.IO;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
namespace Testolini
{
class Program
{
static void Main(string[] args)
{
var filename = Path.GetTempFileName();
var word = WordprocessingDocument.Create(filename, DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
word.AddMainDocumentPart();
word.MainDocumentPart.Document = new Document(
new Body(
new Paragraph(
new Run(
new Paragraph(
new Run(
new Text("test1"))),
new Paragraph(
new Run(
new Text("test2"))),
new Paragraph(
new Run(
new Text("test3")))))));
word.Close();
using (var memorystream = new MemoryStream(File.ReadAllBytes(filename)))
{
var word2 = WordprocessingDocument.Open(memorystream, true);
var descendants = word2.MainDocumentPart.Document.Body.Descendants();
word.Close();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果你遇到同样的问题。这可能是因为 …
我现在搜索了一下,但是我无法找到一种以编程方式从XML Schema自动生成数据的方法.假设我有这个XML架构:
<xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema" name ="Persons">
<xs:complexType>
<xs:sequence>
<xs:element name="Person">
<xs:complexType>
<xs:sequence>
<xs:element name="FirstName" type="xs:string" />
<xs:element name="LastName" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
我可以使用VS函数"生成示例XML"从此创建XML
有没有办法以编程方式执行此操作?
编辑:指定.我不想自己创建所有对象并以编程方式插入数据.我想让它自动创建对象和属性,就像VS中的"生成示例XML"一样.这样做的原因是我想更改XSD而不必对xml样本生成做任何事情.
我想创建一个可以转换XML的XSLT,以便在输出XML(来自XSLT)中排除XSD中未定义的所有元素和属性.
让我们说你有这个XSD.
<xs:element name="parent">
<xs:complexType>
<xs:sequence>
<xs:element name="keptElement1" />
<xs:element name="keptElement2" />
</xs:sequence>
<xs:attribute name="keptAttribute1" />
<xs:attribute name="keptAttribute2" />
</complexType>
</xsd:element>
Run Code Online (Sandbox Code Playgroud)
你有这个输入XML
<parent keptAttribute1="kept"
keptAttribute2="kept"
notKeptAttribute3="not kept"
notKeptAttribute4="not kept">
<notKeptElement0>not kept</notKeptElement0>
<keptElement1>kept</keptElement1>
<keptElement2>kept</keptElement2>
<notKeptElement3>not kept</notKeptElement3>
</parent>
Run Code Online (Sandbox Code Playgroud)
然后我想让输出Xml看起来像这样.
<parent keptAttribute1="kept"
keptAttribute2="kept">
<keptElement1>kept</keptElement1>
<keptElement2>kept</keptElement2>
</parent>
Run Code Online (Sandbox Code Playgroud)
我可以通过指定元素来做到这一点,但这就是我的xslt技能所达到的目标.对于所有元素和所有属性,我一般都有问题.
我有一个通过 OpenWriter 方法创建的 BlobStream。
var blob = CloudContainer.GetBlobReference(name));
if (blob == null)
{
return null;
}
return blob.OpenWrite();
Run Code Online (Sandbox Code Playgroud)
使用此流,我想寻找或设置位置,但每次执行此操作时,我都会收到 NotSupportedException。经过一些研究后,我发现 canSeek 设置为 false,这导致了这个问题。但是,仅当长度未知时,CanSeek 才为 false。但是当我运行调试器时长度是已知的。
为什么 CanSeek 是假的?我怎样才能将其设置为true?
c# ×5
angularjs ×2
xml ×2
xsd ×2
asp.net-mvc ×1
azure ×1
bytearray ×1
delegates ×1
dynamic ×1
javascript ×1
memory ×1
nunit ×1
openxml ×1
sample ×1
seek ×1
streamwriter ×1
types ×1
unit-testing ×1
xslt ×1