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

C# WeakFunc类代码示例

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

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



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

示例1: RelayCommand

 /// <summary>
 /// Initializes a new instance of the RelayCommand class.
 /// </summary>
 /// <param name="execute">The execution logic.</param>
 /// <param name="canExecute">The execution status logic.</param>
 /// <exception cref="T:System.ArgumentNullException">If the execute argument is null.</exception>
 public RelayCommand(Action execute, Func<bool> canExecute)
 {
     if (execute == null)
     {
         throw new ArgumentNullException("execute");
     }
     this._execute = new WeakAction(execute);
     if (canExecute != null)
     {
         this._canExecute = new WeakFunc<bool>(canExecute);
     }
 }
开发者ID:yue-fei,项目名称:csharp-mvvm,代码行数:18,代码来源:Command.cs


示例2: RelayCommand

        /// <summary>
        /// Initializes a new instance of the RelayCommand class.
        /// </summary>
        /// <param name="execute">The execution logic.</param>
        /// <param name="canExecute">The execution status logic.</param>
        /// <exception cref="ArgumentNullException">If the execute argument is null.</exception>
        public RelayCommand(Action execute, Func<bool> canExecute)
        {
            Idle = true;

            if (execute == null)
            {
                throw new ArgumentNullException("execute");
            }

            ExecuteAction = new WeakAction(execute);

            if (canExecute != null)
            {
                _canExecute = new WeakFunc<bool>(canExecute);
            }
        }
开发者ID:jprofi,项目名称:MSProjects,代码行数:22,代码来源:RelayCommand.cs


示例3: ActionCommand

        /// <summary>
        /// Initializes a new instance of the <see cref="ActionCommand"/> class.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="methodName">Name of the method.</param>
        public ActionCommand(object target, string methodName) {
            if (target == null)
                throw new ArgumentNullException("target");

            targetReference = new WeakReference(target);
            method = target.GetType().GetMethod(methodName);
            if (method == null)
                throw new ArgumentException(@"Specified method cannot be found.", "methodName");

            guardName = "Can" + method.Name;
            var guard = target.GetType().GetMethod("get_" + guardName);
            var inpc = target as INotifyPropertyChanged;
            if (inpc == null || guard == null) return;

            WeakEventHandler.Register<PropertyChangedEventArgs>(inpc, "PropertyChanged", OnPropertyChanged);
            canExecute = new WeakFunc<bool>(inpc, guard);
        }
开发者ID:kmcginnes,项目名称:Caliburn.Micro.Extras,代码行数:22,代码来源:ActionCommand.cs


示例4: PublicTestClassWithResult

        public PublicTestClassWithResult(WeakActionTestCase testCase)
        {
            switch (testCase)
            {
                case WeakActionTestCase.PublicNamedMethod:
                    Func = new WeakFunc<string>(
                        this,
                        DoStuffPublically);
                    break;
                case WeakActionTestCase.PrivateNamedMethod:
                    Func = new WeakFunc<string>(
                        this,
                        DoStuffPrivately);
                    break;
                case WeakActionTestCase.PublicStaticMethod:
                    Func = new WeakFunc<string>(
                        this,
                        DoStuffPublicallyAndStatically);
                    break;
                case WeakActionTestCase.PrivateStaticMethod:
                    Func = new WeakFunc<string>(
                        this,
                        DoStuffPrivatelyAndStatically);
                    break;
                case WeakActionTestCase.AnonymousStaticMethod:
                    Func = new WeakFunc<string>(
                        this,
                        () =>
                        {
                            Result = Expected;
                            return Result;
                        });
                    break;
                case WeakActionTestCase.AnonymousMethod:
                    Func = new WeakFunc<string>(
                        this,
                        () =>
                        {
                            Result = Expected + _index;
                            return Result;
                        });
                    break;
            }

        }
开发者ID:name2name2,项目名称:mvvmlight,代码行数:45,代码来源:PublicTestClassWithResult.cs


