Exemplo n.º 1
0
 public EnumFile(Type type, TsDir rootDir) : base(type, rootDir)
 {
     Properties.AddRange(Enum.GetNames(type).Select(name =>
     {
         var stringValue = "";
         var val         = (Enum.Parse(type, name));
         var t           = val.GetType().GetEnumUnderlyingType();
         if (t.FullName == typeof(int).FullName)
         {
             stringValue = ((int)val).ToString();
         }
         else if (t.FullName == typeof(byte).FullName)
         {
             stringValue = ((byte)val).ToString();
         }
         else
         {
             Console.WriteLine("Unknown enum underlying type");
         }
         return(new EnumProperty
         {
             Name = name,
             Value = stringValue,
         });
     }));
 }
Exemplo n.º 2
0
 public InterfaceFile(TypeBuilder builder, Type type, TsDir rootDir, bool forceInterfaceForProperties = false) : base(type, rootDir)
 {
     if (!Export.StartsWith("I"))
     {
         Export = $"I{Export}";
     }
     Properties.AddRange(type.GetProperties().PropertyFilter()
                         .Select(prop => new TypedInterfaceProperty(builder, prop, forceInterfaceForProperties)));
     Fields.AddRange(type.GetFields().FieldFilter().Select(field => new TypedFieldProperty(builder, field)));
 }
Exemplo n.º 3
0
        public TsDir Down(string dirName)
        {
            var child = _children.FirstOrDefault(c => c.DirName.Equals(dirName, StringComparison.OrdinalIgnoreCase));

            if (child != null)
            {
                return(child);
            }

            child = new TsDir {
                DirName = dirName, ParentDir = this
            };
            _children.Add(child);
            return(child);
        }
Exemplo n.º 4
0
        public ClassFile(TypeBuilder builder, Type type, TsDir rootDir) : base(type, rootDir)
        {
            Properties.AddRange(type.GetProperties().PropertyFilter()
                                .Select(prop =>
            {
                var tsProp = new TypedClassProperty(builder, prop);

                foreach (var decorator in builder.DefaultClassPropertyDecorators)
                {
                    tsProp.Decorators.Add(decorator);
                }

                return(tsProp);
            }));

            Fields.AddRange(type.GetFields().FieldFilter().Select(field => new TypedFieldProperty(builder, field)));
        }
Exemplo n.º 5
0
 protected TypedFile(Type type, TsDir rootDir) : base(type.Name,
                                                      type.Namespace == null ? rootDir : type.Namespace.Split('.').Aggregate(rootDir, (current, namespacePart) => current.Down(namespacePart)))
 {
     Type   = type;
     Export = type.Name;
 }
Exemplo n.º 6
0
        public string ImportPath(TsDir targetDir, string targetFile)
        {
            if (this == targetDir)
            {
                return($"./{targetFile}");
            }

            if (ParentDir == targetDir)
            {
                return($"../{targetFile}");
            }

            //need to switch to a non recursive solution?
            TsDir ChildPath(TsDir start)
            {
                foreach (var child in start.Children)
                {
                    if (child == targetDir)
                    {
                        return(child);
                    }

                    if (!child.Children.Any())
                    {
                        continue;
                    }

                    var r = ChildPath(child);
                    if (r != null)
                    {
                        return(child);
                    }
                }

                return(null);
            }

            var result    = new List <string>();
            var s         = this;
            var childTest = ChildPath(s);

            if (childTest != null)
            {
                result.Add(".");
            }

            while (childTest == null && s != null)
            {
                //once s is null we have made it to the top of the tree
                result.Add("..");
                s = s.ParentDir;
                if (s == null)
                {
                    throw new Exception("target directory not found");
                }
                childTest = ChildPath(s);
            }

            if (childTest != null)
            {
                result.Add(childTest.DirName);
                while (childTest != targetDir)
                {
                    childTest = ChildPath(childTest);
                    result.Add(childTest.DirName);
                }

                result.Add(targetFile);

                return(string.Join("/", result.ToArray()));
            }

            throw new Exception("Something went wrong");
        }
Exemplo n.º 7
0
 protected TsFile(string fileName, TsDir directory)
 {
     FileName  = fileName;
     Directory = directory;
 }
Exemplo n.º 8
0
 public string Import(TsDir targetDir)
 {
     return($"import {{ {Export.Replace("[]","")} }} from {TypeBuilder.TickStile}{targetDir.ImportPath(Directory, FileName)}{TypeBuilder.TickStile};");
 }
 public UnionTypeDefinition(string export, TsDir directory) : base(export, directory)
 {
     Export = export;
 }