|
Are you trying to determine if it implements ICollection<T> or a concrete instance of ICollection<T> (say ICollection<int> )?
You could try using the <a href="http://msdn2.microsoft.com/en-us/library/system.type.isassignablefrom.aspx">IsAssignableFrom</a>[<a href="http://msdn2.microsoft.com/en-us/library/system.type.isassignablefrom.aspx" target="_blank" title="New Window">^</a>] method to determine if it implements any ICollection<T> or the IsGenericType[^] property?
You could also take a look at the ContainsGenericParameters[^].
|
|
|
|
|
I'm trying to determine if it implements ICollection<>, not a specific type like ICollection<int>.
IsAssignableFrom is a nice magical method, but it only works for specific types.
Anyways, I think I found the right way to do what I want (after, of course, putting my question in a public space...). Thanks for your help. Here's my solution, and the problem stated in sharper terms:
Supposing type X as follows,
class X
{
private class WackyClass<T> : ICollection<T>, IList<int> { }
private class XList : WackyClass<string> { }
static public readonly object Data = new XList();
}
Implement this method, which has no access to X's private types:
/// <example><code>
/// Type[][] args = GetGenericArgs(X.Data, typeof(ICollection<>));
/// Assert(args == new Type[][] {new Type[] {typeof(string)}, new Type[] {typeof(int)}});
/// </code></example>
Type[][] GetGenericArgs(Type subType, Type genericType);
Here is an implementation I feel much better about
if (genericType.IsGenericTypeDefinition == false)
if (genericType.IsGenericType && genericType.IsAssignableFrom(subType))
return new Type[][] { genericType.GetGenericArguments() };
else
return new Type[][] { };
else
{
IEnumerable<Type> candidates;
if (genericType.IsInterface)
candidates = subType.GetInterfaces();
else
candidates = Iterators.Traverse<Type>(subType, "BaseType");
List<Type[]> result = new List<Type[]>();
foreach (Type candidate in candidates)
if (candidate.IsGenericType && candidate.GetGenericTypeDefinition() == genericType)
result.Add(candidate.GetGenericArguments());
return result.ToArray();
}
|
|
|
|
|
I have a window that when it is minimized it is displayed in system tray. The problem is that from time to time I have to show different messages via a messagebox and the message box doesn't appear. When the window is maximized the messageboxes appear.
I am fighting against the Universe...
Reference-Rick Cook
|
|
|
|
|
You need to display the message box on the desktop. You can do this with this overload of the Show()[^] method. This overload allows you to specify additional options[^]. You want to specify the DefaultDesktopOnly option and (I think) pass null for the owner.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi all
while am writing to a text file using the way
PrintTextWrite.WriteLine(PSLNO.PadRight(3) + " " + PKCODE.PadRight(14) + " " + PITEMNAME.PadRight(45) + " " + PQTY.PadLeft(40) + " " + PRT.PadRight(11) + " " + PTOT1.PadLeft(20));
when PITEMNAME length increases there is alignment problem for PQTY & PRT & PTOT1
am i doing it proper way or is there any other way to set format for text file ???
thanks in advance
|
|
|
|
|
rowdykuttan wrote: when PITEMNAME length increases there is alignment problem for PQTY & PRT & PTOT1
Then check the lenth first, and if it is too large then truncate it. Or increase the space in the format.
|
|
|
|
|
am sending this text file to a DOT MATRIX printer, that too to a PREPRINTED STATIONARY, is there any way i can specify X & Y positions in text file or printer
|
|
|
|
|
rowdykuttan wrote: am sending this text file to a DOT MATRIX printer, that too to a PREPRINTED STATIONARY
You might like to specify that next time. It helps people understand your problem.
If you have a fixed external constraint like the size of preprinted paper then you have to truncate the information printed. Lop off a few characters. You'll find an appropriate method on the string class. Subseq, Substring or some such thing.
rowdykuttan wrote: is there any way i can specify X & Y positions in text file
If the file is formated as fixed length lines then you can calculate any XY position in the file and Seek to it.
(Y*LineLength) + X
LineLength includes the two character line feed and carriage return characters. It also assumes a fixed 8-bit character encoding.
|
|
|
|
|
If PITEMNAME's length is > 45, it is going to push everything over. You could truncate at 45 or you look at all the PITEMNAME values (assuming you are looping and trying to dump out data in columns) and set the pad accordingly rather than specifying 45.
If you are limited to your width and 45 is max, truncating is what I'd do, probably.
Good Luck!
It isn't enough to do well in life.
One must do good when and where one can.
Otherwise, what's the point?
|
|
|
|
|
Are you looking to do something like this?
1 George Washington April 30, 1789
2 John Adams March 4, 1797
3 Thomas Jefferson March 4, 1801
4 James Madison March 4, 1809
5 James Monroe March 4, 1817
6 John Quincy Adams March 4, 1825
7 Andrew Jackson March 4, 1829
8 Martin Van Buren March 4, 1837
9 William H. Harrison
March 4, 1841
10 John Tyler April 4, 1841
|
|
|
|
|
yes exactly but for William H. Harrison its comming in next line, i have left space for it like
1 George Washington April 30, 1789
2 John Adams March 4, 1797
3 Thomas Jefferson March 4, 1801
4 James Madison March 4, 1809
5 James Monroe March 4, 1817
6 John Quincy Adams March 4, 1825
7 Andrew Jackson March 4, 1829
8 Martin Van Buren March 4, 1837
9 William H. Harrison March 4, 1841
10 John Tyler April 4, 1841
i have enough space like this after name, plz tell me how to do it
|
|
|
|
|
You'll have to use <pre> tags in your response so I can see your formatting. Just modify your response, then I'll have another look.
|
|
|
|
|
1 George Washington April 30, 1789
2 John Adams March 4, 1797
3 Thomas Jefferson March 4, 1801
4 James Madison March 4, 1809
5 James Monroe March 4, 1817
6 John Quincy Adams March 4, 1825
7 Andrew Jackson March 4, 1829
8 Martin Van Buren March 4, 1837
9 William H. Harrison March 4, 1841
10 John Tyler April 4, 1841
|
|
|
|
|
Are you saying you want to adjust all the lines to account for the longest?
|
|
|
|
|
|
Ah, then scan through the data keeping track of the longest value length, then go through printing using those values.
|
|
|
|
|
Using vs05, I open the Data Source view, then click the Add New Data Source thing.
I add the database I want and all the tables show up. I can edit things using Edit DataSet with Designer without issue. Can preview data, and the results are what they are supposed to be.
Problem: When I try to drag a table to a form I get the error: “Length cannot be less than zero. Parameter name: length”
Any thoughts on what I’m neglecting to do here?
|
|
|
|
|
Seriously, don't use the wizards, don't drag and drop data connections. Write the code yourself - You'll be much happier, and it will work a lot better.
|
|
|
|
|
I'm glad somebody said that. I've never used the visual tools for database and was kinda starting to worry that I was missing out on something important. I even avoid using DataSets as much as possible, and I HATE the DataGrid.
|
|
|
|
|
How come it that you took the words out of my mouth?
I can only agree, i made the connections only once in one nice class and i reuse it in all my projects
|
|
|
|
|
ESTANNY wrote: How come it that you took the words out of my mouth?
It wasn't intentional. But the shock must have been quite something - It took you over 4 hours to recover and let me know!
|
|
|
|
|
This has so got to be a CE thing... because if I do what I’m trying in the full-blown framework, I’ve no problems at all.
In this CE, I can connect to the database using the wizards but, if I write the connection string, it refuses to connect.
It’s the same string, I copied it right out of the designer.
The length = 0 thing(from the first post) magically disappeared (no idea why, I didn’t do anything different when it stopped) but now even dropping a table on a form will give me a disturbingly vague “SQLException” error.
|
|
|
|
|
r u using windows or webapplication ?
|
|
|
|
|
Well, in this current edition… I’m developing in CE for little RF devices with almost no memory.
I’m going to try doing this programmatically, as was suggested, and see what happens.
Considering the lack of processing power on these things, I’m thinking about moving all processing to a server and accessing through WebMethods.
Assuming I don’t take a baseball bat to my computer
|
|
|
|
|
I want to Draw a Custom Background for the selected Item
Here is what I've tried
<br />
MyListBox()
{<br />
<br />
this.SetStyle(ControlStyles.DoubleBuffer, true);<br />
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);<br />
<br />
base.DrawMode = DrawMode.OwnerDrawVariable;<br />
<br />
this.DrawItem += new DrawItemEventHandler(this.DrawItemHandler); <br />
this.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.MeasureItemHandler);<br />
}<br />
private void MeasureItemHandler(object sender, MeasureItemEventArgs e)<br />
{<br />
e.ItemHeight = (int)(e.Graphics.MeasureString(this.Items[e.Index].ToString(), this.Font).Height);<br />
}<br />
private void DrawItemHandler(object sender, DrawItemEventArgs e)<br />
{<br />
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;<br />
<br />
if( e.Index == this.SelectedIndex)<br />
DrawItemBackground(e.Graphics, e.Bounds, Color.Peru);
else<br />
DrawItemBackground(e.Graphics, e.Bounds, Color.Pink);
<br />
e.Graphics.DrawString(this.Items[e.Index].ToString(), this.Font, this.writeBrush, e.Bounds); <br />
}<br />
Now, Everything shows up correctly initially but as I continue changing the selected Item the newer ones get painted properly but the old ones are not repainted. So all the items which are selected by me get painted in Peru. What I want is that only the one which the user selects gets its background painted in Peru and others Pink (repainted as non selected Items).
So Please Advice what am I missing.
Thanks...
|
|
|
|
|