本文整理汇总了C#中AttributeType.GetDefault方法的典型用法代码示例。如果您正苦于以下问题:C# AttributeType.GetDefault方法的具体用法?C# AttributeType.GetDefault怎么用?C# AttributeType.GetDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AttributeType
的用法示例。
在下文中一共展示了AttributeType.GetDefault方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDefaultValue
public void TestDefaultValue()
{
AttributeType type = new AttributeType("test", typeof(string));
AttributeInfo test = new AttributeInfo("test", type);
test.DefaultValue = "foo";
Assert.AreEqual(test.DefaultValue, "foo");
test.DefaultValue = null;
Assert.AreEqual(test.DefaultValue, type.GetDefault());
Assert.Throws<InvalidOperationException>(delegate { test.DefaultValue = 1; });
AttributeType length2Type = new AttributeType("length2Type", typeof(int[]), 2);
AttributeInfo length2Info = new AttributeInfo("length2", length2Type);
Assert.AreEqual(length2Info.DefaultValue, length2Type.GetDefault());
Assert.AreEqual(length2Info.DefaultValue, new int[] { default(int), default(int) });
DomNodeType nodeType = new DomNodeType("testNodeType");
nodeType.Define(length2Info);
DomNode node = new DomNode(nodeType);
Assert.AreEqual(node.GetAttribute(length2Info), length2Info.DefaultValue);
node.SetAttribute(length2Info, new int[] { 1, 2 });
Assert.AreEqual(node.GetAttribute(length2Info), new int[] { 1, 2 });
node.SetAttribute(length2Info, new int[] { 1 });
Assert.AreEqual(node.GetAttribute(length2Info), new int[] { 1 });
AttributeType length1Type = new AttributeType("length1Type", typeof(int[]), 1);
AttributeInfo length1Info = new AttributeInfo("length1", length1Type);
Assert.AreEqual(length1Info.DefaultValue, length1Type.GetDefault());
Assert.AreEqual(length1Info.DefaultValue, new int[] { default(int) });
nodeType = new DomNodeType("testNodeType");
nodeType.Define(length1Info);
node = new DomNode(nodeType);
Assert.AreEqual(node.GetAttribute(length1Info), length1Info.DefaultValue);
node.SetAttribute(length1Info, new int[] { 1 });
Assert.AreEqual(node.GetAttribute(length1Info), new int[] { 1 });
}
示例2: TestConstructor
public void TestConstructor()
{
AttributeType type = new AttributeType("test", typeof(string));
AttributeInfo test = new AttributeInfo("test", type);
Assert.AreEqual(test.Name, "test");
Assert.AreEqual(test.Type, type);
Assert.AreEqual(test.DefaultValue, type.GetDefault());
}