|
Thank you for your answer.
In this case, there's a basic interface that Csla.Silverlight.PrimitiveCriteria class implements, but that interface contains only basic methods. For example, Value property is specific for Csla.Silverlight.PrimitiveCriteria class. Other properties can be specific for other classes. What to do in that case?
|
|
|
|
|
I'd add my own interface. It doesn't have to be implemented in the CSLA-classes, just in the classes that you're going to serialize.
That would give you the option to deserialize 'unknown', check if it matches an known interface and cast it thereto.
I are Troll
|
|
|
|
|
The problem is that I can't change the code in the classes I deserialize. They are all in some DLL that I use in my DLL.
|
|
|
|
|
Tesic Goran wrote: The problem is that I can't change the code in the classes I deserialize.
Are they sealed ? If not, inherit, wrap and add an interface
I are Troll
|
|
|
|
|
If I understand you correctly, I could create new class, for example PrimitiveCriteriaNew that inherits from Csla.Silverlight.PrimitiveCriteria and implements new IInterfaceNew in this way:
public interface IInterfaceNew
{
}
public class PrimitiveCriteriaNew : Csla.Silverlight.PrimitiveCriteria, IInterfaceNew
{
}
And use it in this way:
object o = Csla.Serialization.Mobile.MobileFormatter.Deserialize(bin);
object val = ((PrimitiveCriteriaNew)o).Value;
Is this correct? If so, if I have 1000 classes in that external DLL, I should do the same 1000 times?
|
|
|
|
|
Tesic Goran wrote: Is this correct?
Looks good to me, although I'd suggest you keep the interface-type after the cast, like this;
object o = Csla.Serialization.Mobile.MobileFormatter.Deserialize(bin);
IInterfaceNew val = ((IInterfaceNew)o).Value;
Tesic Goran wrote: If so, if I have 1000 classes in that external DLL, I should do the same 1000 times?
No, you can probably generalize some interfaces in a way that they can be re-used.
I are Troll
|
|
|
|
|
Hi,
Instead of writing :
object o = Csla.Serialization.Mobile.MobileFormatter.Deserialize(bin);
object val = ((Csla.Silverlight.PrimitiveCriteria)o).Value;
You may go with dynamic here: Simple reading and access
dynamic o = Csla.Serialization.Mobile.MobileFormatter.Deserialize(bin);
object val = o.Value;
You don't need to cast it any where
For more details about dynamic you may go on this.
Perform Reflection and XML Traversing Using the dynamic Keyword in C#[^]
This may be helpful to you.
Thank You
|
|
|
|
|
|
i Need to develop a windows service which will log whatever website is visited from the pc where this service will be running. user can use any browser to browse the site but i want my win service will log site name,IP address,time when visit etc. i have no concept how to accomplish this. do i need to read network card. if yes then how extarct all my require data from network card. it is not about any hacking.
tbhattacharjee
|
|
|
|
|
|
Tridip Bhattacharjee wrote: i have no concept how to accomplish this.
Logging traffic (and blocking it) can be done using a firewall or a proxy.
Tridip Bhattacharjee wrote: user can use any browser to browse the site but i want my win service will log site name,IP address,time when visit etc
When I launch MSN Messenger and it starts to fetch the ads - does that count as browsing a website?
Tridip Bhattacharjee wrote: it is not about any hacking.
You're right, it's about logging - do make sure that the subject knows his/her actions are being logged, or a court might rule otherwise.
I are Troll
|
|
|
|
|
The standard way to do this is to write a proxy server, or, just use one off-the-shelf. Your program requirements, as you've listed, are not that uncommon.
|
|
|
|
|
How to set the correct mask without promt chars display and right logic to enter IP address without starting zeros and parse it since the returned value are numbers without separating char?
9ine
|
|
|
|
|
|
Iam using vs2010. And I need to access my sql table in various places. For that in VB2008 I used by modules. But in C# I don't know where to keep the below codes in a place and how to access it from various forms... The code look like below...
public string ConStr_1 = "Data Source=2.2.1.90; initial Catalog=MyDatabse; User Id=abcd; Password=1234";
public System.Data.SqlClient.SqlConnection Con = new System.Data.SqlClient.SqlConnection();
public System.Data.DataTable MyTbl = new System.Data.DataTable();
public System.Data.SqlClient.SqlDataAdapter MyDAp = new System.Data.SqlClient.SqlDataAdapter();
string My_Qry = "Select * from MyTable";
public void MyTblCollection()
{
Con.ConnectionString = ConStr_1;
Con.Open();
MyDAp = new SqlDataAdapter(My_Qry, Con);
MyDAp.Fill(MyTbl);
Con.Close();
}
Hence where to add these code for further access with all other forms.[same like module in vb]
Thanks
|
|
|
|
|
Write a Data Access Layer class and pass a reference to it to each Form that requires it.
|
|
|
|
|
Not even a minor sneer on DataTables and DataSets?
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
No, too early yet. And I do use DataTables (when appropriate) in mine.
I considered giving an example of building a List with a DataReader, but decided I really needed a shower.
|
|
|
|
|
PIEBALDconsult wrote: but decided I really needed a shower.
that's kind of a strange reaction to using DataTable s...
BTW, why have the old tried/true methods of database acces ssuddenly gone out of favor, and what are used in their places?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
John Simmons / outlaw programmer wrote: that's kind of a strange reaction to using DataTable s...
More in response to DataAdapter s. There, now I had to take another shower, are you happy now?
John Simmons / outlaw programmer wrote: the old tried/true methods of database acces
You mean like PRO*C and ESQL ? Or ODBC ?
John Simmons / outlaw programmer wrote: why have ... gone out of favor
Because the namby-pamby WSIWYG drag-and-drop crowd can't write decent SQL and think that everything should be an object regardless of whether or not it makes any sense for it to be.
John Simmons / outlaw programmer wrote: what are used in their places?
ADO.net is OK if you use it properly. Linq, EF, and other things that lay atop it and hide the developer's ineptitude, not so much.
I still hope to develop something like PRO*C for C#.
|
|
|
|
|
you can have classes that aren't forms. I suggest you read some of the nice database articles here on CodeProject, maybe this one: Using ADO.NET for beginners[^]
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
That does look like a good article. I guess I've never seen it before because it was posted before I joined. I'll have to read it more fully later.
|
|
|
|
|
When I have variables that need to be accessible application-wide, I keep them in a static class. Using some of your example code:
public static class Globals
{
public static string ConStr_1 = "...";
public static void MyMethod()
{
}
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
I have done something similar to that in the past. I went as far as storing the individual connection string elements in App.config... so I don't hard code them.
|
|
|
|
|
That's not a good technique for a database connection because sometimes you need more than one -- use a regular class.
|
|
|
|