本文整理汇总了C#中Optional类的典型用法代码示例。如果您正苦于以下问题:C# Optional类的具体用法?C# Optional怎么用?C# Optional使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Optional类属于命名空间,在下文中一共展示了Optional类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectFromQuery
private SelectFromQuery(bool? restriction, TopExpression top, Sequence<ColumnItem> columnItems, Optional<DestinationRowset> intoClause, FromClause fromClause, Optional<Predicate> whereClause, Optional<Sequence<Expression>> groupByClause, Optional<Predicate> havingClause,
Optional<Sequence<OrderExpression>> orderList, ForClause forClause, RowsetCombineClause unionClause): base(restriction, top, columnItems, intoClause, whereClause, forClause, unionClause) {
this.fromClause = fromClause;
this.groupByClause = groupByClause.ToList();
this.havingClause = havingClause;
this.orderList = orderList.ToList();
}
示例2: ActiveContext
internal ActiveContext(IActiveContextClr2Java clr2Java)
{
InstanceId = Guid.NewGuid().ToString("N");
Clr2Java = clr2Java;
_serializer = new AvroConfigurationSerializer();
_parentId = Optional<string>.OfNullable(clr2Java.GetParentId());
}
示例3: ServerSettings
// constructors
/// <summary>
/// Initializes a new instance of the <see cref="ServerSettings"/> class.
/// </summary>
/// <param name="heartbeatInterval">The heartbeat interval.</param>
/// <param name="heartbeatTimeout">The heartbeat timeout.</param>
public ServerSettings(
Optional<TimeSpan> heartbeatInterval = default(Optional<TimeSpan>),
Optional<TimeSpan> heartbeatTimeout = default(Optional<TimeSpan>))
{
_heartbeatInterval = Ensure.IsInfiniteOrGreaterThanOrEqualToZero(heartbeatInterval.WithDefault(DefaultHeartbeatInterval), "heartbeatInterval");
_heartbeatTimeout = Ensure.IsInfiniteOrGreaterThanOrEqualToZero(heartbeatTimeout.WithDefault(DefaultHeartbeatTimeout), "heartbeatTimeout");
}
示例4: Deserialize
public void Deserialize(Deserializer deserializer)
{
this.Unknown0 = deserializer.ReadInt16();
this.Unknown1 = deserializer.ReadVarint();
this.Unknown2 = deserializer.ReadByte();
this.Unknown3 = deserializer.ReadVarint();
byte unknown4Length = deserializer.ReadByte();
if (unknown4Length > 81)
{
throw new InvalidDataException();
}
Unknown4 = new byte[unknown4Length];
for (int i = 0; i < Unknown4.Length; i++)
{
Unknown4[i] = deserializer.ReadByte();
}
this.Unknown5 = deserializer.ReadVector4();
this.Unknown6 = deserializer.ReadVarint();
if (deserializer.ReadBoolean())
{
this.Unknown7 = new Optional<Vector4>(deserializer.ReadVector4());
}
else
{
this.Unknown7 = null;
}
this.Unknown8 = deserializer.ReadByte();
this.Unknown9 = deserializer.ReadByte();
this.Unknown10 = deserializer.ReadByte();
this.Unknown11 = deserializer.ReadInt16();
this.Unknown12 = deserializer.ReadInt16();
this.Unknown13 = deserializer.ReadInt16();
}
示例5: CommonTableExpression
public CommonTableExpression(AliasName aliasName, Optional<Sequence<ColumnName>> columnNames, SelectQuery selectQuery) {
Debug.Assert(aliasName != null);
Debug.Assert(selectQuery != null);
this.aliasName = aliasName;
this.columnNames = columnNames.ToList();
this.selectQuery = selectQuery;
}
示例6: ContextRuntime
/// <summary>
/// Create a new ContextRuntime.
/// </summary>
/// <param name="serviceInjector"></param>
/// <param name="contextConfiguration">the Configuration for this context.</param>
/// <param name="parentContext"></param>
public ContextRuntime(
IInjector serviceInjector,
IConfiguration contextConfiguration,
Optional<ContextRuntime> parentContext)
{
ContextConfiguration config = contextConfiguration as ContextConfiguration;
if (config == null)
{
var e = new ArgumentException("contextConfiguration is not of type ContextConfiguration");
Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
}
_contextLifeCycle = new ContextLifeCycle(config.Id);
_serviceInjector = serviceInjector;
_parentContext = parentContext;
try
{
_contextInjector = serviceInjector.ForkInjector();
}
catch (Exception e)
{
Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
Optional<string> parentId = ParentContext.IsPresent() ?
Optional<string>.Of(ParentContext.Value.Id) :
Optional<string>.Empty();
ContextClientCodeException ex = new ContextClientCodeException(ContextClientCodeException.GetId(contextConfiguration), parentId, "Unable to spawn context", e);
Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
}
// Trigger the context start events on contextInjector.
_contextLifeCycle.Start();
}
示例7: With
private CompletionRules With(
Optional<bool> dismissIfEmpty = default(Optional<bool>),
Optional<bool> dismissIfLastCharacterDeleted = default(Optional<bool>),
Optional<ImmutableArray<char>> defaultCommitCharacters = default(Optional<ImmutableArray<char>>),
Optional<EnterKeyRule> defaultEnterKeyRule = default(Optional<EnterKeyRule>))
{
var newDismissIfEmpty = dismissIfEmpty.HasValue ? dismissIfEmpty.Value : this.DismissIfEmpty;
var newDismissIfLastCharacterDeleted = dismissIfLastCharacterDeleted.HasValue ? dismissIfLastCharacterDeleted.Value : this.DismissIfLastCharacterDeleted;
var newDefaultCommitCharacters = defaultCommitCharacters.HasValue ? defaultCommitCharacters.Value : this.DefaultCommitCharacters;
var newDefaultEnterKeyRule = defaultEnterKeyRule.HasValue ? defaultEnterKeyRule.Value : this.DefaultEnterKeyRule;
if (newDismissIfEmpty == this.DismissIfEmpty
&& newDismissIfLastCharacterDeleted == this.DismissIfLastCharacterDeleted
&& newDefaultCommitCharacters == this.DefaultCommitCharacters
&& newDefaultEnterKeyRule == this.DefaultEnterKeyRule)
{
return this;
}
else
{
return Create(
newDismissIfEmpty,
newDismissIfLastCharacterDeleted,
newDefaultCommitCharacters,
newDefaultEnterKeyRule);
}
}
示例8: ContextException
internal ContextException(
string contextId, Optional<string> parentId, string message, Exception inner) :
base(message, inner)
{
_contextId = contextId;
_parentId = parentId;
}
示例9: WhenOptionalIsSet
public void WhenOptionalIsSet()
{
var optional = new Optional<Int32>(123);
Assert.IsTrue(optional.IsSet);
Assert.AreEqual(optional.Value, 123);
}
示例10: TableForeignKeyConstraint
public TableForeignKeyConstraint(ConstraintName constraintName, Sequence<ColumnName> columnNames, Qualified<SchemaName, TableName> refTableName, Optional<Sequence<ColumnName>> refColumnNames, Sequence<ForeignKeyAction> keyActions): base(constraintName) {
Debug.Assert(refTableName != null);
this.columnNames = columnNames.ToList();
this.refTableName = refTableName;
this.refColumnNames = refColumnNames.ToList();
this.keyActions = keyActions.ToList();
}
示例11: CreateBinaryNuspec
static void CreateBinaryNuspec(
string id,
string compiler,
IEnumerable<Targets.ItemDefinitionGroup> itemDefinitionGroupList,
IEnumerable<Nuspec.File> fileList,
IEnumerable<Nuspec.Dependency> dependencyList,
Optional<string> name,
IEnumerable<string> platformList)
{
var info = Config.CompilerMap[compiler];
var description =
id +
". Compiler: " +
info.Name +
". Platforms: " +
string.Join(", ", platformList) +
".";
Nuspec.Create(
id,
id,
Package.CompilerVersion(info),
description,
itemDefinitionGroupList,
fileList,
Enumerable.Empty<CompilationUnit>(),
dependencyList,
new[] { "binaries", compiler }.
Concat(name.ToEnumerable()).
Concat(platformList));
}
示例12: 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;
}
示例13: EvaluatorException
internal EvaluatorException(string evaluatorId, string message, string javaStackTrace)
: base(message)
{
_evaluatorId = evaluatorId;
_javaStackTrace = string.IsNullOrWhiteSpace(javaStackTrace)
? Optional<string>.Empty()
: Optional<string>.Of(javaStackTrace);
}
示例14: With
// methods
/// <summary>
/// Returns a new ServerSettings instance with some settings changed.
/// </summary>
/// <param name="heartbeatInterval">The heartbeat interval.</param>
/// <param name="heartbeatTimeout">The heartbeat timeout.</param>
/// <returns>A new ServerSettings instance.</returns>
public ServerSettings With(
Optional<TimeSpan> heartbeatInterval = default(Optional<TimeSpan>),
Optional<TimeSpan> heartbeatTimeout = default(Optional<TimeSpan>))
{
return new ServerSettings(
heartbeatInterval: heartbeatInterval.WithDefault(_heartbeatInterval),
heartbeatTimeout: heartbeatTimeout.WithDefault(_heartbeatTimeout));
}
示例15: ResultCentricAggregateQueryTestResult
/// <summary>
/// Initializes a new instance of the <see cref="ResultCentricAggregateQueryTestResult"/> class.
/// </summary>
/// <param name="specification">The specification.</param>
/// <param name="state">The state.</param>
/// <param name="actualResult">The actual result.</param>
/// <param name="actualException">The actual exception.</param>
/// <param name="actualEvents">The actual events.</param>
internal ResultCentricAggregateQueryTestResult(ResultCentricAggregateQueryTestSpecification specification, TestResultState state, Optional<object> actualResult, Optional<Exception> actualException, Optional<object[]> actualEvents)
{
_specification = specification;
_state = state;
_actualResult = actualResult;
_actualException = actualException;
_actualEvents = actualEvents;
}