本文整理汇总了C#中RestSharp.Deserializers.XmlAttributeDeserializer类的典型用法代码示例。如果您正苦于以下问题:C# XmlAttributeDeserializer类的具体用法?C# XmlAttributeDeserializer怎么用?C# XmlAttributeDeserializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XmlAttributeDeserializer类属于RestSharp.Deserializers命名空间,在下文中一共展示了XmlAttributeDeserializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Complete
public CompleteResponse Complete(Lang lang, string q, int limit = 1)
{
RestRequest request = new RestRequest("complete");
request.AddParameter("key", _key);
request.AddParameter("lang", lang.ToString().ToLowerInvariant());
request.AddParameter("q", q);
request.AddParameter("limit", limit);
RestResponse response = (RestResponse)_client.Execute(request);
XmlAttributeDeserializer deserializer = new XmlAttributeDeserializer();
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var completeResponse = deserializer.Deserialize<CompleteResponse>(response);
return completeResponse;
}
else
{
if (response.StatusCode != 0)
{
var error = deserializer.Deserialize<YandexError>(response);
throw new YandexLinguisticsException(error);
}
else
{
throw new YandexLinguisticsException(0, response.ErrorMessage);
}
}
}
示例2: Can_Deserialize_To_Standalone_List_Without_Matching_Class_Case
public void Can_Deserialize_To_Standalone_List_Without_Matching_Class_Case()
{
string xmlpath = this.PathFor("InlineListSample.xml");
XDocument doc = XDocument.Load(xmlpath);
XmlAttributeDeserializer xml = new XmlAttributeDeserializer();
List<Image> output = xml.Deserialize<List<Image>>(new RestResponse { Content = doc.ToString() });
Assert.IsNotEmpty(output);
Assert.AreEqual(4, output.Count);
}
示例3: Can_Deserialize_To_Standalone_List_With_Matching_Class_Case
public void Can_Deserialize_To_Standalone_List_With_Matching_Class_Case()
{
var xmlpath = PathFor("InlineListSample.xml");
var doc = XDocument.Load(xmlpath);
var xml = new XmlAttributeDeserializer();
var output = xml.Deserialize<List<image>>(new RestResponse { Content = doc.ToString() });
Assert.NotEmpty(output);
Assert.Equal(4, output.Count);
}
示例4: Can_Deserialize_To_List_Inheritor_From_Custom_Root_With_Attributes
public void Can_Deserialize_To_List_Inheritor_From_Custom_Root_With_Attributes()
{
string xmlpath = this.PathFor("ListWithAttributes.xml");
XDocument doc = XDocument.Load(xmlpath);
XmlAttributeDeserializer xml = new XmlAttributeDeserializer { RootElement = "Calls" };
TwilioCallList output = xml.Deserialize<TwilioCallList>(new RestResponse { Content = doc.ToString() });
Assert.AreEqual(3, output.NumPages);
Assert.IsNotEmpty(output);
Assert.AreEqual(2, output.Count);
}
示例5: Can_Deserialize_artistGetPastEvents
public void Can_Deserialize_artistGetPastEvents()
{
var xmlpath = Environment.CurrentDirectory + @"\..\..\..\Lastfm.Tests\Responses\Artist\artistGetPastEvents.xml";
var doc = XDocument.Load(xmlpath);
var response = new RestResponse { Content = doc.ToString() };
var d = new XmlAttributeDeserializer();
var output = d.Deserialize<LastfmResponse<EventsList>>(response);
Assert.AreEqual("Blur", output.Value.Events[2].Headliner);
}
示例6: Can_Deserialize_Boolean_From_Number
public void Can_Deserialize_Boolean_From_Number()
{
var xmlpath = PathFor("boolean_from_number.xml");
var doc = XDocument.Load(xmlpath);
var response = new RestResponse { Content = doc.ToString() };
var d = new XmlAttributeDeserializer();
var output = d.Deserialize<SampleClasses.BooleanTest>(response);
Assert.True(output.Value);
}
示例7: Can_Deserialize_POI
public void Can_Deserialize_POI()
{
var xmlpath = Environment.CurrentDirectory + @"\..\..\..\LonelySharp.Tests\Responses\POI_Details.xml";
var doc = XDocument.Load(xmlpath);
var response = new RestResponse { Content = doc.ToString() };
var d = new XmlAttributeDeserializer();
var output = d.Deserialize<POI>(response);
Assert.AreEqual(output.Name, "Alhambra Lounge");
Assert.AreEqual(output.Urls[0].Value, "www.alhambralounge.com");
}
示例8: Can_Deserialize_Place_Listing
public void Can_Deserialize_Place_Listing()
{
var xmlpath = Environment.CurrentDirectory + @"\..\..\..\LonelySharp.Tests\Responses\Places_List.xml";
var doc = XDocument.Load(xmlpath);
var response = new RestResponse { Content = doc.ToString() };
var d = new XmlAttributeDeserializer();
var output = d.Deserialize<PlaceCollection>(response);
Assert.AreEqual(output[0].Fullname, "Australia & Pacific -> Australia -> Queensland -> Brisbane");
Assert.AreEqual(output[0].Northlatitude, -27.434999);
}
示例9: Can_Deserialize_Lists_of_Simple_Types
public void Can_Deserialize_Lists_of_Simple_Types()
{
var xmlpath = PathFor("xmllists.xml");
var doc = XDocument.Load(xmlpath);
var xml = new XmlAttributeDeserializer();
var output = xml.Deserialize<SimpleTypesListSample>(new RestResponse() { Content = doc.ToString() });
Assert.NotEmpty(output.Names);
Assert.NotEmpty(output.Numbers);
Assert.False(output.Names[0].Length == 0);
Assert.False(output.Numbers.Sum() == 0);
}
示例10: Can_Deserialize_artistGetImages
public void Can_Deserialize_artistGetImages()
{
var xmlpath = Environment.CurrentDirectory + @"\..\..\..\Lastfm.Tests\Responses\Artist\artistGetImages.xml";
var doc = XDocument.Load(xmlpath);
var response = new RestResponse { Content = doc.ToString() };
var d = new XmlAttributeDeserializer();
var output = d.Deserialize<LastfmResponse<ImageList>>(response);
Assert.AreEqual(50, output.Value.images.Count);
Assert.AreEqual("VanderWaals", output.Value.images[1].owner.name);
Assert.AreEqual(6, output.Value.images[1].sizes.Count);
}
示例11: Can_Deserialize_artistGetInfo
public void Can_Deserialize_artistGetInfo()
{
var xmlpath = Environment.CurrentDirectory + @"\..\..\..\Lastfm.Tests\Responses\Artist\artistGetInfo.xml";
var doc = XDocument.Load(xmlpath);
var response = new RestResponse { Content = doc.ToString() };
var d = new XmlAttributeDeserializer();
var output = d.Deserialize<LastfmResponse<Artist>>(response);
Assert.AreEqual("Blur", output.Value.Name);
Assert.AreEqual(5, output.Value.similar.Count);
Assert.AreEqual("http://www.last.fm/music/Blur", output.Value.Url);
Assert.AreEqual("ba853904-ae25-4ebb-89d6-c44cfbd71bd2", output.Value.MusicBrainzID);
}
示例12: GetLangs
public Lang[] GetLangs()
{
RestRequest request = new RestRequest("getLangs");
request.AddParameter("key", _key);
RestResponse response = (RestResponse)_client.Execute(request);
XmlAttributeDeserializer deserializer = new XmlAttributeDeserializer();
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var strs = deserializer.Deserialize<List<string>>(response);
var allLangs = (Lang[])Enum.GetValues(typeof(Lang));
Lang[] result = allLangs.Where(lang => strs.Contains(lang.ToString().ToLowerInvariant())).ToArray();
return result;
}
else
{
var error = deserializer.Deserialize<YandexError>(response);
throw new YandexLinguisticsException(error);
}
}
示例13: Can_Deserialize_Attributes_On_Default_Root
public void Can_Deserialize_Attributes_On_Default_Root()
{
var doc = CreateAttributesXml();
var response = new RestResponse { Content = doc };
var d = new XmlAttributeDeserializer();
var p = d.Deserialize<PersonForXml>(response);
Assert.Equal("John Sheehan", p.Name);
Assert.Equal(new DateTime(2009, 9, 25, 0, 6, 1), p.StartDate);
Assert.Equal(28, p.Age);
Assert.Equal(long.MaxValue, p.BigNumber);
Assert.Equal(99.9999m, p.Percent);
Assert.Equal(false, p.IsCool);
Assert.Equal(new Guid(GuidString), p.UniqueId);
Assert.Equal(new Uri("http://example.com", UriKind.RelativeOrAbsolute), p.Url);
Assert.Equal(new Uri("/foo/bar", UriKind.RelativeOrAbsolute), p.UrlPath);
Assert.NotNull(p.BestFriend);
Assert.Equal("The Fonz", p.BestFriend.Name);
Assert.Equal(1952, p.BestFriend.Since);
}
示例14: Can_Deserialize_TimeSpan
public void Can_Deserialize_TimeSpan()
{
var culture = CultureInfo.InvariantCulture;
var doc = new XDocument(culture);
TimeSpan? nullTimespan = null;
TimeSpan? nullValueTimeSpan = new TimeSpan(21, 30, 7);
var root = new XElement("Person");
root.Add(new XElement("Tick", new TimeSpan(468006)));
root.Add(new XElement("Millisecond", new TimeSpan(0, 0, 0, 0, 125)));
root.Add(new XElement("Second", new TimeSpan(0, 0, 8)));
root.Add(new XElement("Minute", new TimeSpan(0, 55, 2)));
root.Add(new XElement("Hour", new TimeSpan(21, 30, 7)));
root.Add(new XElement("NullableWithoutValue", nullTimespan));
root.Add(new XElement("NullableWithValue", nullValueTimeSpan));
doc.Add(root);
var response = new RestResponse { Content = doc.ToString() };
var d = new XmlAttributeDeserializer()
{
Culture = culture,
};
var payload = d.Deserialize<TimeSpanTestStructure>(response);
Assert.Equal(new TimeSpan(468006), payload.Tick);
Assert.Equal(new TimeSpan(0, 0, 0, 0, 125), payload.Millisecond);
Assert.Equal(new TimeSpan(0, 0, 8), payload.Second);
Assert.Equal(new TimeSpan(0, 55, 2), payload.Minute);
Assert.Equal(new TimeSpan(21, 30, 7), payload.Hour);
Assert.Null(payload.NullableWithoutValue);
Assert.NotNull(payload.NullableWithValue);
Assert.Equal(new TimeSpan(21, 30, 7), payload.NullableWithValue.Value);
}
示例15: Can_Deserialize_Root_Elements_Without_Matching_Case_And_Dashes
public void Can_Deserialize_Root_Elements_Without_Matching_Case_And_Dashes()
{
var doc = CreateLowerCasedRootElementWithDashesXml();
var response = new RestResponse { Content = doc };
var d = new XmlAttributeDeserializer();
var p = d.Deserialize<List<IncomingInvoice>>(response);
Assert.NotNull(p);
Assert.Equal(1, p.Count);
Assert.Equal(45, p[0].ConceptId);
}