Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

MCEdwards

@MCEdwards
About
Posts
15
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Is it true about Chrome?
    M MCEdwards

    I think officially it is when 20% of your code is JavaScript and you can use the term Ajax three times in a sentence meaningfully. ;P

    The Lounge com question

  • Hobbies
    M MCEdwards

    Just a few: Kung Fu Power Kiting Climbing Walking Gym Motorbiking I find that I need to do something active to balance out the long hours of sitting at a computer. After about 8 hours at a computer my face looks like this X|

    The Lounge sales question

  • Casting Nightmare
    M MCEdwards

    Ok I have found that this is not possible but I wanted to know if anyone knew a way around this problem. I have an abstract item class called AbstractMyItem, from this class I implement several items, one for example is MyBox. So the code for the box is:

    public abstract class AbstractMyItem{}

    public class MyBox: AbstractMyItem{}

    For each item I want there to be a provider that performs some basic functionality for example:

    public interface IMyItemProvider{
    public AbstractMyItem [] LoadItems();
    }

    So for each I create a provider from the interface:

    public class MyBoxProvider : IMyItemProvider {
    public AbstractMyItem [] LoadItems();
    }

    However this creates a lot of casting as I have to cast the AbstractMyItem class to the MyBox class. It makes more sense to use generics like this:

    public interface IMyItemProvider<T> where T : AbstractMyItem{
    public T[] LoadItems();
    }

    public class MyBoxProvider : IMyItemProvider<MyBox>{
    public MyBox[] LoadItems();
    }

    However as I said before I need to create a list of these providers. So in theory the obvious solution is:

    List<IMyItemProvider<AbstractMyItem>> providers = new List<IMyItemProvider<AbstractMyItem>>();

    providers.Add((IMyItemProvider<AbstractMyItem> ) MyBoxProvider);

    However this will not work. You can't cast the concrete class to a the interfaced generic type. This does not work:

    IMyItemProvider<AbstractMyItem> instance = (IMyItemProvider<AbstractMyItem> ) MyBoxProvider;

    So the question. Anyone know of a good way to get around this problem? To be able to use generics with a list and assign my concrete classes to it? It would be nice to say (I know this not real code).

    List<IMyItemProvider<inherits AbstractMyItem>> providers = new List<IMyItemProvider<inherits AbstractMyItem>>();

    providers.Add((IMyItemProvider<AbstractMyItem> ) MyBoxProvider);

    C# question help tutorial

  • problem with web controls
    M MCEdwards

    This message means that you are trying to place a text box outside the page form. You need to ensure that you place the textbox between a form tag with runat="server". For example: <asp:TextBox id="textbox1" runat="server" /> If you want the textbox to be in the table then ensure that the table is between the form tags. The simplest solution is to add the form tag to the master page so that it wraps the content place holder, this means that any page that inherits the master page will automatically have the form tag. This is not best practice because it will mean that pages that do not use forms will have the form and therefore view state sent with them which increase page download times and eats your bandwidth, but for quick test solution its job done. Hope this helps.

    ASP.NET help visual-studio sysadmin json tutorial

  • How can I load an image in C#
    M MCEdwards

    Apoll The contructor is run when the a class is instantiated. A constructor has the same name as the class. In your code the constructor is public Form1(){ InitializeComponent(); } What you will want to do is pass in the file name from the arguments list into this constructor. Modify the constructor to accept the path as a string like so: public Form1(string ImagePath){ InitializeComponent(); } Then in the main method pass the path to the new form like so: static void Main(string[] arguments) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1(arguments[0])); } I have assumed that the path is stored as the first item in the array. You can then call the initialize method and pass in the path to the file (you will of course have to modify your initialize method to accept the file path as a parameter. Hope this helps. :)

    C# question csharp

  • Get number used for Enum
    M MCEdwards

    I think a slightly better solution in this case is to use the int type rather than the Int32 object. I have not really used the Int32 object but I assume that it acts in the same way as other objects in that it passes itself by reference instead of value. This may then catch out other developers who are used to integers being value types and not objects. Instead use: TestEnum te = new TestEnum(); int enumNumber = (int) te; Hope this helps.

    C# question

  • Sending http request to server using C#.net
    M MCEdwards

    I .Net Framework 2 there is a very useful calls called the System.Net.WebClient class. This class contains methods that allow you to quickly make http and https requests and process the return. You can set headers and post information. I have used it to create a http post to remote servers and receive a response. Here is some code: Byte [] PostData = System.Text.Encoding.ASCII.GetBytes("hello world"); System.Net.WebClient client = new System.Net.WebClient(); Byte[] Response = oClient.UploadData("http://www.somewhereintheworld.com", "POST", PostData); return System.Text.Encoding.ASCII.GetString(Response); These first line just turns the post data I want to send into a byte array. I create the WebClient object on the second line and then on the third line I tell the client to send the data to the target website as a post action with the byte array I have created. This returns a byte array that I then need to turn back into a string which is done on the last line. Happy browsing.

    C# csharp help sysadmin

  • MVC Framework
    M MCEdwards

    We have just started to use castle and its very good. The main problem we found was that there is not a huge amount of information about it but once you understand it (whichfor me was a hours demo by a fellow techi so all the hard work had been done ;P) we were up and running. We did not use the MVC pattern with it however, we have preferred the MVP pattern. We found this related better to the way we wanted to work with ASP.NET page and made it very easy to tie the pages to the presenters.

    The Lounge asp-net csharp architecture question

  • Asynchronous Web Service Calls from Client Application
    M MCEdwards

    By the looks of it no, you will need to create a way of checking that all the async request have completed. For more info on async see: http://www.developer.com/net/net/article.php/11087\_3481691\_1 and for creating async ASP.NET pages that consume web services see: http://msdn.microsoft.com/msdnmag/issues/05/10/WickedCode/

    C# csharp help

  • Asynchronous Web Service Calls from Client Application
    M MCEdwards

    Sorry my information is a little out of date. Things have changed it seems from 1.1 to 2. Anyway I created a quick test service and console app. You need to assign an event handler to the completed event for the method invoked. Then invoke the method using the async method call. The result of the method call is contained in the event args passed into the event handler. You have to think about the race condition between the main thread and the async thread when using this method of invoking the async call. Here is my code: static void Main(string[] args) { TestConsoleApp.localhost.Test Test = new TestConsoleApp.localhost.Test(); Test.HelloWorldCompleted += new TestConsoleApp.localhost.HelloWorldCompletedEventHandler(Test_HelloWorldCompleted); Test.HelloWorldAsync(); Console.ReadLine(); } static void Test_HelloWorldCompleted(object sender, TestConsoleApp.localhost.HelloWorldCompletedEventArgs e) { Console.Write(e.Result.ToString()); } Hope this makes sense

    C# csharp help

  • Asynchronous Web Service Calls from Client Application
    M MCEdwards

    Did you manually create the web reference or did you use VS to generate the web reference? If you are using VS remove the reference to the web service and delete the generated cs file. Then add the reference again, there should be no probably with this since all the async behavior is controlled by .Net on the client application side. The remote server does not need to know anything about the async behavior of the client. If however you have created the class yourself you will need to manually add the async calls. Here are some useful links: http://msdn2.microsoft.com/en-us/library/d9w023sx(VS.71).aspx http://www.c-sharpcorner.com/UploadFile/ssrivastav/UsingAsynchronousWebServices11232005071049AM/UsingAsynchronousWebServices.aspx

    C# csharp help

  • Managing Configuration
    M MCEdwards

    We are having problems correctly managing our configuration files across multiple servers and environments. Currently we either save a separate copies of the configuration files for each environment or comment out values for other environments and add the new environments values beneath. There has to be a better way!!! Does anyone know of an application that will manage these configuration files? Something that preferably will also version control the configuration files?

    .NET (Core and Framework) workspace collaboration question announcement

  • Synchronous message transmission
    M MCEdwards

    It seems to me that if each message is being send async over different sockets you are going to need some way of identifying which sets of messages are related, the order in which they are meant to arrive and the total number to expect. The simplest solution I can think of is to create a message header that details this information. The receiving system should then be able store incomplete message sets and wait until the total number of messages has arrived before sorting them by message order. The receiver will need to be designed to be able to handle multiple sets of messages being sent at the same time to avoid data clashes. I would also add some sort of check sum if the data is going over a public network to ensure that no one has tried to inject messages into the system.

    The Lounge com tutorial question

  • January 1st Code Project Poll
    M MCEdwards

    Edina is right in that Vista needs new hardware but vendor as selling substandard hardware with Vista on it. This means that end users think that VIsta is slow, badly designed and worse than XP. I have a neighbor who sold Vista on a Intel Celeron Laptop with 512mb of memory, unsurprisingly the laptop started up and then decided that life was not worth living and took the next 30 minutes to get onto the desktop. On the flip side Vista has it's own fair share of faults, mainly not being compatible with older software, even Microsoft's own software. I am a .NET programmer and was very surprised to find that I could not use parts of Visual Studio without running it in administrator mode. I then found that some other programs could not perform the tasks they needed without going into Administrator mode. This seems odd to me because it creates a loop hole in the security setup. It would not take mush for a hacker to design something that runs in VS knowing that it will probably be run in Administrator mode on a Vista machine and then take over the machine. I am sure there other apps in a similar situation. Overall vista has done nothing new, was not as great an improvement as XP was over previous versions.

    The Lounge csharp ios visual-studio question announcement

  • another preference question....
    M MCEdwards

    One advantage of using the Init() method comes from being able to subscribe to the an Event that is fired when the class values are initiated. If you want an series of events to fire immediately after the class has been initialized this would not be possible using a constructor. Using an Init() you can create the class, subscribe events and then populate the data. So imagine that you new class is passed through a set of methods, you may not know at what time within the methods it is being populated but you can still capture the event a perform some action upon it. To be honest I have yet to use this type of setup and have found that using constructors is more than sufficient.

    The Lounge question c++ design collaboration performance
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups