예제 #1
0
        /// <summary>
        /// Initialisiert eine neue Instanz der class <see cref="TypeSerializer"/> für das
        /// nicht serialisierbare Objekt <paramref name="instance"/> für eine Serialisierung mittles
        /// Reflection.
        /// </summary>
        /// <param name="instance">The instance.</param>
        private TypeSerializer(object instance)
        {
            using (var log = new EnterExitLogger(s_log, "instance = {0}", instance)) {
                m_instance     = instance;
                m_type         = m_instance.GetType();
                m_fields       = new FieldSerializerDict();
                m_constructors = new ConstructorReflectorDict();

                foreach (var ci in m_type.GetConstructors(MemberReflector.AllInstanceDeclared))
                {
                    var ctor = new ConstructorReflector(ci);
                    m_constructors.Add(TypeReflector.BuildMethodSignature(ci), ctor);
                    if (ctor.IsDefaultConstructor)
                    {
                        m_defaultConstructor = ctor;
                    }
                }

                var fields = m_type.GetFields(MemberReflector.AllInstanceDeclared);

                foreach (var fi in fields)
                {
                    var fieldValue = fi.GetValue(m_instance);
                    fieldValue = CreateSerializerWrapper(fieldValue);

                    m_fields.Add(fi.Name, new FieldSerializer(fi, fieldValue));
                }
            }
        }
예제 #2
0
 protected TypeSerializer(SerializationInfo si, StreamingContext context)
 {
     using (var log = new EnterExitLogger(s_log, "si = {0}", si)) {
         m_type               = (Type)si.GetValue("m_type", typeof(Type));
         m_fields             = (FieldSerializerDict)si.GetValue("m_fields", typeof(FieldSerializerDict));
         m_constructors       = (ConstructorReflectorDict)si.GetValue("m_constructors", typeof(ConstructorReflectorDict));
         m_defaultConstructor = (ConstructorReflector)si.GetValue("m_defaultConstructor", typeof(ConstructorReflector));
     }
 }