开发者

Ignoring invalid/non-relevant field attributes in C# class definitions

开发者 https://www.devze.com 2023-04-06 06:28 出处:网络
I\'ve defined a class file, and I am using it for two purposes (in an attempt to adhere to the DRY principle).There are Attributes on some of the fields, which are used at runtime by program A.Program

I've defined a class file, and I am using it for two purposes (in an attempt to adhere to the DRY principle). There are Attributes on some of the fields, which are used at runtime by program A. Program B doesn't know about these, so it refuses to compile when I include these classes in the project. I can see two methods of working around this but don't love either one of them:

  1. Add a reference to program A's DLL - I don't like the idea of adding this dependency just to avoid the compilation error

  2. Add a preprocessor directive and wrap each one with #if, #else statements. There are lots, so I don't love this method much either.

Any more elegant solution anyone can think of to make my project ignore these attributes or otherwise fix the issue?

PS. Program A is a program using the class defi开发者_如何学Pythonnition at runtime, with filehelpers (http://filehelpers.sourceforge.net/), which is why the arrangement seems a bit unorthodox. Once this has imported the data, program B will (if I encounter no showstoppers!) use EF code first to model against that same data.


You have another option: putting the attribute class (and any other class shared by the two programs) in a separate library and reference it from both program A and program B.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号