Пример #1
0
 /// <summary>
 /// Generates the comments for the parameters of the constructor
 /// </summary>
 /// <param name="sb">
 /// The String Builder to add the code to
 /// </param>
 /// <param name="properties">
 /// Properties of the info class
 /// </param>
 protected static void DoConstructorParamComments(StringBuilder sb, PropertyInfoBase[] properties)
 {
     foreach (PropertyInfoBase pi in properties)
     {
         sb.AppendLine(
             "        /// <param name=\"" + Helpers.GetVariableName(pi.Name) + "\">" + pi.Description + "</param>");
     }
 }
Пример #2
0
 /// <summary>
 /// Generate the unit test code for the constructor that takes parameters
 /// </summary>
 /// <param name="sb">string build to append the code to</param>
 /// <param name="className">name of the class</param>
 /// <param name="properties">collection of properties</param>
 /// <param name="baseClassName">name of the base class</param>
 /// <param name="baseClassProperties">collection of base class properties</param>
 protected override void DoConstructorWithParameters(
     StringBuilder sb,
     string className,
     PropertyInfoBase[] properties,
     string baseClassName,
     PropertyInfoBase[] baseClassProperties)
 {
 }
 /// <summary>
 /// Produces code for class specific methods
 /// </summary>
 /// <param name="sb">
 /// The String Builder to add the code to
 /// </param>
 /// <param name="mainNamespaceName">
 /// The main namespace
 /// </param>
 /// <param name="subNamespace">
 /// The sub namespace, if any
 /// </param>
 /// <param name="className">
 /// The class name
 /// </param>
 /// <param name="properties">
 /// Properties of the info class
 /// </param>
 /// <param name="baseClassName">
 /// The name of the base class
 /// </param>
 /// <param name="baseClassProperties">
 /// The properties of the base class
 /// </param>
 protected override void DoClassSpecificMethods(
     StringBuilder sb,
     string mainNamespaceName,
     string subNamespace,
     string className,
     PropertyInfoBase[] properties,
     string baseClassName,
     PropertyInfoBase[] baseClassProperties)
 {
 }
 /// <summary>
 /// Produces code for class specific methods
 /// </summary>
 /// <param name="sb">
 /// The String Builder to add the code to
 /// </param>
 /// <param name="mainNamespaceName">
 /// The main namespace
 /// </param>
 /// <param name="subNamespace">
 /// The sub namespace, if any
 /// </param>
 /// <param name="className">
 /// The class name
 /// </param>
 /// <param name="properties">
 /// Properties of the info class
 /// </param>
 /// <param name="baseClassName">
 /// The name of the base class
 /// </param>
 /// <param name="baseClassProperties">
 /// The properties of the base class
 /// </param>
 protected override void DoClassSpecificMethods(
     StringBuilder sb,
     string mainNamespaceName,
     string subNamespace,
     string className,
     PropertyInfoBase[] properties,
     string baseClassName,
     PropertyInfoBase[] baseClassProperties)
 {
     DoGetDifferencesMethod(sb, mainNamespaceName, subNamespace, className, properties, baseClassProperties);
 }
        /// <summary>
        /// Gets the type for a property
        /// </summary>
        /// <param name="pi">
        /// The property to generate a type for
        /// </param>
        /// <returns>
        /// .NET data type
        /// </returns>
        private string GetPropertyType(PropertyInfoBase pi)
        {
            if (pi == null)
            {
                throw new ArgumentNullException("pi");
            }

            string optional = (pi.Optional && !pi.NetDataType.Equals("string", StringComparison.Ordinal))
                                  ? "?"
                                  : string.Empty;
            return pi.GetCSharpDataTypeDeclaration() + optional;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MockClassGenerationParameters"/> class.
 /// </summary>
 /// <param name="mainNamespaceName">
 /// The main namespace name.
 /// </param>
 /// <param name="subNamespace">
 /// The sub namespace.
 /// </param>
 /// <param name="className">
 /// The class name.
 /// </param>
 /// <param name="properties">
 /// The properties.
 /// </param>
 /// <param name="baseClassProperties">
 /// The base class properties.
 /// </param>
 /// <param name="companyName">
 /// The company name.
 /// </param>
 /// <param name="copyrightBanner">
 /// The copyright banner.
 /// </param>
 /// <param name="copyrightStartYear">
 /// The copyright start year.
 /// </param>
 /// <param name="baseClassName">
 /// The base class name.
 /// </param>
 /// <param name="classRemarks">
 /// The class remarks.
 /// </param>
 public MockClassGenerationParameters(string mainNamespaceName, string subNamespace, string className, PropertyInfoBase[] properties, PropertyInfoBase[] baseClassProperties, string companyName, string[] copyrightBanner, int copyrightStartYear, string baseClassName, string classRemarks)
 {
     this.MainNamespaceName = mainNamespaceName;
     this.SubNamespace = subNamespace;
     this.ClassName = className;
     this.Properties = properties;
     this.BaseClassProperties = baseClassProperties;
     this.CompanyName = companyName;
     this.CopyrightBanner = copyrightBanner;
     this.CopyrightStartYear = copyrightStartYear;
     this.BaseClassName = baseClassName;
     this.ClassRemarks = classRemarks;
 }
        /// <summary>
        /// Generates code for the properties.
        /// </summary>
        /// <param name="sb">The string builder to append code to</param>
        /// <param name="tabCount">The depth count of the tabs</param>
        /// <param name="properties">collection of properties to generate code for</param>
        /// <param name="isBaseInterface">Whether this is the base interface</param>
        protected override void DoProperties(StringBuilder sb, int tabCount, PropertyInfoBase[] properties, bool isBaseInterface)
        {
            var position = 0;
            while (position < properties.Length)
            {
                var property = properties[position];

                sb.AppendLine("{0}/// <summary>Gets a value indicating whether there is a difference for {1}</summary>", Helpers.GetTabs(tabCount), property.Description);
                sb.AppendLine("{0}bool {1} {{ get; }}", Helpers.GetTabs(tabCount), property.Name);

                if (position <= properties.Length)
                {
                    sb.AppendLine(string.Empty);
                }

                position++;
            }
        }
        /// <summary>
        /// Generates code for the properties.
        /// </summary>
        /// <param name="sb">The string builder to append code to</param>
        /// <param name="tabCount">The depth count of the tabs</param>
        /// <param name="properties">collection of properties to generate code for</param>
        /// <param name="isBaseInterface">Whether this is the base interface</param>
        protected override void DoProperties(StringBuilder sb, int tabCount, PropertyInfoBase[] properties, bool isBaseInterface)
        {
            var position = 0;
            while (position < properties.Length)
            {
                var property = properties[position];

                sb.AppendLine("{0}/// <summary>Gets {1}</summary>", Helpers.GetTabs(tabCount), property.Description);
                sb.AppendLine("{0}{1} {2} {{ get; }}", Helpers.GetTabs(tabCount), this.GetPropertyType(property), property.Name);

                if (position <= properties.Length)
                {
                    sb.AppendLine(string.Empty);
                }

                position++;
            }
        }
Пример #9
0
        /// <summary>
        /// Generates the code that gets the row data for reading a data reader into a strongly typed class
        /// </summary>
        /// <param name="generatedCode">
        /// The String Builder to add the code to
        /// </param>
        /// <param name="properties">
        /// The collection of properties for the class
        /// </param>
        protected static void DoDifferenceGetRowData(StringBuilder generatedCode, PropertyInfoBase[] properties)
        {
            if (generatedCode == null)
            {
                throw new ArgumentNullException(nameof(generatedCode));
            }

            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            foreach (var pi in properties.Where(pi => pi.SqlDataReaderType != null))
            {
                generatedCode.AppendLine("            bool " + Helpers.GetVariableName("row" + pi.Name) + " = false;");
                generatedCode.AppendLine("            if (" + Helpers.GetVariableName(pi.Name) + "Ordinal > -1)");
                generatedCode.AppendLine("            {");
                generatedCode.AppendLine(
                    "                " + Helpers.GetVariableName("row" + pi.Name) + " = dataReader.GetBoolean("
                    + Helpers.GetVariableName(pi.Name) + "Ordinal);");
                generatedCode.AppendLine("            }");
                generatedCode.AppendLine(string.Empty);
            }
        }
Пример #10
0
 /// <summary>
 /// Gets the type to be used for a parameter in the constructor
 /// </summary>
 /// <param name="propertyInfo">
 /// the property
 /// </param>
 /// <returns>
 /// the constructor parameter type
 /// </returns>
 protected abstract string GetConstructorParameterType(PropertyInfoBase propertyInfo);
Пример #11
0
        /// <summary>
        /// Builds the Properties Region
        /// </summary>
        /// <param name="sb">
        /// The String Builder to add the code to
        /// </param>
        /// <param name="properties">
        /// The collection of properties for the class
        /// </param>
        /// <param name="baseClassProperties">
        /// The properties of the base class
        /// </param>
        protected virtual void DoPropertiesRegion(StringBuilder sb, PropertyInfoBase[] properties, PropertyInfoBase[] baseClassProperties)
        {
            sb.AppendLine("        #region properties");

            int i = 1;
            foreach (PropertyInfoBase pi in properties)
            {
                sb.AppendLine("        /// <summary>");
                sb.AppendLine("        /// Gets or sets " + pi.Description);
                sb.AppendLine("        /// </summary>");

                sb.AppendLine(
                    "        [System.Diagnostics.CodeAnalysis.SuppressMessage(\"StyleCop.CSharp.ReadabilityRules\", \"SA1121:UseBuiltInTypeAlias\", Justification = \"Reviewed. Suppression is OK here.\")]");

                // WCF Data Member Information
                string required = "IsRequired = " + (!pi.Optional).ToString().ToLower(CultureInfo.InvariantCulture);
                string order = ", Order = " + i++;

                string dataMemberAttributes = "(" + required + order + ")";
                sb.AppendLine("        [System.Runtime.Serialization.DataMember" + dataMemberAttributes + "]");

                // Data Annotation Information
                if (!pi.Optional)
                {
                    sb.AppendLine("        [System.ComponentModel.DataAnnotations.Required]");
                }

                var propertySpecificAnnotations = pi.GetDataAnnotations();
                if (!string.IsNullOrWhiteSpace(propertySpecificAnnotations))
                {
                    sb.AppendLine(propertySpecificAnnotations);
                }

                sb.AppendLine("        public " + this.GetPropertyType(pi) + " " + pi.Name);
                sb.AppendLine("        {");
                if (pi.GenerateAutoProperty)
                {
                    sb.AppendLine("            get;");
                    sb.AppendLine("            set;");
                }
                else
                {
                    sb.AppendLine("            get");
                    sb.AppendLine("            {");
                    sb.AppendLine("                return this." + Helpers.GetVariableName(pi.Name) + ";");
                    sb.AppendLine("            }");
                    sb.AppendLine(string.Empty);
                    this.OnDoPropertyMutator(sb, pi);
                }

                sb.AppendLine("        }");
                sb.AppendLine(string.Empty);
            }

            this.OnDoClassSpecificProperties(sb, properties);

            sb.AppendLine("        #endregion");
            sb.AppendLine(string.Empty);
        }
Пример #12
0
        /// <summary>
        /// Builds the methods required by the IComparable interface
        /// </summary>
        /// <param name="sb">
        /// StringBuilder to add the code to
        /// </param>
        /// <param name="className">
        /// Name of the class
        /// </param>
        /// <param name="properties">
        /// Collection of properties in the class
        /// </param>
        /// <param name="baseClassName">
        /// Base class name, if not using the default
        /// </param>
        /// <param name="baseClassProperties">
        /// Properties in the base class, if any
        /// </param>
        protected virtual void DoIComparableRegion(
            StringBuilder sb, string className, PropertyInfoBase[] properties, string baseClassName, PropertyInfoBase[] baseClassProperties)
        {
            sb.AppendLine("        #region IComparable methods");
            sb.AppendLine(string.Empty);
            sb.AppendLine(Helpers.GetAutoGeneratedWarning());
            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// Compares the current instance with another object of the same type.");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        /// <param name=\"other\">");
            sb.AppendLine("        /// The instance to compare to");
            sb.AppendLine("        /// </param>");
            sb.AppendLine("        /// <returns>");
            sb.AppendLine("        /// 0 if equal, otherwise non zero");
            sb.AppendLine("        /// </returns>");
            string modifier = (!string.IsNullOrWhiteSpace(baseClassName) && baseClassProperties != null
                               && baseClassProperties.Length > 0)
                                  ? null
                                  : "override ";
            sb.AppendLine(
                "        public " + modifier + "int CompareTo(" + className + this.GetClassSuffix() + " other)");
            sb.AppendLine("        {");
            sb.AppendLine("            if (other == null)");
            sb.AppendLine("            {");
            sb.AppendLine("                throw new System.ArgumentNullException(\"other\");");
            sb.AppendLine("            }");
            sb.AppendLine(string.Empty);

            bool checkResultDeclared = false;

            if (!string.IsNullOrWhiteSpace(baseClassName) && baseClassProperties != null
                && baseClassProperties.Length > 0)
            {
                sb.AppendLine(string.Empty);
                sb.AppendLine("        var checkResult = base.CompareTo(other);");
                sb.AppendLine("        if (checkResult != 0)");
                sb.AppendLine("        {");
                sb.AppendLine("            return checkResult;");
                sb.AppendLine("        }");
                sb.AppendLine(string.Empty);

                checkResultDeclared = true;
            }

            this.OnDoCompareToProperties(sb, properties, baseClassProperties, checkResultDeclared);

            sb.AppendLine("            return 0;");
            sb.AppendLine("        }");
            sb.AppendLine(string.Empty);
            sb.AppendLine("        #endregion");
        }
Пример #13
0
        /// <summary>
        /// Builds the Fields Region
        /// </summary>
        /// <param name="sb">
        /// The String Builder to add the code to
        /// </param>
        /// <param name="properties">
        /// The collection of properties for the class
        /// </param>
        protected virtual void DoFieldsRegion(StringBuilder sb, PropertyInfoBase[] properties)
        {
            sb.AppendLine("        #region fields");

            foreach (PropertyInfoBase pi in properties.Where(pi => !pi.GenerateAutoProperty))
            {
                sb.AppendLine("            /// <summary>");
                sb.AppendLine("            /// " + pi.Description);
                sb.AppendLine("            /// </summary>");
                sb.AppendLine(
                    "            [System.Diagnostics.CodeAnalysis.SuppressMessage(\"StyleCop.CSharp.ReadabilityRules\", \"SA1121:UseBuiltInTypeAlias\", Justification = \"Reviewed. Suppression is OK here.\")]");
                this.OnDoFieldItem(sb, pi);
                sb.AppendLine(string.Empty);
            }

            sb.AppendLine("        #endregion");
            sb.AppendLine(string.Empty);
        }
Пример #14
0
        /// <summary>
        /// Generates the parameters for the constructor
        /// </summary>
        /// <param name="sb">
        /// The String Builder to add the code to
        /// </param>
        /// <param name="properties">
        /// Properties of the info class
        /// </param>
        /// <param name="baseClassName">
        /// The name of the base class
        /// </param>
        /// <param name="baseClassProperties">
        /// The properties of the base class
        /// </param>
        protected void DoConstructorParameters(
            StringBuilder sb, PropertyInfoBase[] properties, string baseClassName, PropertyInfoBase[] baseClassProperties)
        {
            int counter = 0;
            if (string.IsNullOrWhiteSpace(baseClassName) == false && baseClassProperties != null
                && baseClassProperties.Length > 0)
            {
                while (counter < baseClassProperties.Length)
                {
                    sb.Append(
                        "            " + this.GetConstructorParameterType(baseClassProperties[counter]) + " "
                        + Helpers.GetVariableName(baseClassProperties[counter].Name) + ",");
                    counter++;
                }

                counter = 0;
            }

            while (counter < properties.Length)
            {
                sb.Append(
                    "            " + this.GetConstructorParameterType(properties[counter]) + " "
                    + Helpers.GetVariableName(properties[counter].Name));
                counter++;
                sb.AppendLine(counter < properties.Length ? "," : ")");
            }
        }
        /// <summary>
        /// Gets the value of the property when converting to a string array.
        /// </summary>
        /// <param name="pi">
        /// property information
        /// </param>
        /// <returns>
        /// the value of the property when converting to a string array
        /// </returns>
        protected override string GetValueForToStringArray(PropertyInfoBase pi)
        {
            if (pi == null)
            {
                throw new ArgumentNullException("pi");
            }

            return pi.Name + " ? \"1\" : \"0\"";
        }
        /// <summary>
        /// Generates the code for comparing properties in the CompareTo method
        /// </summary>
        /// <param name="sb">
        /// StringBuilder to add the code to
        /// </param>
        /// <param name="properties">
        /// The property to generate code for
        /// </param>
        /// <param name="baseClassProperties">
        /// Properties in the base class, if any
        /// </param>
        /// <param name="checkResultDeclared">
        /// Whether the check result variable has been declared yet
        /// </param>
        protected override void OnDoCompareToProperties(
            StringBuilder sb, PropertyInfoBase[] properties, PropertyInfoBase[] baseClassProperties, bool checkResultDeclared)
        {
            int returnResultCounter = (baseClassProperties == null) ? 1 : baseClassProperties.Length + 1;

            foreach (PropertyInfoBase pi in properties)
            {
                sb.Append("            ");
                if (!checkResultDeclared)
                {
                    sb.Append("int ");
                }

                sb.AppendLine("            checkResult = " + pi.Name + ".CompareTo(other." + pi.Name + ");");
                sb.AppendLine("            if(checkResult != 0)");
                sb.AppendLine("            {");
                sb.AppendLine(
                    "                return (checkResult > 0) ? " + returnResultCounter + " : -" + returnResultCounter
                    + ";");
                sb.AppendLine("            }");
                sb.AppendLine(string.Empty);

                if (!checkResultDeclared)
                {
                    checkResultDeclared = true;
                }

                returnResultCounter++;
            }
        }
Пример #17
0
 /// <summary>
 /// Gets the value of the property when converting to a string array.
 /// </summary>
 /// <param name="pi">
 /// property information
 /// </param>
 /// <returns>
 /// the value of the property when converting to a string array
 /// </returns>
 protected abstract string GetValueForToStringArray(PropertyInfoBase pi);
 /// <summary>
 /// Builds the Fields Region
 /// </summary>
 /// <param name="sb">
 /// The String Builder to add the code to
 /// </param>
 /// <param name="properties">
 /// The collection of properties for the class
 /// </param>
 protected override void DoFieldsRegion(StringBuilder sb, PropertyInfoBase[] properties)
 {
     // no op
 }
        /// <summary>
        /// Generates the mutator for the property
        /// </summary>
        /// <param name="sb">
        /// The String Builder to add the code to
        /// </param>
        /// <param name="pi">
        /// The property to generate the mutator for
        /// </param>
        protected override void OnDoPropertyMutator(StringBuilder sb, PropertyInfoBase pi)
        {
            if (sb == null)
            {
                throw new ArgumentNullException("sb");
            }

            if (pi == null)
            {
                throw new ArgumentNullException("pi");
            }

            sb.AppendLine("            set");
            sb.AppendLine("            {");
            sb.AppendLine("                _" + Helpers.GetVariableName(pi.Name) + " = value;");
            sb.AppendLine("            }");
        }
        /// <summary>
        /// Generates the field code for a property member
        /// </summary>
        /// <param name="sb">
        /// The String Builder to add the code to
        /// </param>
        /// <param name="pi">
        /// The property to generate a field for
        /// </param>
        protected override void OnDoFieldItem(StringBuilder sb, PropertyInfoBase pi)
        {
            if (sb == null)
            {
                throw new ArgumentNullException("sb");
            }

            if (pi == null)
            {
                throw new ArgumentNullException("pi");
            }

            sb.AppendLine("            bool _" + Helpers.GetVariableName(pi.Name) + ";");
        }
Пример #21
0
 /// <summary>
 /// Gets the type for a property
 /// </summary>
 /// <param name="pi">
 /// The property to generate a type for
 /// </param>
 /// <returns>
 /// .NET data type
 /// </returns>
 protected abstract string GetPropertyType(PropertyInfoBase pi);
Пример #22
0
 /// <summary>
 /// Generates the code for comparing properties in the CompareTo method
 /// </summary>
 /// <param name="sb">
 /// StringBuilder to add the code to
 /// </param>
 /// <param name="properties">
 /// The properties to generate code for
 /// </param>
 /// <param name="baseClassProperties">
 /// Properties in the base class, if any
 /// </param>
 /// <param name="checkResultDeclared">
 /// Whether the check result variable has been declared yet
 /// </param>
 protected abstract void OnDoCompareToProperties(
     StringBuilder sb, PropertyInfoBase[] properties, PropertyInfoBase[] baseClassProperties, bool checkResultDeclared);
Пример #23
0
 /// <summary>
 /// Generates the setter for the property
 /// </summary>
 /// <param name="sb">
 /// The String Builder to add the code to
 /// </param>
 /// <param name="pi">
 /// The property to generate the setter for
 /// </param>
 protected abstract void OnDoPropertyMutator(StringBuilder sb, PropertyInfoBase pi);
        /// <summary>
        /// Does any class specific properties. For example the count property on the difference class
        /// </summary>
        /// <param name="sb">
        /// The String Builder to add the code to
        /// </param>
        /// <param name="properties">
        /// The collection of properties for the class
        /// </param>
        protected override void OnDoClassSpecificProperties(StringBuilder sb, PropertyInfoBase[] properties)
        {
            if (sb == null)
            {
                throw new ArgumentNullException("sb");
            }

            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            sb.AppendLine("            /// <summary>");
            sb.AppendLine("            /// Gets the number of properties that are different");
            sb.AppendLine("            /// </summary>");
            sb.AppendLine("            /// <return>");
            sb.AppendLine("            /// the number of properties that are different");
            sb.AppendLine("            /// </return>");
            sb.AppendLine("            public override int Count");
            sb.AppendLine("            {");
            sb.AppendLine("                get");
            sb.AppendLine("                {");
            sb.AppendLine("                    return");

            sb.AppendLine("                    (" + properties[0].Name + " ? 1 : 0)");
            for (int i = 1; i < properties.Length; i++)
            {
                sb.AppendLine("                    + (" + properties[i].Name + " ? 1 : 0)");
            }

            sb.AppendLine("                    ;");
            sb.AppendLine("                }");
            sb.AppendLine("            }");
            sb.AppendLine(string.Empty);
        }
Пример #25
0
 /// <summary>
 /// Does any class specific properties. For example the count property on the difference class
 /// </summary>
 /// <param name="sb">
 /// The String Builder to add the code to
 /// </param>
 /// <param name="properties">
 /// The collection of properties for the class
 /// </param>
 protected abstract void OnDoClassSpecificProperties(StringBuilder sb, PropertyInfoBase[] properties);
Пример #26
0
        /// <summary>
        /// The do constructor method.
        /// </summary>
        /// <param name="sb">
        /// The String Builder to add the code to
        /// </param>
        /// <param name="className">
        /// The class name
        /// </param>
        /// <param name="properties">
        /// Properties of the info class
        /// </param>
        /// <param name="baseClassName">
        /// The name of the base class
        /// </param>
        /// <param name="baseClassProperties">
        /// The properties of the base class
        /// </param>
        protected virtual void DoConstructorMethod(
            StringBuilder sb, string className, PropertyInfoBase[] properties, string baseClassName, PropertyInfoBase[] baseClassProperties)
        {
            // Default Constructor
            sb.AppendLine(Helpers.GetAutoGeneratedWarning());
            sb.AppendLine("        /// <summary>");
            sb.AppendLine(
                "        /// Initializes a new instance of the <see cref=\"" + className + this.GetClassSuffix()
                + "\"/> class.");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public " + className + this.GetClassSuffix() + "()");
            sb.AppendLine("        {");
            sb.AppendLine("        }");
            sb.AppendLine(string.Empty);

            // Copy Constructor
            sb.AppendLine("        /// <summary>");
            sb.AppendLine(
                "        /// Initializes a new instance of the <see cref=\"" + className + this.GetClassSuffix()
                + "\"/> class.");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        /// <param name=\"other\">");
            sb.AppendLine("        /// Object to copy");
            sb.AppendLine("        /// </param>");
            sb.AppendLine(
                "        public " + className + this.GetClassSuffix() + "(" + className + this.GetClassSuffix()
                + " other)");
            sb.AppendLine("        {");
            sb.AppendLine("            if (other == null)");
            sb.AppendLine("            {");
            sb.AppendLine("                throw new System.ArgumentNullException(\"other\");");
            sb.AppendLine("            }");
            sb.AppendLine(string.Empty);

            foreach (PropertyInfoBase pi in properties)
            {
                sb.AppendLine("            this." + pi.Name + " = other." + pi.Name + ";");
            }

            sb.AppendLine("        }");

            // Constructor
            sb.AppendLine(string.Empty);
            sb.AppendLine(Helpers.GetAutoGeneratedWarning());
            sb.AppendLine("        /// <summary>");
            sb.AppendLine(
                "        /// Initializes a new instance of the <see cref=\"" + className + this.GetClassSuffix()
                + "\"/> class.");
            sb.AppendLine("        /// </summary>");

            if (string.IsNullOrWhiteSpace(baseClassName) == false && baseClassProperties != null
                && baseClassProperties.Length > 0)
            {
                DoConstructorParamComments(sb, baseClassProperties);
            }

            DoConstructorParamComments(sb, properties);

            sb.AppendLine("        public " + className + this.GetClassSuffix() + "(");

            this.DoConstructorParameters(sb, properties, baseClassName, baseClassProperties);

            if (string.IsNullOrWhiteSpace(baseClassName) == false && baseClassProperties != null
                && baseClassProperties.Length > 0)
            {
                sb.AppendLine("            : base(");

                int counter = 0;
                while (counter < baseClassProperties.Length)
                {
                    sb.Append("                " + Helpers.GetVariableName(baseClassProperties[counter].Name));
                    counter++;
                    sb.AppendLine(counter < baseClassProperties.Length ? "," : ")");
                }
            }

            sb.AppendLine("            {");

            foreach (PropertyInfoBase pi in properties)
            {
                sb.AppendLine("            this." + pi.Name + " = " + Helpers.GetVariableName(pi.Name) + ";");
            }

            sb.AppendLine("        }");
            sb.AppendLine(string.Empty);
        }
Пример #27
0
 /// <summary>
 /// Generates the field code for a property member
 /// </summary>
 /// <param name="sb">
 /// The String Builder to add the code to
 /// </param>
 /// <param name="pi">
 /// The property to generate a field for
 /// </param>
 protected abstract void OnDoFieldItem(StringBuilder sb, PropertyInfoBase pi);
 /// <summary>
 /// Gets the type for a property
 /// </summary>
 /// <param name="pi">
 /// The property to generate a type for
 /// </param>
 /// <returns>
 /// .NET data type
 /// </returns>
 protected override string GetPropertyType(PropertyInfoBase pi)
 {
     return "bool";
 }
Пример #29
0
        /// <summary>
        /// Generates the code for the our methods region
        /// </summary>
        /// <param name="sb">
        /// StringBuilder to add the code to
        /// </param>
        /// <param name="mainNamespaceName">
        /// The main namespace
        /// </param>
        /// <param name="subNamespace">
        /// The sub namespace, if any
        /// </param>
        /// <param name="className">
        /// The class name
        /// </param>
        /// <param name="properties">
        /// Properties of the info class
        /// </param>
        /// <param name="baseClassName">
        /// The name of the base class
        /// </param>
        /// <param name="baseClassProperties">
        /// The properties of the base class
        /// </param>
        private void DoOurMethodsRegion(
            StringBuilder sb,
            string mainNamespaceName,
            string subNamespace,
            string className,
            PropertyInfoBase[] properties,
            string baseClassName,
            PropertyInfoBase[] baseClassProperties)
        {
            sb.AppendLine("    #region our methods");
            sb.AppendLine(string.Empty);

            this.DoGetHashCodeMethod(sb, properties, baseClassProperties);

            sb.AppendLine(string.Empty);

            sb.AppendLine(string.Empty);

            sb.AppendLine(string.Empty);

            this.DoClassSpecificMethods(
                sb, mainNamespaceName, subNamespace, className, properties, baseClassName, baseClassProperties);

            sb.AppendLine("        #endregion");
        }
Пример #30
0
        protected static void DoOdataVocabulariesMethod(
            StringBuilder sb,
            string mainNamespaceName,
            string subNamespace,
            string className,
            PropertyInfoBase[] properties,
            PropertyInfoBase[] baseClassProperties)
        {
            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// Gets the CDSL that defines the OData Vocabularies for this class");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine(
                "        public static " + (baseClassProperties != null ? "new " : string.Empty)
                + "System.Xml.XmlReader GetOdataVocabularies()");
            sb.AppendLine("        {");

            string fullNamespace = mainNamespaceName
                                   + (!string.IsNullOrWhiteSpace(subNamespace) ? "." + subNamespace : null);

            foreach (PropertyInfoBase property in properties)
            {
                sb.AppendLine("            // " + property.Name);
                sb.AppendLine(string.Empty);
            }

            sb.AppendLine("        var schema = new XElement(");
            sb.AppendLine("            \"Schema\",");
            sb.AppendLine("            new XAttribute(\"Namespace\", \"" + fullNamespace + "\"),");
            sb.AppendLine("            new XAttribute(\"xmlns\", \"http://schemas.microsoft.com/ado/2009/11/edm\"),");
            sb.AppendLine("            // using directive");
            sb.AppendLine("            new XElement(");
            sb.AppendLine("                \"Using\",");
            sb.AppendLine("                new XAttribute(\"Namespace\", \"Org.OData.Validation.V1\"),");
            sb.AppendLine("                new XAttribute(\"Alias\", \"Validation\"),");

            string fullClassName = fullNamespace + "." + className;
            if (baseClassProperties != null && baseClassProperties.Any())
            {
                for (int position = 0; position < baseClassProperties.Count() - 1; position++)
                {
                    sb.AppendLine("                new XElement(\"Annotations\",");
                    sb.AppendLine(
                        "                    new XAttribute(\"Target\", \"" + fullClassName + "/"
                        + baseClassProperties[position].Name + "\")),");
                }

                sb.AppendLine("                new XElement(");
                sb.AppendLine("                    \"Annotations\",");
                sb.AppendLine(
                    "                    new XAttribute(\"Target\", \"" + fullClassName + "/"
                    + baseClassProperties[baseClassProperties.Count() - 1].Name + "\")),");
            }

            for (int position = 0; position < properties.Count() - 1; position++)
            {
                sb.AppendLine("                new XElement(");
                sb.AppendLine("                    \"Annotations\",");
                sb.AppendLine(
                    "                    new XAttribute(\"Target\", \"" + fullClassName + "/"
                    + properties[position].Name + "\")),");
            }

            sb.AppendLine("                new XElement(");
            sb.AppendLine("                    \"Annotations\",");
            sb.AppendLine(
                "                    new XAttribute(\"Target\", \"" + fullClassName + "/"
                + properties[properties.Count() - 1].Name + "\"))));");
            sb.AppendLine(string.Empty);
            sb.AppendLine("        Debug.Assert(schema.Document != null, \"schema.Document != null\");");
            sb.AppendLine("        return schema.Document.CreateReader();");
            sb.AppendLine("        }");
        }