I'm having difficulty with creating dynamic types, TypeBuilder is attained through module builder which in turn comes from assembly builder. I assumed that if you save the assembly you'd save the type (made with the typebuilder) as well. When I save and load the assembly it comes back as having no types
Is there a certain set of rules the type or assembly must comply to for it to be valid
If so, what might those rules be
I greatly appreciate any assistance on the matter
Jax 2 3168
Jax <an*******@discussions.microsoft.com> wrote: I'm having difficulty with creating dynamic types, TypeBuilder is attained through module builder which in turn comes from assembly builder. I assumed that if you save the assembly you'd save the type (made with the typebuilder) as well. When I save and load the assembly it comes back as having no types.
Is there a certain set of rules the type or assembly must comply to for it to be valid?
If so, what might those rules be?
It should be fine, so long as you've called TypeBuilder.CreateType.
Could you post a short but complete example of the problem?
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Thanks for replying Jon
Creating a type from a form
The form returns to this method an arraylist of TypeObjects the object contains 2 strings, name and type. example: "Width" "System.Int32
I try to match the types at the end and my messageboxes tell me the results
The first messageBox matches fine
Then I save and load the assembly and attempt a further match, this one is always false, in debugger the loaded assembly has no types
AssemblyName an = new AssemblyName()
an.Name = "myAssembly"
AppDomain currentDomain = AppDomain.CurrentDomain
AssemblyBuilder ab = currentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave)
ModuleBuilder mb = ab.DefineDynamicModule("myModule")
TypeBuilder tBuild = mb.DefineType("myType", TypeAttributes.Public)
foreach(TypeObject to in alTypeObjects
tBuild.DefineField(to.name, System.Type.GetType(to.type),FieldAttributes.Priva te)
System.Type[] types = new System.Type[1]
types[0] = System.Type.GetType(to.type)
tBuild.DefineProperty(to.type.ToUpper(), PropertyAttributes.HasDefault, System.Type.GetType(to.type), types);
Type theType = tBuild.CreateType()
object o = Activator.CreateInstance(theType)
Type aType = mb.GetType("myType")
if(aType == theType
MessageBox.Show("Type match")
ab.Save("myassembly.dll")
Assembly a = Assembly.LoadFrom("myassembly.dll")
aType = a.GetType("myType")
if(aType == theType
MessageBox.Show("Type match")
els
{MessageBox.Show("2nd match not found");} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: I Decker |
last post by:
Hi all,
Hope this is the right group.
I am writing a program in c# to open create an excel document, enter
some data, save it and then email it as an attachment. I have
successfully created...
|
by: Richard Dutton |
last post by:
I would like to be able to modify a type at runtime so that I can add an IL
prologue and epilogue to its methods (either to implement some kind of
aspect-oriented programming framework, or a simple...
|
by: Michael |
last post by:
Hi!
I'm writing some code that will enable me to create new types using xml.
Now, the only problem I have is that the default value I've set using the
FieldBuilder.SetConstant method doesn't show...
|
by: ssg31415926 |
last post by:
I've been trying to save a hashtable in an Application Settings file.
I need to save settings for each tabPage on a form. Trouble is, the
number of tabPages is determined at runtime, so I can't...
|
by: mast2as |
last post by:
Hi there, for a long time I've been trying to think of way of saving
different data of different types using one single class (well 2 in
reality, a class for the data, and 1 class for a list of...
|
by: Desmond Cassidy |
last post by:
Hi,
There must be an easy way to do this ?
How do you take a type from the ExecutingAssembly (e.g. a Class with a
few properties and constructors) and persist it (Copy) to a different
Assembly...
|
by: Angel Of Death |
last post by:
I have a method. It takes some XML as a parameter. Depending on the
content of the XML it should create a specific object and call a KNOWN
method.
So: public void PersistXml(string XmlData){}
...
|
by: Peter Morris |
last post by:
Hi all
I am using TypeBuilder to generate an assembly dynamically, a property on
one of the classes needs to be List<OtherGeneratedClass>. I am trying the
code in Jon Skeet's book
...
|
by: neovantage |
last post by:
Hey all,
i have created image by mixing logo and the original image. It create image and show in the same window.
I have done 3 steps for this.
First i upload an image to my server by using...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |