/// <summary> /// Returns object reference for supplied metahandle /// </summary> public object HandleToReference(MetaHandle handle, TypeRegistry treg, SlimFormat format, SlimReader reader) { Debug.Assert(m_Mode == SerializationOperation.Deserializing, "HandleToReference() called while serializing", DebugAction.Throw); if (handle.IsInlinedString) return handle.Metadata.Value.StringValue; if (handle.IsInlinedTypeValue) { var tref = treg[ handle.Metadata.Value ];//adding this type to registry if it is not there yet return tref; } if (handle.IsInlinedRefType) { var tref = treg[ handle.Metadata.Value ];//adding this type to registry if it is not there yet var ra = format.GetReadActionForRefType(tref); if (ra!=null) { var inst = ra(reader); m_List.Add(inst); return inst; } else throw new SlimDeserializationException("Internal error HandleToReference: no read action for ref type, but ref mhandle is inlined"); } int idx = (int)handle.Handle; if (idx<m_List.Count) return m_List[idx]; if (!handle.Metadata.HasValue) throw new SlimDeserializationException(StringConsts.SLIM_HNDLTOREF_MISSING_TYPE_NAME_ERROR + handle.ToString()); Type type; var metadata = handle.Metadata.Value; if (metadata.StringValue!=null)//need to search for possible array descriptor { var ip = metadata.StringValue.IndexOf('|');//array descriptor start if (ip>0) { var tname = metadata.StringValue.Substring(0, ip); if (TypeRegistry.IsNullHandle(tname)) return null; type = treg[ tname ]; } else { if (TypeRegistry.IsNullHandle(metadata)) return null; type = treg[ metadata ]; } } else { if (TypeRegistry.IsNullHandle(metadata)) return null; type = treg[ metadata ]; } object instance = null; if (type.IsArray) //DKh 20130712 Removed repetitive code that was refactored into Arrays class instance = Arrays.DescriptorToArray(metadata.StringValue, type); else //20130715 DKh instance = SerializationUtils.MakeNewObjectInstance(type); m_List.Add(instance); return instance; }
/// <summary> /// Returns object reference for supplied metahandle /// </summary> public object HandleToReference(MetaHandle handle, TypeRegistry treg, SlimFormat format, SlimReader reader) { if (handle.IsInlinedString) return handle.Metadata; if (handle.IsInlinedTypeValue) { var tref = treg.GetByHandle(handle.Metadata);//adding this type to registry if it is not there yet return tref; } if (handle.IsInlinedRefType) { var tref = treg.GetByHandle(handle.Metadata);//adding this type to registry if it is not there yet var ra = format.GetReadActionForRefType(tref); if (ra!=null) { var inst = ra(reader); m_List.Add(inst); m_Dict.Add(inst, m_List.Count - 1); return inst; } else throw new SlimDeserializationException("Internal error HandleToReference: no read action for ref type, but ref mhandle is inlined"); } int idx = (int)handle.Handle; if (idx<m_List.Count) return m_List[idx]; if (string.IsNullOrEmpty(handle.Metadata)) throw new SlimDeserializationException(StringConsts.SLIM_HNDLTOREF_MISSING_TYPE_NAME_ERROR + handle.ToString()); var metadata = handle.Metadata; var ip = metadata.IndexOf('|'); //var segments = metadata.Split('|'); var th = ip>0 ? metadata.Substring(0, ip) : metadata; //20140701 DKh var type = treg[th];//segments[0]]; object instance = null; if (type.IsArray) //DKh 20130712 Removed repetitive code that was refactored into Arrays class instance = Arrays.DescriptorToArray(metadata, treg, type); else //20130715 DKh instance = SerializationUtils.MakeNewObjectInstance(type); m_List.Add(instance); m_Dict.Add(instance, m_List.Count - 1); return instance; }