I need to cast an object to a System.Type object.
I’ve read that C# is statically typed so that would not be possible.
Is this true?
If yes, how can I accomplish this?
Assembly myDll = Assembly.LoadFrom(dllData.Path);
Type manyAttribute = myDll.GetExportedTypes().FirstOrDefault(...);
Type multiplicityAttribute = myDll.GetExportedTypes().FirstOrDefault(..);
//Here is the problem
propertiesOnOtherFile = propertiesOnOtherFile.Where(t =>
t.GetCustomAttributes(false).Any(ca =>
!string.IsNullOrEmpty(((multiplicityAttribute)ca).PropertyName)));
This is the line:
((multiplicityAttribute)ca).PropertyName)
Is there any other way to do this?
EDIT:
Due to many questions, this is my scope:
public class PocoClass
{
[ManyAttribute]
public ObjectX MyProp;
}
ManyAttribute declaration
{
public string PropertyName;
}
ManyAttribute is in the dynamicly loaded DLL.
Then, as in my example above, I need to cast the customAttribute (ManyAttribute) to ManyAttribute so I check PropertyName’s value.
I still don’t get this… but this should work.