Re: [ADVANCED-DOTNET] Adapting code for .NET 2.0 CE

2006-08-03 Thread Sébastien Lorion
OK, I think my first question was badly formulated. So here is the intended one: Do delegates can prevent objects from being garbage collected in .NET 2.0 Compact Framework ? In other words, do they keep a strong reference on their target ? After some testing, it looks like the answer is no. Fol

Re: [ADVANCED-DOTNET] Gripe out the C# compiler...

2006-08-03 Thread Sébastien Lorion
bool b1 = (FixDBNull.Convert(dr["myIntColumn1"], 0) == 1); bool b2 = (FixDBNull.Convert(dr["myIntColumn1"], 0) == -1); bool b3 = (FixDBNull.Convert(dr["myStringColumn1"], "N") == "Y"); You cannot assume 1 == true, especially with databases. Sébastien On 8/3/06, Mike Andrews <[EMAIL PROTECTED]>

Re: [ADVANCED-DOTNET] Gripe out the C# compiler...

2006-08-03 Thread Mike Andrews
First, I agree that the whole concept of generics is just to prevent the problems as everyone has stated. Yet, I have a good reason for wanting such a cast. Take for example this generic class: public static class FixDBNull { /// /// Verifys that the specified data is not DBNU

Re: [ADVANCED-DOTNET] Using reflection to enumerate static fields

2006-08-03 Thread Ryan Parlee
I got things working just after I sent this email. Here's the solution for anyone interested: FieldInfo[] fields = typeof(Ids).GetFields( BindingFlags.Public | BindingFlags.Static); foreach (FieldInfo field in fields) { // Now using GetValu

[ADVANCED-DOTNET] Using reflection to enumerate static fields

2006-08-03 Thread Ryan Parlee
I have the following classes: public class IdDef { public IdDef(int id, bool hasA, bool hasB) { this.Id =id; this.HasA = hasA; this.HasB = hasB; } public int Id; public bool HasA; public bool HasB; } public class Ids { privat

Re: [ADVANCED-DOTNET] Gripe out the C# compiler...

2006-08-03 Thread Marc Brooks
Can anyone tell me any good reason why the C# compiler will not allow casting an int to a bool? 0) Because a bool is not an int (and a System.Boolean is not a System.Int32 etc...) 1) To resolve the ambiguity about what value true is (e.g. -1, non-zero, whatever). 2) To prevent stupidity like the

Re: [ADVANCED-DOTNET] Adapting code for .NET 2.0 CE

2006-08-03 Thread Sébastien Lorion
What I meant by "I can use a conditional compile and use a simple delegate in CF" is that the classes that use WeakMulticastDelegate in our framework could use a simple delegate in CF with a conditional compile and I would exclude this class from the CF solution. Sébastien On 8/3/06, Sébastien

Re: [ADVANCED-DOTNET] Adapting code for .NET 2.0 CE

2006-08-03 Thread Sébastien Lorion
So how does .NET 2.0 CF deals with delegate targets ? Do they prevent objects from being garbage collected ? Of course I can use a conditional compile and use a simple delegate in CF, but if delegate still keep a strong reference to their target, then I would need to find a way around that. Séba

Re: [ADVANCED-DOTNET] Adapting code for .NET 2.0 CE

2006-08-03 Thread Frans Bouma
You could use a conditional compile, which makes the routine not usable on CF.NET but that's a given, as CF.NET can't deal with the feature you need anyway. A conditional compile then could make your code compilable on .NET 2.0 and CF.NET 2.0 as well. Be sure that if you use the Serializable

Re: [ADVANCED-DOTNET] Gripe out the C# compiler...

2006-08-03 Thread John Brett
Can anyone tell me any good reason why the C# compiler will not allow casting an int to a bool? What's the mapping of integers to boolean values? If you're a C (C++) programmer, you'll say 0 -> false !0 -> true and consider the answer blindingly obvious. The question would be less obvious to a

[ADVANCED-DOTNET] Adapting code for .NET 2.0 CE

2006-08-03 Thread Sébastien Lorion
Hello everyone, I am in the process of adapting our internal framework (for .NET 2.0) to the .NET 2.0 CF (target is Windows CE 5.0). So far, it is only a matter of removing stuff and using different overloads, but now I got this problem: We have a WeakMulticastDelegate class that we use in vari

Re: [ADVANCED-DOTNET] Gripe out the C# compiler...

2006-08-03 Thread Frans Bouma
> Can anyone tell me any good reason why the C# compiler will > not allow casting an int to a bool? because a bool isn't an int? :) It's not C++ ;) FB > > example: > > bool x = (bool)1; > > > instead of doing something like this: > bool x = Convert.ToBoolean(1); > or > bo

Re: [ADVANCED-DOTNET] Gripe out the C# compiler...

2006-08-03 Thread Chris Anderson
bool x = (value != 0); > -Original Message- > From: Discussion of advanced .NET topics. > [mailto:[EMAIL PROTECTED] On Behalf Of Mike Andrews > Sent: 03 August 2006 14:16 > To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM > Subject: [ADVANCED-DOTNET] Gripe out the C# compiler... > > Guys, > > C

Re: [ADVANCED-DOTNET] Gripe out the C# compiler...

2006-08-03 Thread Bob Provencher
In cases like that I usually do something like bool x = ( value != 0 ); -Original Message- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Mike Andrews Sent: Thursday, August 03, 2006 9:15 AM To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: [ADVANCED-DOTNE

[ADVANCED-DOTNET] Gripe out the C# compiler...

2006-08-03 Thread Mike Andrews
Guys, Can anyone tell me any good reason why the C# compiler will not allow casting an int to a bool? example: bool x = (bool)1; instead of doing something like this: bool x = Convert.ToBoolean(1); or bool x = bool.Parse(1); Makes it very difficult to write generic methods where I need to ca