Ejemplo n.º 1
0
        private static void AlternateMethodsForCreatingAHL7MessageObject(string msgText)
        {
            Console.WriteLine("\r\nCreating a HL7Message Object");
            Console.WriteLine("----------------------------");
            Console.WriteLine("Method 1 : Implicit cast: HL7Message mesg = msgText;");
            HL7Message mesgImplicit = msgText;

            // Alternatively = use an Explicit cast
            Console.WriteLine("Method 2 : Explicit cast: mesg = (HL7Message)msgText;");
            var mesgExplicit = (HL7Message)msgText;

            // OR simply use the constructor
            Console.WriteLine("Method 3 : Constructor: mesg = new HL7Message(msgText);");
            var mesgFromCtor = new HL7Message(msgText);

            // All Three methods produce the same result.
            Console.WriteLine("\r\nAll produce the same result:");
            Console.WriteLine($"TypeOf mesgImplicit {mesgImplicit.GetType()} - {mesgImplicit.Element("MSH")}");
            Console.WriteLine($"TypeOf mesgExplicit {mesgExplicit.GetType()} - {mesgExplicit.Element("MSH")}");
            Console.WriteLine($"TypeOf mesgfromCtor {mesgFromCtor.GetType()} - {mesgFromCtor.Element("MSH")}");
            Console.WriteLine();
        }