|
public class OtherClass <br />
{<br />
Delegate _dSend;<br />
public OtherClass(Delegate dSend)<br />
{<br />
_dSend = dSend; <br />
}
works!!
Thanks Robert for your suggestion. Can now send and catch delegates in every direction.
|
|
|
|
|
What I want to do is say
"Only Add classes that implement interfaceA or interfaceB"
so saying
public List<T> where T: interfaceA, interfaceB {}
but that says they must implement both interface A and B.
How can I say A or B?
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
You can't. Probably the best option would be to use a factory method or a singleton, with a derived class for each interface. This is the same method used by the Comparer<T>.Default property.
For example:
public abstract class MyClass<T>
{
private static readonly MyClass<T> _instance = CreateInstance();
public static MyClass<T> Instance
{
get { return _instance; }
}
private static MyClass<T> CreateInstance()
{
Type itemType = typeof(T);
Type resultType = null;
if (typeof(InterfaceA).IsAssignableFrom(itemType))
{
resultType = typeof(<span>MyClassA<></span>).MakeGenericType(itemType);
}
else if (typeof(InterfaceB).IsAssignableFrom(itemType))
{
resultType = typeof(<span>MyClassB<></span>).MakeGenericType(itemType);
}
if (null == resultType) throw new ArgumentException("Type parameter \"T\" must implement InterfaceA or InterfaceB.");
return (<span>MyClass<T></span>)Activator.CreateInstance(resultType);
}
}
internal sealed class MyClassA<T> : MyClass<T> where T : InterfaceA
{
...
}
internal sealed class MyClassB<T> : MyClass<T> where T : InterfaceB
{
...
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
That both A and B implement then you can check for it instead.
public interface IShape;
public interface IEvenPolygon : IShape;
public interface IOddPolygon : IShape;
public List<t> where T: IShape;
The problem is what you want isn't type safe.
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
|
|
|
|
|
Do you have the source code to interfaceA and interfaceB? If so:
interface IAmDaddy
{
}
interface interfaceA : IAmDaddy
{
}
interface interfaceB : IAmDaddy
{
}
public List<T> where T : IAmDaddy
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Dumbest. Movie. Title. Evaaar.
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Hi
could any one show me the best way to extract the info i need from the file below. Basicly the files are hand historys from a poker site and i would like to keep track of how often a player calls checks folds and so on. The file is in html (hoping it posts ok) , or if any one could tell me if it would be better to convert the file to xml (if possible) and extract the data that way?
well here is a short part of the file .....
Real Money Ring Game | Table Name | Hand ID | Game | Stakes | Casanova | 10474702-12327 | Holdem Limit | $0.25/$0.50 | [Jul 31 16:03:20] : Hand Start. | [Jul 31 16:03:20] : Seat 1 : davebass has $31.99 | [Jul 31 16:03:20] : Seat 2 : PoKaBoT has $15.21 | [Jul 31 16:03:20] : Seat 4 : WC2006 has $9.82 | [Jul 31 16:03:20] : Seat 6 : xbambamx has $8.02 | [Jul 31 16:03:20] : Seat 8 : drurylane has $23.05 | [Jul 31 16:03:20] : Seat 9 : modeselect has $3.34 | [Jul 31 16:03:20] : xbambamx is the dealer. | [Jul 31 16:03:21] : drurylane posted small blind. | [Jul 31 16:03:21] : modeselect posted big blind. | [Jul 31 16:03:21] : Game [12327] started with 6 players. | [Jul 31 16:03:21] : Dealing Hole Cards. | [Jul 31 16:03:21] : Seat 2 : PoKaBoT has 5s Ts | [Jul 31 16:03:25] : davebass folded. | [Jul 31 16:03:26] : PoKaBoT folded. | [Jul 31 16:03:29] : WC2006 called $0.25 | [Jul 31 16:03:32] : xbambamx folded. | [Jul 31 16:03:34] : drurylane called $0.13 | [Jul 31 16:03:35] : modeselect checked. | [Jul 31 16:03:36] : Dealing flop. | [Jul 31 16:03:36] : Board cards [As Kc 4d] | [Jul 31 16:03:38] : drurylane checked. | [Jul 31 16:03:38] : modeselect checked. | [Jul 31 16:03:42] : WC2006 checked. | [Jul 31 16:03:42] : Dealing turn. | [Jul 31 16:03:42] : Board cards [As Kc 4d 8s] | [Jul 31 16:03:45] : drurylane bet $0.50 | [Jul 31 16:03:45] : modeselect folded. | [Jul 31 16:03:52] : WC2006 called $0.50 and raised $0.50 | [Jul 31 16:03:53] : drurylane called $0.50 | [Jul 31 16:03:53] : Dealing river. | [Jul 31 16:03:53] : Board cards [As Kc 4d 8s Js] | [Jul 31 16:03:56] : drurylane checked. | [Jul 31 16:03:57] : WC2006 bet $0.50 | [Jul 31 16:03:58] : drurylane called $0.50 | [Jul 31 16:03:58] : Showdown! | [Jul 31 16:04:00] : Seat 4 : WC2006 has 8d Ac | [Jul 31 16:04:00] : WC2006 has Two Pair: Aces and 8s | [Jul 31 16:04:01] : WC2006 wins $3.57 with Two Pair: Aces and 8s | [Jul 31 16:04:10] : Hand is over. |
Table of contents |
if i havent been very clear or this file has posted terribly and you would like to help i could always email a file to you to take a look @ ... many thanx
The top part of the file which looks extreemly messy in the post is not all that important its just the hand numbers , the main part is where you can see "Hand Start" .
|
|
|
|
|
Have you tried opening this up with an XML parser? It looks well-formed enough that you could do that. In this case, you could use an XmlDocument object and start grabbing data out of it.
Logifusion[^]
If not entertaining, write your Congressman.
|
|
|
|
|
Hi,
Use Regex to search for specific patterns.
<br />
"(\\w+)\\s*=\\s*"<br />
"\"\\s*(.*?)\\s*\""
These will match all the attributes in the html like name = "value"
Try forming the proper regex for your situation.
<marquee>"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
Hi
When I'm trying to Add something to my ListvView (multiple columns), I receive this strange error in debug mode:
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
The code (*):
lstProps.Items.Add(new ListViewItem(new string[] {"one", "two" }));
Which resides in private void receivedIt(RemovableStorage r, EventArgs e) .
The strange thing is that the same code (*) does work in the Form_Load method, or some Botton_Click method! Am I doing something totally wrong?
I am searching for 2 days now and all the online samples are doing the same - and I'm getting a bit of dissapointed in the ListView control Hopefully someone can help me?
Thanks a lot!
|
|
|
|
|
You are probably trying to access the ListView control from a non-UI thread. You can use the InvokeRequired property to determine whether you are on the UI thread, and the Invoke method to transfer execution to the UI thread.
For example:
private delegate void ReceivedItDelegate(RemovableStorage e, EventArgs e);
private void receivedIt(RemovableStorage r, EventArgs e)
{
if (this.InvokeRequired)
{
this.Invoke(
new ReceivedItDelegate(receivedIt),
new object[2] { r, e });
}
else
{
lstProps.Items.Add(...);
...
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Hi Richard
Indeed! It works! Jiha!
Thanks a lot!
Something I never should found on my own!
Greetings
|
|
|
|
|
Hi there:
As you know we can compile a C Sharp program at DOS prompt like
csc MyProgram.cs
Where MyProgram.cs is the source code file.
Now i want to perform the same compilation through another C Sharp Program. Like i made a program named ShellExecution, which tries to compile another C Sharp Source Code File called "First.cs" lying in my c directory. The program runs fine without any exceptions; it opens the dos window and runs csc, but nothing happens and seems like the file name "First.cs" is not being passed to the csc.exe as a parameter. I have used the following code for executing the compilation process:
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\CSC.exe";
process.StartInfo.Arguments = "C:\\First.cs";
process.StartInfo.UseShellExecute = true;
process.StartInfo.RedirectStandardOutput = false;
process.StartInfo.CreateNoWindow = false;
process.Start();
process.WaitForExit();
Please help me out!!!!
|
|
|
|
|
Check out the CSharpCodeProvider. It can compile from a CodeDom model, from files, or from strings.
Link[^]
Logifusion[^]
If not entertaining, write your Congressman.
|
|
|
|
|
i'm working with MenuItem that i attached to a notifyIconTray... i want 2 add to on of the Menuitem meber new members "on the fly" from combobox, so when i add 2 combobox, i want it 2 be added to the member in the menuitem.the problem is .. that it works only once,,, after i maximize and minimize it back, it wont show me the other members of the Member of the menuitem....
any ideas y it happens ?
it looks like that:
private void Form1_Resize(object sender, System.EventArgs e)
{
if (FormWindowState.Minimized == WindowState)
{
menuItemEntireCat.MenuItems.Clear();
MenuItem[] CatMenuItems= new MenuItem[catcombobox2.Items.Count];
for(int i=0;i
|
|
|
|
|
It seems like you have some error here :
vedmack wrote: MenuItem[] CatMenuItems= new MenuItem[catcombobox2.Items.Count];
for(int i=0;i{
CatMenuItems[i]=new MenuItem();
And why would you do somethinglike this in the resize event ?
------------------------------ "The Soapbox has been so ..."
|
|
|
|
|
ok solved it....
altho its nothing 2 do with the resize event...
its just i need 2 re-add it to the root menuitem...
|
|
|
|
|
Hi, I need to work with windows system process(e.g closing IE explorer). so how shall I go about doing it.
|
|
|
|
|
|
You can also use WMI (Windows Management Interface) and query for processes.
|
|
|
|
|
hi,
I have a class association generated from an xsd file. There is a one to many relationship that exists between the classes Order and Product.
I can set the properties for order like this: Order.Number = 1;
I can create a new instance of Products like this:
Products x = new Products();
x.name="blabla";
x.type="blabla";
now the problem is that I cannot add a Product to my order class.
I'm not sure how. plus I should be able to add multiple products to this class. The syntax is like this in my Order class:
*******************************************
private Product[] product Field;
/// <remarks>
[System.Xml.Serialization.XmlElementAttribute("Product")]
public Product[] Product {
get {
return this.productField;
}
set {
this.productField = value;
}
}
***********************************
Does anyone know the syntax to do this? or is it even possible?
I'm losing it. I've been trying to get this forever....
Please write back if you know the answer? Thanks if you do.
ChaciMulch
|
|
|
|
|
hi,
You can add a method to your Order class called AddProduct as follows:
<br />
class Order<br />
{<br />
.<br />
.<br />
.<br />
public void AddProduct(Product product)<br />
{<br />
ArrayList products=new ArrayList(this.productField);<br />
products.Add(product);<br />
this.productField=(Product[])products.ToArray(typeof(Product));<br />
}<br />
}<br />
Since you are storing products in an array you can not add an item to it, therefor you should use an ArrayList to add an item to the array and to cast it to the array again
Regards
|
|
|
|
|
Thanks so much.. Its almost working now but I needed one change.
In the first line I just had to take out the 'this.productField'
in order to get it to work. (not sure why)
it will add one object, but if i try to add another one, it just overwrites
the first one. i need to add multiple products per order. am i doing something wrong?
Thanks Again.
Mulch
-- modified at 15:54 Thursday 24th August, 2006
|
|
|
|
|
Hi
If you take out the first line you will lose other products that have been added to your array.You should add those items too.
Instead of
<br />
ArrayList products=new ArrayList(this.productField);<br />
write:
<br />
ArrayList products=new ArrayList();<br />
products.AddRange(this.productField);<br />
Although both methods should result the same thing ( added products so far,should be added to the ArrayList).
There's another way that I don't like and that's
<br />
ArrayList products=new ArrayList();<br />
foreach(Product item in this.productField)<br />
products.Add(item);<br />
please let me know if it's not working again
Regards
|
|
|
|
|
I still can't get it to work. I may be adding these lines in the wrong order.
this is how I tried implementing it:
ArrayList products = new ArrayList();
products.AddRange(this.productField);
products.Add(code);
this.productField = (Product[])products.ToArray(typeof(Product));
At least now I'm getting some sort of error in my browser. It is below. It seems like 'this.productField' is set to null at this point or something like that. I'm just confused. I'm not really following exactly what is happening here. I didn't think it would be this hard when I started. I created this class from an xsd and I thought that i would be able to add multiple sub class items automatically.
Any other ideas to what I'm doing wrong?
someone else said to try using a collection but I've never done that either and I just need to get this working as fast as possible. Thanks.
System.ArgumentNullException: Collection cannot be null.
Parameter name: c
at System.Collections.ArrayList.InsertRange(Int32 index, ICollection c)
at System.Collections.ArrayList.AddRange(ICollection c)
at RepairRequests.AddOpCode(OperationCode code) in c:\Inetpub\wwwroot\ASIAPI\App_Code\RepairOrder.cs:line 515
at Service.GetRepReq() in c:\Inetpub\wwwroot\ASIAPI\App_Code\Service.cs:line 134
at Service.GetRO() in c:\Inetpub\wwwroot\ASIAPI\App_Code\Service.cs:line 62
at Service.GetROData(String RO_ID) in c:\Inetpub\wwwroot\ASIAPI\App_Code\Service.cs:line 30
|
|
|
|
|
I see
That's because productsField is null for the first time that you want to add a product
then wrtie:
<br />
....<br />
if(productField!=null) products.AddRange(productField);<br />
....<br />
or you can make it empty (instead of null):
<br />
...<br />
private Product[] productField=new Product[]{};<br />
...<br />
and there would be no need to check if productField is null in AddProduct routine.
I Prefer the second approach.
Regards
|
|
|
|