コード例 #1
0
        public override void Write(ICSharpFormatter formatter, bool comment = true)
        {
            if (comment)
            {
                Comment?.Write(formatter);
            }
            string @enum = string.Join(",\r\n", Values.Select(v => $"{v.Key} = {v.Value}"));

            formatter.WriteLine($"{(Access != AccessSpecifier.Private ? Access.ToString().ToLower() + " " : "")} enum {Name}{{");
            formatter.WriteLine(@enum);
            formatter.WriteLine($"}}");
        }
コード例 #2
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     if (comment)
     {
         if (Comment != null)
         {
             Comment.Write(formatter);
         }
     }
     foreach (var attr in Attributes)
     {
         formatter.WriteLine($"[{attr}]");
     }
     formatter.WriteLine($"{((Closure.ClosureType != ClosureType.Interface && Closure.ClosureType != ClosureType.AnonymousInterface && Access != AccessSpecifier.Private) ? Access.ToString().ToLower() + " " : "")}{(Closure.ClosureType != ClosureType.Interface && Closure.ClosureType != ClosureType.AnonymousInterface ? /*"extern "*/"virtual " : "")}{(Static ? /*"static "*/"" : "")}{(Abstract ? "abstract " : "")}{Type} {Name.FormatCSharpName()} {{ {(GetSpecifier != AccessSpecifier.Public ? GetSpecifier.ToString().ToLower() + " " : "")}get; {(SetSpecifier != AccessSpecifier.Public ? SetSpecifier.ToString().ToLower() + " " : "")}set; }}");
 }
コード例 #3
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     if (comment)
     {
         Comment?.Write(formatter);
     }
     foreach (var attr in Attributes)
     {
         formatter.WriteLine($"[{attr}]");
     }
     formatter.Write($"{Access.ToString().ToLower()}{(Static ? " static" : "")}{(Readonly ? " readonly" : "")} {Type} {Name}{(InitialValue != null ? $" = {InitialValue}" : "")}");
     if (Closure.ClosureType != ClosureType.Argument)
     {
         formatter.WriteLine(";");
     }
 }
コード例 #4
0
 protected override void PreObjectWrite(ICSharpFormatter formatter)
 {
     foreach (var attr in Attributes)
     {
         formatter.WriteLine($"[{attr}]");
     }
 }
コード例 #5
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     if (Alias.Name != Name)
     {
         string g = "";
         if (GenericTypes.Count() > 0)
         {
             g = "<" + string.Join(", ", GenericTypes.Select(gg => gg.ToString())) + ">";
         }
         formatter.WriteLine($"public class {Name}{g} : TypeAlias");
         formatter.WriteLine($"{{");
         formatter.WriteLine($"public {Name}({Alias.Name} value) {{ Value = value; }}");
         formatter.WriteLine($"public static implicit operator {Name}{g}({Alias.Name} value){{ return new {Name}{g}(value); }}");
         formatter.WriteLine($"}}");
     }
     //base.Write(formatter, comment);
 }
コード例 #6
0
 void Implement(ICSharpFormatter formatter, Interface @interface, Property property, bool comment, bool @explicit = false, string rewritePropertyName = null)
 {
     if (comment)
     {
         property?.Comment.Write(formatter);
     }
     if (!@explicit)
     {
         formatter.WriteLine($"public extern {property.Type} {property.Name} {{ get; set; }}");
     }
     else
     {
         if (rewritePropertyName != null)
         {
             formatter.WriteLine($"[Name(\"{property.Name}\")]");
         }
         rewritePropertyName = rewritePropertyName ?? $"{@interface.FullName}.{property.Name}";
         formatter.WriteLine($"extern {property.Type} {rewritePropertyName} {{ get; set; }}");
     }
 }
