|
Have you tried Google[^] to look for a .NET wrapper around the zlib libraries?
|
|
|
|
|
What is this Google you speak of?
|
|
|
|
|
It's this new-fangled contraption that automagically gives you the answer to any question you ask. I know, it's heresey, isn't it?
|
|
|
|
|
And it really works[^]...
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
yep, but didnt find anything about Zlib
Becoming Programmer...
|
|
|
|
|
|
opps..!! i forgot to click on it
Becoming Programmer...
|
|
|
|
|
I have myObject and I want to know whether it is an instance of ICollection<T> for some unknown T. In simple cases, this might suffice:
myObject.GetType().GetGenericArguments()
However, I have many classes like this:
class XCollection : MySuperCollection<X>
class YCollection : MySuperList<Y>
So myObject's immediate type may not have any generic arguments. Remembering that one class my implement ICollection<T> for many types T, I'd like a method like this:
/// <returns>
/// The value of GetGenericArgs(), a Type[], for each specific type of the
/// given genericType that is implemented by subType.
/// </returns>
Type[][] GetGenericArgs(Type genericType, Type subType)
Which could be used like this:
Type[][] elementTypes = GetGenericArgs(typeof(ICollection<>), myObject.GetType())
// elementTypes == new Type[][] { new Type[] { typeof(X) } };
One way is to require genericType to implement ICollection<>, check for methods named 'GetEnumerator', get each possible T implied by these methods, and then check whether myObject is an instance of ICollection<T> for each specific possibility. I can implement this, and I'm sure it will work, but it's Wrong. Is there an appropriate way to do this?
|
|
|
|
|
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?
|
|
|
|