コード例 #1
0
        /// <summary>   Returns source code for an accessor method for a particular Structure. </summary>
        ///
        /// <exception cref="Exception">    Thrown when an exception error condition occurs. </exception>
        ///
        /// <param name="group">        The group. </param>
        /// <param name="structure">    The structure. </param>
        ///
        /// <returns>   A System.String. </returns>

        public static System.String makeAccessor(GroupDef group, int structure)
        {
            System.Text.StringBuilder source = new System.Text.StringBuilder();

            IStructureDef def = group.Structures[structure];

            System.String name       = def.Name;
            System.String indexName  = group.getIndexName(name);
            System.String getterName = indexName;

            if (def is GroupDef)
            {
                System.String unqualifiedName = ((GroupDef)def).UnqualifiedName;
                getterName = group.getIndexName(unqualifiedName);
            }

            //make accessor for first (or only) rep ...
            source.Append("\t///<summary>\r\n");
            source.Append("\t/// Returns ");
            if (def.Repeating)
            {
                source.Append(" first repetition of ");
            }
            source.Append(indexName);
            source.Append(" (");
            source.Append(def.Description);
            source.Append(") - creates it if necessary\r\n");
            source.Append("\t///</summary>\r\n");
            source.Append("\tpublic ");
            source.Append(def.Name);
            source.Append(" ");
            if (def.Repeating)
            {
                source.Append("Get");
                source.Append(getterName);
                source.Append("() {\r\n");
            }
            else
            {
                source.Append(getterName);
                source.Append(" { \r\n");
                source.Append("get{\r\n");
            }
            source.Append("\t   ");
            source.Append(def.Name);
            source.Append(" ret = null;\r\n");
            source.Append("\t   try {\r\n");
            source.Append("\t      ret = (");
            source.Append(def.Name);
            source.Append(")this.GetStructure(\"");
            source.Append(getterName);
            source.Append("\");\r\n");
            source.Append("\t   } catch(HL7Exception e) {\r\n");
            source.Append(
                "\t      HapiLogFactory.GetHapiLog(GetType()).Error(\"Unexpected error accessing data - this is probably a bug in the source code generator.\", e);\r\n");
            source.Append("\t      throw new System.Exception(\"An unexpected error ocurred\",e);\r\n");
            source.Append("\t   }\r\n");
            source.Append("\t   return ret;\r\n");
            if (!def.Repeating)
            {
                source.Append("\t}\r\n");
            }
            source.Append("\t}\r\n\r\n");

            if (def.Repeating)
            {
                //make accessor for specific rep ...
                source.Append("\t///<summary>\r\n");
                source.Append("\t///Returns a specific repetition of ");
                source.Append(indexName);
                source.Append("\r\n");
                source.Append("\t/// * (");
                source.Append(def.Description);
                source.Append(") - creates it if necessary\r\n");
                source.Append("\t/// throws HL7Exception if the repetition requested is more than one \r\n");
                source.Append("\t///     greater than the number of existing repetitions.\r\n");
                source.Append("\t///</summary>\r\n");
                source.Append("\tpublic ");
                source.Append(def.Name);
                source.Append(" Get");
                source.Append(getterName);
                source.Append("(int rep) { \r\n");
                source.Append("\t   return (");
                source.Append(def.Name);
                source.Append(")this.GetStructure(\"");
                source.Append(getterName);
                source.Append("\", rep);\r\n");
                source.Append("\t}\r\n\r\n");

                //make accessor for number of reps
                source.Append("\t/** \r\n");
                source.Append("\t * Returns the number of existing repetitions of ");
                source.Append(indexName);
                source.Append(" \r\n");
                source.Append("\t */ \r\n");
                source.Append("\tpublic int ");
                source.Append(getterName);
                source.Append("RepetitionsUsed { \r\n");
                source.Append("get{\r\n");
                source.Append("\t    int reps = -1; \r\n");
                source.Append("\t    try { \r\n");
                source.Append("\t        reps = this.GetAll(\"");
                source.Append(getterName);
                source.Append("\").Length; \r\n");
                source.Append("\t    } catch (HL7Exception e) { \r\n");
                source.Append(
                    "\t        string message = \"Unexpected error accessing data - this is probably a bug in the source code generator.\"; \r\n");
                source.Append("\t        HapiLogFactory.GetHapiLog(GetType()).Error(message, e); \r\n");
                source.Append("\t        throw new System.Exception(message);\r\n");
                source.Append("\t    } \r\n");
                source.Append("\t    return reps; \r\n");
                source.Append("\t}\r\n");
                source.Append("\t} \r\n\r\n");
            }

            return(source.ToString());
        }
