frhagn / Typewriter

Automatic TypeScript template generation from C# source files
http://frhagn.github.io/Typewriter
Apache License 2.0
536 stars 132 forks source link

cannot access names of static properties of a class #109

Open Tschaul opened 8 years ago

Tschaul commented 8 years ago

Hi,

Thanks a lot for your efforts at typewriter. So far it worked flawlessly for me. But now i ran into a problem. I want to generate typings for my server-side resources (resx-files). But the "Properties" of the generated classes (in the .designer.cs fiels) are empty. The only reason i see why this should be is that these are all static properties.

Is there a way to get a list of the static properties programatically inside typewriter?

Greetings

PS: I only need the names not the values!

frhagn commented 8 years ago

Hi @Tschaul, unfortunately it's only possible to access public instance members at the moment. However, Typewriter 2.0 will have a richer code model including access to static properties.

Tschaul commented 8 years ago

Cool, thank you!

gldfdp commented 8 years ago

It is indeed a must have functionality

@Tschaul here a quick and dirty work around that I use to generate static access to resources:

string Resources(Class classe){

    //return classe.FullName;

      var assembly  = System.Reflection.Assembly.LoadFile(@"MyPathResources.dll");

      if(assembly==null){
            return "ERROR assembly";
      }

      List<string> result = new List<string>();

      foreach(var type in assembly.GetTypes().Where(t=>t.Name==classe.Name))
      {     
            var properties = type.GetProperties();

            result.Add(string.Join(Environment.NewLine+"\t",properties.Where(p=>p.CanRead && p.GetGetMethod().IsStatic && p.PropertyType==typeof(string))
            .Select(p=> string.Format("static {0} : string = \"{1}\";", p.Name, p.GetValue(null,null), classe.name, classe.Name))));
      }           

      return string.Join(Environment.NewLine,result);

    }
stevie1706 commented 7 years ago

I would be keen on adding some angular 2 extensions when your version 2.0 is ready.

mikestu commented 6 years ago

Any update for v2, which would have .resx support? Thanks!