Answer Questions
Shawn de Wet retrieving the type of a generic Type argument
Hello, I have a question considering generics.If we take the next code snippet: public abstract class TypedResourceRetriever<T>{ public Type ResourceType{ get { return T; } } } This code does not work. I wonder why microsoft did not make this work. It would be really handy for me to have this feature in the C# language. I solved the problem with the code below: public abstract class TypedResourceRetriever<T>{ public Type ResourceType{ get { Type t = this.GetType(); while (! t.Name.StartsWith("TypedResourceRetriever")){ t = t.BaseType; } return t.GetGenericArguments()[0]; } } } Obviously this is not the way to do it. (if someone o ...Show All
Paryse Compare filename to a mask
I have a FileInfo object. I need to compare the FullName property to a mask like "*.jpg" or "warcraft.*" or " rant.bmp" to see if it matches. How can I do this Thanks I need to compare the filename against any legitimate filename mask, the ones used by windows including * and . Not just the ones listed. Hi Joel, the method GetFiles in the class System.IO.Directory gives you the possibility to specify a search pattern. If you already have a file list and cannot search through a directory, you'll need to check the names with regular expressions. -- Regards, Daniel Kuppitz Hi Haris, Have i reached u ...Show All
RayDMS Modifying an exception by ref?
I'd appreciate opinions on how to handle this. I created a generic Retry function that implements some logic for retrying an operation until it is successful or a user cancels operation. One essential part of this Retry functionality is allowing the caller to specify a delegate that handles an exception and returns a bool indicating whether retrying should continue or not. This allows the delegate to implement specialized operations like checking exception handling policies, or prompting the user with a message box telling them to reestablish network connectivity and then retry, or if they choose cancel then the exception handler can return false to signal the retry function to give up. In the case that the exception handler indicates fals ...Show All
mNilysg how to calculate age?
how can i calculate age in years and months.. for example 26y 2m DateTime birthday = ...... TimeSpan age = DateTime.Now - birthday; int years = age.Days/ 365; int months = (age.Days - (year * 365))/30; string strAge = String.Format("{0}y {1}m", years, months); What have you tried so far The following might inspire you... public static long TimeSpan(DateTime begin, DateTime end, SpanUnit spanUnit) { TimeSpan ts = ts = end - begin; switch (spanUnit) { case SpanUnit.Year: return end.Year - begin.Year; case SpanUnit.Month: return (end.Month - begin.Month) + (12 * (end.Year - begin.Year)); case SpanUnit.Weekday: return Fix ...Show All
Rocking Karthik How to activate the forms application?
Hi, I am developing a windows form application.If my application is minimized how can I make it visible . my application is waiting for a event from a hook procedure. I tried SetFocus() but it returned the "false". How can I achive this. Regards, Hemant. take a look here http://www.pinvoke.net/default.aspx/user32/SetForegroundWindow.html diff=y hope this helps I've tested it here, setting WindowState to Normal after calling AppActivate, and it works fine. The following code will work: Process process = Process .GetCurrentProcess(); Microsoft.VisualBasic. Interaction .AppActivate(process.Id); You'll need to add a reference to the Microsoft.VisualBasic assembly, an ...Show All
Maplesoft automagically adding "" {} () [] etc...
I was at an MSDN event yesterday and the presenter enabled a setting in VS2005 that would automatically add a pair of quotes "" whenever the context was expecting it. I have looked in my options of VS2005 standard and I can't find an options which does this. I have found options which purports to automagically add braces {} when a new line is typed I.E. class MyClass { <these added when new line (enter key) typed. } However my system doesn't do this. Is there a master setting somewhere that enables these enhancements Thanks Edwin EdwinSmith wrote: I was at an MSDN event yesterday Ironically I learned about an intellisense feature at a MS event too. It was the property templ ...Show All
nativecpp Quick question - typedef in C#
Hi! I'd like to define my own type in C#. Is there any command similar to C++ typedef using DWORD = System.UInt32; should do it. But note that the statement is scoped per file. You can use "using" to create type name alias. OK - thanks. Sorry - that doesn't tell me anything. I tried using uint DWORD; - an error occured Could you give me a code sample how to do this it's explained here, with examples: http://msdn2.microsoft.com/en-us/library/sf0df423.aspx ...Show All
SnowJim how to avoid downloading the whole .net framewrok to run the c# application
hi , here is the prob... when i finished my program ,,i published it.>> then i sent it to a friend >> then the program asked him to download the .net framwork which is too big 200 mb or more . i changed the prerequirements in the publishment properties ,,>>>sent the program again .>>and it didn't ask for the .net frame work but ofcourse it didn't work so here is the question... Is there is anyway to avoid downloading this whole big framework and running my small apllication is there something like dll 's or that could be installed with my application which will run it instead of framwork.. please answer me ,,and i'll be so greatful. and i wish my question will be helpful for other beg ...Show All
thelonesoldier Centronics Ports
Is possible to control ports LPT in Visual C# similar SerialPorts The SerialPort class provded with the .NET framework is only a wrapper around the Win32 APIs, there's no wrapper for LPT, you have to write your own (or find a 3rd party driver) and then write a P/Invoke wrapper to use it from a managed language. Check this thread ... ...Show All
David Pallmann True Copying Reference-Value Objects
I have stumbled upon the following problem: Given an object (any reference-value class) O1, how can I copy it to another object O2. O1 = O2; //will only copy the reference, but I want a new object being exactly identic to the old one. Also, how can I do the same thing on an Array int[] arr1, arr2; arr1 = arr2;// also, doesn't work, only copies the reference Hope I made myself clear enough. Thanks in advanced. Hi, You need to implement it yourself. Meaning you need to override the base implementation and give your own "deep" copy. Guy kolbis Thank you for the answer, but I have another question. How do I do a deep copy of ArrayList the ArrayList ...Show All
Dan Sherwin Pet Shop for C# 2005 ...
Hi folks ... I realize this might be better in the asp.net forum, but posting a thread there seems to be a bit of a mystery. Please excuse the location. I'm wondering if there is a "Pet Shop" demo for C# and asp.net that is more recent than the 3.0 version, and works w/ Visual Studio 2005. Thanks DB here you go... http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnbda/html/bdasamppet4X.asp ...Show All
pmanisekaran ProgressBar Dilemma
My user wishes to see visual proof that their app is processing files. I've never used a ProgressBar before and I'm trying to get a test to work before I 'muddy-up' my production app. I've gotten to the point that I can get the Value to display as each record in a file is read; however, when it gets to the final record it displays the following exception: Value of '1894' is not valid for 'Value'. 'Value' should be between 'minimum' and 'maximum'. Parameter name: Value I know what the problem is (there's 1893 records in my test file), I just don't know how to fix it. I've tried to set the record count to it's value +1 ( this . thisProgressBar . Maximum = Convert . ToInt32 ( m_strInputFile . Length / 1024 + 1 ); ), but still g ...Show All
Greg Wojan Problem with loading/unloading DLL from a separate appDomain
Hi, I want to dynamically loading assembly dll to have an instance of a type in that assembly. The thing is the assembly is updated on demand frequently so I need to unload and then reload the dll. So I load it from a separate domain. First I create a new appDomain using AppDomainSetup with shadow copy enabled: AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory; setup.CachePath = AppDomain.CurrentDomain.BaseDirectory+"\\Shadow"; setup.ApplicationName = "Loading"; setup.ShadowCopyFiles = "true"; setup.ShadowCopyDirectories = AppDomain.CurrentDomain.BaseDirectory; newDomain = AppDomain.CreateDomain( "loaderDomain", null, setup); Then a remoteLoader is created ...Show All
Naftis Access a un object from another object without passing a reference
Hi. I'm using remoting to serve data, now i want write in a textbox and when a petition arrive , return de text in the textbox. Example: public class Form1:Form { TextBox Textbox1 = new TextBox(); Textbox1.Text ="text to send by Pettion1"; } public class RemotingServer: MarshalByRefObject { public string Pettition1(string sString) { // How to access to Textbox1.Text from here return sString; } } The problem is that the object RemotingServer don't create in Form1, only create when foreging cliente execute a query... thus i can't access to the string that contains Textbox1.Text because i haven't any reference to Form1 ... some idea for do it In other projects, i can pass a reference in the class ...Show All
xlordt Unable to open the physical file"
I have just completed the installation of Visual C# Express and I am attempting to connect to a delivered SQL .mdf database using the database browser of the IDE. When I test the connection, I'm getting an error that the system is unable to open the physical file and "The Process cannot access the file because it is being used by another process". I do not have any other applications open other than Visual C# Express. I have tried shutting down and rebooting the computer but I still get the same error. Does anyone have any suggestions on how I can around this problem Thanks, Richard . try using Unlocker http://ccollomb.free.fr/unlocker/ ...Show All