コード例 #2
0
ファイル: GroupGenerator.cs プロジェクト: liddictm/nHapi
		/// <summary> Returns source code for an accessor method for a particular Structure. </summary>
		public static String makeAccessor(GroupDef group, int structure)
		{
			StringBuilder source = new StringBuilder();

			IStructureDef def = group.Structures[structure];

			String name = def.Name;
			String indexName = group.getIndexName(name);
			String getterName = indexName;

			if (def is GroupDef)
			{
				String unqualifiedName = ((GroupDef) def).UnqualifiedName;
				getterName = group.getIndexName(unqualifiedName);
			}

			//make accessor for first (or only) rep ... 
			source.Append("\t///<summary>\r\n");
			source.Append("\t/// Returns ");
			if (def.Repeating)
				source.Append(" first repetition of ");
			source.Append(indexName);
			source.Append(" (");
			source.Append(def.Description);
			source.Append(") - creates it if necessary\r\n");
			source.Append("\t///</summary>\r\n");
			source.Append("\tpublic ");
			source.Append(def.Name);
			source.Append(" ");
			if (def.Repeating)
			{
				source.Append("Get");
				source.Append(getterName);
				source.Append("() {\r\n");
			}
			else
			{
				source.Append(getterName);
				source.Append(" { \r\n");
				source.Append("get{\r\n");
			}
			source.Append("\t   ");
			source.Append(def.Name);
			source.Append(" ret = null;\r\n");
			source.Append("\t   try {\r\n");
			source.Append("\t      ret = (");
			source.Append(def.Name);
			source.Append(")this.GetStructure(\"");
			source.Append(getterName);
			source.Append("\");\r\n");
			source.Append("\t   } catch(HL7Exception e) {\r\n");
			source.Append(
				"\t      HapiLogFactory.GetHapiLog(GetType()).Error(\"Unexpected error accessing data - this is probably a bug in the source code generator.\", e);\r\n");
			source.Append("\t      throw new System.Exception(\"An unexpected error ocurred\",e);\r\n");
			source.Append("\t   }\r\n");
			source.Append("\t   return ret;\r\n");
			if (!def.Repeating)
				source.Append("\t}\r\n");
			source.Append("\t}\r\n\r\n");

			if (def.Repeating)
			{
				//make accessor for specific rep ... 
				source.Append("\t///<summary>\r\n");
				source.Append("\t///Returns a specific repetition of ");
				source.Append(indexName);
				source.Append("\r\n");
				source.Append("\t/// * (");
				source.Append(def.Description);
				source.Append(") - creates it if necessary\r\n");
				source.Append("\t/// throws HL7Exception if the repetition requested is more than one \r\n");
				source.Append("\t///     greater than the number of existing repetitions.\r\n");
				source.Append("\t///</summary>\r\n");
				source.Append("\tpublic ");
				source.Append(def.Name);
				source.Append(" Get");
				source.Append(getterName);
				source.Append("(int rep) { \r\n");
				source.Append("\t   return (");
				source.Append(def.Name);
				source.Append(")this.GetStructure(\"");
				source.Append(getterName);
				source.Append("\", rep);\r\n");
				source.Append("\t}\r\n\r\n");

				//make accessor for number of reps
				source.Append("\t/** \r\n");
				source.Append("\t * Returns the number of existing repetitions of ");
				source.Append(indexName);
				source.Append(" \r\n");
				source.Append("\t */ \r\n");
				source.Append("\tpublic int ");
				source.Append(getterName);
				source.Append("RepetitionsUsed { \r\n");
				source.Append("get{\r\n");
				source.Append("\t    int reps = -1; \r\n");
				source.Append("\t    try { \r\n");
				source.Append("\t        reps = this.GetAll(\"");
				source.Append(getterName);
				source.Append("\").Length; \r\n");
				source.Append("\t    } catch (HL7Exception e) { \r\n");
				source.Append(
					"\t        string message = \"Unexpected error accessing data - this is probably a bug in the source code generator.\"; \r\n");
				source.Append("\t        HapiLogFactory.GetHapiLog(GetType()).Error(message, e); \r\n");
				source.Append("\t        throw new System.Exception(message);\r\n");
				source.Append("\t    } \r\n");
				source.Append("\t    return reps; \r\n");
				source.Append("\t}\r\n");
				source.Append("\t} \r\n\r\n");
			}

			return source.ToString();
		}
