473,856 Members | 1,601 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 3223
Jax <an*******@disc ussions.microso ft.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.Cre ateType.
Could you post a short but complete example of the problem?

--
Jon Skeet - <sk***@pobox.co m>
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.Int 32
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.Curre ntDomain
AssemblyBuilder ab = currentDomain.D efineDynamicAss embly(an, AssemblyBuilder Access.RunAndSa ve)
ModuleBuilder mb = ab.DefineDynami cModule("myModu le")
TypeBuilder tBuild = mb.DefineType(" myType", TypeAttributes. Public)
foreach(TypeObj ect to in alTypeObjects

tBuild.DefineFi eld(to.name, System.Type.Get Type(to.type),F ieldAttributes. Private)
System.Type[] types = new System.Type[1]
types[0] = System.Type.Get Type(to.type)
tBuild.DefinePr operty(to.type. ToUpper(), PropertyAttribu tes.HasDefault, System.Type.Get Type(to.type), types);
Type theType = tBuild.CreateTy pe()
object o = Activator.Creat eInstance(theTy pe)

Type aType = mb.GetType("myT ype")
if(aType == theType
MessageBox.Show ("Type match")
ab.Save("myasse mbly.dll")
Assembly a = Assembly.LoadFr om("myassembly. dll")
aType = a.GetType("myTy pe")
if(aType == theType
MessageBox.Show ("Type match")
els
{MessageBox.Sho w("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
41186
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. Again this seems to work as the file is created. However once I close the excel file and try and...
1
4624
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 code before and after calls to the inner object's methods, but for my own edification I'd like to...
3
3105
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
3611
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, I created a new Forms app to test it out and created a Settings file. It didn't offer me the...
2
1677
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 parameters for 1 attribute will vary each time we run the application). Each parameter can be of a different...
0
908
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 Assembly looking for the specific Type
2
6597
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
1547
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
3109
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 embedded logo image to the path where i first upload the original image i mean i want to overwrite...
0
9764
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10790
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10390
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9535
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7098
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5762
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4580
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
2
4176
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3203
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.