|
You just specify the type between the angle brackets:
List<myType> lista = new List<myType>();
Now you have a list of myType objects.
---
single minded; short sighted; long gone;
|
|
|
|
|
You can`t do that !
<br />
Error 1 The type or namespace name 'myType' could not be found (are you missing a using directive or an assembly reference?) D:\Documents and Settings\IvanM\My Documents\Visual Studio 2005\Projects\WindowsApplication4\WindowsApplication4\Form1.cs 24 18 WindowsApplication4<br />
|
|
|
|
|
He meant how to create List<mytype> during runtime
|
|
|
|
|
I see.
Why would anyone want to do that? Why not just using a List<object>?
Better yet, why not make an interface that the class can implement, so that you can create a list of that interface, and don't have to use reflection for anything that has to do with the objects.
---
single minded; short sighted; long gone;
|
|
|
|
|
You can do it like this:
<br />
Assembly asm = Assembly.LoadFile(@"C:\MyDll.dll");<br />
Type myType = asm.GetType("WindowsApplication4.Class1");<br />
<br />
Type ListType = typeof(List<>);<br />
Type ListOfMyType = ListType.MakeGenericType(myType);<br />
|
|
|
|
|
Thanks Giorgi,
only one question remains how to add objects to ListOfMyType? Thanks alot!
|
|
|
|
|
First you will need to create instance of ListOfMyType. You can do it like this:
<br />
object myObject = Activator.CreateInstance(ListOfMyType);<br />
Then use InvokeMember method of Type class to invoke any method of ListOfMyType class. Here is an example from MSDN: Type.InvokeMember Method[^]
|
|
|
|
|
I think that you can`t invoke Add member
Code:
<br />
myObject.GetType().InvokeMember("Add", BindingFlags.Public | BindingFlags.InvokeMethod, null, myObject, new object[] { myType1 } );<br />
Error:
<br />
Method 'System.Collections.Generic.List`1[[MojDll.Class1, MojDll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Add' not found.<br />
|
|
|
|
|
I think it should look like this:
<br />
ListOfMyType.InvokeMember("Add", BindingFlags.Public | BindingFlags.InvokeMethod, null, myObject, new object[] { myType1 } );<br />
|
|
|
|
|
Ah didn`t created instance of class .... everything works now thanks !
|
|
|
|
|
You are welcome
|
|
|
|
|
//code is like this...
[XmlRoot("AutoupData")]
public class AutoupData
{
private ArrayList VersionArray;
public AutoupData()
{
VersionArray = new ArrayList();
}
[System.Xml.Serialization.XmlElement("versionInfo")]
public VersionC[] VersionInfos
{
get
{
VersionC[] VersionInfos = new VersionC[VersionArray.Count];
VersionArray.CopyTo(VersionInfos);
return VersionInfos;
}
set
{
if (value == null) return;
VersionC[] VersionInfos = (VersionC[])value;
VersionArray.Clear();
foreach (VersionC Versioninfo in VersionInfos)
VersionArray.Add(Versioninfo);
}
}
public int AddItem(VersionC VersionInfo)
{
return VersionArray.Add(VersionInfo);
}
}
public class VersionC
{
[XmlAttribute("version")]
public float version;
public VersionC()
{
}
public VersionC(float Version)
{
version = Version;
}
}
//code end...
is this using boxing and unboxing?
if it does then how can I convert this code to generic one?
I'm trying hard but the concept is so difficult to me.
please help me.
thanks.
|
|
|
|
|
arbrsoft wrote: is this using boxing and unboxing?
No. VersionC is a class . Only struct s cause boxing and unboxing.
arbrsoft wrote: if it does then how can I convert this code to generic one?
If you are using .NET 2.0 you should look at the Collection classes and then return a ReadOnlyCollection rather than copy arrays around. It might improve your design.
|
|
|
|
|
Hello everyone,
Can someone tell me little about streaming Media Files (Movie) over network using .Net Frame work?
I would like to make am Windows Application with can be used to receive and play movie files in the user application. Right now I am reading about DirectShow but I cannot find anything on sending and receiving media files (Audio/Video) over Network.
Any help to put me in the right direction will be great. Thank you very much and have a great day.
Khoramdin
|
|
|
|
|
there is an ole field in the database , now i want that pic to show in the c# form.
How can i do it?
Soniagupta1@yahoo.co.in
|
|
|
|
|
do u want to show pic in the windows imahe control of windows form.
Hello Forum
Always be in touch to help about the topic ASP.NET
|
|
|
|
|
yes sir
Soniagupta1@yahoo.co.in
|
|
|
|
|
What strikes in my mind about ur problem is that u try to save path of image u want to display and than using pic control in windows u can dynamically set the property of path of control to image from database.
reply me if found any confussion or i am understanding mistaken.
Hello Forum
Always be in touch to help about the topic ASP.NET
|
|
|
|
|
sir i am not storing the image path in the database , there exist an ole type column there i am saving the image.
Soniagupta1@yahoo.co.in
|
|
|
|
|
may i know what exact the functionality is there are many possible ways to resolve the same.
Hello Forum
Always be in touch to help about the topic ASP.NET
|
|
|
|
|
sir, all i want to do is to show the pic in the image control (the pic which is stored in the database in the ole type).
Soniagupta1@yahoo.co.in
|
|
|
|
|
are u able to retrive image from data base in correct format.
Hello Forum
Always be in touch to help about the topic ASP.NET
|
|
|
|
|
this is the problem i am not being able to retrieve the image and i am not being able to show the image in the c# form.
Soniagupta1@yahoo.co.in
|
|
|
|
|
commandbutton1.Picture = LoadPicture(recordset !Olefieldname)
OR
Drawing.ImageConverter.ConvertFrom(object)
Try this... i am not sire but i hope from Drawing class the object of ole is get converted to image type and assign to pic control.
Hello Forum
Always be in touch to help about the topic ASP.NET
|
|
|
|
|