示例5: TestStaticMethodWithNonNullTarget

        public void TestStaticMethodWithNonNullTarget()
        {
            Reset();

            _common = new CommonTestClass();
            _reference = new WeakReference(_common);
            Assert.IsTrue(_reference.IsAlive);

            var func = new WeakFunc<string>(_common, DoStuffStaticWithResult);
            Assert.IsTrue(func.IsAlive);

            _common = null;
            GC.Collect();

            Assert.IsFalse(_reference.IsAlive);
            Assert.IsFalse(func.IsAlive);
        }
开发者ID:name2name2,项目名称:mvvmlight,代码行数:17,代码来源:WeakFuncTest.cs


示例6: TestStaticMethodWithNullTarget

 public void TestStaticMethodWithNullTarget()
 {
     Reset();
     var func = new WeakFunc<string>(null, DoStuffStaticWithResult);
     Assert.IsTrue(func.IsAlive);
 }
开发者ID:name2name2,项目名称:mvvmlight,代码行数:6,代码来源:WeakFuncTest.cs


示例7: GetFunc

            public WeakFunc<string> GetFunc(WeakActionTestCase testCase)
            {
                WeakFunc<string> action = null;

                switch (testCase)
                {
                    case WeakActionTestCase.PublicNamedMethod:
                        action = new WeakFunc<string>(
                            this,
                            DoStuffPublicallyWithResult);
                        break;
                    case WeakActionTestCase.InternalNamedMethod:
                        action = new WeakFunc<string>(
                            this,
                            DoStuffInternallyWithResult);
                        break;
                    case WeakActionTestCase.PrivateNamedMethod:
                        action = new WeakFunc<string>(
                            this,
                            DoStuffPrivatelyWithResult);
                        break;
                    case WeakActionTestCase.PublicStaticMethod:
                        action = new WeakFunc<string>(
                            this,
                            DoStuffPublicallyAndStaticallyWithResult);
                        break;
                    case WeakActionTestCase.InternalStaticMethod:
                        action = new WeakFunc<string>(
                            this,
                            DoStuffInternallyAndStaticallyWithResult);
                        break;
                    case WeakActionTestCase.PrivateStaticMethod:
                        action = new WeakFunc<string>(
                            this,
                            DoStuffPrivatelyAndStaticallyWithResult);
                        break;
                    case WeakActionTestCase.AnonymousStaticMethod:
                        action = new WeakFunc<string>(
                            this,
                            () =>
                                {
                                    Result = Expected;
                                    return Result;
                                });
                        break;
                    case WeakActionTestCase.AnonymousMethod:
                        action = new WeakFunc<string>(
                            this,
                            () =>
                                {
                                    Result = Expected + _index;
                                    return Result;
                                });
                        break;
                }

                return action;
            }
开发者ID:jprofi,项目名称:MSProjects,代码行数:58,代码来源:WeakFuncNestedTest.cs


示例8: TestNonStaticMethodWithNullTarget

 public void TestNonStaticMethodWithNullTarget()
 {
     Reset();
     WeakFunc<string> func = new WeakFunc<string>(null, DoStuffWithResult);
     Assert.IsFalse(func.IsAlive);
 }
开发者ID:jprofi,项目名称:MSProjects,代码行数:6,代码来源:WeakFuncTest.cs


示例9: TestInternalNestedClassAnonymousStaticMethod

        public void TestInternalNestedClassAnonymousStaticMethod()
        {
            Reset();

            _itemInternal = new InternalNestedTestClass();
            _reference = new WeakReference(_itemInternal);

            _action = _itemInternal.GetFunc(WeakActionTestCase.AnonymousStaticMethod);

            Assert.IsTrue(_reference.IsAlive);
            Assert.IsTrue(_action.IsAlive);

            string result = _action.Execute();

            Assert.AreEqual(
                InternalNestedTestClass.Expected,
                InternalNestedTestClass.Result);
            Assert.AreEqual(
                InternalNestedTestClass.Expected,
                result);

            _itemInternal = null;
            GC.Collect();

            Assert.IsFalse(_reference.IsAlive);
        }
