mybatis报错:getString/getxxx not implemented for class oracle.jdbc.driver.T4CBlobAccessor

报错如下:导致原因----->当时我写了一个只有部分属性的构造函数

一.首先,你得排除你的xml文件里面的字段类型与实体与数据库里面是一致的,如果检查了没问题但是还是报错,那就继续往下看👇👇👇👇👇👇

二.走到了这里,那就得往mybatis底层里面走了:

1.通过打断点得方式可以发现,mybatis在执行查询sql后会调用实体得构造函数进行字段得映射:

大家都知道实体里默认是会有一个无参构造函数,但是当你自己写了一个显性得构造函数时,就不会自动创建无参构造函数了(除非你再写一个显性得无参构造函数);

2.然后写了一个查询部分属性的sql,比如select  update_time,name from user_info where xxxx;

但是构造函数为VO(int  value1,string value2),此时mybatis查询成功后调用构造函数进行映射,会尝试将data类型的update_time映射为int类型,如此便报错了;

3.那么造成这样的原因是什么呢,下面两张图就可以看懂了:

构造函数获取顺序为,先看无参构造函数是否存在,若不存在,则取显性构造函数,至于用哪个,则取决于你查询sql返回的字段个数与哪个构造函数个数相等,如果相等,就开始映射:

4.源码逻辑如下:

5.那如果既没有无参构造函数,有参构造函数的个数跟查询字段个数匹配不上会出现什么情况呢?

那就是如下报错:无法转换为内部表示

6.解决方法:添加一个显性无参构造方法即可!

