.net

How to write a generic class that implements an interface having generic methods with constraints defined

I'm new to Generics implementation and need inputs on 2 issues I face : I have an interface ICommand defined as : public ICommand { List<T> Execute<T>() where T : IValidationResult; IDomain<T> GetDO<T>() where T : IValidationResult; } intentionally I have it as non-generic as I have to add a collection of different commands. ...

Write Binary File

I am reading data from an IPhone App that uses http POST to transfer the image to the Server I can read this into a an binary and it does write to a file (See below) the issue I have is when I open the image it fails. You can see the code from the Iphone on this post: http://stackoverflow.com/questions/1547967/asp-http-post-read-data C...

How do I use an IF statement in a loop with StringTemplate

This displays nothing: $Articles:{ $if(i!=1)$ display in between articles $endif$ $it.Text } This displays as expected $Articles:{ display in between articles $it.Text } Any ideas on how to get this working? ...

Generate random string

I need to generate a random string with a given length. This is my code so far. The problem is the random string is like "RRRRRR" or "SSSSS" The same letter every time. Just when i restart the app the letter change. I need something like "asrDvgDgREGd" public string GenerateChar() { Random random = new Random(); ...

Is it possible to get an IEnumerator<T> from a T[]?

Let's say I want to create a collection class that is thread-safe by default. Internally, the class has a protected List<T> property called Values. For starters, it makes sense to have the class implement ICollection<T>. Some of this interface's members are quite easy to implement; for example, Count returns this.Values.Count. But imp...

Do I need to call Graphics.Dispose()?

In a VB.NET program I'm creating a new bitmap image, I then call Graphics.FromImage to get a Graphics object to draw on the bitmap. The image is then displayed to the user. All the code samples I've seen always call .Dispose() on Bitmaps and Graphics objects, but is there any need to do that when neither have touched files on disk? Are ...

Storing Nhibernate ISession in Remote object contexts

Im currently building a remote object service that will expose a Server Activated object (per call, not singleton) that uses NHibernate. What i would like to know is there a way to tie a Nhibernate Isession to a .net Remote equivalent to the HttpSession.Context- an ISession per call of my remote object. I have a feeling that a per threa...

C# / Windows Forms - Display a PowerPoint slide-show without Office installed?

Hi guys, I know I can display a Powerpoint presentation within my own form (see here), but I'm wondering whether there is a way to get rid of Microsoft Office as a requirement? I guess basically what I'm asking for is a library which will display Powerpoint slide-shows without my users having to install MS Office on every machine. They...

C# Constants and Delegates

I've seen delgates and constants before in code but when and where are the appropiate times to use these? The uses that I've seen I can see other ways to program around them? Could any one tell me there true benefits for I've never used either. ...

.NET Throwing Custom Exceptions

Can anyone shed some light on the pros and cons of throwing custom exceptions (which inherit from System.Exception), or the proper way to use them? I'm already aware of the when/when not to throw exception, but I am looking for guidance on how to create my own custom exceptions. ...

How to determine the binding order of network interfaces on Windows using .NET?

I'm trying to find the magical answer to the "what's the primary IP address" of a system. My research has determined that the answer to "best" means this: Look at [system.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() for interfaces with default gateways assigned. If you only find one, then you are done. If there's...

C# Delegates Real World Usage

I've previously asked a question of about Delegates does anyone have a must have scenario where I would have to use a delegate? How does this improve my C# code? Just as many scenarios I use it in I've always seem to be able to program around it. ...

Options for showing a limited set of time zones?

I've always admired applications that, when asking you to indicate a timezone, only show you a set of likely options (in my case, only North American timezones), with an option to show more - rather than always forcing you to pick through dozens of obscure timezones. Any thoughts how to go about this in .NET? My first thought was to def...

How can a .Net application become a subscriber to a JMS (ActiveMQ) topic?

Please lay out the various ways for a .Net application to become a JMS (ActiveMQ) topic subscriber. Detailed and production-quality solutions would of course be best. ...

Mutable String Editing in C# / .NET

I want to take and edit a string in-place in a .NET app. I know that StringBuilder allows me to do in-place appends, inserts, and replaces, but it does not allow an easy way of doing stuff like this: while (script.IndexOf("@Unique", StringComparison.InvariantCultureIgnoreCase) != -1) { int Location = script.IndexOf("@Unique", String...

C# newbie with DateTime variable I want to set to null

I have an output data class with a DateTime variable. I want to clear that to a null value in a loader class but the compiler complains with: Cannot convert null to 'System.Data.Time' because it is a non-nullable value type. I understand that, but if I change the type to DateTime? creating the nullable type wrapper I get: No overload ...

I need to implement C# deep copy constructors with inheritance. What patterns are there to choose from?

I wish to implement a deepcopy of my classes hierarchy in C# public Class ParentObj : ICloneable { protected int myA; public virtual Object Clone () { ParentObj newObj = new ParentObj(); newObj.myA = theObj.MyA; return newObj; } } public Class ChildObj : ParentObj { ...

Using MAML for conceptual documentation of library

I am working on a new library and I am using XML comments for API documentation along with SandCastle which works really well. But I need to write additional documentation which covers concepts, overall architecture, working demos etc, class diagrams etc. I have 2 options: Use some wiki engine and write documentation wiki style. Use ...

Can making a method static improve performance, and under what circumstances?

When, if ever, is it faster to pass arguments as arguments to a static method rather than have the method be non-static and access the same values via instance members. Assume the method accesses these members in a read-only fashion. All other things being equal, calling a static method is slightly faster than calling an instance metho...

WPF - Can I use a derived style (ie. BasedOn) when overriding the ControlTemplate?

I have a style that overrides the ControlTemplate of the element (in this case, Label). So, I can use TemplateBinding to give the consumer control of certain things within the ControlTemplate. For example, I can set FontSize and Background explicitly in the Control and have access to these values within the ControlTemplate. However, th...