开发者ID:jprofi,项目名称:MSProjects,代码行数:26,代码来源:WeakFuncNestedTest.cs


示例10: TestPublicClassPublicStaticMethod

        public void TestPublicClassPublicStaticMethod()
        {
            Reset();

            _itemPublic = new PublicTestClass();
            _reference = new WeakReference(_itemPublic);

            _action = _itemPublic.GetFunc(WeakActionTestCase.PublicStaticMethod);

            Assert.IsTrue(_reference.IsAlive);
            Assert.IsTrue(_action.IsAlive);

            var result = _action.Execute();

            Assert.AreEqual(
                PublicTestClass.Expected + PublicTestClass.PublicStatic,
                PublicTestClass.Result);
            Assert.AreEqual(
                PublicTestClass.Expected + PublicTestClass.PublicStatic,
                result);

            _itemPublic = null;
            GC.Collect();

            Assert.IsFalse(_reference.IsAlive);
        }
开发者ID:name2name2,项目名称:mvvmlight,代码行数:26,代码来源:WeakFuncTest.cs


示例11: TestInternalClassAnonymousStaticMethod

        public void TestInternalClassAnonymousStaticMethod()
        {
            Reset();

            const string parameter = "My parameter";

            _itemInternal = new InternalTestClass<string>();
            _reference = new WeakReference(_itemInternal);

            _action = _itemInternal.GetFunc(WeakActionTestCase.AnonymousStaticMethod);

            Assert.IsTrue(_reference.IsAlive);
            Assert.IsTrue(_action.IsAlive);

            string result = _action.Execute(parameter);

            Assert.AreEqual(
                InternalTestClass<string>.Expected + parameter,
                InternalTestClass<string>.Result);
            Assert.AreEqual(
                InternalTestClass<string>.Expected + parameter,
                result);

            _itemInternal = null;
            GC.Collect();

            Assert.IsFalse(_reference.IsAlive);
        }
开发者ID:jprofi,项目名称:MSProjects,代码行数:28,代码来源:WeakFuncGenericTest.cs


示例12: TestPublicClassPublicStaticMethod

        public void TestPublicClassPublicStaticMethod()
        {
            Reset();

            const string parameter = "My parameter";

            _itemPublic = new PublicTestClass<string>();
            _reference = new WeakReference(_itemPublic);

            _action = _itemPublic.GetFunc(WeakActionTestCase.PublicStaticMethod);

            Assert.IsTrue(_reference.IsAlive);
            Assert.IsTrue(_action.IsAlive);

            var result = _action.Execute(parameter);

            Assert.AreEqual(
                PublicTestClass<string>.Expected + PublicTestClass<string>.PublicStatic + parameter,
                PublicTestClass<string>.Result);
            Assert.AreEqual(
                PublicTestClass<string>.Expected + PublicTestClass<string>.PublicStatic + parameter,
                result);

            _itemPublic = null;
            GC.Collect();

            Assert.IsFalse(_reference.IsAlive);
        }
开发者ID:timdetering,项目名称:mvvmlight,代码行数:28,代码来源:WeakFuncGenericTest.cs


示例13: TestPublicNestedClassPublicNamedMethod

        public void TestPublicNestedClassPublicNamedMethod()
        {
            Reset();

            const int index = 99;

            _itemPublic = new PublicNestedTestClass(index);

            _action = _itemPublic.GetFunc(WeakActionTestCase.PublicNamedMethod);

            _reference = new WeakReference(_itemPublic);
            Assert.IsTrue(_reference.IsAlive);
            Assert.IsTrue(_action.IsAlive);

            var result = _action.Execute();

            Assert.AreEqual(
                PublicNestedTestClass.Expected + PublicNestedTestClass.Public + index,
                PublicNestedTestClass.Result);
            Assert.AreEqual(
                PublicNestedTestClass.Expected + PublicNestedTestClass.Public + index,
                result);

            _itemPublic = null;
            GC.Collect();

            Assert.IsFalse(_reference.IsAlive);
        }
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:28,代码来源:WeakFuncNestedTest.cs


