コード例 #1
0
 protected override void PreObjectWrite(ICSharpFormatter formatter)
 {
     foreach (var attr in Attributes)
     {
         formatter.WriteLine($"[{attr}]");
     }
 }
コード例 #2
0
 protected override void WriteObjectFields(ICSharpFormatter formatter, bool comment)
 {
     if (ClosureType != ClosureType.Interface && !DisableInterfaceFieldImplementation)
     {
         FieldRewriteSeed = new Dictionary <string, int>();
         ImplementInterface(formatter, comment);
     }
 }
コード例 #3
0
        public override void Write(ICSharpFormatter formatter, bool comment = true)
        {
            string genericTypes = string.Join(", ", GenericTypes.Select(cls => cls.Name));

            if (GenericTypes.Count() > 0)
            {
                genericTypes = "<" + genericTypes + ">";
            }

            base.Write(formatter);
        }
コード例 #4
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     if (ReferencedObject != null)
     {
         ReferencedObject.Write(formatter, comment);
     }
     else
     {
         base.Write(formatter, comment);
     }
 }
コード例 #5
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     if (Alias != null)
     {
         //Alias.Write(formatter);
     }
     else
     {
         base.Write(formatter, comment);
     }
 }
コード例 #6
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($"}}");
        }
コード例 #7
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; }}");
 }
コード例 #8
0
        protected override void WriteObjectConstraint(ICSharpFormatter formatter)
        {
            string baseClasses = null;

            if (!DisableBaseClassImplementation)
            {
                baseClasses = string.Join(", ", Extends.Concat(Implements).ToList().ConvertAll(cls => cls.Name));
                if (!string.IsNullOrEmpty(baseClasses))
                {
                    baseClasses = " : " + baseClasses;
                }
                formatter.Write(baseClasses);
            }
            base.WriteObjectConstraint(formatter);
        }
コード例 #9
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(";");
     }
 }
コード例 #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 (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);
 }
コード例 #12
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);
         }
     }
 }
コード例 #13
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     if (_internalType)
     {
         return;
     }
     //for classes with constraint that says any, create a class to inherit from this with all the parameters replaced as object
     if (GenericTypes.All(t => {
         if (t is GenericType gType)
         {
             return(gType.Constraints.Any(c => c.Name == "object"));
         }
         return(false);
     }))
     {
         var newClass = new ConcreteClass(Closure, base.Name, Access, Partial, new Class[] { this });
     }
     base.Write(formatter, comment);
 }
コード例 #14
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     if (!IsParams)
     {
         if (Optional)
         {
             //InitialValue = Type.DefaultValue;
         }
         base.Write(formatter, comment);
         //if (!IsLastParameter)
         //{
         //    formatter.Write(", ");
         //}
     }
     else
     {
         formatter.Write($"params {Type} {Name}");
     }
 }
コード例 #15
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; }}");
     }
 }
コード例 #16
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("}");
 }
コード例 #17
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})");
            }
        }
コード例 #18
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; }}");
            }
        }
コード例 #19
0
 public abstract void Write(ICSharpFormatter formatter, bool comment = true);
コード例 #20
0
 protected virtual void PreObjectWrite(ICSharpFormatter formatter)
 {
 }
コード例 #21
0
 protected virtual void WriteObjectConstraint(ICSharpFormatter formatter)
 {
 }
コード例 #22
0
 protected virtual void PostWrite(ICSharpFormatter formatter)
 {
 }
コード例 #23
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     formatter.WriteLine($"using {NameSpace};");
 }
コード例 #24
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     formatter.Write($"delegate {Return} {Name}");
     base.Write(formatter, comment);
 }
コード例 #25
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     formatter.Write($"{Name}");
 }
