本文整理汇总了C#中DomNodeType类的典型用法代码示例。如果您正苦于以下问题:C# DomNodeType类的具体用法?C# DomNodeType怎么用?C# DomNodeType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DomNodeType类属于命名空间,在下文中一共展示了DomNodeType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: TestValidate
public void TestValidate()
{
DomNodeType childType = new DomNodeType("child");
DomNodeType parentType = new DomNodeType("parent");
ChildInfo childInfo = new ChildInfo("child", childType, true);
parentType.Define(childInfo);
DomNode parent = new DomNode(parentType);
IList<DomNode> childList = parent.GetChildList(childInfo);
DomNode child1 = new DomNode(childType);
DomNode child2 = new DomNode(childType);
DomNode child3 = new DomNode(childType);
ChildCountRule test = new ChildCountRule(1, 2);
// 0 children. Not valid.
Assert.False(test.Validate(parent, null, childInfo));
// 1 child. Valid.
childList.Add(child1);
Assert.True(test.Validate(parent, null, childInfo));
// 2 children. Valid.
childList.Add(child2);
Assert.True(test.Validate(parent, null, childInfo));
// 3 children. Not valid.
childList.Add(child3);
Assert.False(test.Validate(parent, null, childInfo));
// 0 children. Not valid.
childList.Clear();
Assert.False(test.Validate(parent, null, childInfo));
}
示例3: TestDuplicateNames
// Tests http://tracker.ship.scea.com/jira/browse/WWSATF-1370
// Test adding two types of extensions that have the same Name but different FullName.
public void TestDuplicateNames()
{
var domType = new DomNodeType("domType");
var extension = new ExtensionInfo<TestExtensionInfo>();
domType.Define(extension);
var domDerivedType = new DomNodeType("domDerivedType", domType);
var anotherExtension = new ExtensionInfo<AnotherName.TestExtensionInfo>();
domDerivedType.Define(anotherExtension);
var domNode = new DomNode(domDerivedType);
domNode.InitializeExtensions();
Assert.IsTrue(domNode.GetExtension(extension).GetType() == typeof(TestExtensionInfo));
Assert.IsTrue(domNode.GetExtension(anotherExtension).GetType() == typeof(AnotherName.TestExtensionInfo));
ExtensionInfo getInfo = domType.GetExtensionInfo("UnitTests.Atf.Dom.TestExtensionInfo");
Assert.IsNotNull(getInfo);
Assert.AreEqual(getInfo, extension);
getInfo = domDerivedType.GetExtensionInfo("UnitTests.Atf.Dom.TestExtensionInfo");
Assert.IsNotNull(getInfo);
Assert.AreEqual(getInfo, extension);
ExtensionInfo anotherGetInfo = domDerivedType.GetExtensionInfo("UnitTests.Atf.Dom.AnotherName.TestExtensionInfo");
Assert.IsNotNull(anotherGetInfo);
Assert.AreEqual(anotherGetInfo, anotherExtension);
}
示例4: NativeAttributeInfo
public NativeAttributeInfo(DomNodeType type, string name, uint typeId, uint propId)
{
DefiningType = type;
Name = name;
TypeId = typeId;
PropertyId = propId;
}
示例5: TestCreate
public void TestCreate()
{
var domType = new DomNodeType("test");
var extension = new ExtensionInfo<TestExtensionInfo>();
var created = extension.Create(new DomNode(domType)) as TestExtensionInfo;
Assert.NotNull(created);
}
示例6: TestBaseType
public void TestBaseType()
{
DomNodeType test = new DomNodeType("test");
Assert.AreEqual(test.BaseType, DomNodeType.BaseOfAllTypes);
DomNodeType baseType = new DomNodeType("base");
test.BaseType = baseType;
Assert.AreEqual(test.BaseType, baseType);
#pragma warning disable 219 //Disable the unused local variable warning. We need the side-effect of creating the DomNode.
DomNode node = new DomNode(test);
#pragma warning restore 219
// base type is now frozen
Assert.Throws<InvalidOperationException>(delegate { test.BaseType = new DomNodeType("newBase"); });
test = new DomNodeType(
"test",
null,
EmptyEnumerable<AttributeInfo>.Instance,
EmptyEnumerable<ChildInfo>.Instance,
EmptyEnumerable<ExtensionInfo>.Instance);
Assert.AreEqual(test.BaseType, DomNodeType.BaseOfAllTypes);
test.BaseType = baseType;
Assert.AreEqual(test.BaseType, baseType);
// ReSharper disable once RedundantAssignment
node = new DomNode(test);
Assert.Throws<InvalidOperationException>(delegate { test.BaseType = new DomNodeType("newBase"); });
}
示例7: TestBaseType
public void TestBaseType()
{
DomNodeType test = new DomNodeType("test");
Assert.AreEqual(test.BaseType, DomNodeType.BaseOfAllTypes);
DomNodeType baseType = new DomNodeType("base");
test.BaseType = baseType;
Assert.AreEqual(test.BaseType, baseType);
DomNode node = new DomNode(test);
// base type is now frozen
Assert.Throws<InvalidOperationException>(delegate { test.BaseType = new DomNodeType("newBase"); });
test = new DomNodeType(
"test",
null,
EmptyEnumerable<AttributeInfo>.Instance,
EmptyEnumerable<ChildInfo>.Instance,
EmptyEnumerable<ExtensionInfo>.Instance);
Assert.AreEqual(test.BaseType, DomNodeType.BaseOfAllTypes);
test.BaseType = baseType;
Assert.AreEqual(test.BaseType, baseType);
node = new DomNode(test);
Assert.Throws<InvalidOperationException>(delegate { test.BaseType = new DomNodeType("newBase"); });
}
示例8: TestConstructor
public void TestConstructor()
{
DomNodeType type = new DomNodeType("child");
ChildInfo info = new ChildInfo("test", type);
DomNode test = new DomNode(type, info);
Assert.AreSame(test.Type, type);
Assert.AreSame(test.ChildInfo, info);
}
示例9: TestListConstructor
public void TestListConstructor()
{
DomNodeType type = new DomNodeType("child");
ChildInfo test = new ChildInfo("test", type, true);
Assert.AreEqual(test.Name, "test");
Assert.AreEqual(test.Type, type);
Assert.True(test.IsList);
}
示例10: TestLineage
public void TestLineage()
{
DomNodeType child = new DomNodeType("child");
Utilities.TestSequenceEqual(child.Lineage, child, DomNodeType.BaseOfAllTypes);
DomNodeType parent = new DomNodeType("parent");
child.BaseType = parent;
Utilities.TestSequenceEqual(child.Lineage, child, parent, DomNodeType.BaseOfAllTypes);
}
示例11: NodeTypePaletteItem
/// <summary>
/// Constructor</summary>
/// <param name="nodeType">DomNodeType that this object applies to</param>
/// <param name="name">User-readable name of this DomNodeType</param>
/// <param name="description">User-readable description of this DomNodeType</param>
/// <param name="category">Category of DomNodeType</param>
/// <param name="imageKey">Image resource name, e.g., "DomTreeEditorSample.Resources.form.png"</param>
public NodeTypePaletteItem(
DomNodeType nodeType,
string name,
string description,
string category,
object imageKey)
: this(nodeType, name, description, category, imageKey, new DomNode(nodeType))
{
}
示例12: ChildInfo
/// <summary>
/// Constructor</summary>
/// <param name="name">Field name</param>
/// <param name="type">Field type</param>
/// <param name="isList">Whether there is 1 child, or a list of children</param>
public ChildInfo(
string name,
DomNodeType type,
bool isList)
: base(name)
{
m_type = type;
m_isList = isList;
}
示例13: TestEquality
public void TestEquality()
{
var attrType1 = new AttributeType("xkcd", typeof(string));
var attrInfo1 = new AttributeInfo("xkcd", attrType1);
var domNodeType = new DomNodeType("WebComic", DomNodeType.BaseOfAllTypes);
var childInfo1 = new ChildInfo("xkcd", domNodeType);
attrInfo1.DefaultValue = "Firefly";
var desc1 = new ChildAttributePropertyDescriptor(
"xkcd", attrInfo1, childInfo1, "Category 1", "A commonly used word or phrase in the xkcd comic", true);
int originalHashCode = desc1.GetHashCode();
// test if two identically created property descriptors compare as being equal
var desc2 = new ChildAttributePropertyDescriptor(
"xkcd", attrInfo1, childInfo1, "Category 1", "A commonly used word or phrase in the xkcd comic", true);
Assert.AreEqual(desc1, desc2);
Assert.AreEqual(desc1.GetHashCode(), desc2.GetHashCode());
// test category being different; oddly, although I think they should not be considered equal,
// the .Net PropertyDescriptor ignores the difference in category name. So, I'm guessing that
// the AttributePropertyDescriptor should behave the same as PropertyDescriptor.
var desc3 = new ChildAttributePropertyDescriptor(
"xkcd", attrInfo1, childInfo1, "Category 2", "A commonly used word or phrase in the xkcd comic", true);
Assert.AreEqual(desc1, desc3);
Assert.AreEqual(desc1.GetHashCode(), desc3.GetHashCode());
// test description being different; similarly here, the .Net PropertyDescriptor doesn't care.
var desc4 = new ChildAttributePropertyDescriptor(
"xkcd", attrInfo1, childInfo1, "Category 1", "slightly different description", true);
Assert.AreEqual(desc1, desc4);
Assert.AreEqual(desc1.GetHashCode(), desc4.GetHashCode());
// test readOnly being different; ditto for read-only flag!
var desc5 = new ChildAttributePropertyDescriptor(
"xkcd", attrInfo1, childInfo1, "Category 1", "A commonly used word or phrase in the xkcd comic", false);
Assert.AreEqual(desc1, desc5);
Assert.AreEqual(desc1.GetHashCode(), desc5.GetHashCode());
// test that the hash code hasn't changed after using the AttributeInfo
var attrInfo2 = new AttributeInfo("xkcd", attrType1);
domNodeType.Define(attrInfo2);
Assert.AreEqual(desc1.GetHashCode(), originalHashCode);
// test that the hash code hasn't changed after creating a derived DomNodeType
var derivedDomNodeType = new DomNodeType("ScientificWebComic", domNodeType);
var derivedAttrInfo = new AttributeInfo("xkcd", attrType1);
var derivedChildInfo = new ChildInfo("xkcd", derivedDomNodeType);
derivedDomNodeType.Define(derivedAttrInfo);
Assert.AreEqual(desc1.GetHashCode(), originalHashCode);
// test that an AttributeInfo used in a derived DomNodeType doesn't change equality or hash code
var desc6 = new ChildAttributePropertyDescriptor(
"xkcd", derivedAttrInfo, derivedChildInfo, "Category 1", "A commonly used word or phrase in the xkcd comic", true);
Assert.AreEqual(desc1, desc6);
Assert.AreEqual(desc1.GetHashCode(), desc6.GetHashCode());
}
示例14: NodeTypePaletteItem
/// <summary>
/// Constructor</summary>
/// <param name="nodeType">DomNodeType that this object applies to</param>
/// <param name="name">User-readable name of this DomNodeType</param>
/// <param name="description">User-readable description of this DomNodeType</param>
/// <param name="imageName">Image resource name, e.g., "DomTreeEditorSample.Resources.form.png"</param>
public NodeTypePaletteItem(
DomNodeType nodeType,
string name,
string description,
string imageName)
{
NodeType = nodeType;
Name = name;
Description = description;
ImageName = imageName;
}
示例15: TestChildParent
public void TestChildParent()
{
DomNodeType type = new DomNodeType("type");
ChildInfo childInfo = new ChildInfo("child", type, true);
type.Define(childInfo);
DomNode child = new DomNode(type);
DomNode parent = new DomNode(type);
parent.GetChildList(childInfo).Add(child);
Assert.AreSame(child.Parent, parent);
}