I have a problem, im trying to dynamically create a type using .Net reflection and c#.
Using the the TypeBuilder object i create field in the specified type :
TypeBuilder oObjectBuilder = (TypeBuilder)oClassObject;
FieldBuilder oFieldBuilder = oObjectBuilder.DefineField(strFieldName,oFieldType,FieldAttributes.Public);
My problem is that DefineField does not trow an exception if there is a field already defined with the same name "strFieldName" and theres not way to detect if the field already exist before creating it
FindMembers and GetField trow a NotSupported Exception as its not a RuntimeType and still in definition because i havent call the CreateType function.
I could bypass this problem by keeping an hashtable or an array we the already defined field name but this add unecessary overhead in my code.
Anyone have a solution with that or know how to do it wiht the TypeBuilder object ?I
There should be a function that return the list of current field of current type in definition even if it wasnt created first with the CreateType.
I appreciate any help . Thank you