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); }
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); }
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); }
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); }
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); }
/// <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); } }
/// <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 <T> execute, Func <T, bool> canExecute) { if (execute == null) { throw new ArgumentNullException("execute"); } _execute = new WeakAction <T>(execute); if (canExecute != null) { _canExecute = new WeakFunc <T, bool>(canExecute); } }
/// <summary> /// Initializes a new instance of the RelayCommand class. /// </summary> /// <param name="execute"> /// The execution logic. IMPORTANT: Note that closures are not supported at the moment due to the use of WeakActions (see http://stackoverflow.com/questions/25730530/). /// </param> /// <param name="canExecute"> /// The execution status logic. IMPORTANT: Note that closures are not supported at the moment due to the use of WeakActions (see http://stackoverflow.com/questions/25730530/). /// </param> /// <exception cref="ArgumentNullException">If the execute argument is null.</exception> public RelayCommand(Action <T> execute, Func <T, Boolean> canExecute) { if (execute == null) { throw new ArgumentNullException("execute"); } this.execute = new WeakAction <T>(execute); if (canExecute != null) { this.canExecute = new WeakFunc <T, Boolean>(canExecute); } }
/// <summary> /// Initializes a new instance of the RelayCommand class. /// </summary> /// <param name="execute">The execution logic. IMPORTANT: If the action causes a closure, /// you must set keepTargetAlive to true to avoid side effects. </param> /// <param name="canExecute">The execution status logic. IMPORTANT: If the func causes a closure, /// you must set keepTargetAlive to true to avoid side effects. </param> /// <param name="keepTargetAlive">If true, the target of the Action will /// be kept as a hard reference, which might cause a memory leak. You should only set this /// parameter to true if the action is causing a closures. See /// http://galasoft.ch/s/mvvmweakaction. </param> /// <exception cref="ArgumentNullException">If the execute argument is null.</exception> public RelayCommand(Action execute, Func <bool> canExecute, bool keepTargetAlive = false) { if (execute == null) { throw new ArgumentNullException("execute"); } _execute = new WeakAction(execute, keepTargetAlive); if (canExecute != null) { _canExecute = new WeakFunc <bool>(canExecute, keepTargetAlive); } }
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; } }
private AsyncRelayCommand( Func <T, bool> canExecute, Func <T, Task> execute, bool keepTargetAlive = true) { _execute = new WeakFunc <T, Task>(execute, keepTargetAlive); _canExecute = new WeakFunc <T, bool>( canExecute == null ? obj => true : new Func <T, bool>(obj => canExecute(obj)), keepTargetAlive); _canExecuteInternal = true; }
AsyncRelayCommand(Func <Task> asyncExecute, Action execute, Func <bool> canExecute) : base(execute, canExecute) { if (execute == null) { throw new ArgumentNullException(nameof(execute)); } if (asyncExecute == null) { throw new ArgumentNullException(nameof(asyncExecute)); } this.asyncExecute = new WeakFunc <Task>(asyncExecute); //this.execute = execute; }
public void NonGeneric_PublicMethod() { var target = new FuncTarget(); var weakFunc = new WeakFunc <bool>(target, target.PublicFuncToExecute); bool result; Assert.IsTrue(weakFunc.Execute(out result)); Assert.AreEqual(1, target.PublicFuncExecutedCount); target = null; GC.Collect(); Assert.IsFalse(weakFunc.IsTargetAlive); }
/// <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); } }
/// <summary> /// Initialises a new instance of the <see cref="RelayCommand"/> class. /// </summary> /// <param name="action"> /// The action. /// </param> /// <param name="canExec"> /// The can exec. /// </param> public RelayCommand(Action action, Func <bool> canExec) { if (action == null) { throw new ArgumentNullException("action"); } this._execute = new WeakAction(action); if (canExec == null) { return; } this._canExecute = new WeakFunc <bool>(canExec); }
/// <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); }
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; } }
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); }
/// <summary> /// Initializes a new instance of the <see cref="AsyncCommand"/> class. /// </summary> /// <param name="execute"> /// The Function executed when Execute or ExecuteAsync is called. IMPORTANT: Note that closures are not supported /// at the moment due to the use of WeakActions (see http://stackoverflow.com/questions/25730530/). /// </param> /// <param name="canExecute">The Function that verifies whether or not AsyncCommand should execute.</param> /// <param name="onException">If an exception is thrown in the Task, <c>onException</c> will be executed.</param> public AsyncCommand( Func <Task> execute, Func <bool>?canExecute = null, Action <Exception>?onException = null) : base(onException) { if (execute == null) { throw new ArgumentNullException(nameof(execute)); } _execute = new WeakFunc <Task>(execute); if (canExecute != null) { _canExecute = new WeakFunc <bool>(canExecute); } }
public InternalTestClassWithResult(WeakActionTestCase testCase, T parameter) { _parameter = parameter; switch (testCase) { case WeakActionTestCase.PublicNamedMethod: Func = new WeakFunc <T, string>( this, DoStuffPublically); break; case WeakActionTestCase.PrivateNamedMethod: Func = new WeakFunc <T, string>( this, DoStuffPrivately); break; case WeakActionTestCase.PublicStaticMethod: Func = new WeakFunc <T, string>( this, DoStuffPublicallyAndStatically); break; case WeakActionTestCase.PrivateStaticMethod: Func = new WeakFunc <T, string>( this, DoStuffPrivatelyAndStatically); break; case WeakActionTestCase.AnonymousStaticMethod: Func = new WeakFunc <T, string>( this, p => Result = Expected + p); break; case WeakActionTestCase.AnonymousMethod: Func = new WeakFunc <T, string>( this, p => Result = Expected + _index + p); break; } }
public void Register <TMessage>(IMessageReceiver recipient, object?token, bool receiveDerivedMessagesToo, Func <TMessage, Task> action) { lock (registerLock) { Type messageType = typeof(TMessage); if (messageType.IsGenericType) { messageType = messageType.GetGenericTypeDefinition(); } Dictionary <Type, List <WeakFuncAndToken> > recipients = receiveDerivedMessagesToo ? recipientsOfSubclassesAction : recipientsStrictAction; lock (recipients) { List <WeakFuncAndToken> list; if (!recipients.ContainsKey(messageType)) { list = new List <WeakFuncAndToken>(); recipients.Add(messageType, list); } else { list = recipients[messageType]; } WeakFunc <TMessage> weakFunc = new WeakFunc <TMessage>(recipient, action); WeakFuncAndToken item = new WeakFuncAndToken { Func = weakFunc, Token = token }; list.Add(item); } } RequestCleanup(); }
public AsyncRelayCommand(IErrorHandler errorHandler, Action <T> execute, Func <bool> canExecute = null) { _errorHandler = errorHandler; _canExecuteResult = false; if (execute == null) { throw new ArgumentNullException(nameof(execute)); } _execute = new WeakAction <T>(execute); if (canExecute == null) { return; } _canExecute = new WeakFunc <bool>(canExecute); _canExecuteworker = new BackgroundWorker(); _canExecuteworker.DoWork += (sender, args) => RunCanExecute(args); _canExecuteworker.RunWorkerCompleted += (sender, args) => RaiseCanExecuteChanged(args); }
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); var 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(); #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 }
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; }
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); }
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 }
/// <summary> /// Initializes a new instance of the <see cref="WeakActionItem{T}"/> class. /// </summary> /// <param name="excuteAction">The excute action.</param> /// <param name="canExcuteAction">The can excute action.</param> /// <param name="target">The target.</param> public WeakActionItem(WeakAction <T> excuteAction, WeakFunc <T, bool> canExcuteAction, object target) { ExcuteAction = excuteAction; CanExcuteAction = canExcuteAction; Target = new WeakReference(target); }
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); }
public ActionableTableViewDelegate(Func <UITableViewRowAction[]> getActionsForRow) { _getActionsForRow = new WeakFunc <UITableViewRowAction[]>(getActionsForRow); }
public ContextMenuHandler(Func <T, ContextMenuComponent> contextMenuComponentFunc) { _contextMenuComponentFunc = new WeakFunc <T, ContextMenuComponent>(contextMenuComponentFunc); }
public void TestInternalClassAnonymousMethod() { Reset(); const int index = 99; const string parameter = "My parameter"; _itemInternal = new InternalTestClass<string>(index); _reference = new WeakReference(_itemInternal); _action = _itemInternal.GetFunc(WeakActionTestCase.AnonymousMethod); Assert.IsTrue(_reference.IsAlive); Assert.IsTrue(_action.IsAlive); var result = _action.Execute(parameter); Assert.AreEqual( InternalTestClass<string>.Expected + index + parameter, InternalTestClass<string>.Result); Assert.AreEqual( InternalTestClass<string>.Expected + index + parameter, result); _itemInternal = 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 }
public WeakFunc <T, string> GetFunc(WeakActionTestCase testCase) { WeakFunc <T, string> action = null; switch (testCase) { case WeakActionTestCase.PublicNamedMethod: action = new WeakFunc <T, string>( this, DoStuffPublicallyWithResult); break; case WeakActionTestCase.InternalNamedMethod: action = new WeakFunc <T, string>( this, DoStuffInternallyWithResult); break; case WeakActionTestCase.PrivateNamedMethod: action = new WeakFunc <T, string>( this, DoStuffPrivatelyWithResult); break; case WeakActionTestCase.PublicStaticMethod: action = new WeakFunc <T, string>( this, DoStuffPublicallyAndStaticallyWithResult); break; case WeakActionTestCase.InternalStaticMethod: action = new WeakFunc <T, string>( this, DoStuffInternallyAndStaticallyWithResult); break; case WeakActionTestCase.PrivateStaticMethod: action = new WeakFunc <T, string>( this, DoStuffPrivatelyAndStaticallyWithResult); break; case WeakActionTestCase.AnonymousStaticMethod: action = new WeakFunc <T, string>( this, p => { Result = Expected + p; return(Result); }); break; case WeakActionTestCase.AnonymousMethod: action = new WeakFunc <T, string>( this, p => { Result = Expected + _index + p; return(Result); }); break; } return(action); }
/// <summary> /// /// </summary> /// <param name="action"></param> /// <param name="canExecute"></param> public RelayCommand(Action action, Func<bool> canExecute = null) { this.action = new WeakDelegate<Action>(action); this.canExecute = null != canExecute ? new WeakFunc<bool>(canExecute) : null; }
public AsyncCommand(Func <T, Task> command, IAsyncOperationStatusManager asyncOperationStatusManager, IErrorHandler errorHandler) { this.errorHandler = errorHandler; this.asyncOperationStatusManager = asyncOperationStatusManager ?? throw new ArgumentNullException(nameof(asyncOperationStatusManager)); this.command = new WeakFunc <T, Task>(command ?? throw new ArgumentNullException(nameof(command))); }
public AsyncMediatorRegistration(object target, Func <T, Task> asyncAction) { Target = target; _weakAsyncAction = new WeakFunc <T, Task>(target, asyncAction); }
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); }
public void TestStaticMethodWithNullTarget() { Reset(); var func = new WeakFunc<string>(null, DoStuffStaticWithResult); Assert.IsTrue(func.IsAlive); }
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); }
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); }
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); }
public void TestNonStaticMethodWithNullTarget() { Reset(); WeakFunc<string> func = new WeakFunc<string>(null, DoStuffWithResult); Assert.IsFalse(func.IsAlive); }
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); }