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; }

        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?

Edited by DaveTran: n/a

7 Years
Discussion Span
Last Post by DaveTran

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.