本文整理汇总了C#中ISegment.NumFields方法的典型用法代码示例。如果您正苦于以下问题:C# ISegment.NumFields方法的具体用法?C# ISegment.NumFields怎么用?C# ISegment.NumFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISegment
的用法示例。
在下文中一共展示了ISegment.NumFields方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: copy
/// <summary> Copies contents from the source segment to the destination segment. This
/// method calls copy(Type, Type) on each repetition of each field (see additional
/// behavioural description there). An attempt is made to copy each repetition of
/// each field in the source segment, regardless of whether the corresponding
/// destination field is repeating or even exists.
/// </summary>
/// <param name="from">the segment from which data are copied
/// </param>
/// <param name="to">the segment into which data are copied
/// </param>
public static void copy(ISegment from, ISegment to)
{
int n = from.NumFields();
for (int i = 1; i <= n; i++)
{
IType[] reps = from.GetField(i);
for (int j = 0; j < reps.Length; j++)
{
copy(reps[j], to.GetField(i, j));
}
}
}
示例2: Encode
public static String Encode(ISegment source, EncodingCharacters encodingChars)
{
StringBuilder result = new StringBuilder();
result.Append(source.GetStructureName());
result.Append(encodingChars.FieldSeparator);
//start at field 2 for MSH segment because field 1 is the field delimiter
int startAt = 1;
if (IsDelimDefSegment(source.GetStructureName()))
startAt = 2;
//loop through fields; for every field delimit any repetitions and add field delimiter after ...
int numFields = source.NumFields();
for (int i = startAt; i <= numFields; i++)
{
try
{
IType[] reps = source.GetField(i);
for (int j = 0; j < reps.Length; j++)
{
String fieldText = Encode(reps[j], encodingChars);
//if this is MSH-2, then it shouldn't be escaped, so unescape it again
if (IsDelimDefSegment(source.GetStructureName()) && i == 2)
fieldText = Escape.unescape(fieldText, encodingChars);
result.Append(fieldText);
if (j < reps.Length - 1)
result.Append(encodingChars.RepetitionSeparator);
}
}
catch (HL7Exception e)
{
log.Error("Error while encoding segment: ", e);
}
result.Append(encodingChars.FieldSeparator);
}
//strip trailing delimiters ...
return StripExtraDelimiters(result.ToString(), encodingChars.FieldSeparator);
}
示例3: Parse
/// <summary> Parses a segment string and populates the given Segment object. Unexpected fields are
/// added as Varies' at the end of the segment.
///
/// </summary>
/// <throws> HL7Exception if the given string does not contain the </throws>
/// <summary> given segment or if the string is not encoded properly
/// </summary>
public virtual void Parse(ISegment destination, String segment, EncodingCharacters encodingChars)
{
int fieldOffset = 0;
if (IsDelimDefSegment(destination.GetStructureName()))
{
fieldOffset = 1;
//set field 1 to fourth character of string
Terser.Set(destination, 1, 0, 1, 1, Convert.ToString(encodingChars.FieldSeparator));
}
String[] fields = Split(segment, Convert.ToString(encodingChars.FieldSeparator));
for (int i = 1; i < fields.Length; i++)
{
String[] reps = Split(fields[i], Convert.ToString(encodingChars.RepetitionSeparator));
if (log.DebugEnabled)
{
log.Debug(reps.Length + "reps delimited by: " + encodingChars.RepetitionSeparator);
}
//MSH-2 will get split incorrectly so we have to fudge it ...
bool isMSH2 = IsDelimDefSegment(destination.GetStructureName()) && i + fieldOffset == 2;
if (isMSH2)
{
reps = new String[1];
reps[0] = fields[i];
}
for (int j = 0; j < reps.Length; j++)
{
try
{
StringBuilder statusMessage = new StringBuilder("Parsing field ");
statusMessage.Append(i + fieldOffset);
statusMessage.Append(" repetition ");
statusMessage.Append(j);
log.Debug(statusMessage.ToString());
if (i > 0 && i <= destination.NumFields() && j < destination.GetMaxCardinality(i))
{
IType field = destination.GetField(i + fieldOffset, j);
if (isMSH2)
{
Terser.getPrimitive(field, 1, 1).Value = reps[j];
}
else
{
Parse(field, reps[j], encodingChars);
}
}
else
{
StringBuilder errorMessage = new StringBuilder("Unexpected repitition for field ");
statusMessage.Append(i + fieldOffset);
statusMessage.Append(" repetition ");
statusMessage.Append(j);
statusMessage.Append(", ignoring extra repititions.");
log.Debug(statusMessage.ToString());
}
}
catch (HL7Exception e)
{
//set the field location and throw again ...
e.FieldPosition = i + fieldOffset;
e.SegmentRepetition = MessageIterator.getIndex(destination.ParentStructure, destination).rep;
e.SegmentName = destination.GetStructureName();
throw;
}
}
}
//set data type of OBX-5
if (destination.GetType().FullName.IndexOf("OBX") >= 0)
{
Varies.fixOBX5(destination, Factory);
}
}
示例4: Encode
/// <summary> Populates the given Element with data from the given Segment, by inserting
/// Elements corresponding to the Segment's fields, their components, etc. Returns
/// true if there is at least one data value in the segment.
/// </summary>
public virtual bool Encode(ISegment segmentObject, XmlElement segmentElement)
{
bool hasValue = false;
int n = segmentObject.NumFields();
for (int i = 1; i <= n; i++)
{
String name = MakeElementName(segmentObject, i);
IType[] reps = segmentObject.GetField(i);
for (int j = 0; j < reps.Length; j++)
{
XmlElement newNode = segmentElement.OwnerDocument.CreateElement(name);
bool componentHasValue = Encode(reps[j], newNode);
if (componentHasValue)
{
try
{
segmentElement.AppendChild(newNode);
}
catch (Exception e)
{
throw new HL7Exception("DOMException encoding Segment: ", HL7Exception.APPLICATION_INTERNAL_ERROR, e);
}
hasValue = true;
}
}
}
return hasValue;
}