当前位置: 首页>>代码示例>>C#>>正文


C# Serializer.WriteType方法代码示例

本文整理汇总了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"]);
		}
开发者ID:Robin--,项目名称:swaggerwcf,代码行数:21,代码来源:SerializerTests.cs

示例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"]);
        }
开发者ID:mattmhersh,项目名称:WCFRestDemo,代码行数:22,代码来源:SerializerTests.cs

示例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")));
		}
开发者ID:Robin--,项目名称:swaggerwcf,代码行数:24,代码来源:SerializerTests.cs

示例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"]);
 }
开发者ID:mattmhersh,项目名称:WCFRestDemo,代码行数:13,代码来源:SerializerTests.cs

示例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);
 }
开发者ID:mattmhersh,项目名称:WCFRestDemo,代码行数:15,代码来源:SerializerTests.cs

示例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"]);
        }
开发者ID:mattmhersh,项目名称:WCFRestDemo,代码行数:19,代码来源:SerializerTests.cs

示例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"]);
 }
开发者ID:mattmhersh,项目名称:WCFRestDemo,代码行数:9,代码来源:SerializerTests.cs

示例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"]);
 }
开发者ID:mattmhersh,项目名称:WCFRestDemo,代码行数:11,代码来源:SerializerTests.cs

示例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);
 }
开发者ID:mattmhersh,项目名称:WCFRestDemo,代码行数:10,代码来源:SerializerTests.cs


注:本文中的Serializer.WriteType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。