Closed daniel-white closed 6 months ago
What problem do you solve?
What problem do you solve?
It solves one case where the properties are defined in a code generated class file. One wouldn’t want to put the attributes in there as they’d get overwritten by the generator
ok
@nblumhardt is this something you would take a PR for? I'd be happy to start looking how to add this.
I've found this as a potential option: https://stackoverflow.com/questions/17873576/metadata-were-not-loaded-using-metadatatype
Hi @daniel-white - I think so :+1:
doh. the attribute isn't available in .net standard, so i could add one to the library and reflect on that or just wait till everything is .net 5.
Targeting netcoreapp3.0 or 3.1 would also be fine 👍
I am scaffolding repeatedly a database structure and separated all attributes in a separate file. So I have exactly the same problem.
@nblumhardt May be we can somehow work together to get it done. I am not experienced in multi-targeting, so I would need some help here.
According to Micosoft it sounds to go straight to net5.0.
So was digging a litte deeper into this.
@daniel-white is right, metadatatype comes from Net Framework and is available in net core 3.x but not in net standard. So I will proceed with net5.0
@digitalsigi are you still interested in submitting a PR for this?
Unfortunately not for the moment. I am still busy with a larger project. Had a quick look into the code, it looks feasable, but its more than just hack an go. If it helps, I could provide some code snippets showing how to dig into attributes hierarchies.
This issue was marked as stale since it has not been active for a long time
OK, got a ping from github. Here a code snippet I am using to get all properties which are then filtered to select only those with my Custom Attribute:
var propBaseType = vmType.GetProperties().ToList();
var metaType = vmType.GetCustomAttributes<MetadataTypeAttribute>(true).ToList().FirstOrDefault();
var metaProp = new List<PropertyInfo>();
if (metaType != null)
{
var metaClass = metaType.MetadataClassType;
metaProp = metaClass.GetProperties().ToList();
}
var propConcat = metaProp.Concat(propBaseType) // Concatenate properties of MetaData class and Base class
// Take only first -> the one of Metadata, assumed metadata has the avs attribute
// if base class bears an avs attibute it is silently ignored
.OrderBy(m => m.Name)
;
I guess something like this has to be added in GetPropertiesRecursive, but I still can't find the time to do it.
It definetely can be added. The main thing here is to match attributes from other type to the properties of original type.
If someone wants to work on this issue, I will be grateful.
I don't think I will work on this feature. Anyone can start up from #91.
ping @daniel-white @digitalsigi
This issue was marked as stale since it has not been active for a long time
System.ComponentModel.DataAnnotations.MetadataTypeAttribute
is a handy bridge to attributes defined in other files, especially in code generated files. It works with the validation frameworks. I don't see why it wouldn't here.Example:
I think it would be great if both sources could be utilized, but the configuration on the primary class would win in the event of a conflict.