本文整理汇总了C#中Serializer.WriteType方法的典型用法代码示例。如果您正苦于以下问题:C# Serializer.WriteType方法的具体用法?C# Serializer.WriteType怎么用?C# Serializer.WriteType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serializer
的用法示例。
在下文中一共展示了Serializer.WriteType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanWriteCompositeType
public void CanWriteCompositeType()
{
Serializer serializer = new Serializer(null);
string model = serializer.WriteType(typeof (SampleService.CompositeType), new Stack<Type>());
Assert.IsFalse(string.IsNullOrEmpty(model));
var obj = JObject.Parse(model);
Assert.AreEqual("SampleService.CompositeType", obj["id"]);
var props = obj["properties"] as JObject;
Assert.IsNotNull(props);
Assert.IsTrue(props.HasValues);
Assert.AreEqual(7, props.Count);
Assert.AreEqual(true, props["BoolValue"]["required"]);
Assert.AreEqual("array", props["ArrayValue"]["type"]);
Assert.AreEqual("string", props["EnumValue"]["type"]);
Assert.AreEqual(false, props["EnumValue"]["required"]);
Assert.AreEqual("integer(16)", props["ShortValue"]["type"]);
}
示例2: CanHideHiddenTypes
public void CanHideHiddenTypes()
{
//gets the Secret property when it's tag isn't configured
var serializerAll = new Serializer(null);
string modelAll = serializerAll.WriteType(typeof (SampleService.CompositeType), new Stack<Type>());
Assert.IsFalse(string.IsNullOrEmpty(modelAll));
var objAll = JObject.Parse(modelAll);
Assert.IsNotNull(objAll["properties"]["ArrayValue"]);
Assert.IsNotNull(objAll["properties"]["Secret"]);
//hides it when it is
var serializer = new Serializer(new[] {"InternalUse"});
string model = serializer.WriteType(typeof (SampleService.CompositeType), new Stack<Type>());
Assert.IsFalse(string.IsNullOrEmpty(model));
var obj = JObject.Parse(model);
Assert.IsNotNull(obj["properties"]["ArrayValue"]);
Assert.IsNull(obj["properties"]["Secret"]);
}
示例3: CanWriteContainerProperty
public void CanWriteContainerProperty()
{
Serializer serializer = new Serializer(null);
string model = serializer.WriteType(typeof (SampleService.CompositeType), new Stack<Type>());
Assert.IsFalse(string.IsNullOrEmpty(model));
var obj = JObject.Parse(HttpUtility.UrlDecode(model));
Assert.AreEqual("SampleService.CompositeType", obj["id"].ToString());
var container = obj["properties"]["ArrayValue"];
Assert.IsNotNull(container);
Assert.AreEqual("array", container["type"]);
Assert.AreEqual("string", container["items"]["$ref"]);
var enumProperty = obj["properties"]["EnumValue"];
Assert.IsNotNull(enumProperty);
Assert.AreEqual("string", enumProperty["type"]);
var enumValues = enumProperty["enum"] as JArray;
Assert.AreEqual(3, enumValues.Count);
Assert.IsTrue(enumValues.Any(v => v.ToString().Equals("Alpha")));
}
示例4: CanWriteArrayMemberProperties
public void CanWriteArrayMemberProperties()
{
var serializer = new Serializer(null);
var serialized = serializer.WriteType(typeof(ModelSampleC), new Stack<Type>());
Assert.IsFalse(string.IsNullOrEmpty(serialized));
var jObj = JObject.Parse(serialized);
Assert.IsNotNull(jObj["properties"]["ArrayOfSamples"]);
var arrayElementTypeValue = jObj["properties"]["ArrayOfSamples"]["items"]["$ref"];
Assert.AreEqual("ModelSampleName", arrayElementTypeValue);
var container = jObj["properties"]["ArrayOfSamples"];
Assert.IsNotNull(container);
Assert.AreEqual("my list description", container["description"]);
}
示例5: CanWriteParentChildContractsInCorrectOrder
public void CanWriteParentChildContractsInCorrectOrder()
{
var serializer = new Serializer(null);
var serialized = serializer.WriteType(typeof(ModelSampleFurtherDerived), new Stack<Type>());
Assert.IsFalse(string.IsNullOrEmpty(serialized));
var jObj = JObject.Parse(serialized);
var properties = jObj["properties"];
Assert.AreEqual(6, properties.Count());
Assert.AreEqual("TestBaseString", ((JProperty)properties.ElementAt(0)).Name);
Assert.AreEqual("TestBaseString2", ((JProperty)properties.ElementAt(1)).Name);
Assert.AreEqual("TestDerivedString1", ((JProperty)properties.ElementAt(2)).Name);
Assert.AreEqual("TestDerivedString2", ((JProperty)properties.ElementAt(3)).Name);
Assert.AreEqual("TestFurtherDerivedString1", ((JProperty)properties.ElementAt(4)).Name);
Assert.AreEqual("TestFurtherDerivedString2", ((JProperty)properties.ElementAt(5)).Name);
}
示例6: CanWriteMemberProperties
public void CanWriteMemberProperties()
{
var serializer = new Serializer(null);
var type = serializer.WriteType(typeof (ModelSampleA), new Stack<Type>());
Assert.IsFalse(string.IsNullOrEmpty(type));
var obj = JObject.Parse(type);
var container = obj["properties"]["MyString"];
Assert.IsNotNull(container);
Assert.AreEqual("string(10)", container["type"]);
Assert.AreEqual("my string description", container["description"]);
var anotherSerializer = new Serializer(null);
var sampleCModelSerialized = anotherSerializer.WriteType(typeof (ModelSampleC), new Stack<Type>());
Assert.IsFalse(string.IsNullOrEmpty(sampleCModelSerialized));
var sbObj = JObject.Parse(sampleCModelSerialized);
var sbContainer = sbObj["properties"]["MyString2"];
Assert.IsNotNull(sbContainer);
Assert.AreEqual("string", sbContainer["type"]);
}
示例7: CanWriteDataMemberName
public void CanWriteDataMemberName()
{
var serializer = new Serializer(null);
var serialized = serializer.WriteType(typeof(ModelSampleWithDataContractName), new Stack<Type>());
Assert.IsFalse(string.IsNullOrEmpty(serialized));
var jObj = JObject.Parse(serialized);
Assert.AreEqual("ModelSampleName", jObj["id"]);
Assert.IsNotNull(jObj["properties"]["CustomMemberName"]);
}
示例8: CanWriteCustomReturnTypeNameInDataContractWithoutFullName
public void CanWriteCustomReturnTypeNameInDataContractWithoutFullName()
{
var serializer = new Serializer(null);
var serialized = serializer.WriteType(typeof (ModelSampleWithDataContractName), new Stack<Type>());
Assert.IsFalse(string.IsNullOrEmpty(serialized));
var jObj = JObject.Parse(serialized);
Assert.AreEqual("ModelSampleName", jObj["id"]);
var container = jObj["properties"]["CustomReturnType"];
Assert.IsNotNull(container);
Assert.AreEqual("ModelSampleReferenced", container["type"]);
}
示例9: CanWriteArrayTypeNameWithDataContractName
public void CanWriteArrayTypeNameWithDataContractName()
{
var serializer = new Serializer(null);
var serialized = serializer.WriteType(typeof (ModelSampleC), new Stack<Type>());
Assert.IsFalse(string.IsNullOrEmpty(serialized));
var jObj = JObject.Parse(serialized);
Assert.IsNotNull(jObj["properties"]["ArrayOfSamples"]);
var arrayElementTypeValue = jObj["properties"]["ArrayOfSamples"]["items"]["$ref"];
Assert.AreEqual("ModelSampleName", arrayElementTypeValue);
}