本文整理汇总了C#中Parent.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Parent.GetType方法的具体用法?C# Parent.GetType怎么用?C# Parent.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parent
的用法示例。
在下文中一共展示了Parent.GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteAsync_WritesWhenConfiguredWithPreserveReferences
public async Task WriteAsync_WritesWhenConfiguredWithPreserveReferences()
{
// Arrange
var sampleId = 1;
var sampleName = "Parent";
var InstanceNamespace = "http://www.w3.org/2001/XMLSchema-instance";
var SerializationNamespace = "http://schemas.microsoft.com/2003/10/Serialization/";
var expectedOutput = string.Format(
"<Parent xmlns:i=\"{0}\" z:Id=\"{2}\" xmlns:z=\"{1}\">" +
"<Children z:Id=\"2\" z:Size=\"1\">" +
"<Child z:Id=\"3\"><Id>{2}</Id><Parent z:Ref=\"1\" i:nil=\"true\" />" +
"</Child></Children><Name z:Id=\"4\">{3}</Name></Parent>",
InstanceNamespace,
SerializationNamespace,
sampleId,
sampleName);
var child = new Child { Id = sampleId };
var parent = new Parent { Name = sampleName, Children = new List<Child> { child } };
child.Parent = parent;
var settings = new DataContractSerializerSettings
{
PreserveObjectReferences = true
};
var formatter = new XmlDataContractSerializerOutputFormatter
{
SerializerSettings = settings
};
var outputFormatterContext = GetOutputFormatterContext(parent, parent.GetType());
// Act
await formatter.WriteAsync(outputFormatterContext);
// Assert
var body = outputFormatterContext.HttpContext.Response.Body;
body.Position = 0;
var content = new StreamReader(body).ReadToEnd();
XmlAssert.Equal(expectedOutput, content);
}
示例2: ChildNameChanges
public void ChildNameChanges()
{
var parent = new Parent { Child = new Child("") };
parent.Child.Parent = parent;
var propertyChanges = new List<string>();
var changes = new List<EventArgs>();
using (var tracker = Track.Changes(parent, ReferenceHandling.Structural))
{
tracker.PropertyChanged += (_, e) => propertyChanges.Add(e.PropertyName);
tracker.Changed += (_, e) => changes.Add(e);
Assert.AreEqual(0, tracker.Changes);
CollectionAssert.IsEmpty(propertyChanges);
CollectionAssert.IsEmpty(changes);
Assert.AreEqual(0, tracker.Changes);
CollectionAssert.IsEmpty(changes);
parent.Child.Name += "abc";
Assert.AreEqual(1, tracker.Changes);
CollectionAssert.AreEqual(new[] { "Changes" }, propertyChanges);
var rootChangeEventArgs = RootChangeEventArgs.Create(ChangeTrackerNode.GetOrCreate(parent.Child, tracker.Settings, false).Value, new PropertyChangeEventArgs(parent.Child, parent.Child.GetProperty(nameof(Child.Name))));
var expected = new[] { new PropertyGraphChangedEventArgs<ChangeTrackerNode>(ChangeTrackerNode.GetOrCreate(parent, tracker.Settings, false).Value, parent.GetType().GetProperty("Child"), rootChangeEventArgs) };
CollectionAssert.AreEqual(expected, changes, EventArgsComparer.Default);
}
}
示例3: WriteAsync_ThrowsWhenNotConfiguredWithPreserveReferences
public async Task WriteAsync_ThrowsWhenNotConfiguredWithPreserveReferences()
{
// Arrange
var child = new Child { Id = 1 };
var parent = new Parent { Name = "Parent", Children = new List<Child> { child } };
child.Parent = parent;
var formatter = new XmlDataContractSerializerOutputFormatter();
var outputFormatterContext = GetOutputFormatterContext(parent, parent.GetType());
// Act & Assert
await Assert.ThrowsAsync(typeof(SerializationException),
async () => await formatter.WriteAsync(outputFormatterContext));
}