示例14: TestPublicClassInternalNamedMethod

        public void TestPublicClassInternalNamedMethod()
        {
            Reset();

            const int index = 99;

            _itemPublic = new PublicTestClass(index);
            _reference = new WeakReference(_itemPublic);

            _action = _itemPublic.GetFunc(WeakActionTestCase.InternalNamedMethod);

            Assert.IsTrue(_reference.IsAlive);
            Assert.IsTrue(_action.IsAlive);

            var result = _action.Execute();

            Assert.AreEqual(
                PublicTestClass.Expected + PublicTestClass.Internal + index,
                PublicTestClass.Result);
            Assert.AreEqual(
                PublicTestClass.Expected + PublicTestClass.Internal + index,
                result);

            _itemPublic = null;
            GC.Collect();

#if SILVERLIGHT
            Assert.IsTrue(_reference.IsAlive); // Anonymous, private and internal methods cannot be GCed
            _action = null;
            GC.Collect();
            Assert.IsFalse(_reference.IsAlive);
#else
            Assert.IsFalse(_reference.IsAlive);
#endif
        }
开发者ID:name2name2,项目名称:mvvmlight,代码行数:35,代码来源:WeakFuncTest.cs


示例15: TestPublicClassInternalNamedMethod

        public void TestPublicClassInternalNamedMethod()
        {
            Reset();

            const string parameter = "My parameter";
            const int index = 99;

            _itemPublic = new PublicTestClass<string>(index);
            _reference = new WeakReference(_itemPublic);

            _action = _itemPublic.GetFunc(WeakActionTestCase.InternalNamedMethod);

            Assert.IsTrue(_reference.IsAlive);
            Assert.IsTrue(_action.IsAlive);

            string result = _action.Execute(parameter);

            Assert.AreEqual(
                PublicTestClass<string>.Expected + PublicTestClass<string>.Internal + index + parameter,
                PublicTestClass<string>.Result);
            Assert.AreEqual(
                PublicTestClass<string>.Expected + PublicTestClass<string>.Internal + index + parameter,
                result);

            _itemPublic = null;
            GC.Collect();

            Assert.IsFalse(_reference.IsAlive);
        }
开发者ID:jprofi,项目名称:MSProjects,代码行数:29,代码来源:WeakFuncGenericTest.cs


示例16: TestInternalClassPrivateStaticMethod

        public void TestInternalClassPrivateStaticMethod()
        {
            Reset();

            _itemInternal = new InternalTestClass();
            _reference = new WeakReference(_itemInternal);

            _action = _itemInternal.GetFunc(WeakActionTestCase.PrivateStaticMethod);

            Assert.IsTrue(_reference.IsAlive);
            Assert.IsTrue(_action.IsAlive);

            var result = _action.Execute();

            Assert.AreEqual(
                InternalTestClass.Expected + InternalTestClass.PrivateStatic,
                InternalTestClass.Result);
            Assert.AreEqual(
                InternalTestClass.Expected + InternalTestClass.PrivateStatic,
                result);

            _itemInternal = null;
            GC.Collect();

            Assert.IsFalse(_reference.IsAlive);
        }
开发者ID:name2name2,项目名称:mvvmlight,代码行数:26,代码来源:WeakFuncTest.cs


