解析如下代码,怎么实例化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);
}