本文整理汇总了C#中DummyClass.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# DummyClass.GetType方法的具体用法?C# DummyClass.GetType怎么用?C# DummyClass.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DummyClass
的用法示例。
在下文中一共展示了DummyClass.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EndMemberAssignsInstanceToParentProperty
public void EndMemberAssignsInstanceToParentProperty()
{
var state = new StackingLinkedList<Level>();
var dummyClass = new DummyClass();
var xamlType = WiringContext.TypeContext.GetXamlType(dummyClass.GetType());
state.Push(
new Level
{
Instance = dummyClass,
XamlMember = xamlType.GetMember("Child"),
});
var childClass = new ChildClass();
state.Push(
new Level
{
XamlType = xamlType,
Instance = childClass,
});
var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());
sut.Process(X.EndObject());
Assert.AreEqual(1, state.Count);
var expectedInstance = state.CurrentValue.Instance;
Assert.AreSame(expectedInstance, dummyClass);
Assert.AreSame(((DummyClass)expectedInstance).Child, childClass);
}
示例2: LoadWithRootInstance
public void LoadWithRootInstance()
{
var dummy = new DummyClass
{
AnotherProperty = "Other value",
SampleProperty = "Will be overwritten"
};
var loader = new XamlXmlLoader(new ObjectAssembler(WiringContext, new ObjectAssemblerSettings { RootInstance = dummy }), WiringContext);
var actual = loader.Load("<DummyClass xmlns=\"root\" SampleProperty=\"Value\" />");
Assert.IsInstanceOfType(actual, dummy.GetType());
Assert.AreEqual(((DummyClass)actual).SampleProperty, "Value");
Assert.AreEqual(((DummyClass)actual).AnotherProperty, "Other value");
}
示例3: LoadWithRootInstance
public void LoadWithRootInstance()
{
var dummy = new DummyClass
{
AnotherProperty = "Other value",
SampleProperty = "Will be overwritten"
};
var loader = new XmlLoader(new DummyParserFactory(RuntimeTypeSource));
var actual = loader.FromString("<DummyClass xmlns=\"root\" SampleProperty=\"Value\" />", dummy);
Assert.IsType(dummy.GetType(), actual);
Assert.Equal("Value", ((DummyClass)actual).SampleProperty);
Assert.Equal("Other value", ((DummyClass)actual).AnotherProperty);
}
示例4: LoadWithRootInstance
public void LoadWithRootInstance()
{
var dummy = new DummyClass
{
AnotherProperty = "Other value",
SampleProperty = "Will be overwritten"
};
var loader = new XamlLoader(new DummyXamlParserFactory(WiringContext));
var actual = loader.Load("<DummyClass xmlns=\"root\" SampleProperty=\"Value\" />", dummy);
Assert.IsInstanceOfType(actual, dummy.GetType());
Assert.AreEqual("Value", ((DummyClass)actual).SampleProperty);
Assert.AreEqual("Other value", ((DummyClass)actual).AnotherProperty);
}
示例5: GivenConfiguredInstance_StartMemberSetsTheMember
public void GivenConfiguredInstance_StartMemberSetsTheMember()
{
var state = new StackingLinkedList<Level>();
var dummyClass = new DummyClass();
var xamlType = WiringContext.TypeContext.GetXamlType(dummyClass.GetType());
state.Push(
new Level
{
Instance = dummyClass,
XamlType = xamlType,
});
var xamlMember = xamlType.GetMember("Items");
var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());
sut.Process(X.StartMember<DummyClass>(d => d.Items));
Assert.AreEqual(1, state.Count);
Assert.AreEqual(state.CurrentValue.XamlMember, xamlMember);
}
示例6: XmlSerializerOutputFormatterDoesntFlushOutputStream
public async Task XmlSerializerOutputFormatterDoesntFlushOutputStream()
{
// Arrange
var sampleInput = new DummyClass { SampleInt = 10 };
var formatter = new XmlSerializerOutputFormatter();
var outputFormatterContext = GetOutputFormatterContext(sampleInput, sampleInput.GetType());
var response = outputFormatterContext.HttpContext.Response;
response.Body = FlushReportingStream.GetThrowingStream();
// Act & Assert
await formatter.WriteAsync(outputFormatterContext);
}
示例7: VerifyBodyIsNotClosedAfterOutputIsWritten
public async Task VerifyBodyIsNotClosedAfterOutputIsWritten()
{
// Arrange
var sampleInput = new DummyClass { SampleInt = 10 };
var formatter = new XmlSerializerOutputFormatter();
var outputFormatterContext = GetOutputFormatterContext(sampleInput, sampleInput.GetType());
// Act
await formatter.WriteAsync(outputFormatterContext);
// Assert
Assert.NotNull(outputFormatterContext.HttpContext.Response.Body);
Assert.True(outputFormatterContext.HttpContext.Response.Body.CanRead);
}
示例8: XmlSerializerOutputFormatterWritesIndentedOutput
public async Task XmlSerializerOutputFormatterWritesIndentedOutput()
{
// Arrange
var expectedOutput =
"<DummyClass xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <SampleInt>10</SampleInt>\r\n</DummyClass>";
var sampleInput = new DummyClass { SampleInt = 10 };
var formatter = new XmlSerializerOutputFormatter();
formatter.WriterSettings.Indent = true;
var outputFormatterContext = GetOutputFormatterContext(sampleInput, sampleInput.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);
}
示例9: XmlSerializerOutputFormatterWritesUTF16Output
public async Task XmlSerializerOutputFormatterWritesUTF16Output()
{
// Arrange
var expectedOutput =
"<?xml version=\"1.0\" encoding=\"utf-16\"?>" +
"<DummyClass xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><SampleInt>10</SampleInt></DummyClass>";
var sampleInput = new DummyClass { SampleInt = 10 };
var outputFormatterContext =
GetOutputFormatterContext(sampleInput, sampleInput.GetType(), "application/xml; charset=utf-16");
var formatter = new XmlSerializerOutputFormatter();
formatter.WriterSettings.OmitXmlDeclaration = false;
// Act
await formatter.WriteAsync(outputFormatterContext);
// Assert
var body = outputFormatterContext.HttpContext.Response.Body;
body.Position = 0;
var content = new StreamReader(
body,
new UnicodeEncoding(bigEndian: false, byteOrderMark: false, throwOnInvalidBytes: true)).ReadToEnd();
XmlAssert.Equal(expectedOutput, content);
}
示例10: XmlSerializerOutputFormatterWritesOnModifiedWriterSettings
public async Task XmlSerializerOutputFormatterWritesOnModifiedWriterSettings()
{
// Arrange
var expectedOutput =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<DummyClass xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><SampleInt>10</SampleInt></DummyClass>";
var sampleInput = new DummyClass { SampleInt = 10 };
var outputFormatterContext = GetOutputFormatterContext(sampleInput, sampleInput.GetType());
var formatter = new XmlSerializerOutputFormatter(
new System.Xml.XmlWriterSettings
{
OmitXmlDeclaration = false,
CloseOutput = false
});
// 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);
}
示例11: SuppliedWriterSettings_TakeAffect
public async Task SuppliedWriterSettings_TakeAffect()
{
// Arrange
var writerSettings = FormattingUtilities.GetDefaultXmlWriterSettings();
writerSettings.OmitXmlDeclaration = false;
var sampleInput = new DummyClass { SampleInt = 10 };
var formatterContext = GetOutputFormatterContext(sampleInput, sampleInput.GetType());
var formatter = new XmlSerializerOutputFormatter(writerSettings);
var expectedOutput = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<DummyClass xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><SampleInt>10</SampleInt></DummyClass>";
// Act
await formatter.WriteAsync(formatterContext);
// Assert
var body = formatterContext.HttpContext.Response.Body;
body.Position = 0;
var content = new StreamReader(body).ReadToEnd();
XmlAssert.Equal(expectedOutput, content);
}
示例12: WriteAsync_WritesSimpleTypes
public async Task WriteAsync_WritesSimpleTypes()
{
// Arrange
var expectedOutput =
"<DummyClass xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
"<SampleInt>10</SampleInt></DummyClass>";
var sampleInput = new DummyClass { SampleInt = 10 };
var formatter = new XmlDataContractSerializerOutputFormatter();
var outputFormatterContext = GetOutputFormatterContext(sampleInput, sampleInput.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);
}
示例13: WriteAsync_WritesIndentedOutput
public async Task WriteAsync_WritesIndentedOutput()
{
// Arrange
var sampleInput = new DummyClass { SampleInt = 10 };
var formatter = new XmlDataContractSerializerOutputFormatter();
formatter.WriterSettings.Indent = true;
var outputFormatterContext = GetOutputFormatterContext(sampleInput, sampleInput.GetType());
// Act
await formatter.WriteAsync(outputFormatterContext);
// Assert
Assert.NotNull(outputFormatterContext.ActionContext.HttpContext.Response.Body);
outputFormatterContext.ActionContext.HttpContext.Response.Body.Position = 0;
var outputString = new StreamReader(outputFormatterContext.ActionContext.HttpContext.Response.Body,
Encoding.UTF8).ReadToEnd();
XmlAssert.Equal("<DummyClass xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
"\r\n <SampleInt>10</SampleInt>\r\n</DummyClass>",
outputString);
}
示例14: WriteAsync_WritesUTF16Output
public async Task WriteAsync_WritesUTF16Output()
{
// Arrange
var sampleInput = new DummyClass { SampleInt = 10 };
var outputFormatterContext = GetOutputFormatterContext(sampleInput, sampleInput.GetType(),
"application/xml; charset=utf-16");
var formatter = new XmlDataContractSerializerOutputFormatter();
formatter.WriterSettings.OmitXmlDeclaration = false;
// Act
await formatter.WriteAsync(outputFormatterContext);
// Assert
Assert.NotNull(outputFormatterContext.ActionContext.HttpContext.Response.Body);
outputFormatterContext.ActionContext.HttpContext.Response.Body.Position = 0;
XmlAssert.Equal("<?xml version=\"1.0\" encoding=\"utf-16\"?>" +
"<DummyClass xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
"<SampleInt>10</SampleInt></DummyClass>",
new StreamReader(outputFormatterContext.ActionContext.HttpContext.Response.Body,
Encodings.UTF16EncodingLittleEndian).ReadToEnd());
}
示例15: WriteAsync_WritesOnModifiedWriterSettings
public async Task WriteAsync_WritesOnModifiedWriterSettings()
{
// Arrange
var sampleInput = new DummyClass { SampleInt = 10 };
var outputFormatterContext = GetOutputFormatterContext(sampleInput, sampleInput.GetType());
var formatter = new XmlDataContractSerializerOutputFormatter(
new System.Xml.XmlWriterSettings
{
OmitXmlDeclaration = false,
CloseOutput = false
});
// Act
await formatter.WriteAsync(outputFormatterContext);
// Assert
Assert.NotNull(outputFormatterContext.ActionContext.HttpContext.Response.Body);
outputFormatterContext.ActionContext.HttpContext.Response.Body.Position = 0;
XmlAssert.Equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<DummyClass xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
"<SampleInt>10</SampleInt></DummyClass>",
new StreamReader(outputFormatterContext.ActionContext.HttpContext.Response.Body,
Encoding.UTF8).ReadToEnd());
}