解析如下代码,怎么实例化DicomAttributeCollection并添加元素 public class DicomAttributeCollection : System.Collections.Generic.IEnumerable<DicomAttribute>, System.Collections.IEnumerable, System.IDisposable { private SortedDictionary<uint, DicomAttribute> _attributeList = new SortedDictionary<uint, DicomAttribute>(); private long _bytesRead; private long _bytesRemain; private bool _disposed; private byte[] bPixelData; private byte[] bPixelDataType; public DicomAttribute this[uint tag] { get { return this._attributeList[tag]; } } public DicomAttribute this[Tag tag] { get { return this._attributeList[(uint)tag]; } } public int Count { get { return this._attributeList.Count; } } internal long ReadStream(System.IO.Stream s, TransferSyntax tsn, long streamLength) { if (streamLength >= DicomAttribute.UndefinedLength) { throw new DicomException("Tag value exceed the maximum length of the tag"); } System.IO.BinaryReader binaryReader = EndianBinaryReader.CreateBinaryReader(s, tsn.Endian); this._bytesRemain = streamLength; while (this._bytesRemain >= 4L) { ushort group = binaryReader.ReadUInt16(); ushort element = binaryReader.ReadUInt16(); this.RecordBytesRead(4L); DicomTag tag = new DicomTag(group, element); DicomAttribute dicomAttribute; if (tsn.IsExplicitVR) { string vr = new string(binaryReader.ReadChars(2)); this.RecordBytesRead(2L); VR vR = DicomVR.GetVR(vr); dicomAttribute = DicomAttribute.CreateAttribute(tag, vR); } else { dicomAttribute = DicomAttribute.CreateAttribute(tag); } ulong read = dicomAttribute.ReadStream(s, tsn); this.RecordBytesRead((long)read); this.AddDicomAttribute(dicomAttribute); } return this._bytesRead; } internal long ReadStream(System.IO.Stream s, TransferSyntax tsn, DicomTag stopTag) { long result; try { if (stopTag == null) { result = 0L; } else { System.IO.BinaryReader binaryReader = EndianBinaryReader.CreateBinaryReader(s, tsn.Endian); ushort group = binaryReader.ReadUInt16(); ushort element = binaryReader.ReadUInt16(); this.RecordBytesRead(4L); DicomTag dicomTag = new DicomTag(group, element); while (dicomTag <= stopTag && s.Position < s.Length - 1L) { DicomAttribute dicomAttribute; if (tsn.IsExplicitVR && dicomTag.TagVR.VR != VR.ITEM) { string vr = new string(binaryReader.ReadChars(2)); this.RecordBytesRead(2L); VR vR = DicomVR.GetVR(vr); dicomAttribute = DicomAttribute.CreateAttribute(dicomTag, vR); } else { dicomAttribute = DicomAttribute.CreateAttribute(dicomTag); } ulong read = dicomAttribute.ReadStream(s, tsn); this.RecordBytesRead((long)read); this.AddDicomAttribute(dicomAttribute); if (s.Position + 4L >= s.Length) { break; } group = binaryReader.ReadUInt16(); element = binaryReader.ReadUInt16(); dicomTag = new DicomTag(group, element); this.RecordBytesRead(4L); } s.Position -= 4L; this.RecordBytesRead(-4L); result = this._bytesRead; } } catch (DicomException ex) { ex.Source = this.ToString(); throw ex; } catch (System.Exception ex2) { throw ex2; } return result; } public void AddDicomAttribute(DicomAttribute attribute) { try { if (attribute != null && !this._attributeList.ContainsKey(attribute.Tag.Value)) { this._attributeList.Add(attribute.Tag.Value, attribute); } } catch (System.Exception ex) { DataHeaderLog.PLOG_ERROR(string.Concat(new object[] { "Add attribute element to Collection failed", ex.ToString(), "Attribute's Tag is:", attribute.Tag.Value })); } } public void RemoveDicomAttribute(DicomAttribute attribute) { this.RemoveDicomAttribute(attribute.Tag.Value); } public void RemoveDicomAttribute(Tag tag) { this.RemoveDicomAttribute((uint)tag); } public void RemoveDicomAttribute(uint tag) { try { if (!this._attributeList.ContainsKey(tag)) { return; } } catch (System.Exception ex) { DataHeaderLog.PLOG_ERROR(string.Concat(new object[] { "Remove attribute element from collection failed", ex.ToString(), "Tag is:", tag })); return; } this._attributeList.Remove(tag); } public bool Contains(Tag tag) { return this._attributeList.ContainsKey((uint)tag); } public bool Contains(uint tag) { return this._attributeList.ContainsKey(tag); } public bool Contains(DicomTag tag) { return this._attributeList.ContainsKey(tag.Value); } internal uint CalculateValueLength(TransferSyntax tsn) { if (this._attributeList == null || this._attributeList.Count == 0) { return 0u; } uint num = 0u; foreach (DicomAttribute current in this._attributeList.Values) { num += current.CalculateValueLength(tsn); } return num; } internal ulong WriteStream(System.IO.Stream s, TransferSyntax tsn) { ulong num = 0uL; foreach (DicomAttribute current in this._attributeList.Values) { num += current.WriteStream(s, tsn); } return num; } public bool SerializeToByteStream(DataHeaderWriteStream builder) { bool result = true; if (builder == null) { return false; } foreach (DicomAttribute current in this._attributeList.Values) { ByteStreamArchive.EnumArchiveType archiveElementType = current.GetArchiveElementType(); if (archiveElementType != ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_ITEM_LIST) { result = current.SerializeToByteStream(builder); } else { DicomAttributeSQ dicomAttributeSQ = current as DicomAttributeSQ; if (dicomAttributeSQ != null) { result = dicomAttributeSQ.SerializeToByteStream(builder); } } } return result; } private bool LongToByteArray(long lValue, out byte[] ret) { bool result; try { ret = null; string text = lValue.ToString(); if (9 > text.Length) { text = new string('0', 9 - text.Length) + text; } char[] array = text.ToCharArray(); ret = new byte[9]; for (int i = 0; i < 9; i++) { ret[i] = System.Convert.ToByte(array[i]); } result = true; } catch (System.Exception ex) { DataHeaderLog.PLOG_ERROR("from long to byte array failed" + ex.Message); ret = null; result = false; } return result; } private static bool ByteArrayToLong(byte[] bValue, out long ret) { bool result; try { char[] array = new char[9]; for (int i = 0; i < bValue.Length; i++) { array[i] = System.Convert.ToChar(bValue[i]); } string value = new string(array); ret = System.Convert.ToInt64(value); result = true; } catch (System.Exception ex) { DataHeaderLog.PLOG_ERROR("From byte array to long failed" + ex.Message); ret = 0L; result = false; } return result; } public bool SerializeToProtoElement(ProtoDataHeader pdh, uint depth, uint sequenceNo) { if (pdh == null) { return false; } foreach (DicomAttribute current in this._attributeList.Values) { ByteStreamArchive.EnumArchiveType archiveElementType = current.GetArchiveElementType(); if (archiveElementType != ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_ITEM_LIST) { ProtoElement protoElement = current.SerializeToProtoElement(depth, sequenceNo); if (protoElement != null) { pdh.ElementValueList.Add(protoElement); DataHeaderLog.PLOG_TRAC_INFO(string.Concat(new object[] { "Tag value is :", protoElement.Tag, "element's type is ", protoElement.Type.ToString() })); } } else { DicomAttributeSQ dicomAttributeSQ = current as DicomAttributeSQ; if (dicomAttributeSQ != null) { dicomAttributeSQ.SerializeToProtoElement(pdh, depth, sequenceNo); } } } return true; } public bool Serialize(out byte[] output) { output = null; StreamWriterFactory streamWriterFactory = new StreamWriterFactory(); DataHeaderWriteStream dataHeaderWriteStream = null; streamWriterFactory.Creator(ref dataHeaderWriteStream); if (streamWriterFactory.bProtoBufFlag) { ProtoDataHeader protoDataHeader = new ProtoDataHeader(); if (this.SerializeToProtoElement(protoDataHeader, 0u, 0u)) { output = protoDataHeader.ToByteArray(); return true; } } else { if (this.SerializeToByteStream(dataHeaderWriteStream)) { dataHeaderWriteStream.WriteTotalSize(); output = dataHeaderWriteStream.ToArray(); return true; } } return false; } public static DicomAttributeCollection Deserialize(byte[] input) { DicomAttributeCollection dicomAttributeCollection = new DicomAttributeCollection(); StreamReaderFactory streamReaderFactory = new StreamReaderFactory(); DataHeaderReadStream dataHeaderReadStream = null; if (!streamReaderFactory.Creator(ref input, ref dataHeaderReadStream)) { return null; } if (!dataHeaderReadStream.Deserialize(dicomAttributeCollection)) { return null; } return dicomAttributeCollection; } private void RecordBytesRead(long read) { this._bytesRead += read; this._bytesRemain -= read; } public System.Collections.Generic.IEnumerator<DicomAttribute> GetEnumerator() { return this._attributeList.Values.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return this.GetEnumerator(); } public void Dispose() { if (!this._disposed) { foreach (DicomAttribute current in this._attributeList.Values) { current.Dispose(); } if (this.bPixelData != null) { this.bPixelData = null; } if (this.bPixelDataType != null) { this.bPixelDataType = null; } this._attributeList.Clear(); this._attributeList = null; this._disposed = true; } System.GC.SuppressFinalize(this); } } public abstract class DicomAttribute : System.IDisposable { protected const uint _undefinedLength = 4294967295u; private DicomTag _tag; private string _sVR; protected System.IO.BinaryReader _streamReader; protected ulong _bytesRead; protected System.IO.BinaryWriter _streamWriter; protected ulong _bytesWrite; protected bool _disposed; protected bool _needPadding; private static string[] _arrayVR = new string[] { "AE", "AS", "AT", "CS", "DA", "DS", "DT", "FD", "FL", "IS", "LO", "LT", "OB", "OD", "OF", "OV", "OW", "PN", "SH", "SL", "SQ", "SS", "ST", "SV", "TM", "UC", "UI", "UL", "UN", "UR", "US", "UT", "UV", "lt", "na", "ox", "xs" }; public DicomTag Tag { get { return this._tag; } } public ulong BytesRead { get { return this._bytesRead; } } public ulong BytesWrite { get { return this._bytesWrite; } } public static long UndefinedLength { get { return (long)((ulong)-1); } } public abstract int ValueCount { get; } public DicomTag GetDicomTag() { return this._tag; } protected DicomAttribute(DicomTag tag) { this._tag = tag; } public virtual ByteStreamArchive.EnumArchiveType GetArchiveElementType() { return ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_UNKNOWN; } public virtual bool SetString(int index, string value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetInt16(int index, short value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetInt32(int index, int value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetInt64(int index, long value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetUInt16(int index, ushort value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetUInt32(int index, uint value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetUInt32S(int index, uint[] value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetUInt64(int index, ulong value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetUInt64S(int index, ulong[] value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetFloat32(int index, float value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetFloat32S(int index, float[] value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetFloat64(int index, double value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetFloat64S(int index, double[] value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetDateTime(int index, System.DateTime value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetAttributeCollection(int index, DicomAttributeCollection item) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool PushBackAttributeCollection(DicomAttributeCollection item) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetBytes(int index, byte[] value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual bool SetOffSetTable(int[] value) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return false; } public virtual void SetVR(string sVR) { if (string.IsNullOrEmpty(sVR)) { return; } this._sVR = (DicomAttribute.isValidVR(ref sVR) ? sVR : "UN"); } public virtual bool GetString(int index, out string ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = ""; return false; } public virtual bool GetInt16(int index, out short ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0; return false; } public virtual bool GetInt32(int index, out int ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0; return false; } public virtual bool GetInt64(int index, out long ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0L; return false; } public virtual bool GetUInt16(int index, out ushort ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0; return false; } public virtual bool GetUInt32(int index, out uint ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0u; return false; } public virtual bool GetUInt32S(int index, out uint[] ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = null; return false; } public virtual bool GetUInt64(int index, out ulong ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0uL; return false; } public virtual bool GetUInt64S(int index, out ulong[] ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = null; return false; } public virtual bool GetFloat32(int index, out float ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0f; return false; } public virtual bool GetFloat32S(int index, out float[] ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = null; return false; } public virtual bool GetFloat64(int index, out double ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0.0; return false; } public virtual bool GetFloat64S(int index, out double[] ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = null; return false; } public virtual bool GetDateTime(int index, out System.DateTime ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = System.DateTime.MinValue; return false; } public virtual bool GetBytes(int index, out byte[] ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = null; return false; } public virtual bool GetOffSetTable(out int[] ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = null; return false; } public virtual bool GetObject(int index, out object ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0; return false; } public virtual bool GetAttributeCollection(int index, out DicomAttributeCollection ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = null; return false; } public virtual bool GetValueToString(int index, out string ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = ""; return false; } public virtual bool GetValueToInt64(int index, out long ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0L; return false; } public virtual bool GetValueToDouble(int index, out double ret) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); ret = 0.0; return false; } public virtual string GetVR() { return this._sVR; } public static bool isValidVR(ref string sVR) { return System.Array.BinarySearch<string>(DicomAttribute._arrayVR, sVR) >= 0; } internal virtual string Dump() { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return null; } internal virtual ulong ReadStream(System.IO.Stream s, TransferSyntax tsn) { return this.ReadStream(s, tsn, s.Position); } internal virtual ulong ReadStream(System.IO.Stream s, TransferSyntax tsn, long startPosition) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return 0uL; } internal virtual ulong WriteStream(System.IO.Stream s, TransferSyntax tsn) { this.WriteStream(s, tsn, s.Position); return this._bytesWrite; } internal virtual void WriteStream(System.IO.Stream s, TransferSyntax tsn, long startPosition) { s.Position = startPosition; this._streamWriter = EndianBinaryWriter.CreateBinaryWriter(s, tsn.Endian); this._streamWriter.Write(this.Tag.GroupNumber); this._streamWriter.Write(this.Tag.ElementNumber); this._bytesWrite += 4uL; int num = (int)this.CalculateValueLength(tsn); if (tsn.IsExplicitVR) { byte[] array = CharacterProcessor.Encode(this.Tag.TagVR.VR.ToString()); this._streamWriter.Write(array); this._bytesWrite += (ulong)((long)array.Length); if (this.Tag.Is16BitLengthField) { this._streamWriter.Write((short)num); this._bytesWrite += 2uL; } else { this._streamWriter.Write(new byte[2]); this._streamWriter.Write(num); this._bytesWrite += 6uL; } } else { this._streamWriter.Write(num); this._bytesWrite += 4uL; } this.WriteAttributeValue(tsn); } public virtual ProtoElement SerializeToProtoElement(uint depth, uint iSequenceNo) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return null; } public virtual bool SerializeToByteStream(DataHeaderWriteStream archive) { DataHeaderLog.PLOG_TRAC_ERROR("NOT IMPLEMENTED!"); return true; } public static DicomAttribute CreateAttribute(uint tag) { return DicomAttribute.CreateAttribute(new DicomTag(tag)); } public static DicomAttribute CreateAttribute(uint tag, string sVR) { return DicomAttribute.CreateAttribute(new DicomTag(tag), sVR); } public static DicomAttribute CreateAttribute(Tag tag) { return DicomAttribute.CreateAttribute(new DicomTag(tag)); } public static DicomAttribute CreateAttribute(Tag tag, string sVR) { return DicomAttribute.CreateAttribute(new DicomTag(tag), sVR); } public static DicomAttribute CreateAttribute(Tag tag, VR vr) { DicomTag dicomTag = DicomDictionary.GetDicomTag((uint)tag, vr); if (dicomTag == null) { return null; } return DicomAttribute.CreateAttribute(dicomTag, vr); } public static DicomAttribute CreateAttribute(ushort group, ushort element) { return DicomAttribute.CreateAttribute(new DicomTag(group, element)); } public static DicomAttribute CreateAttribute(DicomTag tag) { DicomAttribute dicomAttribute; switch (tag.TagVR.VR) { case VR.AE: dicomAttribute = new DicomAttributeAE(tag); dicomAttribute.SetVR("AE"); return dicomAttribute; case VR.AS: dicomAttribute = new DicomAttributeAS(tag); dicomAttribute.SetVR("AS"); return dicomAttribute; case VR.AT: dicomAttribute = new DicomAttributeAT(tag); dicomAttribute.SetVR("AT"); return dicomAttribute; case VR.CS: dicomAttribute = new DicomAttributeCS(tag); dicomAttribute.SetVR("CS"); return dicomAttribute; case VR.DA: dicomAttribute = new DicomAttributeDA(tag); dicomAttribute.SetVR("DA"); return dicomAttribute; case VR.DS: dicomAttribute = new DicomAttributeDS(tag); dicomAttribute.SetVR("DS"); return dicomAttribute; case VR.DT: dicomAttribute = new DicomAttributeDT(tag); dicomAttribute.SetVR("DT"); return dicomAttribute; case VR.FD: dicomAttribute = new DicomAttributeFD(tag); dicomAttribute.SetVR("FD"); return dicomAttribute; case VR.FL: dicomAttribute = new DicomAttributeFL(tag); dicomAttribute.SetVR("FL"); return dicomAttribute; case VR.IS: dicomAttribute = new DicomAttributeIS(tag); dicomAttribute.SetVR("IS"); return dicomAttribute; case VR.LO: dicomAttribute = new DicomAttributeLO(tag); dicomAttribute.SetVR("LO"); return dicomAttribute; case VR.LT: dicomAttribute = new DicomAttributeLT(tag); dicomAttribute.SetVR("LT"); return dicomAttribute; case VR.OB: dicomAttribute = new DicomAttributeOB(tag); dicomAttribute.SetVR("OB"); return dicomAttribute; case VR.OF: dicomAttribute = new DicomAttributeOF(tag); dicomAttribute.SetVR("OF"); return dicomAttribute; case VR.OW: dicomAttribute = new DicomAttributeOW(tag); dicomAttribute.SetVR("OW"); return dicomAttribute; case VR.PN: dicomAttribute = new DicomAttributePN(tag); dicomAttribute.SetVR("PN"); return dicomAttribute; case VR.SH: dicomAttribute = new DicomAttributeSH(tag); dicomAttribute.SetVR("SH"); return dicomAttribute; case VR.SL: dicomAttribute = new DicomAttributeSL(tag); dicomAttribute.SetVR("SL"); return dicomAttribute; case VR.SQ: dicomAttribute = new DicomAttributeSQ(tag); dicomAttribute.SetVR("SQ"); return dicomAttribute; case VR.SS: dicomAttribute = new DicomAttributeSS(tag); dicomAttribute.SetVR("SS"); return dicomAttribute; case VR.ST: dicomAttribute = new DicomAttributeST(tag); dicomAttribute.SetVR("ST"); return dicomAttribute; case VR.TM: dicomAttribute = new DicomAttributeTM(tag); dicomAttribute.SetVR("TM"); return dicomAttribute; case VR.UI: dicomAttribute = new DicomAttributeUI(tag); dicomAttribute.SetVR("UI"); return dicomAttribute; case VR.UL: dicomAttribute = new DicomAttributeUL(tag); dicomAttribute.SetVR("UL"); return dicomAttribute; case VR.US: dicomAttribute = new DicomAttributeUS(tag); dicomAttribute.SetVR("US"); return dicomAttribute; case VR.UT: dicomAttribute = new DicomAttributeUT(tag); dicomAttribute.SetVR("UT"); return dicomAttribute; case VR.OV: dicomAttribute = new DicomAttributeOV(tag); dicomAttribute.SetVR("OV"); return dicomAttribute; case VR.SV: dicomAttribute = new DicomAttributeSV(tag); dicomAttribute.SetVR("SV"); return dicomAttribute; case VR.UV: dicomAttribute = new DicomAttributeUV(tag); dicomAttribute.SetVR("UV"); return dicomAttribute; case VR.ITEM: return new DicomAttributeItemDelimitor(tag); case VR.OD: dicomAttribute = new DicomAttributeOD(tag); dicomAttribute.SetVR("OD"); return dicomAttribute; case VR.OL: dicomAttribute = new DicomAttributeOL(tag); dicomAttribute.SetVR("OL"); return dicomAttribute; case VR.UC: dicomAttribute = new DicomAttributeUC(tag); dicomAttribute.SetVR("UC"); return dicomAttribute; case VR.UR: dicomAttribute = new DicomAttributeUR(tag); dicomAttribute.SetVR("UR"); return dicomAttribute; } dicomAttribute = new DicomAttributeUN(tag); dicomAttribute.SetVR("UN"); return dicomAttribute; } public static DicomAttribute CreateAttribute(DicomTag tag, string sVR) { DicomAttribute dicomAttribute; switch (tag.TagVR.VR) { case VR.AE: dicomAttribute = new DicomAttributeAE(tag); goto IL_216; case VR.AS: dicomAttribute = new DicomAttributeAS(tag); goto IL_216; case VR.AT: dicomAttribute = new DicomAttributeAT(tag); goto IL_216; case VR.CS: dicomAttribute = new DicomAttributeCS(tag); goto IL_216; case VR.DA: dicomAttribute = new DicomAttributeDA(tag); goto IL_216; case VR.DS: dicomAttribute = new DicomAttributeDS(tag); goto IL_216; case VR.DT: dicomAttribute = new DicomAttributeDT(tag); goto IL_216; case VR.FD: dicomAttribute = new DicomAttributeFD(tag); goto IL_216; case VR.FL: dicomAttribute = new DicomAttributeFL(tag); goto IL_216; case VR.IS: dicomAttribute = new DicomAttributeIS(tag); goto IL_216; case VR.LO: dicomAttribute = new DicomAttributeLO(tag); goto IL_216; case VR.LT: dicomAttribute = new DicomAttributeLT(tag); goto IL_216; case VR.OB: dicomAttribute = new DicomAttributeOB(tag); goto IL_216; case VR.OF: dicomAttribute = new DicomAttributeOF(tag); goto IL_216; case VR.OW: dicomAttribute = new DicomAttributeOW(tag); goto IL_216; case VR.PN: dicomAttribute = new DicomAttributePN(tag); goto IL_216; case VR.SH: dicomAttribute = new DicomAttributeSH(tag); goto IL_216; case VR.SL: dicomAttribute = new DicomAttributeSL(tag); goto IL_216; case VR.SQ: dicomAttribute = new DicomAttributeSQ(tag); goto IL_216; case VR.SS: dicomAttribute = new DicomAttributeSS(tag); goto IL_216; case VR.ST: dicomAttribute = new DicomAttributeST(tag); goto IL_216; case VR.TM: dicomAttribute = new DicomAttributeTM(tag); goto IL_216; case VR.UI: dicomAttribute = new DicomAttributeUI(tag); goto IL_216; case VR.UL: dicomAttribute = new DicomAttributeUL(tag); goto IL_216; case VR.US: dicomAttribute = new DicomAttributeUS(tag); goto IL_216; case VR.UT: dicomAttribute = new DicomAttributeUT(tag); goto IL_216; case VR.OV: dicomAttribute = new DicomAttributeOV(tag); goto IL_216; case VR.SV: dicomAttribute = new DicomAttributeSV(tag); goto IL_216; case VR.UV: dicomAttribute = new DicomAttributeUV(tag); goto IL_216; case VR.ITEM: return new DicomAttributeItemDelimitor(tag); case VR.OD: dicomAttribute = new DicomAttributeOD(tag); goto IL_216; case VR.OL: dicomAttribute = new DicomAttributeOL(tag); goto IL_216; case VR.UC: dicomAttribute = new DicomAttributeUC(tag); goto IL_216; case VR.UR: dicomAttribute = new DicomAttributeUR(tag); goto IL_216; } dicomAttribute = new DicomAttributeUN(tag); IL_216: dicomAttribute.SetVR(sVR); return dicomAttribute; } public static DicomAttribute CreateAttribute(DicomTag tag, VR vr) { if (vr != VR.UN && tag.TagVR.VR != VR.UN) { VR arg_21_0 = tag.TagVR.VR; } DicomTag dicomTag = DicomDictionary.GetDicomTag(tag.Value, vr); if (dicomTag == null) { return null; } tag.TagVR = new DicomVR(vr); return DicomAttribute.CreateAttribute(tag); } protected uint GetAttributeValueLength(System.IO.Stream s, TransferSyntax tsn, long startPosition) { if (s == null) { return 0u; } if (tsn == null) { return 0u; } s.Seek(startPosition, System.IO.SeekOrigin.Begin); this._streamReader = EndianBinaryReader.CreateBinaryReader(s, tsn.Endian); uint result; if (tsn.IsExplicitVR) { if (this.Tag.Is16BitLengthField) { result = (uint)this._streamReader.ReadUInt16(); this._bytesRead += 2uL; } else { this._streamReader.ReadBytes(2); result = this._streamReader.ReadUInt32(); this._bytesRead += 6uL; } } else { result = this._streamReader.ReadUInt32(); this._bytesRead += 4uL; } return result; } protected static ProtoElement.Types.ElementType MapArchiveTypeToProtoType(ByteStreamArchive.EnumArchiveType eType) { if (eType <= ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_DATA_HEADER) { if (eType == ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_ITEM) { return ProtoElement.Types.ElementType.TYPE_ITEM; } if (eType == ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_DATA_HEADER) { return ProtoElement.Types.ElementType.TYPE_DATA_HEADER; } } else { switch (eType) { case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_UINT8: return ProtoElement.Types.ElementType.TYPE_UINT8; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_INT16: return ProtoElement.Types.ElementType.TYPE_INT16; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_UINT16: return ProtoElement.Types.ElementType.TYPE_UINT16; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_INT32: return ProtoElement.Types.ElementType.TYPE_INT32; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_UINT32: return ProtoElement.Types.ElementType.TYPE_UINT32; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_SINGLE_FLOAT: return ProtoElement.Types.ElementType.TYPE_SINGLE_FLOAT; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_DOUBLE_FLOAT: return ProtoElement.Types.ElementType.TYPE_DOUBLE_FLOAT; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_TIME: return ProtoElement.Types.ElementType.TYPE_TIME; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_VOIDPOINTER: return ProtoElement.Types.ElementType.TYPE_VOIDPOINTER; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_STRING: return ProtoElement.Types.ElementType.TYPE_STRING; default: switch (eType) { case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_UINT8_ARRAY: return ProtoElement.Types.ElementType.TYPE_UINT8_ARRAY; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_INT16_ARRAY: return ProtoElement.Types.ElementType.TYPE_INT16_ARRAY; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_UINT16_ARRAY: return ProtoElement.Types.ElementType.TYPE_UINT16_ARRAY; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_INT32_ARRAY: return ProtoElement.Types.ElementType.TYPE_INT32_ARRAY; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_UINT32_ARRAY: return ProtoElement.Types.ElementType.TYPE_UINT32_ARRAY; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_SINGLE_FLOAT_ARRAY: return ProtoElement.Types.ElementType.TYPE_SINGLE_FLOAT_ARRAY; case ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_DOUBLE_FLOAT_ARRAY: return ProtoElement.Types.ElementType.TYPE_DOUBLE_FLOAT_ARRAY; default: if (eType == ByteStreamArchive.EnumArchiveType.ARCHIVE_TYPE_ITEM_LIST) { return ProtoElement.Types.ElementType.TYPE_ITEM_LIST; } break; } break; } } return ProtoElement.Types.ElementType.TYPE_UNKNOWN; } internal abstract uint CalculateValueLength(TransferSyntax tsn); protected abstract void WriteAttributeValue(TransferSyntax tsn); public void Dispose() { this.Dispose(true); System.GC.SuppressFinalize(this); } protected abstract void Dispose(bool disposing); }
07-12
### 创建 DicomAttributeCollection 实例 在 C# 中,`DicomAttributeCollection` 是一个用于存储 DICOM 属性的集合类。要创建其实例,只需使用 `new` 关键字调用默认构造函数[^4]。 ```csharp DicomAttributeCollection attributes = new DicomAttributeCollection(); ``` 该语句创建了一个新的 `DicomAttributeCollection` 对象,用于后续添加 DICOM 数据元素。 ### 向 DicomAttributeCollection 添加元素 在创建了 `DicomAttributeCollection` 实例后,可以使用 `AddDicomAttribute` 方法将 `DicomAttribute` 子类的实例添加到集合中[^4]。 例如,添加一个 `DicomLongString` 类型的属性(代表 VR 为 LO 的 DICOM 元素): ```csharp DicomAttribute attribute = new DicomLongString(DicomTag.PatientName); attribute.String = "John Doe"; attributes.AddDicomAttribute(attribute); ``` 上述代码首先创建了一个 `DicomLongString` 实例,并设置其值,然后将其添加到 `DicomAttributeCollection` 实例中。 ### 检索 DicomAttributeCollection 中的特定属性 通过索引器访问方式,可以检索特定标签的数据元素: ```csharp DicomAttribute patientNameAttribute = attributes[DicomTag.PatientName]; if (patientNameAttribute != null) { string patientName = ((DicomLongString)patientNameAttribute).String; } ``` 此段代码演示了如何通过索引器访问 `DicomAttributeCollection` 中的特定 DICOM 属性,并获取其字符串值。 ### 示例:完整创建与操作流程 以下是一个完整的示例,展示如何创建、填充并访问 `DicomAttributeCollection`: ```csharp // 创建 DicomAttributeCollection 实例 DicomAttributeCollection dataset = new DicomAttributeCollection(); // 添加 PatientName 属性 DicomAttribute patientName = new DicomLongString(DicomTag.PatientName); patientName.String = "Doe^John"; dataset.AddDicomAttribute(patientName); // 添加 StudyDate 属性 DicomAttribute studyDate = new DicomDate(DicomTag.StudyDate); studyDate.DateTime = new DateTime(2023, 10, 15); dataset.AddDicomAttribute(studyDate); // 检索 StudyDate 并输出 DicomAttribute retrievedStudyDate = dataset[DicomTag.StudyDate]; if (retrievedStudyDate != null) { Console.WriteLine("Study Date: " + ((DicomDate)retrievedStudyDate).DateTime.ToString("yyyyMMdd")); } ``` 该示例展示了从实例化集合、添加元素到检索值的全过程。 --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值