tl24 / jsonexserializer

Automatically exported from code.google.com/p/jsonexserializer
1 stars 1 forks source link

ENHANCEMENT: IgnoreProperties using RegExp #56

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This isn't an issue, it's a feature request. I'd like to pass a regexp to 
IgnoreProperties and any property that matches, is ignored. 

Thanks
M

Original issue reported on code.google.com by mustafa....@wearemammoth.com on 6 Oct 2010 at 6:46

GoogleCodeExporter commented 9 years ago
That's very good idea.  I would probably use a different method name though to 
distinguish it: 
void IgnorePropertiesMatching(string pattern)
void IgnorePropertiesMatching(RegExp pattern)

Original comment by elliott....@gmail.com on 6 Oct 2010 at 10:08

GoogleCodeExporter commented 9 years ago
Glad to hear it. For anyone else viewing this ticket who wants to do something 
like this prior to the future release, here's an example of how I've gone about 
it:

 var td = s.Config.GetTypeHandler(object_to_serialize.GetType());
 Regex sampleRegex = new Regex(
      "IgnoreThisPropertyRegularExpression",
    RegexOptions.Multiline
    | RegexOptions.CultureInvariant
    | RegexOptions.Compiled
    );

foreach (var prop in td.AllProperties)
 {
     if(sampleRegex.IsMatch(prop.Name))
     {
         prop.Ignored = true;
     }
     else
     {
         prop.Ignored = false;
     }
 }

Original comment by mustafa....@wearemammoth.com on 6 Oct 2010 at 10:26