本文整理汇总了C#中ICollection.?.Any方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.?.Any方法的具体用法?C# ICollection.?.Any怎么用?C# ICollection.?.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.?.Any方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClassifyAsync
/// <summary>
/// Classifies an image based on a given set of classifiers, or all classifiers if no classifiers are specified.
/// </summary>
/// <param name="url">The URL of an image (.jpg, or .png). Redirects are followed, so you can use shortened
/// URLs. The resolved URL is returned in the response. Maximum image size is 2 MB.</param>
/// <param name="acceptLanguage">(Optional) Specifies the language of the output. You can specify en for English,
/// es for Spanish, ar for Arabic, or ja for Japanese. Classifiers for which no
/// translation is available are ommitted. Default value is English.</param>
/// <param name="threshold">(Optional) A floating value that specifies the minimum score a class must have to be
/// displayed in the response. Setting the threshold to 0.0 will return all values,
/// regardless of their classification score.</param>
/// <param name="owners">(Optional) A Collection with the value(s) ClassifierOwner.IBM and/or ClassifierOwner.Me
/// to specify which classifiers to run.</param>
/// <param name="classifierIds">(Optional) Array of classifier Ids to use when classifying the image</param>
/// <returns>A collection of images and their corresponding classifier scores</returns>
public async Task<ClassifyResponse> ClassifyAsync(string url,
AcceptLanguage acceptLanguage = AcceptLanguage.EN,
double? threshold = null,
ICollection<ClassifierOwner> owners = null,
params string[] classifierIds)
{
ClassifyResponse model = new ClassifyResponse();
// Create an HttpClient to make the request using VrClient()
using (var client = VrClient())
{
try
{
var requestString = "api/v3/classify";
// add API key
requestString += "?api_key=" + _vrCreds.ApiKey;
// add API version
requestString += "&version=" + VersionReleaseDate;
// add URL
requestString += "&url=" + url;
// convert the classifierIds array to a comma-separated list and add it to the request
if (classifierIds?.Any() == true && classifierIds[0] != null)
{
requestString += "&classifier_ids=" + string.Join(",", classifierIds);
}
// convert the owners array to a comma-separated list and add it to the request
if (owners?.Any() == true)
{
requestString += "&owners=" + string.Join(",", owners.Select(m => m == ClassifierOwner.IBM ? m.ToString() : m.ToString().ToLowerInvariant()).ToList());
}
// if threshold was not omitted, add it to the request
if (threshold.HasValue)
{
requestString += "&threshold=" + threshold.Value.ToString("F2");
}
// set accepted languages in headers
client.DefaultRequestHeaders.AcceptLanguage.Clear();
client.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue(acceptLanguage.ToString().ToLowerInvariant()));
// send a GET request to the Watson service
var response = await client.GetAsync(requestString);
// if the request succeeded, read the json result as a Response object
if (response.IsSuccessStatusCode)
{
model = await response.Content.ReadAsAsync<ClassifyResponse>();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}
return model;
}
开发者ID:watson-developer-cloud,项目名称:visual-recognition-aspnet,代码行数:75,代码来源:VisualRecognitionService.cs
示例2: SerializeNavigatorRooms
/// <summary>
/// Serializes the navigator rooms.
/// </summary>
/// <param name="reply">The reply.</param>
/// <param name="rooms">The rooms.</param>
private static void SerializeNavigatorRooms(ref ServerMessage reply, ICollection<KeyValuePair<RoomData, int>> rooms)
{
reply.AppendString(string.Empty);
if (!rooms?.Any() ?? true)
{
reply.AppendInteger(0);
reply.AppendBool(false);
return;
}
if (rooms != null)
{
reply.AppendInteger(rooms.Count);
foreach (KeyValuePair<RoomData, int> pair in rooms)
pair.Key.Serialize(reply);
}
reply.AppendBool(false);
}
示例3: JoelRichFeedGenerator
public JoelRichFeedGenerator(ICollection<ILinkParser> parsers)
{
if (parsers?.Any() != true)
throw new ArgumentException("parsers are required", nameof(parsers));
this._parsers = parsers;
}