コード例 #7
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     if (_alreadyDefined)
     {
         return;
     }
     //foreach (var @class in Objects.Where(o => {
     //    if (o is AliasType)
     //        return true;
     //    return false;
     //}))
     //{
     //    @class.Write(formatter, comment);
     //}
     if (Comment != null)
     {
         Comment.Write(formatter, comment);
     }
     if (WillConvertToStaticClass())
     {
         formatter.WriteLine($"public class {Name}" + " {");
     }
     else
     {
         formatter.WriteLine($"namespace {Name}" + " {");
     }
     foreach (var @class in Objects.ToList() /*.Where(o=> {
                                              * if (o is AliasType)
                                              * return false;
                                              * return true;
                                              * })*/)
     {
         @class.Write(formatter, comment);
     }
     foreach (var @namespace in Childs)
     {
         @namespace.Write(formatter, comment);
     }
     formatter.WriteLine("}");
 }
コード例 #8
0
        void Implement(ICSharpFormatter formatter, Interface @interface, Method method, bool comment, bool @explicit = false, string rewriteMethodName = null)
        {
            if (comment)
            {
                method?.Comment.Write(formatter);
            }
            string @params = string.Join(", ", method.Parameters.ConvertAll(p => p.ToString()));

            if (!@explicit)
            {
                formatter.WriteLine($"public extern {method.Return} {method.Name}({@params})");
            }
            else
            {
                if (rewriteMethodName != null)
                {
                    formatter.WriteLine($"[Name(\"{method.Name}\")]");
                }
                rewriteMethodName = rewriteMethodName ?? $"{@interface.FullName}.{method.Name}";
                formatter.WriteLine($"extern {method.Return} {rewriteMethodName}({@params})");
            }
        }
コード例 #9
0
        public override void Write(ICSharpFormatter formatter, bool comment = true)
        {
            if (comment)
            {
                if (Comment != null)
                {
                    Comment.Write(formatter);
                }
            }
            string @params     = string.Join(", ", Parameters.ConvertAll(p => p.ToString()));
            string @paramsName = string.Join(", ", Parameters.ConvertAll(p => p.Name));

            foreach (var attr in Attributes)
            {
                formatter.WriteLine($"[{attr}]");
            }
            if (!IsIndexer)
            {
                string generics = "";
                if (GenericArgs != null && GenericArgs.Count > 0)
                {
                    generics = "<" + string.Join(", ", GenericArgs.ConvertAll(a =>
                    {
                        var v = a.ToString(); if (v == "void")
                        {
                            v = "undefined";
                        }
                        return(v);
                    })) + ">";
                }
                var name = Name.Split(new char[] { '<' })[0];
                formatter.WriteLine($"{((Closure.ClosureType != ClosureType.Interface && Closure.ClosureType != ClosureType.AnonymousInterface && Access != AccessSpecifier.Private) ? Access.ToString().ToLower() + " " : "")}{(Closure.ClosureType != ClosureType.Interface && Closure.ClosureType != ClosureType.AnonymousInterface &&!IsImplicitConverter && !IsConstructor ? /*"extern "*/"virtual " : "")}{(IsImplicitConverter ? "static " : "")}{(Abstract ? "abstract " : "")}{(Return != null ? Return.ToString() + " " : "")}{name.FormatCSharpName()}{generics}({@params}){( Body != null ? Body : Closure.ClosureType != ClosureType.Interface && Closure.ClosureType != ClosureType.AnonymousInterface && !IsImplicitConverter ? ((Return?.Name??"void") != "void" && !IsConstructor ? $" => default({Return});" : ((IsConstructor && Closure is Class && (Closure as Class).Extends.Any(m=> (m is Class) && (m as Class).Methods.Any(mm => mm.IsConstructor)) && false ? $" : base({@paramsName})" : "") + "{ }")) : ";")}");
            }
            else
            {
                formatter.WriteLine($"{((Closure.ClosureType != ClosureType.Interface && Closure.ClosureType != ClosureType.AnonymousInterface && Access != AccessSpecifier.Private) ? Access.ToString().ToLower() + " " : "")}{(Closure.ClosureType != ClosureType.Interface && Closure.ClosureType != ClosureType.AnonymousInterface ? /*"extern "*/"virtual " : "")}{(Static ? /*"static "*/"" : "")}{(Abstract ? "abstract " : "")}{Return} this[{@params}]{{ get; set; }}");
            }
        }
