当前位置: 首页>>代码示例>>C#>>正文


C# Maybe类代码示例

本文整理汇总了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();
        }
开发者ID:helios2k6,项目名称:MobileImageProcessor,代码行数:27,代码来源:FrameHeaderParser.cs

示例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();
		}
开发者ID:cdrnet,项目名称:Lokad.Cloud,代码行数:31,代码来源:CloudProvisioning.cs

示例3: Saving

 public virtual void Saving(Maybe<Deal> deal)
 {
     if(deal.Any())
         _logger.Info($"Saving : {deal}.");
     else
         _logger.Warn($" Try Saving : {deal}.");
 }
开发者ID:evilz,项目名称:solid-sample,代码行数:7,代码来源:DealServiceLogger.cs

示例4: ParseError

 public ParseError(string sourceName, string message, Maybe<long> line, Maybe<long> column)
 {
     SourceName = sourceName;
     Message = message;
     Line = line;
     Column = column;
 }
开发者ID:tr-codegeneration,项目名称:tr-codegeneration,代码行数:7,代码来源:ParseError.cs

示例5: Value_ReturnsValue

        public void Value_ReturnsValue()
        {
            var value = "jepsen";
            var maybe = new Maybe<string>(value);

            maybe.Value.Should().Be(value);
        }
开发者ID:yonglehou,项目名称:servicestack-ratelimit-redis,代码行数:7,代码来源:MaybeTests.cs

示例6: Maybe_String_ValueIsCorrect

		public void Maybe_String_ValueIsCorrect()
		{
			var val = "Value";
			var maybe = new Maybe<string>(val);

			Assert.AreEqual(val, maybe.Value);
		}
开发者ID:BosslandGmbH,项目名称:Buddy.UI,代码行数:7,代码来源:MaybeTests.cs

示例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));
		}
开发者ID:BosslandGmbH,项目名称:Buddy.UI,代码行数:7,代码来源:MaybeTests.cs

示例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);
 }
开发者ID:flq,项目名称:XamlTags,代码行数:7,代码来源:MaybeTests.cs

示例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);
        }
开发者ID:Muraad,项目名称:libaxolotl-net,代码行数:33,代码来源:PreKeyWhisperMessage.cs

示例10: ValueToMaybe

 public void ValueToMaybe()
 {
     int value = 10;
     Maybe<int> maybe = new Maybe<int>(value);
     Assert.IsTrue(maybe.HasValue);
     Assert.AreEqual(value, maybe.Value);
 }
开发者ID:leon737,项目名称:MvcBlanket,代码行数:7,代码来源:MaybeMonadTest.cs

示例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);
        }
开发者ID:BiYiTuan,项目名称:commandline,代码行数:7,代码来源:SpecificationPropertyExtensions.cs

示例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);
        }
开发者ID:jyunfan2015,项目名称:forge,代码行数:11,代码来源:ChatMessageHandler.cs

示例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);
            }
        }
开发者ID:Eyas,项目名称:Ibra,代码行数:25,代码来源:MaybeTests.cs

示例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");
 }
开发者ID:v-samodelkin,项目名称:git-merge-task,代码行数:26,代码来源:Calculator.cs

示例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;
        }
开发者ID:nzkelvin,项目名称:MaybeApplication,代码行数:27,代码来源:Program.cs


注:本文中的Maybe类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。