Exemplo n.º 1
0
 /// <summary>
 /// Returns a list of strings that represent a set of class property declarations in the specified target language,
 /// one for each column.
 /// </summary>
 /// <example>
 /// Assuming the configuration's XmlSystem is set to Linq_XDocument, and TargetLanguage is set to CSharp,
 /// executing "String.Join(" { get; set; }" + Environment.NewLine + "    ", table.Columns.GetClassPropertyDeclarations("public")) + " { get; set; }""
 /// on the AdventureWorks2012 Person.Person table will generate this string:
 /// <code>
 /// public System.Int32 BusinessEntityID  /* primary key 1, foreign key */ { get; set; }
 /// public System.Xml.Linq.XElement AdditionalContactInfo { get; set; }
 /// public System.Xml.Linq.XElement Demographics { get; set; }
 /// public System.Int32 EmailPromotion { get; set; }
 /// public System.String FirstName { get; set; }
 /// public System.String LastName { get; set; }
 /// public System.String MiddleName { get; set; }
 /// public System.DateTime ModifiedDate { get; set; }
 /// public System.Boolean NameStyle { get; set; }
 /// public System.String PersonType { get; set; }
 /// public System.Guid rowguid { get; set; }
 /// public System.String Suffix { get; set; }
 /// public System.String Title { get; set; }
 /// </code>
 /// </example>
 /// <param name="scope">A target language keyword indicating the scope of the class property declarations. Can be blank.</param>
 /// <param name="includeKeyIdentificationComment">An enum value indicating whether or not to include
 /// a comment identifying the column as a primary and/or foreign key (see example code).</param>
 /// <returns>A <see cref="System.Collections.Generic.List{T}">List&lt;String&gt;</see>.</returns>
 public List <String> GetClassPropertyDeclarations(String scope, IncludeKeyIdentificationComment includeKeyIdentificationComment = IncludeKeyIdentificationComment.Yes)
 {
     return
         (this
          .OrderBy(column => column.Name)
          .Select(column => column.GetTargetLanguageProperty(scope, includeKeyIdentificationComment))
          .ToList());
 }
