A delegate used with some overloads of GetValue<T> to get a value of an element
public delegate object GetValueDelegate(string value)
Public Delegate Function GetValueDelegate( _ByVal value As String _) As Object
public delegate Object^ GetValueDelegate(String^ value)
value
a string representation of the DICOM element value that is to be converted
An Object of the desired type.
This delegate is used with certain overloads of GetValue<T>.
The delegate takes a string as input, and converts it into any desired class type. It is used with the GetValue<T> that take GetValueDelegate parameter.
This example will retrieve a value from a data set as a PersonName type using a delegate
using Leadtools;using Leadtools.Dicom;///public class PersonName{private string[] _innerArray = new string[5] {string.Empty, string.Empty, string.Empty, string.Empty,string.Empty };/// Access this person name instance as array. Index range is/// bounded between 0 (family name) and 4 (name suffix).public string this[int index]{set{if (value == null || value.Length < 64)_innerArray[index] = value;elsethrow new DicomException("Length of new entry exceeds 64 characters.");}get { return _innerArray[index]; }}private const int _familyNameIndex = 0;private const int _givenNameIndex = 1;private const int _middleNameIndex = 2;private const int _namePrefixIndex = 3;private const int _nameSuffixIndex = 4;/// Access person name part family name.public string FamilyName{set{if (value == null || value.Length < 64){_fullName = null;_innerArray[_familyNameIndex] = value;}elsethrow new DicomException("Length of family name exceeds 64 characters.");}get { return _innerArray[_familyNameIndex]; }}/// Access person name part given name.public string GivenName{set{if (value == null || value.Length < 64){_fullName = string.Empty;_innerArray[_givenNameIndex] = value;}elsethrow new DicomException("Length of family name exceeds 64 characters.");}get { return _innerArray[_givenNameIndex]; }}/// Access person name part middle name.public string MiddleName{set{if (value == null || value.Length < 64){_fullName = string.Empty;_innerArray[_middleNameIndex] = value;}elsethrow new DicomException("Length of family name exceeds 64 characters.");}get { return _innerArray[_middleNameIndex]; }}/// Access person name part name prefix.public string NamePrefix{set{if (value == null || value.Length < 64){_fullName = string.Empty;_innerArray[_namePrefixIndex] = value;}elsethrow new DicomException("Length of family name exceeds 64 characters.");}get { return _innerArray[_namePrefixIndex]; }}/// Access person name part name suffix.public string NameSuffix{set{if (value == null || value.Length < 64){_fullName = string.Empty;_innerArray[_nameSuffixIndex] = value;}elsethrow new DicomException("Length of family name exceeds 64 characters.");}get { return _innerArray[_nameSuffixIndex]; }}private string _fullName = string.Empty;/// Access full person name string representation. According/// to the DICOM standard "^" is used as separator of different/// person name parts.public string FullName{set{_fullName = value;if (_fullName != null){string[] s;int i;if (_fullName.Contains("^"))s = _fullName.Split('^');elses = _fullName.Split(' ');for (i = 0; i < s.Length; i++){if (s[i].Length < 64){if (i < _innerArray.Length)_innerArray[i] = s[i];}elsethrow new DicomException("Length of family name exceeds 64 characters.");}for (int k = i; k < _innerArray.Length; k++)_innerArray[k] = string.Empty;}}get{if (_fullName == string.Empty){_fullName = _innerArray[0];bool isNotNull = _fullName != string.Empty;int i = 1;while (isNotNull && i < _innerArray.Length){isNotNull = _innerArray[i] != string.Empty;if (isNotNull)_fullName += "^" + _innerArray[i];i++;}}return _fullName;}}/// Creates a new empty person name instance.public PersonName() { }/// Creates a new person name instance from specified full name./// All person name parts have to be separated by "^" according to/// the DICOM standard.public PersonName(string fullName){FullName = fullName;}/// Creates a new person name instance from the different person name parts.public PersonName(string familyName, string givenName,string middleName, string namePrefix, string nameSuffix){FamilyName = familyName;GivenName = givenName;MiddleName = middleName;NamePrefix = namePrefix;NameSuffix = nameSuffix;}/// Return this person name instance's.public override string ToString(){return FullName;}}void DumpPersonName(PersonName pn){String sMsg =string.Format("Family Name: {0}\nGiven Name: {1}\nMiddle Name: {2}\nName Prefix: {3}\nName Suffix: {4}",pn.FamilyName,pn.GivenName,pn.MiddleName,pn.NamePrefix,pn.NameSuffix);MessageBox.Show(sMsg);}private void DicomDataSet_GetValueWithDelegateExample(){// Create a DicomDataSet and add a PatientName// Dicom Spec for Value Representation PN (Person Name)// Elements are in this order:// * family name complex// * given name complex// * middle name// * name prefix// * name suffix.DicomDataSet ds = new DicomDataSet();ds.InsertElementAndSetValue(DicomTag.PatientName, "Smith^John^MiddleName^Mr.^III");// Get a PersonName value of an element by specifying a tag, and using a delegate// Use this form when the type is not native to the dataset// The data is extracted from the field as a string and passed to the provided method.PersonName pn = null;pn = ds.GetValue<PersonName>(DicomTag.PatientName,null,delegate (string data){PersonName t = new PersonName(data);return t;});DumpPersonName(pn);// Another overload, specifying parent elementpn = ds.GetValue<PersonName>(null,true,DicomTag.PatientName,null,delegate (string data){PersonName t = new PersonName(data);return t;});DumpPersonName(pn);// Another overload, this time passing in the DICOM element instead of a tagDicomElement element = ds.FindFirstElement(null, DicomTag.PatientName, true);pn = ds.GetValue<PersonName>(element,null,delegate (string data){PersonName t = new PersonName(data);return t;});DumpPersonName(pn);}
Imports LeadtoolsImports Leadtools.Dicom'''Public Class PersonNamePrivate _innerArray As String() = New String(4) {String.Empty, String.Empty, String.Empty, String.Empty, String.Empty}''' Access this person name instance as array. Index range is''' bounded between 0 (family name) and 4 (name suffix).Default Public Property Item(ByVal index As Integer) As StringSet(ByVal value As String)If value Is Nothing OrElse value.Length < 64 Then_innerArray(index) = valueElseThrow New DicomException("Length of new entry exceeds 64 characters.")End IfEnd SetGetReturn _innerArray(index)End GetEnd PropertyPrivate Const _familyNameIndex As Integer = 0Private Const _givenNameIndex As Integer = 1Private Const _middleNameIndex As Integer = 2Private Const _namePrefixIndex As Integer = 3Private Const _nameSuffixIndex As Integer = 4''' Access person name part family name.Public Property FamilyName() As StringSet(ByVal value As String)If value Is Nothing OrElse value.Length < 64 Then_fullName = Nothing_innerArray(_familyNameIndex) = valueElseThrow New DicomException("Length of family name exceeds 64 characters.")End IfEnd SetGetReturn _innerArray(_familyNameIndex)End GetEnd Property''' Access person name part given name.Public Property GivenName() As StringSet(ByVal value As String)If value Is Nothing OrElse value.Length < 64 Then_fullName = String.Empty_innerArray(_givenNameIndex) = valueElseThrow New DicomException("Length of family name exceeds 64 characters.")End IfEnd SetGetReturn _innerArray(_givenNameIndex)End GetEnd Property''' Access person name part middle name.Public Property MiddleName() As StringSet(ByVal value As String)If value Is Nothing OrElse value.Length < 64 Then_fullName = String.Empty_innerArray(_middleNameIndex) = valueElseThrow New DicomException("Length of family name exceeds 64 characters.")End IfEnd SetGetReturn _innerArray(_middleNameIndex)End GetEnd Property''' Access person name part name prefix.Public Property NamePrefix() As StringSet(ByVal value As String)If value Is Nothing OrElse value.Length < 64 Then_fullName = String.Empty_innerArray(_namePrefixIndex) = valueElseThrow New DicomException("Length of family name exceeds 64 characters.")End IfEnd SetGetReturn _innerArray(_namePrefixIndex)End GetEnd Property''' Access person name part name suffix.Public Property NameSuffix() As StringSet(ByVal value As String)If value Is Nothing OrElse value.Length < 64 Then_fullName = String.Empty_innerArray(_nameSuffixIndex) = valueElseThrow New DicomException("Length of family name exceeds 64 characters.")End IfEnd SetGetReturn _innerArray(_nameSuffixIndex)End GetEnd PropertyPrivate _fullName As String = String.Empty''' Access full person name string representation. According''' to the DICOM standard "^" is used as separator of different''' person name parts.Public Property FullName() As StringSet(ByVal value As String)_fullName = valueIf Not _fullName Is Nothing ThenDim s As String()Dim i As IntegerIf _fullName.Contains("^") Thens = _fullName.Split("^"c)Elses = _fullName.Split(" "c)End Ifi = 0Do While i < s.LengthIf s(i).Length < 64 ThenIf i < _innerArray.Length Then_innerArray(i) = s(i)End IfElseThrow New DicomException("Length of family name exceeds 64 characters.")End Ifi += 1LoopDim k As Integer = iDo While k < _innerArray.Length_innerArray(k) = String.Emptyk += 1LoopEnd IfEnd SetGetIf _fullName = String.Empty Then_fullName = _innerArray(0)Dim isNotNull As Boolean = _fullName <> String.EmptyDim i As Integer = 1Do While isNotNull AndAlso i < _innerArray.LengthisNotNull = _innerArray(i) <> String.EmptyIf isNotNull Then_fullName &= "^" & _innerArray(i)End Ifi += 1LoopEnd IfReturn _fullNameEnd GetEnd Property''' Creates a new empty person name instance.Public Sub New()End Sub''' Creates a new person name instance from specified full name.''' All person name parts have to be separated by "^" according to''' the DICOM standard.Public Sub New(ByVal fullNameIn As String)FullName = fullNameInEnd Sub''' Creates a new person name instance from the different person name parts.Public Sub New(ByVal familyNameIn As String, ByVal givenNameIn As String, ByVal middleNameIn As String, ByVal namePrefixIn As String, ByVal nameSuffixIn As String)FamilyName = familyNameInGivenName = givenNameInMiddleName = middleNameInNamePrefix = namePrefixInNameSuffix = nameSuffixInEnd Sub''' Return this person name instance's.Public Overrides Function ToString() As StringReturn FullNameEnd FunctionEnd ClassPrivate Sub DumpPersonName(ByVal pn As PersonName)Dim sMsg As String = String.Format("Family Name: {0}" & Constants.vbLf & "Given Name: {1}" & Constants.vbLf & "Middle Name: {2}" &Constants.vbLf & "Name Prefix: {3}" & Constants.vbLf & "Name Suffix: {4}", pn.FamilyName, pn.GivenName,pn.MiddleName, pn.NamePrefix, pn.NameSuffix)MessageBox.Show(sMsg)End SubPublic Function MyGetValueDelegate(ByVal s As String) As ObjectDim pn As PersonName = New PersonName(s)MyGetValueDelegate = pnEnd FunctionPrivate Sub DicomDataSet_GetValueWithDelegateExample()' Create a DicomDataSet and add a PatientName' Dicom Spec for Value Representation PN (Person Name)' Elements are in this order:' * family name complex' * given name complex' * middle name' * name prefix' * name suffix.Dim ds As DicomDataSet = New DicomDataSet()ds.InsertElementAndSetValue(DicomTag.PatientName, "Smith^John^MiddleName^Mr.^III")' Get a PersonName value of an element by specifying a tag, and using a delegate' Use this form when the type is not native to the dataset' The data is extracted from the field as a string and passed to the provided method.Dim pn As PersonName = NothingDim myDelegate As GetValueDelegatemyDelegate = AddressOf MyGetValueDelegatepn = ds.GetValue(Of PersonName)(DicomTag.PatientName, Nothing, myDelegate)DumpPersonName(pn)' Another overload, specifying parent elementpn = ds.GetValue(Of PersonName)(Nothing, True, DicomTag.PatientName, Nothing, myDelegate)DumpPersonName(pn)' Another overload, this time passing in the DICOM element instead of a tagDim element As DicomElement = ds.FindFirstElement(Nothing, DicomTag.PatientName, True)pn = ds.GetValue(Of PersonName)(element, Nothing, myDelegate)DumpPersonName(pn)End Sub
using Leadtools;using Leadtools.Dicom;using Leadtools.Examples;public class PersonName{private string[] _innerArray = new string[5] {string.Empty, string.Empty, string.Empty, string.Empty,string.Empty };/// Access this person name instance as array. Index range is/// bounded between 0 (family name) and 4 (name suffix).public string this[int index]{set{if (value == null || value.Length < 64)_innerArray[index] = value;elsethrow new DicomException("Length of new entry exceeds 64 characters.");}get { return _innerArray[index]; }}private const int _familyNameIndex = 0;private const int _givenNameIndex = 1;private const int _middleNameIndex = 2;private const int _namePrefixIndex = 3;private const int _nameSuffixIndex = 4;/// Access person name part family name.public string FamilyName{set{if (value == null || value.Length < 64){_fullName = null;_innerArray[_familyNameIndex] = value;}elsethrow new DicomException("Length of family name exceeds 64 characters.");}get { return _innerArray[_familyNameIndex]; }}/// Access person name part given name.public string GivenName{set{if (value == null || value.Length < 64){_fullName = string.Empty;_innerArray[_givenNameIndex] = value;}elsethrow new DicomException("Length of family name exceeds 64 characters.");}get { return _innerArray[_givenNameIndex]; }}/// Access person name part middle name.public string MiddleName{set{if (value == null || value.Length < 64){_fullName = string.Empty;_innerArray[_middleNameIndex] = value;}elsethrow new DicomException("Length of family name exceeds 64 characters.");}get { return _innerArray[_middleNameIndex]; }}/// Access person name part name prefix.public string NamePrefix{set{if (value == null || value.Length < 64){_fullName = string.Empty;_innerArray[_namePrefixIndex] = value;}elsethrow new DicomException("Length of family name exceeds 64 characters.");}get { return _innerArray[_namePrefixIndex]; }}/// Access person name part name suffix.public string NameSuffix{set{if (value == null || value.Length < 64){_fullName = string.Empty;_innerArray[_nameSuffixIndex] = value;}elsethrow new DicomException("Length of family name exceeds 64 characters.");}get { return _innerArray[_nameSuffixIndex]; }}private string _fullName = string.Empty;/// Access full person name string representation. According/// to the DICOM standard "^" is used as separator of different/// person name parts.public string FullName{set{_fullName = value;if (_fullName != null){string[] s;int i;if (_fullName.Contains("^"))s = _fullName.Split('^');elses = _fullName.Split(' ');for (i = 0; i < s.Length; i++){if (s[i].Length < 64){if (i < _innerArray.Length)_innerArray[i] = s[i];}elsethrow new DicomException("Length of family name exceeds 64 characters.");}for (int k = i; k < _innerArray.Length; k++)_innerArray[k] = string.Empty;}}get{if (_fullName == string.Empty){_fullName = _innerArray[0];bool isNotNull = _fullName != string.Empty;int i = 1;while (isNotNull && i < _innerArray.Length){isNotNull = _innerArray[i] != string.Empty;if (isNotNull)_fullName += "^" + _innerArray[i];i++;}}return _fullName;}}/// Creates a new empty person name instance.public PersonName() { }/// Creates a new person name instance from specified full name./// All person name parts have to be separated by "^" according to/// the DICOM standard.public PersonName(string fullName){FullName = fullName;}/// Creates a new person name instance from the different person name parts.public PersonName(string familyName, string givenName,string middleName, string namePrefix, string nameSuffix){FamilyName = familyName;GivenName = givenName;MiddleName = middleName;NamePrefix = namePrefix;NameSuffix = nameSuffix;}/// Return this person name instance's.public override string ToString(){return FullName;}}void DumpPersonName(PersonName pn){String sMsg =string.Format("Family Name: {0}\nGiven Name: {1}\nMiddle Name: {2}\nName Prefix: {3}\nName Suffix: {4}",pn.FamilyName,pn.GivenName,pn.MiddleName,pn.NamePrefix,pn.NameSuffix);Debug.WriteLine(sMsg);}private void DicomDataSet_GetValueWithDelegateExample(){// Create a DicomDataSet and add a PatientName// Dicom Spec for Value Representation PN (Person Name)// Elements are in this order:// * family name complex// * given name complex// * middle name// * name prefix// * name suffix.DicomDataSet ds = new DicomDataSet();ds.InsertElementAndSetValue(DicomTag.PatientName, "Smith^John^MiddleName^Mr.^III");// Get a PersonName value of an element by specifying a tag, and using a delegate// Use this form when the type is not native to the dataset// The data is extracted from the field as a string and passed to the provided method.PersonName pn = null;pn = ds.GetValue<PersonName>(DicomTag.PatientName,null,delegate (string data){PersonName t = new PersonName(data);return t;});DumpPersonName(pn);// Another overload, specifying parent elementpn = ds.GetValue<PersonName>(null,true,DicomTag.PatientName,null,delegate (string data){PersonName t = new PersonName(data);return t;});DumpPersonName(pn);// Another overload, this time passing in the DICOM element instead of a tagDicomElement element = ds.FindFirstElement(null, DicomTag.PatientName, true);pn = ds.GetValue<PersonName>(element,null,delegate (string data){PersonName t = new PersonName(data);return t;});DumpPersonName(pn);}
Imports LeadtoolsImports Leadtools.DicomPublic Class PersonNamePrivate _innerArray As String() = New String(4) {String.Empty, String.Empty, String.Empty, String.Empty, String.Empty}''' Access this person name instance as array. Index range is''' bounded between 0 (family name) and 4 (name suffix).Default Public Property Item(ByVal index As Integer) As StringSetIf Value Is Nothing OrElse Value.Length < 64 Then_innerArray(index) = ValueElseThrow New DicomException("Length of new entry exceeds 64 characters.")End IfEnd SetGetReturn _innerArray(index)End GetEnd PropertyPrivate Const _familyNameIndex As Integer = 0Private Const _givenNameIndex As Integer = 1Private Const _middleNameIndex As Integer = 2Private Const _namePrefixIndex As Integer = 3Private Const _nameSuffixIndex As Integer = 4''' Access person name part family name.Public Property FamilyName() As StringSetIf Value Is Nothing OrElse Value.Length < 64 Then_fullName = Nothing_innerArray(_familyNameIndex) = ValueElseThrow New DicomException("Length of family name exceeds 64 characters.")End IfEnd SetGetReturn _innerArray(_familyNameIndex)End GetEnd Property''' Access person name part given name.Public Property GivenName() As StringSetIf Value Is Nothing OrElse Value.Length < 64 Then_fullName = String.Empty_innerArray(_givenNameIndex) = ValueElseThrow New DicomException("Length of family name exceeds 64 characters.")End IfEnd SetGetReturn _innerArray(_givenNameIndex)End GetEnd Property''' Access person name part middle name.Public Property MiddleName() As StringSetIf Value Is Nothing OrElse Value.Length < 64 Then_fullName = String.Empty_innerArray(_middleNameIndex) = ValueElseThrow New DicomException("Length of family name exceeds 64 characters.")End IfEnd SetGetReturn _innerArray(_middleNameIndex)End GetEnd Property''' Access person name part name prefix.Public Property NamePrefix() As StringSetIf Value Is Nothing OrElse Value.Length < 64 Then_fullName = String.Empty_innerArray(_namePrefixIndex) = ValueElseThrow New DicomException("Length of family name exceeds 64 characters.")End IfEnd SetGetReturn _innerArray(_namePrefixIndex)End GetEnd Property''' Access person name part name suffix.Public Property NameSuffix() As StringSetIf Value Is Nothing OrElse Value.Length < 64 Then_fullName = String.Empty_innerArray(_nameSuffixIndex) = ValueElseThrow New DicomException("Length of family name exceeds 64 characters.")End IfEnd SetGetReturn _innerArray(_nameSuffixIndex)End GetEnd PropertyPrivate _fullName As String = String.Empty''' Access full person name string representation. According''' to the DICOM standard "^" is used as separator of different''' person name parts.Public Property FullName() As StringSet_fullName = ValueIf Not _fullName Is Nothing ThenDim s As String()Dim i As IntegerIf _fullName.Contains("^") Thens = _fullName.Split("^"c)Elses = _fullName.Split(" "c)End Ifi = 0Do While i < s.LengthIf s(i).Length < 64 ThenIf i < _innerArray.Length Then_innerArray(i) = s(i)End IfElseThrow New DicomException("Length of family name exceeds 64 characters.")End Ifi += 1LoopDim k As Integer = iDo While k < _innerArray.Length_innerArray(k) = String.Emptyk += 1LoopEnd IfEnd SetGetIf _fullName = String.Empty Then_fullName = _innerArray(0)Dim isNotNull As Boolean = _fullName <> String.EmptyDim i As Integer = 1Do While isNotNull AndAlso i < _innerArray.LengthisNotNull = _innerArray(i) <> String.EmptyIf isNotNull Then_fullName &= "^" & _innerArray(i)End Ifi += 1LoopEnd IfReturn _fullNameEnd GetEnd Property''' Creates a new empty person name instance.Public Sub New()End Sub'' Creates a new person name instance from specified full name.'' All person name parts have to be separated by "^" according to'' the DICOM standard.Public Sub New(ByVal fullNameParam As String)FullName = fullNameParamEnd Sub'' Creates a new person name instance from the different person name parts.Public Sub New(ByVal familyNameParam As String,ByVal givenNameParam As String,ByVal middleNameParam As String,ByVal namePrefixParam As String,ByVal nameSuffixParam As String)FamilyName = familyNameParamGivenName = givenNameParamMiddleName = middleNameParamNamePrefix = namePrefixParamNameSuffix = nameSuffixParamEnd Sub''' Return this person name instance's.Public Overrides Function ToString() As StringReturn FullNameEnd FunctionEnd ClassPrivate Sub DumpPersonName(ByVal pn As PersonName)Dim sMsg As String = String.Format("Family Name: {0}" _& Constants.vbLf _& "Given Name: {1}" _& Constants.vbLf _& "Middle Name: {2}" _& Constants.vbLf _& "Name Prefix: {3}" _& Constants.vbLf _& "Name Suffix: {4}",pn.FamilyName,pn.GivenName,pn.MiddleName,pn.NamePrefix,pn.NameSuffix)Debug.WriteLine(sMsg)End SubPrivate Function GetValueDelegate(ByVal data As String) As PersonNameDim t As PersonName = New PersonName(data)Return tEnd FunctionPrivate Sub DicomDataSet_GetValueWithDelegateExample()' Create a DicomDataSet and add a PatientName' Dicom Spec for Value Representation PN (Person Name)' Elements are in this order:' * family name complex' * given name complex' * middle name' * name prefix' * name suffix.Dim ds As DicomDataSet = New DicomDataSet()ds.InsertElementAndSetValue(DicomTag.PatientName, "Smith^John^MiddleName^Mr.^III")' Get a PersonName value of an element by specifying a tag, and using a delegate' Use this form when the type is not native to the dataset' The data is extracted from the field as a string and passed to the provided method.Dim pn As PersonName = Nothingpn = ds.GetValue(Of PersonName)(DicomTag.PatientName, Nothing, AddressOf GetValueDelegate)DumpPersonName(pn)' Another overload, specifying parent elementpn = ds.GetValue(Of PersonName)(Nothing, True, DicomTag.PatientName, Nothing, AddressOf GetValueDelegate)DumpPersonName(pn)' Another overload, this time passing in the DICOM element instead of a tagDim element As DicomElement = ds.FindFirstElement(Nothing, DicomTag.PatientName, True)pn = ds.GetValue(Of PersonName)(element, Nothing, AddressOf GetValueDelegate)DumpPersonName(pn)End Sub
DicomDataSet.GetValue{T}(DicomElement, bool, long, T, GetValueDelegate )
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
