.net

DataBinding: Validate before change

[.NET 2] Situation: class MyObject { string Max { get{...}; set{...}; } string Min { get{...}; set{...}; } } MyObject myObj1 = new MyObject(); // ... code txtMin.DataBindings.Add("Text", myObj1, "Min"); txtMax.DataBindings.Add("Text", myObj1, "Max"); Problem: Need verifying Min < Max bef...

DataPager and Datagrid, How to move to the page of current selecteditem

In a Silverlight project I have a view with a list (DataGrid) of cases. The list is paged with DataPager. My source collection is wrapped in an PagedCollectionView. When an item is created it is added to the list and set as selecteditem in the DataGrid, depending on the list sorting, this could be on another page the the current active ...

Questions about advanced compiler settings in visual studio Express 2008 express edition

All the information I've found regarding compiler settings is with regards to the full version of VS, which seems to be at odds with the express edition. The first point is, there is no option on the screen to say if I'm setting options for debug or release mode. Now to the questions: (1) The enable optimizations option is checked. Is ...

How to replace standard DataAnnotations error messages

Hello. I'm using System.ComponontModel.DataAnnotations to validate my model objects. How could I replace messages standard attributes (Required and StringLength) produce without providing ErrorMessage attribute to each of them or sub classing them? ...

.NET ex.Message vs ex.ToString?

I have code that is logging ex.Message. However I read an article that it's better to use ex.ToString(). This way you retain more crucial information about the error. Is this true, and is it safe to go ahead and replace all code logging ex.Message? I'm also using an XML based layout for log4net. Do you think the ex.ToString() will co...

Bullet indents in PowerPoint 2007 compatibility mode via .NET interop issue

Hello. I've got a really difficult bug and I can't see the fix. The subject drives me insane for real for a long time. Let's consider the following scenario: 1) There is a PowerPoint 2003 presentation. It contains the only slide and the only shape, but the shape contains a text frame including a bulleted list with a random textual repr...

IoC.Resolve vs Constructor Injection

I heard a lot of people saying that it is a bad practice to use IoC.Resolve(), but I never heard a good reason why (if it's all about testing than you can just mock the container, and you're done). now the advantages of using Resolve instead of Constructor Injection is that you don't need to create classes that have 5 parameters in the...

Displaying trailing zeros except when a whole number

Is there a way (in .NET) of removing trailing zeros from a number when using .ToString("..."), but to display to 2 decimal places if the number is not a whole number: (12345.00).ToString(...) should display as 12345 (12345.10).ToString(...) should display as 12345.10 (12345.12).ToString(...) should display as 12345.12 Is there 1 numb...

Office 2003 interop problems, interface, method not found.

This problem is making me crazy. Actually I have multiple problems. First one: Why on earth are is there a _Worksheet and a Worksheetinterface in the Excel interop. They both look the same, except for some attributes on the methods. It's confusing! Second of all: my job today is making a VB.NET file more strict, by settings Option ...

Using a "does not end with" regex for replacement purposes: how to avoid replacing the last character?

I'm using the following regular expression <a href="[^/] to find all links which do not start with a slash. I want to use the result of this regex to replace all <a href="somelink.html"> tags with something like <a href="http://mysite.com/somelink.html"&gt;. But the problem with my regular expression is that (in the above example) th...

What are good ways to architect a custom "ClaimsAuthorizationManager" Windows Identity Foundation class?

I am working on the very first project at my office where we will be using "Windows Identity Foundation" with Claims-Based-Authorization. To this end, Microsoft .net provides the ClaimsAuthorizationManager abstract class. In order to use this class, you override two methods: the constructor and CheckAccess(context as ClaimsAuthorizatio...

i18n yellow screen of death

System.InvalidOperationException:Värdet null kan inte tilldelas en medlem av typen System.Boolean eftersom den är en värdetyp som inte kan ha värdet null. Thank you Microsoft, intentions are good, I know. As if anybody who really finds this information useful would also consider Swedish as the coding lingua franca. The Moldavians can j...

Why is Enumerable.Count() throwing `InvalidOperationException` for converting `null` to `bool`?

Can anyone explain how on earth the following statement can generate System.InvalidOperationException: The value null not be assigned a member of type System.Boolean since it is a value type that cannot have the value null (freely translated from Swedish (see also)). if (user.Friends.Count() == 0) user is a User and Friends is a...

Why is String.Concat not optimized to StringBuilder.Append?

OK, so concatenations of constant string expressions are optimized by the compiler into one string. Great. Now with string concatenation of strings only known at runtime, why does the compiler not optimize string concatenation in loops and concatenations of say more than 10 strings to use StringBuilder.Append instead? I mean, it's possi...

GetHostEntry.AddressList[0] returns ::1 on current Windows version even with IPv6 off. Can I change this?

I'm using a third party library suite that was stupidly hard-coded to call GetHostEntry.AddressList[0] for a local IP address. It is also not written to support IPv6. I disabled IPv6 on all my network interfaces, but AddressList[0] in my test program (and in the 3rd party libraries) still returns {::1} rather than my first IPv4 address. ...

Castle Windsor WCF Facility host based only on a WCF service interface?

I have runtime provided WCF serrvice inteface : [ServiceContract] public interface IHelloService { [OperationContract] string SayHello(string message); } What I'd like to do with my Windsor container (once for each provided service interface) : container.Register(Component .For(typeof(IHelloService)) ...

Is there a way to force OracleCommand.BindByName to be true by default for ODP.NET?

Since the System.Data.OracleClient library has been deprecated, we are in the process of migrating our code base to use Oracle Data Provider for .NET (ODP.NET) instead. One of the issues that we have encountered is that the System.Data.OracleClient uses parameter name binding as opposed to binding by position and all of the code directly...

Trying to write a pleasant parser

I am writing a simple parser that will take a string of the format 20100101,1,2,foo and create an instance of the following class: public class Foo { public DateTime TheDate { get; set; } public int TheFirstInt { get; set; } public int TheSecondInt { get; set; } public string TheString { get; set; } } I would like to b...

Guid == null should not be allowed by the compiler

Possible Duplicate: C# okay with comparing value types to null The behaviour described below is specific to .net-3.5 only Hello, I just ran across the most astonishing behavior in the C# compiler; I have the following code: Guid g1 = Guid.Empty; bool b1= (g1 == null); Well, Guid is not nullable therefore it can never...

Looking for a good exercise to help me get better at Multithreading.

I think of myself as a pretty decent developer, however when it comes to multithreading I'm a total n00b. I mean the only multithreading I've done at work was the very basic stuff like spawning off multiple threads using the ThreadPool to do some background work. No synchronization was necessary, and there was never any need to create th...