Exemplo n.º 2
0
 /// <summary>
 /// Return a list of strings that can be used as a parameter declarations in a stored procedure.
 /// <para>Primary and foreign key columns may optionally be documented with a comment.</para>
 /// </summary>
 /// <example>
 /// Executing "String.Join("," + Environment.NewLine, columns.GetStoredProcedureParameters())"
 /// on the AdventureWorks2012 Person.Person table will generate this string:
 /// <code>
 /// @BusinessEntityID INT  /* primary key 1, foreign key */,
 /// @AdditionalContactInfo XML(CONTENT, AdditionalContactInfoSchemaCollection),
 /// @Demographics XML(CONTENT, IndividualSurveySchemaCollection),
 /// @EmailPromotion INT,
 /// @FirstName NAME,
 /// @LastName NAME,
 /// @MiddleName NAME,
 /// @ModifiedDate DATETIME,
 /// @NameStyle NAMESTYLE,
 /// @PersonType NCHAR(2),
 /// @rowguid UNIQUEIDENTIFIER,
 /// @Suffix NVARCHAR(10),
 /// @Title NVARCHAR(8)
 /// </code>
 /// </example>
 /// <param name="columnType">An enum value indicating what kind of column type(s) to include in the return value.</param>
 /// <param name="includeKeyIdentificationComment">An enum value indicating whether or not to include
 /// a comment identifying the column as a primary and/or foreign key (see example code).</param>
 /// <returns>A <see cref="System.Collections.Generic.List{T}">List&lt;String&gt;</see>.</returns>
 public List <String> GetStoredProcedureParameters(ColumnType columnType, IncludeKeyIdentificationComment includeKeyIdentificationComment = IncludeKeyIdentificationComment.Yes)
 {
     return
         (this
          .Where(column => (column.ColumnType & columnType) > 0)
          .OrderBy(column => column.Name)
          .Select(column => column.GetStoredProcedureParameterDeclaration(includeKeyIdentificationComment))
          .ToList());
 }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a string that can be used in generated code to create a new SqlParameter instance for this column.
        /// </summary>
        /// <param name="includeKeyIdentificationComment">An enum value indicating whether or not to include
        /// a comment identifying the column as a primary and/or foreign key.</param>
        /// <returns>A String.</returns>
        public String GetTargetLanguageSqlParameterText(IncludeKeyIdentificationComment includeKeyIdentificationComment = IncludeKeyIdentificationComment.Yes)
        {
            var comment =
            ((includeKeyIdentificationComment == IncludeKeyIdentificationComment.Yes) && !String.IsNullOrWhiteSpace(this.KeyIdentificationComment))
            ? " " + this.KeyIdentificationComment
            : "";

              if (this._configuration.TargetLanguage.IsCSharp())
              {
            if (this.SqlDbTypeEnumName == "System.Data.SqlDbType.Udt")
              return String.Format("new SqlParameter() {{ ParameterName = \"{0}\", SqlDbType = {1}, UdtTypeName = \"{2}\", Value = {3} }}{4}",
            this.SqlIdentifier, this.SqlDbTypeEnumName, this.NativeServerDataTypeName, this.TargetLanguageSqlParameterValue, comment).Trim();
            else
              return String.Format("new SqlParameter() {{ ParameterName = \"{0}\", SqlDbType = {1}, Value = {2} }}{3}",
            this.SqlIdentifier, this.SqlDbTypeEnumName, this.TargetLanguageSqlParameterValue, comment).Trim();
              }
              else if (this._configuration.TargetLanguage.IsFSharp())
              {
            if (this.SqlDbTypeEnumName == "System.Data.SqlDbType.Udt")
              return String.Format("new SqlParameter(ParameterName = \"{0}\", SqlDbType = {1}, UdtTypeName = \"{2}\", Value = {3}){4}",
            this.SqlIdentifier, this.SqlDbTypeEnumName, this.NativeServerDataTypeName, this.TargetLanguageSqlParameterValue, comment).Trim();
            else
              return String.Format("new SqlParameter(ParameterName = \"{0}\", SqlDbType = {1}, Value = {2}){3}",
            this.SqlIdentifier, this.SqlDbTypeEnumName, this.TargetLanguageSqlParameterValue, comment).Trim();
              }
              else if (this._configuration.TargetLanguage.IsVisualBasic())
              {
            if (this.SqlDbTypeEnumName == "System.Data.SqlDbType.Udt")
              return String.Format("new SqlParameter() With {{ .ParameterName = \"{0}\", .SqlDbType = {1}, .UdtTypeName = \"{2}\", .Value = {3} }}{4}",
            this.SqlIdentifier, this.SqlDbTypeEnumName, this.NativeServerDataTypeName, this.TargetLanguageSqlParameterValue, comment).Trim();
            else
              return String.Format("new SqlParameter() With {{ .ParameterName = \"{0}\", .SqlDbType = {1}, .Value = {2} }}{3}",
            this.SqlIdentifier, this.SqlDbTypeEnumName, this.TargetLanguageSqlParameterValue, comment).Trim();
              }
              else
            throw new NotImplementedException(String.Format(Properties.Resources.UnknownTargetLanguageValue, this._configuration.TargetLanguage));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Return a string that can be used in generated code to represent this column as a target language class property declaration.
        /// </summary>
        /// <param name="scope"></param>
        /// <param name="includeKeyIdentificationComment">An enum value indicating whether or not to include
        /// a comment identifying the column as a primary and/or foreign key.</param>
        /// <returns>A String.</returns>
        public String GetTargetLanguageProperty(String scope, IncludeKeyIdentificationComment includeKeyIdentificationComment = IncludeKeyIdentificationComment.Yes)
        {
            var keyIdentificationComment =
            ((includeKeyIdentificationComment == IncludeKeyIdentificationComment.Yes) && !String.IsNullOrWhiteSpace(this.KeyIdentificationComment))
            ? this.KeyIdentificationComment
            : "";
              var targetLanguage = this._configuration.TargetLanguage;

              if (String.IsNullOrWhiteSpace(this.XmlCollectionName) || !this._configuration.XmlValidationLocation.HasFlag(XmlValidationLocation.PropertySetter))
              {
            var format = "";

            if (targetLanguage.IsCSharp())
            {
              if (targetLanguage.DoesSupportAutoProperties())
            format = "{0} {1} {2} {{ get; set; }} {3}";
              else
            format = @"
            {3}
            {0} {1} {2}
            {{
              get {{ return this.{4}; }}
              set {{ this.{4} = value; }}
            }}
            ";
            }
            else if (targetLanguage.IsFSharp())
            {
              if (targetLanguage.DoesSupportAutoProperties())
            format = "member val {0} {2} = Unchecked.defaultof<{1}> with get, set {3}";
              else
            format = @"
            {3}
            member {0} this.{2} with get() = {4}
            member {0} this.{2} with set value = {4} <- value
            ";
            }
            else if (targetLanguage.IsVisualBasic())
            {
              if (targetLanguage.DoesSupportAutoProperties())
            format = "{0} Property {2}() As {1} {3}";
              else
            format = @"
            {3}
            {0} Property {2}() As {1}
              Get
            Return {4}
              End Get
              Set (Value As {1})
            {4} = value
              End Set
            End Property
            ";
            }
            else
              throw new NotImplementedException(String.Format(Properties.Resources.UnknownTargetLanguageValue, this._configuration.TargetLanguage));

            return String.Format(format, scope, this.ClrTypeName, this.TargetLanguageIdentifier, keyIdentificationComment, this.TargetLanguageBackingStoreIdentifier).Trim();
              }
              else
              {
            if (this._configuration.TargetLanguage.IsCSharp())
              return this.GetXmlValidatedPropertyForCSharp(scope, keyIdentificationComment);
            else if (this._configuration.TargetLanguage.IsFSharp())
              return this.GetXmlValidatedPropertyForFSharp(scope, keyIdentificationComment);
            else if (this._configuration.TargetLanguage.IsVisualBasic())
              return this.GetXmlValidatedPropertyForVisualBasic(scope, keyIdentificationComment);
            else
              throw new NotImplementedException(String.Format(Properties.Resources.UnknownTargetLanguageValue, this._configuration.TargetLanguage));
              }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Return a string that can be used in generated code to represent this column as a target language method parameter.
        /// </summary>
        /// <param name="includeKeyIdentificationComment">An enum value indicating whether or not to include
        /// a comment identifying the column as a primary and/or foreign key.</param>
        /// <returns>A String.</returns>
        public String GetTargetLanguageMethodParameterNameAndType(IncludeKeyIdentificationComment includeKeyIdentificationComment = IncludeKeyIdentificationComment.Yes)
        {
            var format = "";

              if (this._configuration.TargetLanguage.IsCSharp())
            format = "{0} {1}{2}";
              else if (this._configuration.TargetLanguage.IsFSharp())
            format = "({1} : {0}{2})";
              else if (this._configuration.TargetLanguage.IsVisualBasic())
            format = "{1} As {0}{2}";
              else
            throw new NotImplementedException(String.Format(Properties.Resources.UnknownTargetLanguageValue, this._configuration.TargetLanguage));

              return String.Format(format, this.ClrTypeName, this.TargetLanguageIdentifier,
            (((includeKeyIdentificationComment == IncludeKeyIdentificationComment.Yes) && this.KeyIdentificationComment.IsNotEmpty())
              ? " " + this.KeyIdentificationComment
              : "")).Trim();
        }
Exemplo n.º 6
0
 /// <summary>
 /// Return a string that can be used in generated code to represent this column as a target language method parameter name.
 /// </summary>
 /// <param name="includeKeyIdentificationComment">An enum value indicating whether or not to include
 /// a comment identifying the column as a primary and/or foreign key.</param>
 /// <returns>A String.</returns>
 public String GetTargetLanguageMethodParameterName(IncludeKeyIdentificationComment includeKeyIdentificationComment = IncludeKeyIdentificationComment.Yes)
 {
     return String.Concat(this.TargetLanguageIdentifier, " ", this.KeyIdentificationComment).Trim();
 }
Exemplo n.º 7
0
 /// <summary>
 /// Return a string that can be used in generated code to represent this column as a TSQL stored procedure parameter.
 /// </summary>
 /// <param name="includeKeyIdentificationComment">An enum value indicating whether or not to include
 /// a comment identifying the column as a primary and/or foreign key.</param>
 /// <returns>A String.</returns>
 public String GetStoredProcedureParameterDeclaration(IncludeKeyIdentificationComment includeKeyIdentificationComment = IncludeKeyIdentificationComment.Yes)
 {
     return String.Format("{0} {1}{2}", this.SqlIdentifier, this.SqlIdentifierTypeAndSize,
     ((includeKeyIdentificationComment == IncludeKeyIdentificationComment.Yes) && this.KeyIdentificationComment.Trim().Any()) ? " " + this.KeyIdentificationComment : "");
 }
Exemplo n.º 8
0
 /// <summary>
 /// Returns a list of strings that represent a set of SqlParameter constructor declarations in the specified target language,
 /// one for each column.
 /// </summary>
 /// <example>
 /// Assuming the configuration's XmlSystem is set to Linq_XDocument, and TargetLanguage is set to CSharp,
 /// executing ""command.Parameters.Add(" + String.Join(");" + Environment.NewLine + "command.Parameters.Add(", table.Columns.GetTargetLanguageSqlParameterText()) + ");""
 /// on the AdventureWorks2012 Person.Person table will generate this string:
 /// <code>
 /// command.Parameters.Add(new SqlParameter() { ParameterName = "@BusinessEntityID", SqlDbType = System.Data.SqlDbType.Int, Value = BusinessEntityID }  /* primary key 1, foreign key */);
 /// command.Parameters.Add(new SqlParameter() { ParameterName = "@AdditionalContactInfo", SqlDbType = System.Data.SqlDbType.Xml, Value = AdditionalContactInfo.GetSqlXml() });
 /// command.Parameters.Add(new SqlParameter() { ParameterName = "@Demographics", SqlDbType = System.Data.SqlDbType.Xml, Value = Demographics.GetSqlXml() });
 /// command.Parameters.Add(new SqlParameter() { ParameterName = "@EmailPromotion", SqlDbType = System.Data.SqlDbType.Int, Value = EmailPromotion });
 /// command.Parameters.Add(new SqlParameter() { ParameterName = "@FirstName", SqlDbType = System.Data.SqlDbType.NVarChar, Value = FirstName });
 /// command.Parameters.Add(new SqlParameter() { ParameterName = "@LastName", SqlDbType = System.Data.SqlDbType.NVarChar, Value = LastName });
 /// command.Parameters.Add(new SqlParameter() { ParameterName = "@MiddleName", SqlDbType = System.Data.SqlDbType.NVarChar, Value = MiddleName });
 /// command.Parameters.Add(new SqlParameter() { ParameterName = "@ModifiedDate", SqlDbType = System.Data.SqlDbType.DateTime, Value = ModifiedDate });
 /// command.Parameters.Add(new SqlParameter() { ParameterName = "@NameStyle", SqlDbType = System.Data.SqlDbType.Bit, Value = NameStyle });
 /// command.Parameters.Add(new SqlParameter() { ParameterName = "@PersonType", SqlDbType = System.Data.SqlDbType.NChar, Value = PersonType });
 /// command.Parameters.Add(new SqlParameter() { ParameterName = "@rowguid", SqlDbType = System.Data.SqlDbType.UniqueIdentifier, Value = rowguid });
 /// command.Parameters.Add(new SqlParameter() { ParameterName = "@Suffix", SqlDbType = System.Data.SqlDbType.NVarChar, Value = Suffix });
 /// command.Parameters.Add(new SqlParameter() { ParameterName = "@Title", SqlDbType = System.Data.SqlDbType.NVarChar, Value = Title });
 /// </code>
 /// </example>
 /// <param name="includeKeyIdentificationComment">An enum value indicating whether or not to include
 /// a comment identifying the column as a primary and/or foreign key (see example code).</param>
 /// <returns>A <see cref="System.Collections.Generic.List{T}">List&lt;String&gt;</see>.</returns>
 public List <String> GetTargetLanguageSqlParameterText(ColumnType columnType, IncludeKeyIdentificationComment includeKeyIdentificationComment = IncludeKeyIdentificationComment.Yes)
 {
     return
         (this
          .Where(column => (column.ColumnType & columnType) > 0)
          .OrderBy(column => column.Name)
          .Select(column => column.GetTargetLanguageSqlParameterText(includeKeyIdentificationComment))
          .ToList());
 }