GetObjectData не вызывается из определенного класса - PullRequest
0 голосов
/ 06 марта 2020

Я обновил код для большей ясности, часть, которая не вызывается, называется GetObjectData в BaseComp. Когда я сериализую один и тот же объект Components из другого места, он работает без проблем, и все поля и свойства возвращаются нормально (GetObjectData в BaseComp также вызывается правильно). Когда блок-схема сохраняется, она выполняет сериализацию ModelStack, и объект Components (фактически несколько) также сериализуется как часть этого процесса, эта часть работает без проблем.

 [TypeConverterAttribute(typeof(ExpandableObjectConverter)), Serializable]
 class GraphicsList : ISerializable, IEnumerable 
{
    public event ValueErrorEventHandler errorChangedEvent;
    public delegate void ValueErrorEventHandler(object sender, EventArgs e);
    ThermoDynamicOptions thermooptions = new ThermoDynamicOptions();
    public DrawArea drawarea;
    FlowSheet flowsheet = new FlowSheet();
    public FlowSheet Flowsheet { get => flowsheet; set => flowsheet = value; }

    public ThermoDynamicOptions Thermo
    {
        get { return thermooptions; }
        set { thermooptions = value; }
    }

    /// <summary>
    /// Save object to serialization stream
    /// </summary>
    /// <param name="info"></param>
    /// <param name="context"></param>
    [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
    public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        info.AddValue(entryCount, graphicsList.Count);
        info.AddValue("graphicslist", graphicsList, typeof(DrawList));
        info.AddValue("ThermoOptions", Thermo, typeof(ThermoDynamicOptions));
        info.AddValue("CalcMethod", this.CalcType);
        info.AddValue("FlowSheet", Flowsheet, typeof(FlowSheet));
  }
}

[Serializable]
[TypeConverter(typeof(ExpandableObjectConverter))]

  public class FlowSheet : ISerializable
 {
    public static Stack<BaseObject> inconsistencyStack = new stack<BaseObject>();
    public Components FlowsheetComponentList = new Components();
    public Dictionary<Guid, IUnitOperation> modelStack = new Dictionary<Guid, IUnitOperation>();
    public UOMDisplayList UOMDisplayList = new UOMDisplayList();
    private string name = "";

    [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        info.AddValue("ComponentList", FlowsheetComponentList, typeof(Components));
        info.AddValue("UnitList", this.modelStack, typeof(Dictionary<Guid, UnitOperation>));
    }
   }


[TypeConverter(typeof(ExpandableObjectConverter)), Serializable]
public partial class Components : OilExpander, ISerializable, IEnumerable, IEquatable<Components>
{
    List<BaseComp> components = new List<BaseComp>();

    public Temperature T = double.NaN;
    public Pressure P = double.NaN;
    public Quality Q = double.NaN;
    public Enthalpy H = double.NaN;
    public Entropy S = double.NaN;

    SourceEnum origin = SourceEnum.Empty;
    Guid originGuid = Guid.Empty;

    public bool IsPrimary { get; set; }

    public List<BaseComp> ComponentList { get => components; set => components = value; }
    public bool IsFlashed { get => isFlashed; set => isFlashed = value;              }

    [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
    void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
    {
        GetObjectData(info, context);
    }

    [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
    public virtual void GetObjectData(SerializationInfo si, StreamingContext ctx)
    {
        si.AddValue("List", components, typeof(List<BaseComp>));
    }
  }

 [Serializable]
  public class BaseComp : BaseObject, IConsistencyProperty, ICloneable, IComp, IPengRobinson, IComparable, IEquatable<BaseComp>, ISerializable
{
    public Temperature critt; // kelvin
    double molwt, hForm, hVap25;
    Temperature bp_k;
    Temperature ubp, lbp;

    [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
    void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
    {
        GetObjectData(info, context); 
    }

    [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
    public override void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        info.AddValue("IsPure", IsPure);
        info.AddValue("CritT", CritT);
        info.AddValue("CritP", CritP);
        info.AddValue("CritZ", CritZ);
        info.AddValue("CritV", CritV);
        info.AddValue("Omega", Omega);
        info.AddValue("AntK", AntK);
        info.AddValue("VapEnth", VapEnth);
        info.AddValue("MW", molwt);
        info.AddValue("SG", SG);
        info.AddValue("BP", BP);
        info.AddValue("FracVap", FracVap);
        info.AddValue("refenthalpydep1", refenthalpydep1);
        info.AddValue("refentropydep1", refentropydep1);
        info.AddValue("refenthalpydep3", refenthalpydep3);
        info.AddValue("HForm25", HForm25);

        info.AddValue("MoleFraction", molefraction);

        base.GetObjectData(info, context);
    }
  }
...