Пример #1
0
            protected override void VisitType(VBType node)
            {
                Prefix("T:");
                VisitBaseQualifier(node.ContainingNamespace);
                VisitBaseQualifier(node.ContainingType);
                if (node.IsPrimitive)
                {
                    Code.Append(node.TypeCode.ToString());
                    return;
                }
                Code.Append(node.Name);

                if (inCoreType)
                {
                    if (node.TypeParameters.Count > 0)
                    {
                        Code.Append("`" + node.TypeParameters.Count);
                    }
                }
                else
                {
                    // If we're in a parameter, include its concrete type arguments
                    if (node.TypeArguments.Count > 0)
                    {
                        Code.Append("{");
                        VisitCommaList(node.TypeArguments);
                        Code.Append("}");
                    }
                }
            }
Пример #2
0
 void Prefix(string prefix)
 {
     if (Code.ToString().Length == 0)
     {
         Code.Append(prefix);
     }
 }
Пример #3
0
            protected override void VisitMember(VBMember node)
            {
                VisitBaseQualifier(node.ContainingType);
                inCoreType = false;

                string text;

                if (node.IsConstructor)
                {
                    text = "ctor";                              // IndexId uses "ctor", not "#ctor"
                }
                else if (node.IsProperty && node.IsDefault)
                {
                    text = "Item";                      // TODO: Test indexer
                }
                else
                {
                    text = node.Name;
                    int count = node.TypeParameters.Count;
                    if (count > 0)
                    {
                        text = text + "``" + count;
                    }
                }
                Code.Append(text);
                if (node.Parameters.Any() && !node.IsEvent)                     // Events cannot be overloaded, so they don't need signatures
                {
                    VisitParameters(node.Parameters);
                }
            }
Пример #4
0
 public override void GenerateCreateUsingAllColumns()
 {
     Code.Append("\t\tpublic void Create(");
     foreach (var column in Table.Columns)
     {
         if (column.Value.ManagedType.IsValueType)
         {
             Code.Append(column.Value + "? " + column.Value.FieldName + ", ");
         }
         else
         {
             Code.Append(column.Value + " " + column.Value.FieldName + ", ");
         }
     }
     Code.Remove(Code.Length - 2, 2);
     Code.Append(")\n");
     Code.AppendLine("\t\t{");
     Code.AppendLine("\t\t\tCreate(new " + Table.ClassName);
     Code.AppendLine("\t\t\t{");
     foreach (var column in Table.Columns)
     {
         Code.AppendLine("\t\t\t\t" + column.Value.FieldName + " = " + column.Value.FieldName + ", ");
     }
     Code.Remove(Code.Length - 2, 2);
     Code.AppendLine("\n\t\t\t});");
     Code.AppendLine("\t\t}");
     Code.AppendLine();
 }
        public override void GenerateCreateUsingAllColumns()
        {
            Code.AppendLine("\t\t#region INSERT " + Table.Name + " by fields");
            Code.AppendLine();

            GenerateXmlDoc(2, "Inserts a new record to the table specifying all fields", Table.Columns.Select(column => new KeyValuePair <string, string>(column.Value.FieldName, column.Value.FieldName + " value")).ToArray());
            Code.Append("\t\tpublic void Create(");
            foreach (var column in Table.Columns)
            {
                if (column.Value.ManagedType.IsValueType)
                {
                    Code.Append(column.Value + "? " + column.Value.FieldName + ", ");
                }
                else
                {
                    Code.Append(column.Value + " " + column.Value.FieldName + ", ");
                }
            }
            Code.Remove(Code.Length - 2, 2);
            Code.Append(")\n");
            Code.AppendLine("\t\t{");

            Code.AppendLine("\t\t\tthrow new System.NotImplementedException();");

            Code.AppendLine("\t\t}");
            Code.AppendLine();
            Code.AppendLine("\t\t#endregion");
            Code.AppendLine();
        }
Пример #6
0
 protected override void VisitParameter(VBParameter node)
 {
     VisitIfNotNull(node.ParameterType);
     if (node.IsByRef)
     {
         Code.Append("@");
     }
 }
