I have a Ref class

public class Ref<T>
    {
        private Func<T> getter;
        private Action<T> setter;

        /// <summary>
        /// For XML Serialization
        /// </summary>
        private Ref() { }

        public Ref(Func<T> getter, Action<T> setter)
        {
            this.getter = getter;
            this.setter = setter;
        }

        public Func<T> Getter
        {
            get { return getter; }
            set { getter = value; }
        }

        public Action<T> Setter
        {
            get { return setter; }
            set { setter = value; }
        }

        [XmlIgnore]
        public T Value
        {
            get { return getter(); }
            set { setter(value); }
        }
    }

that contains both Func and Action delegates.

If another class has a Ref<float> as one of its properties, how can I correctly serialize and deserialize the Ref<float> class?

I've been playing around with

Type funcType = typeof(Func<>).MakeGenericType(new Type[] { typeof(Ref<float>) });

but I haven't got any closer. Can anyone please help me out here?

Recommended Answers

All 2 Replies

You can't serialize a delegate. Since you can consider it a function pointer, what would it look like when serialized?

Perhaps a GUID assigned to a memory address? I guess I will have to assign this class after deserialization.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.