コード例 #1
0
        public string GenerateCode(CodeGenStyle style = null)
        {
            if (style == null)
            {
                style = new CodeGenStyle();
            }

            var builder = new StringBuilder();

            if (Comment != null)
            {
                builder.AppendLine(Comment.GenerateCode(style));
            }

            foreach (var attribute in Attributes)
            {
                builder.AppendLine(attribute.GenerateCode(style));
            }

            builder.Append(style.Indent);
            builder.Append(Scope.ToString().ToLower());

            var genericList = GenericTypes.Any() ? $"<{string.Join(", ", GenericTypes.Select(gt => gt.Name))}>" : string.Empty;
            var argList     = string.Join(", ", Parameters);

            builder.Append($" delegate {ReturnType} {Name}{genericList}({argList});");

            return(builder.ToString());
        }
コード例 #2
0
        public bool IsEqualTo(TypeReference type)
        {
            if (Type != type.Type)
            {
                return(false);
            }

            if (GenericTypes?.Any() == true && type.GenericTypes?.Any() == true)
            {
                if (GenericTypes.Length != GenericTypes.Length)
                {
                    return(false);
                }

                for (int i = 0; i < GenericTypes.Length; i++)
                {
                    if (!GenericTypes[i].IsEqualTo(type.GenericTypes[i]))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #3
0
ファイル: Type.cs プロジェクト: fossabot/Silk.NET
 /// <inheritdoc />
 public override string ToString()
 {
     return(Name +
            (IsPointer ? new string('*', IndirectionLevels) : string.Empty) +
            (IsArray ? Utilities.GetArrayDimensionString(ArrayDimensions) : string.Empty) +
            (GenericTypes.Any() ? $"<{string.Join(", ", GenericTypes.Select(x => x.Name))}>" : string.Empty));
 }
コード例 #4
0
        public string GenerateCode(CodeGenStyle style = null)
        {
            if (style == null)
            {
                style = new CodeGenStyle();
            }

            var builder = new StringBuilder();

            if (Comment != null)
            {
                builder.AppendLine(Comment.GenerateCode(style));
            }

            foreach (var attribute in Attributes)
            {
                builder.AppendLine(attribute.GenerateCode(style));
            }

            builder.Append(style.Indent);
            builder.Append(Scope.ToString().ToLower());
            builder.Append(" ");

            if (MethodType != MethodType.Normal)
            {
                builder.Append(MethodType.ToString().ToLower());
                builder.Append(" ");
            }

            var genericList = GenericTypes.Any() ? $"<{string.Join(", ", GenericTypes.Select(gt => gt.Name))}>" : string.Empty;

            var argList = string.Join(", ", Parameters);

            builder.AppendLine($"{ReturnType} {Name}{genericList}({argList})");

            foreach (var constrainedGeneric in GenericTypes.Where(gt => gt.Constraint != null))
            {
                style.IndentCount++;
                builder.AppendLine($"{style.Indent}where {constrainedGeneric.Name} : {constrainedGeneric.Constraint}");
                style.IndentCount--;
            }

            builder.AppendLine($"{style.Indent}{{");

            style.IndentCount++;
            builder.AppendLine(style.IndentMultilineString(Body));
            style.IndentCount--;

            builder.Append($"{style.Indent}}}");

            return(builder.ToString());
        }
コード例 #5
0
        public override string ToString()
        {
            var array           = IsArray ? "[]" : string.Empty;
            var nullable        = IsNullable ? "?" : string.Empty;
            var modifier        = IsModifier ? "(M)" : string.Empty;
            var interfaceString = IsInterface ? "(I)" : string.Empty;
            var enumString      = IsEnum ? $"(E)" : string.Empty;
            var arguments       = string.Join(
                ", ",
                Arguments.Select(generic => generic.ToString())
                );
            var action         = IsAction ? $"({arguments}) => " : string.Empty;
            var genericsJoined = string.Join(
                ", ",
                GenericTypes.Select(generic => generic.ToString())
                );
            var generics = GenericTypes.Any() ? $"<{genericsJoined}>" : string.Empty;

            return($"{action} {enumString}{modifier}{interfaceString}{Name}{generics}{array}{nullable}");
        }
コード例 #6
0
        public string GenerateCode(CodeGenStyle style = null)
        {
            if (style == null)
            {
                style = new CodeGenStyle();
            }

            var builder = new StringBuilder();

            if (Comment != null)
            {
                builder.AppendLine(Comment.GenerateCode(style));
            }

            foreach (var attribute in Attributes)
            {
                builder.AppendLine(attribute.GenerateCode(style));
            }

            builder.Append(style.Indent);
            builder.Append(Scope.ToString().ToLower());
            builder.Append(" ");

            if (ClassType != ClassType.Normal)
            {
                builder.Append(ClassType.ToString().ToLower());
                builder.Append(" ");
            }

            var genericList = GenericTypes.Any() ? $"<{string.Join(", ", GenericTypes.Select(gt => gt.Name))}>" : string.Empty;

            builder.Append($"class {Name}{genericList}");

            if (DerivedFrom.Any())
            {
                var derivedFromList = string.Join(", ", DerivedFrom);
                builder.Append($" : {derivedFromList}");
            }

            builder.AppendLine();

            foreach (var constrainedGeneric in GenericTypes.Where(gt => gt.Constraint != null))
            {
                style.IndentCount++;
                builder.AppendLine($"{style.Indent}where {constrainedGeneric.Name} : {constrainedGeneric.Constraint}");
                style.IndentCount--;
            }

            builder.AppendLine($"{style.Indent}{{");

            style.IndentCount++;

            foreach (var constructor in Constructors)
            {
                builder.AppendLine(constructor.GenerateCode(style));
                builder.AppendLine();
            }

            foreach (var variable in Variables)
            {
                builder.AppendLine(variable.GenerateCode(style));
                builder.AppendLine();
            }

            foreach (var property in Properties)
            {
                builder.AppendLine(property.GenerateCode(style));
                builder.AppendLine();
            }

            foreach (var method in Methods)
            {
                builder.AppendLine(method.GenerateCode(style));
                builder.AppendLine();
            }

            style.IndentCount--;

            builder.Append($"{style.Indent}}}");

            return(builder.ToString());
        }
コード例 #7
0
ファイル: ItemClass.cs プロジェクト: kazenetu/CSharpAnalyze
        /// <summary>
        /// 文字列取得
        /// </summary>
        /// <param name="index">前スペース数</param>
        /// <returns>文字列</returns>
        public override string ToString(int index = 0)
        {
            var result     = new StringBuilder();
            var indexSpace = string.Concat(Enumerable.Repeat("  ", index));

            foreach (var comment in Comments)
            {
                result.Append(indexSpace);
                result.AppendLine($"{comment}");
            }

            foreach (var modifier in Modifiers)
            {
                result.Append(indexSpace);
                result.Append($"{modifier} ");
            }
            result.Append($"class {Name}");

            // ジェネリックタイプ
            if (GenericTypes.Any())
            {
                result.Append("<");

                GenericTypes.ForEach(item => {
                    result.Append(item);
                    if (GenericTypes.IndexOf(item) > 0)
                    {
                        result.Append(", ");
                    }
                });

                result.Append(">");
            }

            // スーパークラス/インターフェイス
            if (SuperClass.Any())
            {
                result.Append(" : ");
                SuperClass.ForEach(item => {
                    result.Append(item.Name);
                });
            }
            if (Interfaces.Any())
            {
                if (SuperClass.Any())
                {
                    result.Append(", ");
                }
                Interfaces.ForEach(item => {
                    if (Interfaces.IndexOf(item) > 0)
                    {
                        result.Append(", ");
                    }
                    item.ForEach(expression =>
                    {
                        result.Append(expression.Name);
                    });
                });
            }

            result.AppendLine();
            result.Append(indexSpace);
            result.AppendLine("{");

            Members.ForEach(member => result.AppendLine(member.ToString(index + 1)));

            result.Append(indexSpace);
            result.AppendLine("}");

            return(result.ToString());
        }