コード例 #3
0
ファイル: GroupGenerator.cs プロジェクト: Resipiscence/nHapi
        /// <summary> Returns source code for an accessor method for a particular Structure. </summary>
        public static String makeAccessor(GroupDef group, int structure)
        {
            StringBuilder source = new StringBuilder();

            IStructureDef def = group.Structures[structure];

            String name       = def.Name;
            String indexName  = group.getIndexName(name);
            String getterName = indexName;

            if (def is GroupDef)
            {
                String unqualifiedName = ((GroupDef)def).UnqualifiedName;
                getterName = group.getIndexName(unqualifiedName);
            }

            //make accessor for first (or only) rep ...
            source.Append("\t///<summary>\r\n");
            source.Append("\t/// Returns ");
            if (def.Repeating)
            {
                source.Append(" first repetition of ");
            }
            source.Append(indexName);
            source.Append(" (");
            source.Append(def.Description);
            source.Append(") - creates it if necessary\r\n");
            source.Append("\t///</summary>\r\n");
            source.Append("\tpublic ");
            source.Append(def.Name);
            source.Append(" ");
            if (def.Repeating)
            {
                source.Append("Get");
                source.Append(getterName);
                source.Append("() {\r\n");
            }
            else
            {
                source.Append(getterName);
                source.Append(" { \r\n");
                source.Append("get{\r\n");
            }
            source.Append("\t   ");
            source.Append(def.Name);
            source.Append(" ret = null;\r\n");
            source.Append("\t   try {\r\n");
            source.Append("\t      ret = (");
            source.Append(def.Name);
            source.Append(")this.GetStructure(\"");
            source.Append(getterName);
            source.Append("\");\r\n");
            source.Append("\t   } catch(HL7Exception e) {\r\n");
            source.Append(
                "\t      HapiLogFactory.GetHapiLog(GetType()).Error(\"Unexpected error accessing data - this is probably a bug in the source code generator.\", e);\r\n");
            source.Append("\t      throw new System.Exception(\"An unexpected error ocurred\",e);\r\n");
            source.Append("\t   }\r\n");
            source.Append("\t   return ret;\r\n");
            if (!def.Repeating)
            {
                source.Append("\t}\r\n");
            }
            source.Append("\t}\r\n\r\n");

            if (def.Repeating)
            {
                //make accessor for specific rep ...
                source.Append("\t///<summary>\r\n");
                source.Append("\t///Returns a specific repetition of ");
                source.Append(indexName);
                source.Append("\r\n");
                source.Append("\t/// * (");
                source.Append(def.Description);
                source.Append(") - creates it if necessary\r\n");
                source.Append("\t/// throws HL7Exception if the repetition requested is more than one \r\n");
                source.Append("\t///     greater than the number of existing repetitions.\r\n");
                source.Append("\t///</summary>\r\n");
                source.Append("\tpublic ");
                source.Append(def.Name);
                source.Append(" Get");
                source.Append(getterName);
                source.Append("(int rep) { \r\n");
                source.Append("\t   return (");
                source.Append(def.Name);
                source.Append(")this.GetStructure(\"");
                source.Append(getterName);
                source.Append("\", rep);\r\n");
                source.Append("\t}\r\n\r\n");

                //make accessor for number of reps
                source.Append("\t/** \r\n");
                source.Append("\t * Returns the number of existing repetitions of ");
                source.Append(indexName);
                source.Append(" \r\n");
                source.Append("\t */ \r\n");
                source.Append("\tpublic int ");
                source.Append(getterName);
                source.Append("RepetitionsUsed { \r\n");
                source.Append("get{\r\n");
                source.Append("\t    int reps = -1; \r\n");
                source.Append("\t    try { \r\n");
                source.Append("\t        reps = this.GetAll(\"");
                source.Append(getterName);
                source.Append("\").Length; \r\n");
                source.Append("\t    } catch (HL7Exception e) { \r\n");
                source.Append(
                    "\t        string message = \"Unexpected error accessing data - this is probably a bug in the source code generator.\"; \r\n");
                source.Append("\t        HapiLogFactory.GetHapiLog(GetType()).Error(message, e); \r\n");
                source.Append("\t        throw new System.Exception(message);\r\n");
                source.Append("\t    } \r\n");
                source.Append("\t    return reps; \r\n");
                source.Append("\t}\r\n");
                source.Append("\t} \r\n\r\n");

                // make enumerator
                source.Append("\t/** \r\n");
                source.Append("\t * Enumerate over the " + def.Name + " results \r\n");
                source.Append("\t */ \r\n");
                source.Append("\tpublic IEnumerable<" + def.Name + "> " + getterName + "s \r\n");
                source.Append("\t{ \r\n");
                source.Append("\t\tget\r\n");
                source.Append("\t\t{\r\n");
                source.Append("\t\t\tfor (int rep = 0; rep < " + getterName + "RepetitionsUsed; rep++)\r\n");
                source.Append("\t\t\t{\r\n");
                source.Append("\t\t\t\tyield return (" + def.Name + ")this.GetStructure(\"" + getterName + "\", rep);\r\n");
                source.Append("\t\t\t}\r\n");
                source.Append("\t\t}\r\n");
                source.Append("\t}\r\n\r\n");

                // make Add function
                source.Append("\t///<summary>\r\n");
                source.Append("\t///Adds a new " + def.Name + "\r\n");
                source.Append("\t///</summary>\r\n");
                source.Append("\tpublic " + def.Name + " Add" + getterName + "()\r\n");
                source.Append("\t{\r\n");
                source.Append("\t\treturn this.AddStructure(\"" + getterName + "\") as " + def.Name + ";\r\n");
                source.Append("\t}\r\n");

                source.Append("\r\n");

                // make Remove function
                source.Append("\t///<summary>\r\n");
                source.Append("\t///Removes the given " + def.Name + "\r\n");
                source.Append("\t///</summary>\r\n");
                source.Append("\tpublic void Remove" + getterName + "(" + def.Name + " toRemove)\r\n");
                source.Append("\t{\r\n");
                source.Append("\t\tthis.RemoveStructure(\"" + getterName + "\", toRemove);\r\n");
                source.Append("\t}\r\n");

                source.Append("\r\n");

                // make Remove At function
                source.Append("\t///<summary>\r\n");
                source.Append("\t///Removes the " + def.Name + " at the given index\r\n");
                source.Append("\t///</summary>\r\n");
                source.Append("\tpublic void Remove" + getterName + "At(int index)\r\n");
                source.Append("\t{\r\n");
                source.Append("\t\tthis.RemoveRepetition(\"" + getterName + "\", index);\r\n");
                source.Append("\t}\r\n");

                source.Append("\r\n");
            }

            return(source.ToString());
        }