|
Here's one way to do it (Assuming I understand your question correctly.)
Upload u = new Upload();<br />
Disconnect d = new Disconnect();<br />
<br />
if (u is IDisconnect && d is IDisconnect)<br />
{<br />
}
Brent
|
|
|
|
|
It's late here so I may be missing something, but I would look at using something like:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Type[] ifaceA = typeof(A).GetInterfaces();
Type[] ifaceB = typeof(B).GetInterfaces();
List<Type> types = new List<Type>();
types.AddRange(ifaceA);
foreach (Type t in ifaceB)
{
if (types.Contains(t))
Console.WriteLine("Found {0}", t.Name);
}
}
}
interface IList1
{
void Name();
}
public class B : IList1
{
#region IList1 Members
public void Name()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
}
public class A : IDisposable, IList1
{
#region IDisposable Members
public void Dispose()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
#region IList1 Members
public void Name()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
}
}
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Yup, that's what I was thinking I'd have to do. Just wanted to check in case there was something that already did it for me. Thanks for the code--I'm sure it's close if not exact.
Marc
Thyme In The CountryInteracxPeople are just notoriously impossible. --DavidCrow There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith
|
|
|
|
|
Wouldn't casting both classes to the interface and testing to see if they are null essentially do the same thing?
Something like this:
IList1 t = A as IList1;
IList1 t2 = B as IList1;
if (t != null && t2 != null)
{
...
} The as operator will either return the proper cast if it is supported or null if it isn't.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
You would also have to ensure that A and B were not null to begin with also.
|
|
|
|
|
It would, but I wrote this 5 minutes before going to bed. A little bit tired you might say.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
|
|
Can you access this via code?
only two letters away from being an asset
|
|
|
|
|
TaskManager Extension is source code downloadable. You can inspect its source for API use.
|
|
|
|
|
I have a problem that I have not been able to resolve. I have a C# EXE where I have exposed some interfaces. My problem is that every call to createobject creates a new instance of the application. What I need is one running application from which a client can connect to.
Scenario 1:
Application is launched from command line.
User connects to existing running application using createobject (this does not work...it creates another instance)
Scenario 2:
Application is not running
User run createobject to connect to launch application. App launches (however if another program does a createobject it creates yet another instance).
I have not found anything in my searches that have helped.
Someone please shed some light on this!
Thanks,
Loren
|
|
|
|
|
Hello everyone,
I have a ListView control which is populated with a large number of data (Many rows). As the result of large number of rows I have to use the scrollbar to see the entire rows. I am searching and selecting row of the ListView programmatically. The following code temonstrate this:
ListViewItem foundItem = listView4.FindItemWithText(boxSearch.Text);<br />
int foundItemIndex = listView4.Items.IndexOf(foundItem);<br />
<br />
if (foundItem != null)<br />
{<br />
MessageBox.Show("The Item has already been registered.");<br />
listView4.Focus();<br />
listView4.Items[foundItemIndex].Selected = true;<br />
listView4.Items[foundItemIndex].Focused = true;<br />
}<br />
else<br />
{<br />
MessageBox.Show("The Item has NOT been registered.");<br />
}<br />
Unfortunitly, if the selected row is not in the user's ListView, it can go without notice. Therefore, I would like to move the rows which are visiable in the ListView in order for the user to see the programmatically selected Item. I have been under impression that the following code do the job:
listView4.Items[foundItemIndex].Focused = true;
but unfortunatly, when I add it to the above code it practically does NOTHING.
Can anyone be kind enough to tell me how this can be achieved?
Thank you very much and have a great day.
Khoramdin
|
|
|
|
|
It looks like there is something call topItem. So I think if you change your code to
listView4.TopItem = foundItem;
It should work.
I found this note:
Note
Setting this property has no effect when the Scrollable property value is false.
Setting this property is not supported in versions of the .NET Framework prior to version 2.0.
Hope that helps.
Ben
|
|
|
|
|
Hello,
I got an article how to make BAND object DLL for making Internet Explorer Plugin in C#. Fine, I have followed that article and made an IE plugin in C#. But I dont understand how to install this DLL to Internet Explorer as Plugin. Would you please help.
Thanks and regards
Emran
|
|
|
|
|
I want to add indexed access to a series of identical pre existing properties in a business object class. I can't change the existing properties in any way (they contain business rules and other code and are already in use in other areas) so I want to add some sort of method to access them index style.
For example, here are some hypothetical properties that pre-exist:
public string Custom1 {get{somecodehere;}set{somemorecodehere};}<br />
public string Custom2 {get{somecodehere;}set{somemorecodehere};}<br />
public string Custom3 {get{somecodehere;}set{somemorecodehere};}<br />
etc etc etc
Can I create a generic List<> of those existing properties or an array of properties (or any collection) of those existing properties so I can set and get those properties using their existing code but access them by index?
(without using reflection?)
-- modified at 14:53 Thursday 29th March, 2007
Example (This is part of a much larger and complex class with dozens of other properties, database code etc, this is only an excerpt of the relevant bits for this issue):
<br />
class Class1<br />
{<br />
<br />
private string mCustom0 = null;<br />
private string mCustom1 = null;<br />
private string mCustom2 = null;<br />
<br />
public string Custom0<br />
{<br />
get { return mCustom0; }<br />
set<br />
{<br />
if (bReadOnly) ThrowSetError();<br />
else<br />
{<br />
if (mCustom0 != value)<br />
{<br />
mCustom0 = value;<br />
BrokenRules.Assert("Custom0", Messages.e255, "Custom0", value.Length > 255);<br />
MarkDirty();<br />
}<br />
}<br />
}<br />
}<br />
<br />
public string Custom1<br />
{<br />
get { return mCustom1; }<br />
set<br />
{<br />
if (bReadOnly) ThrowSetError();<br />
else<br />
{<br />
if (mCustom1 != value)<br />
{<br />
mCustom1 = value;<br />
BrokenRules.Assert("Custom1", Messages.e255, "Custom1", value.Length > 255);<br />
MarkDirty();<br />
}<br />
}<br />
}<br />
}<br />
<br />
public string Custom2<br />
{<br />
get { return mCustom2; }<br />
set<br />
{<br />
if (bReadOnly) ThrowSetError();<br />
else<br />
{<br />
if (mCustom2 != value)<br />
{<br />
mCustom2 = value;<br />
BrokenRules.Assert("Custom2", Messages.e255, "Custom2", value.Length > 255);<br />
MarkDirty();<br />
}<br />
}<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
public void SetCustomField(int index, string svalue)<br />
{<br />
switch (index)<br />
{<br />
case 0:<br />
Custom0 = svalue;<br />
break;<br />
case 1:<br />
Custom1 = svalue;<br />
break;<br />
case 2:<br />
Custom2 = svalue;<br />
break;<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
}
-- modified at 14:55 Thursday 29th March, 2007
|
|
|
|
|
Not sure if I completely understand what you are looking for. Something like this?
PropertyCollection[Custom1].Value
You could derive a class from CollectionBase
only two letters away from being an asset
|
|
|
|
|
I can't change the existing code with the exception that I can add anything I want to that class. What I want to do for some new UI code is access those properties by an integer index. I want to set and get those properties like normal, but do it through an as yet undefined....something.
I'm not sure what you're suggesting there but I don't think it's access by integer index, sorry if this isn't clear, I'm not sure how else I can explain it.
If this were a new class that I could write however I want to I would start from scratch with a generick List<string> instead of replicating those properties, instead I have to somehow "fake" it instead.
What I've done as a really crappy workaround for now is created separate set and get methods that accept an integer index and through a long switch statement set or get from the existing properties, but this seems inefficient compared to a directly indexed collection. Perhaps a collection of pointers to the properties, I don't know and searching about it is returning nothing but unrelated results.
|
|
|
|
|
Is this closer or am I totally off base
public class Custom1<br />
{<br />
private string m_Test;<br />
<br />
public enum Property<br />
{<br />
Prop1,<br />
Prop2,<br />
Prop3<br />
}<br />
<br />
public string this[Property x]<br />
{<br />
get<br />
{<br />
switch(x)<br />
{<br />
case Property.Prop1:<br />
return Prop1;<br />
default:<br />
return string.Empty;<br />
}<br />
}<br />
set<br />
{<br />
switch(x)<br />
{<br />
case Property.Prop1:<br />
Prop1 = value;<br />
break;<br />
default:<br />
break;<br />
}<br />
}<br />
}<br />
<br />
public string Prop1<br />
{<br />
set{ m_Test = value;}<br />
get { return m_Test; }<br />
}<br />
}<br />
Custom1 c = new Custom1();<br />
c[Custom1.Property.Prop1] = "Hello, World";<br />
<br />
only two letters away from being an asset
|
|
|
|
|
Hi Mark, that's sort of what I do now as a workaround with the switch statement, I want to do this without a switch statement. I've updated my original post to include a sample class of exactly what I mean.
|
|
|
|
|
Without using reflection that is an interesting question. Sorry I can't think of anything at the moment.
only two letters away from being an asset
|
|
|
|
|
Well I guess on the bright side I feel better that it wasn't something simple and obvious.
Thank you for looking at it, I appreciate it.
|
|
|
|
|
You mean like a List of delegates?
led mike
|
|
|
|
|
No I don't think so, delegates would be used with methods, not properties within the same class.
Maybe what I'm looking for is just not possible without resorting to reflection and string comparison of property names which is not much better than the giant switch statement way of doing it.
|
|
|
|
|
You seem to be eluding to introspection that does exist without all these limitations. Perhaps if you post some code or a link where we could see what you are referring to it might help.
led mike
|
|
|
|
|
Hi Mike I've updated my original post to include a sample class illustrating exactly the problem.
|
|
|
|