using the interface as you had done is a very good solution..
however you could do some other things,but you know languages like C#
don't support such dynamic abilities.(dynamic cast)
I can't have a method could return different objects with different types,
I had a problem,I wanted to create some dynamic objects at runtime(with the given type) I did something else I created an object with the given type and with ConstructorInfo, EventInfo, FieldInfo, MemberInfo, MethodInfo, ParameterInfo, and PropertyInfo...got the value I wanted..(for example in your case you could make the exact attribute you wanted and then get its desired property at runtime)..
Quote:
quote:Originally posted by paulie100
Instead of casting using something like
(Int32) y
In my app, I won't know that y is Int32 at coding time. That info will be loaded from a file or a database. So, if the string variable t is set to "Int32" to hold the type of y, I want to be able to do something like
(Type.GetType("System."+t)) y
|
No,C# doesn't support such abilities,C# is a statically typed language and can't return different objects with different types at run time.
_____________
Mehdi.
software student.