lundi 24 juin 2019

Get Properties with specific Attributes (Just-in-Time compiling)

My task is to find properties with certain attributes out of .cs files. So I get .cs files and I have to search them for certain attributes and save them in XML.

So every propertie with the attribute [ID] I should store the value together with the ID. In the context how I should realize this the word 'Just-in-time compiler' and 'reflection' are used. But I have no idea how to start, because I never worked with Just-in-Time compiler/reflections before.

First I tried it with regular expressions but there I wasn't able to get the properties. .cs file:" [ID(12345678)] public string quack {get; set}"

var searchPatternID = @"(?//.)(?ID(.?\n*?)*?]";

var matches = Regex.Matches(document, searchPatternID );

 foreach (var m in matches)
 {
     Console.WriteLine(m);
 }

Here I only search for the ID. How do I can get the value of "quack"?

[ID(12345678)] public string quack {get; set}

public string wuff {get; set}

Here I would expect the value of quack together with the ID.





Aucun commentaire:

Enregistrer un commentaire