コード例 #26
0
        void ImplementInterface(ICSharpFormatter formatter, bool comment)
        {
            if (Name == "ComponentConfigClass")
            {
            }

            this.interfaces = null;
            this.properties = null;
            this.methods    = null;
            var interfaces       = GetInterfaces();
            var properties       = GetProperties();
            var methods          = GetMethods();
            var directInterfaces = interfaces.Where(m => m.Key.Equals(this)).SelectMany(m => m.Value).ToList();
            var allInterfaces    = directInterfaces.Concat(directInterfaces.SelectMany(it => it.GetInterfaces().SelectMany(itt => itt.Value))).ToList();

            {
                Dictionary <Interface, List <Property> > explicitlyImplementedProperties = new Dictionary <Interface, List <Property> >();
                List <Property> implementedProperties = new List <Property>();
                implementedProperties.AddRange(Properties);
                List <string> implementedPropertyNames = new List <string>();
                implementedPropertyNames.AddRange(Properties.Select(m => m.Name));
                List <string> implementedExplicitInterfaceProperties = new List <string>();
                var           categorizedProperties = properties.Where(m => m.Key is Interface && allInterfaces.Any(mm => mm.Equals(m.Key)));
                foreach (var cp in categorizedProperties)
                {
                    Interface @interface = cp.Key as Interface;
                    IEnumerable <Property> interfaceProperties = cp.Value;
                    if (!explicitlyImplementedProperties.ContainsKey(@interface))
                    {
                        explicitlyImplementedProperties[@interface] = new List <Property>();
                    }
                    foreach (var property in interfaceProperties)
                    {
                        if (!implementedProperties.Any(m => m.Equals(property)))
                        {
                            bool   explicitImpement    = implementedPropertyNames.Any(nm => property.Name.Equals(nm));
                            string rewritePropertyName = null;
                            if (explicitImpement)
                            {
                                if (explicitlyImplementedProperties[@interface].Any(p => p.Equals(property)))
                                {
                                    continue;
                                }
                                if (implementedExplicitInterfaceProperties.Contains($"{@interface.FullName}.{property.Name}"))
                                {
                                    rewritePropertyName = $"{property.Name}{GetFieldRewriteSeed(property.Name)}";
                                }
                            }
                            if (explicitImpement && DisableBaseClassImplementation) //skip explicit implementation
                            {
                                continue;
                            }
                            Implement(formatter, @interface, property, comment, explicitImpement, rewritePropertyName);
                            if (explicitImpement)
                            {
                                explicitlyImplementedProperties[@interface].Add(property);
                            }
                            else
                            {
                                implementedProperties.Add(property);
                            }
                            if (rewritePropertyName != null)
                            {
                                implementedPropertyNames.Add(rewritePropertyName);
                            }
                            else
                            {
                                implementedPropertyNames.Add(property.Name);
                            }
                            if (explicitImpement)
                            {
                                implementedExplicitInterfaceProperties.Add($"{@interface.FullName}.{property.Name}");
                                if (rewritePropertyName != null)
                                {
                                    implementedExplicitInterfaceProperties.Add(rewritePropertyName);
                                }
                            }
                        }
                    }
                }
            }

            {
                Dictionary <Interface, List <Method> > explicitlyImplementedMethods = new Dictionary <Interface, List <Method> >();
                List <Method> implementedMethods = new List <Method>();
                implementedMethods.AddRange(Methods);
                List <string> implementedMethodNames = new List <string>();
                implementedMethodNames.AddRange(Methods.Select(m => m.Name));
                List <string> implementedExplicitInterfaceMethods = new List <string>();
                var           categorizedMethods = methods.Where(m => m.Key is Interface && allInterfaces.Any(mm => mm.Equals(m.Key)));
                foreach (var cp in categorizedMethods)
                {
                    Interface            @interface       = cp.Key as Interface;
                    IEnumerable <Method> interfaceMethods = cp.Value;
                    if (!explicitlyImplementedMethods.ContainsKey(@interface))
                    {
                        explicitlyImplementedMethods[@interface] = new List <Method>();
                    }
                    foreach (var method in interfaceMethods)
                    {
                        if (!implementedMethods.Any(m => m.Equals(method)))
                        {
                            bool   explicitImpement  = implementedMethodNames.Any(nm => method.Name.Equals(nm));
                            string rewriteMethodName = null;
                            if (explicitImpement)
                            {
                                if (explicitlyImplementedMethods[@interface].Any(p => p.Equals(method)))
                                {
                                    continue;
                                }
                                if (implementedExplicitInterfaceMethods.Contains($"{@interface.FullName}.{method.Name}"))
                                {
                                    rewriteMethodName = $"{method.Name}{GetFieldRewriteSeed(method.Name)}";
                                }
                            }
                            if (explicitImpement && DisableBaseClassImplementation) //skip explicit implementation
                            {
                                continue;
                            }
                            Implement(formatter, @interface, method, comment, explicitImpement, rewriteMethodName);
                            if (explicitImpement)
                            {
                                explicitlyImplementedMethods[@interface].Add(method);
                            }
                            else
                            {
                                implementedMethods.Add(method);
                            }
                            if (rewriteMethodName != null)
                            {
                                implementedMethodNames.Add(rewriteMethodName);
                            }
                            else
                            {
                                implementedMethodNames.Add(method.Name);
                            }
                            if (explicitImpement)
                            {
                                implementedExplicitInterfaceMethods.Add($"{@interface.FullName}.{method.Name}");
                                if (rewriteMethodName != null)
                                {
                                    implementedExplicitInterfaceMethods.Add(rewriteMethodName);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #27
0
 protected virtual void WriteObjectFields(ICSharpFormatter formatter, bool comment)
 {
 }
コード例 #28
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     formatter.WriteLine($"public static {Type} {Name.Trim(new char[] { '"' }).FormatCSharpName()} = {Name};");
 }
コード例 #29
0
 public override void Write(ICSharpFormatter formatter, bool comment = true)
 {
     formatter.WriteLine($"///<param name=\"{Name}\">");
     Message.Format(formatter);
     formatter.WriteLine($"///</param>");
 }
コード例 #30
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("}");
        }