• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Maybe类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Maybe的典型用法代码示例。如果您正苦于以下问题:C# Maybe类的具体用法?C# Maybe怎么用?C# Maybe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Maybe类属于命名空间,在下文中一共展示了Maybe类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Constructor_NotNullArgumentShouldHaveValue

        public void Constructor_NotNullArgumentShouldHaveValue()
        {
            Maybe<string> str = new Maybe<string>("abc");

            Assert.IsTrue(str.HasValue);
            Assert.AreEqual("abc", str.Value);
        }
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:7,代码来源:MaybeTests.cs


示例17: 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
        )
        {
            if (width.IsNothing() || height.IsNothing() || framerate.IsNothing())
            {
                return Maybe<Header>.Nothing;
            }

            return (new FileHeader(
                width.Value,
                height.Value,
                framerate.Value,
                pixelAspectRatio,
                colorspace,
                interlacing,
                comments
            ) as Header).ToMaybe();
        }
开发者ID:helios2k6,项目名称:MobileImageProcessor,代码行数:25,代码来源:FileHeaderParser.cs


示例18: Maybe_Equals_BothHaveSameValueIsEqual

		public void Maybe_Equals_BothHaveSameValueIsEqual()
		{
			var a = new Maybe<string>("a");
			var b = new Maybe<string>("a");

			Assert.IsTrue(a.Equals(b));
		}
开发者ID:BosslandGmbH,项目名称:Buddy.UI,代码行数:7,代码来源:MaybeTests.cs


示例19: Maybe_Equals_DifferentValuesAreNotEqual

		public void Maybe_Equals_DifferentValuesAreNotEqual()
		{
			var a = new Maybe<string>("a");
			var b = new Maybe<string>("b");

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


示例20: Add

 static Maybe<int> Add(Maybe<int> x, Maybe<int> y)
 {
     return
         from _x in x
         from _y in y
         where _x < _y
         select _x + _y;
 }
开发者ID:sakapon,项目名称:Samples-2014,代码行数:8,代码来源:Program.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Maze类代码示例发布时间:2022-05-24
下一篇:
C# MatrixType类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap