473,516 Members | 2,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can you save a type created with TypeBuilder?

Jax
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
Nov 15 '05 #1
2 3183
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
Nov 15 '05 #2
Jax
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");}
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
41150
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 an excel document which the user can see (at this stage of development) and passed some data to it. I then used the savas method to save the file....
1
4573
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 profiling tool). I know that a simlpe way to achieve the same behaviour, at least for a type's virtual methods, is to derive a new type and add my...
3
3086
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 up when I pass an instance of the new typ to a property grid. Any ideas why? Best regards Michael
0
3580
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 have individual settings for each page. I decided to hold them in a collection. I started out with a generic Dictionary but that didn't work. So,...
2
1654
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 data). The problem that I try to solve is the following. Imagine a class "Attribute" that needs to save multiple "Parameters" (the number of...
0
894
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 with ALL its Members WITHOUT having to go through the PropertyBuilder, ConstructorBuilder. I have written the code to 1. Plough through the...
2
6556
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){} I then determine what object I should call the Persist method on using a switch statement (not very OO). switch (otype)
2
1514
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 Type.GetType("System.Collections.Generic.List`1") which works fine, but when I need to use the other class....
3
3090
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 move_upload_file, then i resize it using class "thumbnail.class.php" My next step was to embed company logo in it(which i already done) and save new...
0
7280
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7417
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5722
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5114
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4779
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3269
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1625
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
495
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.