473,327 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Factory pattern or Generic Solution for c# 2.0

1
Hi,
i have have to parse server messages on the client side.
Now i need a perfect design pattern to solve it in a clean way.

I have up to 100 messages, if i got a packet with a correct ID for a Message i want to parse that message. Every message is a class that deserialize the bytes.


Now my problem is to cast each message.
How to declare a dynamic Type.


Expand|Select|Wrap|Line Numbers
  1. myMessage varP = new myMessage();
  2. varP.deserialize();

How to get myMessage dynamic that i can cast to 100 Messages without a if block -> if (id ==10) then ...

I had no success doing it like this:

Expand|Select|Wrap|Line Numbers
  1. Type myMessage = mycollection[10].getType();
  2. myMessage varP = new myMessage();





It have to be a .net 2.0 solution better would be 1.1 :-)

Could someone give me a hint to solve such dynamics?

thankfull in advance
Dec 29 '09 #1
0 1220

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Christian Stork | last post by:
Hello everybody, I am using Python to prototype a compression algorithm for tree-shaped data, e.g., XML data or abstract syntax trees. I use a variant of the visitor design pattern--called...
17
by: Medi Montaseri | last post by:
Hi, Given a collection of similar but not exact entities (or products) Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern to provide a common interface to these products....
0
by: Alex | last post by:
I am currently building part of an app where I am using the Factory Pattern. However, I am starting to wonder whether it is the right pattern for the solution I need. The factory basically needs...
5
by: Anders Borum | last post by:
Hello! Whilst refactoring an application, I was looking at optimizing a ModelFactory with generics. Unfortunately, the business objects created by the ModelFactory doesn't provide public...
7
by: Jock | last post by:
Hi all, Could anybody suggest what should be the return type of the method Create in the Factory class? In Java I would have used the wildcards, but here in C# apparently there is no way do do...
0
by: ma740988 | last post by:
I'm going through modern C++ design looking for tips and while hi-tech I suspect one solution to my issue would involve the factory design pattern. // algorithms.h class Algorithms {...
8
by: googlegroups | last post by:
Hi, I need to parse a binary file produced by an embedded system, whose content consists in a set of events laid-out like this: <event 1<data 1<event 2<data 2... <event n<data n> Every...
5
by: Agrona | last post by:
I found this thread: http://www.thescripts.com/forum/thread233505.html only marginally helpful. It seems that going through the callstack is the only way to determine which function may have...
5
by: CSharper | last post by:
I have created a Factory pattern code. One thing I noticed after coding, each factory has some methods they are exactly same and doing the same code using the values specific to each factory, if I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.