本文整理汇总了C#中Optional.IsPresent方法的典型用法代码示例。如果您正苦于以下问题:C# Optional.IsPresent方法的具体用法?C# Optional.IsPresent怎么用?C# Optional.IsPresent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Optional
的用法示例。
在下文中一共展示了Optional.IsPresent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InjectServices
private static IInjector InjectServices(Optional<ServiceConfiguration> serviceConfig)
{
// TODO[JIRA REEF-217]: Use base injector for the Evaluator here instead.
IInjector rootServiceInjector;
if (serviceConfig.IsPresent())
{
rootServiceInjector = TangFactory.GetTang().NewInjector(serviceConfig.Value.TangConfig);
InjectedServices services = null;
try
{
services = rootServiceInjector.GetInstance<InjectedServices>();
}
catch (Exception e)
{
Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, "Failed to instantiate service.", LOGGER);
InvalidOperationException ex = new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Failed to inject service: encoutned error {1} with message [{0}] and stack trace:[{1}]", e, e.Message, e.StackTrace));
Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
}
LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "injected {0} service(s)", services.Services.Count));
}
else
{
rootServiceInjector = TangFactory.GetTang().NewInjector();
LOGGER.Log(Level.Info, "no service provided for injection.");
}
return rootServiceInjector;
}
示例2: GetEvaluatorHeartbeatProto
private EvaluatorHeartbeatProto GetEvaluatorHeartbeatProto(
EvaluatorStatusProto evaluatorStatusProto,
ICollection<ContextStatusProto> contextStatusProtos,
Optional<TaskStatusProto> taskStatusProto)
{
EvaluatorHeartbeatProto evaluatorHeartbeatProto = new EvaluatorHeartbeatProto()
{
timestamp = CurrentTimeMilliSeconds(),
evaluator_status = evaluatorStatusProto
};
foreach (ContextStatusProto contextStatusProto in contextStatusProtos)
{
evaluatorHeartbeatProto.context_status.Add(contextStatusProto);
}
if (taskStatusProto.IsPresent())
{
evaluatorHeartbeatProto.task_status = taskStatusProto.Value;
}
return evaluatorHeartbeatProto;
}