本文整理汇总了C#中Maybe类的典型用法代码示例。如果您正苦于以下问题:C# Maybe类的具体用法?C# Maybe怎么用?C# Maybe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Maybe类属于命名空间,在下文中一共展示了Maybe类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryConstructHeader
protected override Maybe<Header> TryConstructHeader(
Maybe<int> width,
Maybe<int> height,
Maybe<Ratio> framerate,
Maybe<Ratio> pixelAspectRatio,
Maybe<Interlacing> interlacing,
Maybe<ColorSpace> colorspace,
IEnumerable<string> comments
)
{
int inputWidth = width.OrElse(_fileLevelHeader.Width);
int inputHeight = height.OrElse(_fileLevelHeader.Height);
Ratio inputFramerate = framerate.OrElse(_fileLevelHeader.Framerate);
Maybe<Ratio> inputPixelAspectRatio = pixelAspectRatio.Or(_fileLevelHeader.PixelAspectRatio);
Maybe<Interlacing> inputInterlacing = interlacing.Or(_fileLevelHeader.Interlacing);
Maybe<ColorSpace> inputColorSpace = colorspace.Or(_fileLevelHeader.ColorSpace);
IEnumerable<string> inputComments = _fileLevelHeader.Comments.Concat(comments);
return (new FrameHeader(
inputWidth,
inputHeight,
inputFramerate,
inputPixelAspectRatio,
inputColorSpace,
inputInterlacing,
inputComments) as Header).ToMaybe();
}
示例2: CloudProvisioning
/// <summary>IoC constructor.</summary>>
public CloudProvisioning(ICloudConfigurationSettings settings, ILog log)
{
_log = log;
_retryPolicy = AzureManagementPolicies.TransientServerErrorBackOff;
// try get settings and certificate
_deploymentId = CloudEnvironment.AzureDeploymentId;
_subscriptionId = settings.SelfManagementSubscriptionId ?? Maybe.String;
var certificateThumbprint = settings.SelfManagementCertificateThumbprint ?? Maybe.String;
if (certificateThumbprint.HasValue)
{
_certificate = CloudEnvironment.GetCertificate(certificateThumbprint.Value);
}
// early evaluate management status for intrinsic fault states, to skip further processing
if (!_deploymentId.HasValue || !_subscriptionId.HasValue || !certificateThumbprint.HasValue)
{
_status = ManagementStatus.ConfigurationMissing;
return;
}
if (!_certificate.HasValue)
{
_status = ManagementStatus.CertificateMissing;
return;
}
// ok, now try find service matching the deployment
_enabled = true;
TryFindDeployment();
}
示例3: Saving
public virtual void Saving(Maybe<Deal> deal)
{
if(deal.Any())
_logger.Info($"Saving : {deal}.");
else
_logger.Warn($" Try Saving : {deal}.");
}
示例4: ParseError
public ParseError(string sourceName, string message, Maybe<long> line, Maybe<long> column)
{
SourceName = sourceName;
Message = message;
Line = line;
Column = column;
}
示例5: Value_ReturnsValue
public void Value_ReturnsValue()
{
var value = "jepsen";
var maybe = new Maybe<string>(value);
maybe.Value.Should().Be(value);
}
示例6: Maybe_String_ValueIsCorrect
public void Maybe_String_ValueIsCorrect()
{
var val = "Value";
var maybe = new Maybe<string>(val);
Assert.AreEqual(val, maybe.Value);
}
示例7: Maybe_Equals_OnlyLeftHasValueNotEqual
public void Maybe_Equals_OnlyLeftHasValueNotEqual()
{
var a = new Maybe<string>("a");
var b = Maybe<string>.NoValue;
Assert.IsFalse(a.Equals(b));
}
示例8: standard_equality
public void standard_equality()
{
var m1 = new Maybe<int>(3);
var m2 = new Maybe<int>(3);
m1.HasValue.Should().BeTrue();
m1.Should().Be(m2);
}
示例9: PreKeyWhisperMessage
public PreKeyWhisperMessage(UInt32 messageVersion, UInt32 registrationId, Maybe<UInt32> preKeyId,
UInt32 signedPreKeyId, ECPublicKey baseKey, IdentityKey identityKey,
WhisperMessage message)
{
MessageVersion = messageVersion;
RegistrationId = registrationId;
PreKeyId = preKeyId;
SignedPreKeyId = signedPreKeyId;
BaseKey = baseKey;
IdentityKey = identityKey;
Message = message;
var preKeyMessage = new WhisperProtos.PreKeyWhisperMessage {
signedPreKeyId = SignedPreKeyId,
baseKey = BaseKey.Serialize(),
identityKey = IdentityKey.Serialize(),
message = Message.Serialize(),
registrationId = registrationId
};
preKeyId.Do(pKid => preKeyMessage.preKeyId = pKid);
byte[] versionBytes = { ByteUtil.IntsToByteHighAndLow(MessageVersion, CURRENT_VERSION) };
byte[] messageBytes;
using(var stream = new MemoryStream())
{
Serializer.Serialize(stream, preKeyMessage);
messageBytes = stream.ToArray();
}
_serialized = ByteUtil.Combine(versionBytes, messageBytes);
}
示例10: ValueToMaybe
public void ValueToMaybe()
{
int value = 10;
Maybe<int> maybe = new Maybe<int>(value);
Assert.IsTrue(maybe.HasValue);
Assert.AreEqual(value, maybe.Value);
}
示例11: WithValue
public static SpecificationProperty WithValue(this SpecificationProperty specProp, Maybe<object> newValue)
{
if (specProp == null) throw new ArgumentNullException("specProp");
if (newValue == null) throw new ArgumentNullException("newValue");
return SpecificationProperty.Create(specProp.Specification, specProp.Property, newValue);
}
示例12: ShouldDisplay
/// <summary>
/// Returns true if this computer should display the message for the given set of message
/// receivers.
/// </summary>
private bool ShouldDisplay(Maybe<List<Player>> receivers) {
if (receivers.IsEmpty) {
return true;
}
return receivers.Value.Contains(_localPlayer);
}
示例13: Anything_FlatMapWithNothing_CreatesNothing
void Anything_FlatMapWithNothing_CreatesNothing()
{
Func<int, Maybe<int>> iiMap = (x) => Maybe<int>.Nothing;
Func<int, Maybe<string>> isMap = (x) => Maybe<string>.Nothing;
Func<string, Maybe<object>> soMap = (x) => Maybe<object>.Nothing;
Maybe<int>[] int_maybes = new Maybe<int>[] { Maybe.Just(0), Maybe.Just(5), Maybe.Just(3282), Maybe.Just(-42), Maybe<int>.Nothing };
foreach (Maybe<int> m in int_maybes)
{
Maybe<int> ii_result = m.FlatMap(iiMap);
Assert.False(ii_result.HasValue);
Assert.Throws<NotSupportedException>(() => ii_result.Value);
Assert.False(ii_result.FlatMap(iiMap).HasValue);
Assert.False(ii_result.FlatMap(iiMap).FlatMap(iiMap).HasValue);
Assert.False(ii_result.FlatMap(iiMap).Map(x => x * 2).HasValue);
Maybe<string> is_result = m.FlatMap(isMap);
Assert.False(is_result.HasValue);
Assert.Throws<NotSupportedException>(() => is_result.Value);
Assert.False(is_result.FlatMap(soMap).HasValue);
Assert.False(is_result.FlatMap(soMap).Map(o => o.ToString()).HasValue);
}
}
示例14: Calculate
public Maybe<double> Calculate(string[] args)
{
if (args.Length == 0)
return lastResult;
if (args.Length == 1)
return lastResult = TryParseDouble(args[0]);
if (args.Length == 2)
{
// Если не хватает первого аргумента, то использовать lastResult
// Должно работать так:
// 2 + 2
//> 4
// + 1
//>5
return lastResult = Execute(args[0], lastResult.Value, double.Parse(args[1]));
}
if (args.Length == 3)
{
var v1 = TryParseDouble(args[0]);
var v2 = TryParseDouble(args[2]);
if (!v1.HasValue) return v1;
if (!v2.HasValue) return v2;
return lastResult = Execute(args[1], v1.Value, v2.Value);
}
return Maybe<double>.FromError("Error input");
}
示例15: DemoTheNewWayOfNullChecking
static string DemoTheNewWayOfNullChecking()
{
Contact contact = new Contact();
contact.Name = "Sean";
contact.Phone = "12345678";
contact.Age = 24;
//contact.PersonalPet = new Pet()
//{
// PetName = new PetName()
// {
// Name = "My Pet"
// }
//};
// Maybe class allow you to do something similar to int? for the reference types.
Maybe<Contact> maybeContact = new Maybe<Contact>(contact);
var maybePetName = from c in maybeContact
from cp in c.PersonalPet
from pn in cp.PetName
select pn.Name;
if (maybePetName.HasValue)
return maybePetName.Value;
return null;
}