Пример #7
0
 protected override void VisitNamespace(VBNamespace node)
 {
     if (!node.Name.Equals("My", StringComparison.OrdinalIgnoreCase))
     {
         VisitBaseQualifier(node.ContainingNamespace);
     }
     Code.Append(node.Name);
 }
Пример #8
0
 protected void AppendLine()
 {
     if (SkipNewLinesLevel == 0)
     {
         Code.AppendLine();
     }
     else if (ReplaceNewLineWithSpace)
     {
         Code.Append(" ");
     }
 }
Пример #9
0
 protected void AppendIndent()
 {
     if (SkipIndentCounter > 0)
     {
         SkipIndentCounter--;
     }
     else if (SkipNewLinesLevel == 0)
     {
         Code.Append(new string(' ', IndentLevel * IndentSize));
     }
 }
Пример #10
0
 protected override void VisitTypeParameter(VBType node)
 {
     // Method type parameters get two backticks
     if (node.ContainingType == null)
     {
         Code.Append("``" + node.TypeParameterPosition);
     }
     else
     {
         // Type type parameter indices include parameters from the type's outer types.
         Code.Append("`" + (PreTypeParamCount(node.ContainingType) + node.TypeParameterPosition).ToString());
     }
 }
        public override void VisitMethodParameters(MethodParameters mp)
        {
            Code.Append("(");

            var last = mp.Parameters.LastOrDefault();

            foreach (var pd in mp.Parameters)
            {
                pd.Accept(this);
                if (pd != last)
                {
                    Code.Append(", ");
                }
            }

            Code.Append(")");
        }
Пример #12
0
 protected override void VisitArray(VBType node)
 {
     VisitIfNotNull(node.ElementType);
     if (node.Rank == 1)
     {
         Code.Append("[]");
         return;
     }
     Code.Append("[");
     for (int i = 0; i < node.Rank; i++)
     {
         if (i > 0)
         {
             Code.Append(",");
         }
         Code.Append("0:");                          // I think VBType can only be an SZArray
     }
     Code.Append("]");
 }
        public override void GenerateCreateIgnoringPrimaryKey()
        {
            if (string.IsNullOrEmpty(Table.PrimaryKeyColumnName))
            {
                return;
            }

            Code.AppendLine("\t\t#region INSERT Ignoring Primary Key");
            Code.AppendLine();

            GenerateXmlDoc(2, "Inserts a new record to the table without specifying the primary key", (from column in Table.Columns where column.Value.Name != Table.PrimaryKeyColumnName select new KeyValuePair <string, string>(column.Value.FieldName, column.Value.FieldName + " value")).ToArray());
            Code.Append("\t\tpublic void Create(");
            foreach (var column in Table.Columns)
            {
                if (column.Value.Name == Table.PrimaryKeyColumnName)
                {
                    continue;
                }
                if (column.Value.ManagedType.IsValueType)
                {
                    Code.Append(column.Value + "? " + column.Value.FieldName + ", ");
                }
                else
                {
                    Code.Append(column.Value + " " + column.Value.FieldName + ", ");
                }
            }
            Code.Remove(Code.Length - 2, 2);
            Code.Append(")");
            Code.AppendLine();
            Code.AppendLine("\t\t{");

            Code.AppendLine("\t\t\tthrow new System.NotImplementedException();");

            Code.AppendLine("\t\t}");
            Code.AppendLine();
            Code.AppendLine("\t\t#endregion");
            Code.AppendLine();
        }