示例17: TestInternalNestedClassInternalNamedMethod

        public void TestInternalNestedClassInternalNamedMethod()
        {
            Reset();

            const int index = 99;

            _itemInternal = new InternalNestedTestClass(index);
            _reference = new WeakReference(_itemInternal);

            _action = _itemInternal.GetFunc(WeakActionTestCase.InternalNamedMethod);

            Assert.IsTrue(_reference.IsAlive);
            Assert.IsTrue(_action.IsAlive);

            string result = _action.Execute();

            Assert.AreEqual(
                InternalNestedTestClass.Expected + InternalNestedTestClass.Internal + index,
                InternalNestedTestClass.Result);
            Assert.AreEqual(
                InternalNestedTestClass.Expected + InternalNestedTestClass.Internal + index,
                result);

            _itemInternal = null;
            GC.Collect();

            Assert.IsFalse(_reference.IsAlive);
        }
开发者ID:jprofi,项目名称:MSProjects,代码行数:28,代码来源:WeakFuncNestedTest.cs


示例18: TestPrivateNestedClassPublicStaticMethod

        public void TestPrivateNestedClassPublicStaticMethod()
        {
            Reset();

            _itemPrivate = new PrivateNestedTestClass();
            _reference = new WeakReference(_itemPrivate);

            _action = _itemPrivate.GetFunc(WeakActionTestCase.PublicStaticMethod);

            Assert.IsTrue(_reference.IsAlive);
            Assert.IsTrue(_action.IsAlive);

            string result = _action.Execute();

            Assert.AreEqual(
                PrivateNestedTestClass.Expected + PrivateNestedTestClass.PublicStatic,
                PrivateNestedTestClass.Result);
            Assert.AreEqual(
                PrivateNestedTestClass.Expected + PrivateNestedTestClass.PublicStatic,
                result);

            _itemPrivate = null;
            GC.Collect();

            Assert.IsFalse(_reference.IsAlive);
        }
开发者ID:jprofi,项目名称:MSProjects,代码行数:26,代码来源:WeakFuncNestedTest.cs


示例19: TestPrivateNestedClassAnonymousMethod

        public void TestPrivateNestedClassAnonymousMethod()
        {
            Reset();

            const int index = 99;

            _itemPrivate = new PrivateNestedTestClass(index);
            _reference = new WeakReference(_itemPrivate);

            _action = _itemPrivate.GetFunc(WeakActionTestCase.AnonymousMethod);

            Assert.IsTrue(_reference.IsAlive);
            Assert.IsTrue(_action.IsAlive);

            string result = _action.Execute();

            Assert.AreEqual(
                PrivateNestedTestClass.Expected + index,
                PrivateNestedTestClass.Result);
            Assert.AreEqual(
                PrivateNestedTestClass.Expected + index,
                result);

            _itemPrivate = null;
            GC.Collect();

            Assert.IsFalse(_reference.IsAlive);
        }
开发者ID:jprofi,项目名称:MSProjects,代码行数:28,代码来源:WeakFuncNestedTest.cs


示例20: TestInternalClassPrivateNamedMethod

        public void TestInternalClassPrivateNamedMethod()
        {
            Reset();

            const string parameter = "My parameter";
            const int index = 99;

            _itemInternal = new InternalTestClass<string>(index);
            _reference = new WeakReference(_itemInternal);

            _action = _itemInternal.GetFunc(WeakActionTestCase.PrivateNamedMethod);

            Assert.IsTrue(_reference.IsAlive);
            Assert.IsTrue(_action.IsAlive);

            string result = _action.Execute(parameter);

            Assert.AreEqual(
                InternalTestClass<string>.Expected + InternalTestClass<string>.Private + index + parameter,
                InternalTestClass<string>.Result);
            Assert.AreEqual(
                InternalTestClass<string>.Expected + InternalTestClass<string>.Private + index + parameter,
                result);

            _itemInternal = null;
            GC.Collect();

            Assert.IsFalse(_reference.IsAlive);
        }
开发者ID:jprofi,项目名称:MSProjects,代码行数:29,代码来源:WeakFuncGenericTest.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# WeakReference类代码示例发布时间:2022-05-24
下一篇:
C# WeakEventListener类代码示例发布时间: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