Exemple #1
0
        private void WriteMixinProperty(StringBuilder sb, PropertyModel property, string mixinClrName)
        {
            sb.Append("\n");

            // Adds xml summary to each property containing
            // property name and property description
            if (!string.IsNullOrWhiteSpace(property.Name) || !string.IsNullOrWhiteSpace(property.Description))
            {
                sb.Append("\t\t///<summary>\n");

                if (!string.IsNullOrWhiteSpace(property.Description))
                {
                    sb.AppendFormat("\t\t/// {0}: {1}\n", XmlCommentString(property.Name), XmlCommentString(property.Description));
                }
                else
                {
                    sb.AppendFormat("\t\t/// {0}\n", XmlCommentString(property.Name));
                }

                sb.Append("\t\t///</summary>\n");
            }

            WriteGeneratedCodeAttribute(sb, "\t\t");

            if (!property.ModelClrType.IsValueType)
            {
                WriteMaybeNullAttribute(sb, "\t\t", false);
            }
            sb.AppendFormat("\t\t[ImplementPropertyType(\"{0}\")]\n", property.Alias);

            sb.Append("\t\tpublic virtual ");
            WriteClrType(sb, property.ClrTypeName);

            sb.AppendFormat(" {0} => ",
                            property.ClrName);
            WriteNonGenericClrType(sb, GetModelsNamespace() + "." + mixinClrName);
            sb.AppendFormat(".{0}(this, _publishedValueFallback);\n",
                            MixinStaticGetterName(property.ClrName));
        }
Exemple #2
0
        private void WriteProperty(StringBuilder sb, TypeModel type, PropertyModel property, string mixinClrName = null)
        {
            var mixinStatic = mixinClrName != null;

            sb.Append("\n");

            if (property.Errors != null)
            {
                sb.Append("\t\t/*\n");
                sb.Append("\t\t * THIS PROPERTY CANNOT BE IMPLEMENTED, BECAUSE:\n");
                sb.Append("\t\t *\n");
                var first = true;
                foreach (var error in property.Errors)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append("\t\t *\n");
                    }
                    foreach (var s in SplitError(error))
                    {
                        sb.Append("\t\t * ");
                        sb.Append(s);
                        sb.Append("\n");
                    }
                }
                sb.Append("\t\t *\n");
                sb.Append("\n");
            }

            // Adds xml summary to each property containing
            // property name and property description
            if (!string.IsNullOrWhiteSpace(property.Name) || !string.IsNullOrWhiteSpace(property.Description))
            {
                sb.Append("\t\t///<summary>\n");

                if (!string.IsNullOrWhiteSpace(property.Description))
                {
                    sb.AppendFormat("\t\t/// {0}: {1}\n", XmlCommentString(property.Name), XmlCommentString(property.Description));
                }
                else
                {
                    sb.AppendFormat("\t\t/// {0}\n", XmlCommentString(property.Name));
                }

                sb.Append("\t\t///</summary>\n");
            }

            WriteGeneratedCodeAttribute(sb, "\t\t");
            if (!property.ModelClrType.IsValueType)
            {
                WriteMaybeNullAttribute(sb, "\t\t");
            }
            sb.AppendFormat("\t\t[ImplementPropertyType(\"{0}\")]\n", property.Alias);

            if (mixinStatic)
            {
                sb.Append("\t\tpublic virtual ");
                WriteClrType(sb, property.ClrTypeName);
                sb.AppendFormat(" {0} => {1}(this, _publishedValueFallback);\n",
                                property.ClrName, MixinStaticGetterName(property.ClrName));
            }
            else
            {
                sb.Append("\t\tpublic virtual ");
                WriteClrType(sb, property.ClrTypeName);
                sb.AppendFormat(" {0} => this.Value",
                                property.ClrName);
                if (property.ModelClrType != typeof(object))
                {
                    sb.Append("<");
                    WriteClrType(sb, property.ClrTypeName);
                    sb.Append(">");
                }
                sb.AppendFormat("(_publishedValueFallback, \"{0}\");\n",
                                property.Alias);
            }

            if (property.Errors != null)
            {
                sb.Append("\n");
                sb.Append("\t\t *\n");
                sb.Append("\t\t */\n");
            }

            if (!mixinStatic)
            {
                return;
            }

            var mixinStaticGetterName = MixinStaticGetterName(property.ClrName);

            //if (type.StaticMixinMethods.Contains(mixinStaticGetterName)) return;

            sb.Append("\n");

            if (!string.IsNullOrWhiteSpace(property.Name))
            {
                sb.AppendFormat("\t\t/// <summary>Static getter for {0}</summary>\n", XmlCommentString(property.Name));
            }

            WriteGeneratedCodeAttribute(sb, "\t\t");
            if (!property.ModelClrType.IsValueType)
            {
                WriteMaybeNullAttribute(sb, "\t\t", true);
            }
            sb.Append("\t\tpublic static ");
            WriteClrType(sb, property.ClrTypeName);
            sb.AppendFormat(" {0}(I{1} that, IPublishedValueFallback publishedValueFallback) => that.Value",
                            mixinStaticGetterName, mixinClrName);
            if (property.ModelClrType != typeof(object))
            {
                sb.Append("<");
                WriteClrType(sb, property.ClrTypeName);
                sb.Append(">");
            }
            sb.AppendFormat("(publishedValueFallback, \"{0}\");\n",
                            property.Alias);
        }