/// <summary> /// Handles the assignemnt from ReflectedData into CLR fieldInfo. Override to make conversions, i.e. string to bool, int to string etc... /// Return true to indicate that default framework implementation should not be called /// </summary> public abstract bool SetFieldValue(ReadingStrategy readingStrategy, object instance, FieldInfo fieldInfo, CompositeReflectedData data, MetaComplexType.MetaField mfield);
/// <summary> /// Handles the deserialization of the object instance from CompoisteReflectedData. Returns a set of fields that were handles by this implementation /// so that framework code can skip them. Return null or empty set when method is not implemented /// </summary> public abstract HashSet<MetaComplexType.MetaField> DeserializeFromCompositeReflectedData(object instance, CompositeReflectedData data);
/// <summary> /// Handles the deserialization of the object instance from CompoisteReflectedData. Returns a set of fields that were handles by this implementation /// so that framework code can skip them. Return null or empty set when method is not implemented /// </summary> public abstract HashSet <MetaComplexType.MetaField> DeserializeFromCompositeReflectedData(object instance, CompositeReflectedData data);
/// <summary> /// Performs the assignment of portable data into native field /// </summary> public virtual void SetFieldData(object instance, FieldInfo fieldInfo, CompositeReflectedData data, MetaComplexType.MetaField mfield) { var nativeData = data.Document.PortableDataToNativeData(this, data.m_FieldData[mfield.m_Index]); fieldInfo.SetValue(instance, nativeData); }
public virtual void DeserializeObjectFromCompositeReflectedData(object instance, CompositeReflectedData data) { var t = instance.GetType(); //1 check for attribute --------------- var attr = (PortableObjectDocumentDeserializationTransform)t .GetCustomAttributes(typeof(PortableObjectDocumentDeserializationTransform), false) .FirstOrDefault(); HashSet<MetaComplexType.MetaField> alreadyHandled = null; if (attr!=null) alreadyHandled = attr.DeserializeFromCompositeReflectedData(instance, data); //2 read data var mfields = data.Type; foreach(var mfld in mfields) { if (alreadyHandled!=null && alreadyHandled.Contains(mfld)) continue; //find field if (mfld.m_FieldInfo==null) { //1. try attr if (attr!=null) mfld.m_FieldInfo = attr.ResolveField(t, mfld); //2. try built in method if (mfld.m_FieldInfo==null) mfld.m_FieldInfo = ResolveField(t, mfld); //3. skip this field altogether if it can not be read if (mfld.m_FieldInfo==null) continue; } var handled = false; if (attr!=null) handled = attr.SetFieldValue(this, instance, mfld.m_FieldInfo, data, mfld); if (!handled) SetFieldData(instance, mfld.m_FieldInfo, data, mfld); } }
public virtual void DeserializeObjectFromCompositeReflectedData(object instance, CompositeReflectedData data) { var t = instance.GetType(); //1 check for attribute --------------- var attr = (PortableObjectDocumentDeserializationTransform)t .GetCustomAttributes(typeof(PortableObjectDocumentDeserializationTransform), false) .FirstOrDefault(); HashSet <MetaComplexType.MetaField> alreadyHandled = null; if (attr != null) { alreadyHandled = attr.DeserializeFromCompositeReflectedData(instance, data); } //2 read data var mfields = data.Type; foreach (var mfld in mfields) { if (alreadyHandled != null && alreadyHandled.Contains(mfld)) { continue; } //find field if (mfld.m_FieldInfo == null) { //1. try attr if (attr != null) { mfld.m_FieldInfo = attr.ResolveField(t, mfld); } //2. try built in method if (mfld.m_FieldInfo == null) { mfld.m_FieldInfo = ResolveField(t, mfld); } //3. skip this field altogether if it can not be read if (mfld.m_FieldInfo == null) { continue; } } var handled = false; if (attr != null) { handled = attr.SetFieldValue(this, instance, mfld.m_FieldInfo, data, mfld); } if (!handled) { SetFieldData(instance, mfld.m_FieldInfo, data, mfld); } } }