Пример #14
0
 public override void GenerateCreateIgnoringPrimaryKey()
 {
     Code.Append("\t\tpublic void Create(");
     foreach (var column in Table.Columns)
     {
         if (column.Value.Name == Table.PrimaryKeyColumnName)
         {
             continue;
         }
         if (column.Value.ManagedType.IsValueType)
         {
             Code.Append(column.Value + "? " + column.Value.FieldName + ", ");
         }
         else
         {
             Code.Append(column.Value + " " + column.Value.FieldName + ", ");
         }
     }
     Code.Remove(Code.Length - 2, 2);
     Code.Append(")");
     Code.AppendLine();
     Code.AppendLine("\t\t{");
     Code.AppendLine("\t\t\tCreate(new " + Table.ClassName);
     Code.AppendLine("\t\t\t{");
     foreach (var column in Table.Columns)
     {
         if (column.Value.Name == Table.PrimaryKeyColumnName)
         {
             continue;
         }
         Code.AppendLine("\t\t\t\t" + column.Value.FieldName + " = " + column.Value.FieldName + ", ");
     }
     Code.Remove(Code.Length - 2, 2);
     Code.AppendLine("\n\t\t\t});");
     Code.AppendLine("\t\t}");
     Code.AppendLine();
 }
        /// <summary>
        /// Create the beginning of the source code
        /// </summary>
        private void InitCode(GraphicVisual visual)
        {
            indent1 = SourceFormatterHelper.GetSourceIndent(1);
            MethodBodyIndent = SourceFormatterHelper.GetSourceIndent(2);
            var indent2 = MethodBodyIndent;

            if (normalizeAspect != NormalizeGeometrySourceAspect.Individual)
            {
                string scaleVariableName = string.Empty;
                string opositeVariableName = string.Empty;
                string methodName = string.Empty;
                string opositeMethodName = string.Empty;

                switch (normalizeAspect)
                {
                    case NormalizeGeometrySourceAspect.Width:
                        scaleVariableName = "width";
                        opositeVariableName = "height";
                        methodName = "CreateFromWidth";
                        opositeMethodName = "CreateFromHeight";
                        break;

                    case NormalizeGeometrySourceAspect.Height:
                        scaleVariableName = "height";
                        opositeVariableName = "width";
                        methodName = "CreateFromHeight";
                        opositeMethodName = "CreateFromWidth";
                        break;
                }

                // class header 
                Code.AppendLine("/// <summary>");
                Code.AppendLine("/// Create a geometry.");
                Code.AppendLine("/// The origin is normalized to 0/0.");
                Code.AppendLine(string.Format("/// The {0} is normalized to 1.0, the aspect ratio is kept", scaleVariableName));
                Code.AppendLine(string.Format("/// from the original stream, which means the {0} might be", opositeVariableName));
                Code.AppendLine("/// greater than 1 (depending on the aspect ratio).");
                Code.AppendLine("/// </summary>");
                Code.AppendLine("private static class xyzGeometry");
                Code.AppendLine("{");

                // the aspect ratio constant
                Code.AppendLine($"{indent1}/// <summary>");
                Code.AppendLine($"{indent1}/// The aspect ratio (height/width) of the geometry");
                Code.AppendLine($"{indent1}/// </summary>");
                Code.AppendLine(string.Format("{0}public const double AspectRatio = {1};", indent1, aspectRatio.ToString("G", CultureInfo.InvariantCulture)));
                Code.AppendLine();

                // the creation method for the opposite
                string offsetMethodParameterString = string.Empty;
                string offsetParameterString = string.Empty;

                if (includeOffset)
                {
                    offsetMethodParameterString = "double left, double top, ";
                    offsetParameterString = "left, top, ";
                }

                Code.AppendLine($"{indent1}/// <summary>");
                Code.AppendLine($"{indent1}/// Create the geometry from the given {opositeVariableName} and keep the original aspect ratio");
                Code.AppendLine($"{indent1}/// </summary>");
                Code.AppendLine(string.Format("{0}/// <param name=\"{1}\">the {1} in WPF units</param>", indent1, opositeVariableName));
                Code.AppendLine($"{indent1}/// <returns>Returns the geometry</returns>");

                Code.AppendLine($"{indent1}public static Geometry {opositeMethodName}({offsetMethodParameterString}double {opositeVariableName})");
                Code.AppendLine($"{indent1}{{");

                if (normalizeAspect == NormalizeGeometrySourceAspect.Width)
                {
                    Code.AppendLine($"{indent2}return {methodName}({offsetParameterString}{opositeVariableName} / AspectRatio);");
                }
                else
                {
                    Code.AppendLine($"{indent2}return {methodName}({offsetParameterString}{opositeVariableName} * AspectRatio);");
                }

                Code.AppendLine($"{indent1}}}");
                Code.AppendLine();

                // primary creation method
                Code.AppendLine($"{indent1}/// <summary>");
                Code.AppendLine($"{indent1}/// Create the geometry from the given {scaleVariableName} and keep the original aspect ratio");

                if (!string.IsNullOrEmpty(filename))
                {
                    Code.AppendLine(string.Format("{0}/// Shapes extracted from file \"{1}\"", indent1, filename));
                }

                Code.AppendLine($"{indent1}/// Generated from the following stream geometry:");

                var streams = StreamSourceGenerator.GenerateStreamGeometries(visual);

                foreach (var stream in streams)
                {
                    Code.Append($"{indent1}/// ");
                    Code.AppendLine(stream);
                }

                Code.AppendLine($"{indent1}/// </summary>");
                Code.AppendLine(string.Format("{0}/// <param name=\"{1}\">the {1} in WPF units</param>", indent1, scaleVariableName));
                Code.AppendLine($"{indent1}/// <returns>Returns the geometry</returns>");

                Code.AppendLine($"{indent1}public static Geometry {methodName}({offsetMethodParameterString}double {scaleVariableName})");

                Code.AppendLine($"{indent1}{{");
                Code.AppendLine($"{indent2}double scale = {scaleVariableName};");
            }
            else
            {
                // class header 
                Code.AppendLine("/// <summary>");
                Code.AppendLine("/// Create a geometry.");
                Code.AppendLine("/// The origin is normalized to 0/0.");
                Code.AppendLine("/// Width and height are normalized independently to 1.0");
                Code.AppendLine("/// </summary>");
                Code.AppendLine("private static class XYZGeometry");
                Code.AppendLine("{");

                // the aspect ratio constant
                Code.AppendLine($"{indent1}/// <summary>");
                Code.AppendLine($"{indent1}/// The aspect ratio (height/width) of the original geometry");
                Code.AppendLine($"{indent1}/// </summary>");
                Code.AppendLine(string.Format("{0}public const double AspectRatio = {1};", indent1, aspectRatio.ToString("G", CultureInfo.InvariantCulture)));
                Code.AppendLine();

                string offsetMethodParameterString = string.Empty;
                string offsetParameterString = string.Empty;

                if (includeOffset)
                {
                    offsetMethodParameterString = "double left, double top, ";
                    offsetParameterString = "left, top, ";
                }

                // the creation method for
                CreateSecondaryCreationMethod(Code, NormalizeGeometrySourceAspect.Height, "CreateFromHeight", "Create", "height", offsetMethodParameterString, offsetParameterString);
                CreateSecondaryCreationMethod(Code, NormalizeGeometrySourceAspect.Width, "CreateFromWidth", "Create", "width", offsetMethodParameterString, offsetParameterString);

                // primary creation method
                Code.AppendLine($"{indent1}/// <summary>");
                Code.AppendLine($"{indent1}/// Create the geometry from the given width and height with any aspect ratio");

                if (!string.IsNullOrEmpty(filename))
                {
                    Code.AppendLine(string.Format("{0}/// Shapes extracted from file \"{1}\"", indent1, filename));
                }

                Code.AppendLine($"{indent1}/// Generated from the following stream geometry:");

                var streams = StreamSourceGenerator.GenerateStreamGeometries(visual);

                foreach (var stream in streams)
                {
                    Code.Append($"{indent1}/// ");
                    Code.AppendLine(stream);
                }

                Code.AppendLine($"{indent1}/// </summary>");
                Code.AppendLine($"{indent1}/// <param name=\"width\">the width in WPF units</param>");
                Code.AppendLine($"{indent1}/// <param name=\"height\">the height in WPF units</param>");
                Code.AppendLine($"{indent1}/// <returns>Returns the geometry</returns>");

                Code.AppendLine($"{indent1}public static Geometry Create({offsetMethodParameterString}double width, double height)");
                Code.AppendLine($"{indent1}{{");
            }
        }
Пример #16
0
 protected override void VisitPointer(VBType node)
 {
     VisitIfNotNull(node.ElementType);
     Code.Append("*");
 }
 private void Indent()
 {
     Code.Append(new string(' ', IndentLevel * IndentSize));
 }
Пример #18
0
 public virtual void AddLine(string line)
 {
     Code.Append(' ', Style.Space * IndentLevel);
     Code.Append(line);
     Code.Append(Environment.NewLine);
 }
Пример #19
0
 protected override void VisitAnonymousType(VBType node)
 {
     Code.Append("vb#AnonymousType");
 }