コード例 #10
0
        public static void Format(this string comment, ICSharpFormatter formatter)
        {
            string[] split        = comment.Split(new char[] { '\n' });
            int      minLeftSpace = split.Min(v => CountLeftSpace(v));

            for (int i = 0; i < split.Length; i++)
            {
                if ((i == 0 || i == split.Length - 1) && string.IsNullOrEmpty(split[i].Trim()))
                {
                    continue;
                }
                split[i] = split[i].Substring(minLeftSpace).TrimEnd();
                formatter.WriteLine($"///{split[i]}");
//                formatter.WriteLine($"///<para>{split[i]}</para>");
            }
        }
コード例 #11
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     if (Summary != null || Return != null || (Params != null && Params.Count > 0))
     {
         formatter.WriteLine($"");
         if (Summary != null)
         {
             Summary.Write(formatter);
         }
         foreach (var m in Params)
         {
             m.Write(formatter);
         }
         if (Return != null)
         {
             Return.Write(formatter);
         }
     }
 }
コード例 #12
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     formatter.WriteLine($"using {NameSpace};");
 }
コード例 #13
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     formatter.WriteLine($"///<param name=\"{Name}\">");
     Message.Format(formatter);
     formatter.WriteLine($"///</param>");
 }
コード例 #14
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     formatter.WriteLine($"public static {Type} {Name.Trim(new char[] { '"' }).FormatCSharpName()} = {Name};");
 }
コード例 #15
0
        public override void Write(ICSharpFormatter formatter, bool comment = true)
        {
            if (comment)
            {
                if (Comment != null)
                {
                    Comment.Write(formatter);
                }
            }
            PreObjectWrite(formatter);
            formatter.Write(Definition);
            WriteObjectConstraint(formatter);
            formatter.WriteLine("");
            formatter.WriteLine("{");
            foreach (var m in InnerObjects.Distinct())
            {
                m.Write(formatter, comment);
            }
            List <ICSharpSyntax> generatedFields = new List <ICSharpSyntax>();
            List <string>        generatedNames  = new List <string>();
            int ix = 1;

            foreach (var m in Variables)
            {
                if (!generatedFields.Any(f => f.Equals(m)))
                {
                    string originalName = m.Name;
                    string name         = m.Name;
                    if (generatedNames.Contains(name))
                    {
                        //name += ix++;
                        //m.Attributes.Add($"Name(\"{originalName}\")");
                        //m.Name = name;
                    }
                    m.Write(formatter, comment);
                    generatedNames.Add(name);
                    generatedFields.Add(m);
                }
            }
            ix = 1;
            foreach (var property in Properties)
            {
                if (!generatedFields.Any(f => f.Equals(property)))
                {
                    string originalName = property.Name;
                    string name         = property.Name;
                    if (generatedNames.Contains(name))
                    {
                        //name += ix++;
                        //property.Attributes.Add($"Name(\"{originalName}\")");
                        //property.Name = name;
                    }
                    property.Write(formatter, comment);
                    generatedNames.Add(name);
                    generatedFields.Add(property);
                }
            }
            ix = 1;
            foreach (var m in Methods)
            {
                if (!generatedFields.Any(f => f.Equals(m)))
                {
                    string originalName = m.Name;
                    string name         = m.Name;
                    if (generatedNames.Contains(name) && !m.IsConstructor)
                    {
                        //name += ix++;
                        //m.Attributes.Add($"Name(\"{originalName}\")");
                        //m.Name = name;
                    }
                    m.Write(formatter, comment);
                    generatedNames.Add(name);
                    generatedFields.Add(m);
                }
            }
            WriteObjectFields(formatter, comment);
            formatter.WriteLine("}");
        }
コード例 #16
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     formatter.WriteLine($"///<return>");
     Message.Format(formatter);
     formatter.WriteLine($"///</return>");
 }