Serializing anonymous delegates in C#

前端 未结 6 1412
我在风中等你
我在风中等你 2020-12-01 02:59

I am trying to determine what issues could be caused by using the following serialization surrogate to enable serialization of anonymous functions/delegate/lambdas.

6条回答
  •  無奈伤痛
    2020-12-01 03:35

    Some objects need execute arbitrary "events" reaching some condition.

    Just how arbitrary are these events? Can they be counted, assigned ID's and mapped to referentially?

    public class Command where T : ISerializable
    {
      T _target;
      int _actionId;
      int _conditionId;
    
      public Command(T Target, int ActionId, int ConditionId)
      {
        _target = Target;
        _actionId = ActionId;
        _conditionId = ConditionId;
      }
    
      public bool FireRule()
      {
        Func theCondition = conditionMap.LookupCondition(_conditionId)
        Action theAction = actionMap.LookupAction(_actionId);
    
        if (theCondition(_target))
        {
          theAction(_target);
          return true;
        }
        return false;
      }  
    }
    

提交回复
热议问题