.net

Are anonymous types a good thing to use outside of LINQ?

While analyzing some ASP.NET MVC projects I got to see anonymous types scattered all over. HTML helpers have them: <%=Html.TextBox("view.Address", "address", new { Class = "text_field" })%> A lot of the return types for actions have them: JsonNetResult jsonNetResult = new JsonNetResult { Formatting = Formatting.Indented, Data ...

C# LINQ State of DeleteOnSubmit()

I am working on a web service for creating, changing and removing hotel reservations (bookings). One booking can contain several stays (a stay is a link between a room, the services ordered, etc.). Each stay has it's own time period, so you can create 3 stays in the same booking, for 3 different weeks. My problem arises when bookings ne...

Convert complex bool condition from string to bool in .NET

I need to parse complex expresion from string to bool. It can only contain: * boolean values (true/false), * parenthesis, * AND/OR operands (&&, ||) Eg: bool.Parse("((true || false) && (false || false)) || (true || false)" Any idea how to achieve this? ...

Create a regular class or an Inner class for a Parameter Object?

Instead of passing many arguments to a method, I was encapsulating it into an argument object. note: simplied for demo For such a case, what would be a better practice? • Create a class and name it as InventorySaveArgs? -- or -- • Create a nested class and name it as SaveArgs? And would you also explain why one would choose...

What are ways to solve Memory Leaks in C#

I'm learning C#. From what I know, you have to set things up correctly to have the garbage collector actually delete everything as it should be. I'm looking for wisdom learned over the years from you, the intelligent. I'm coming from a C++ background and am VERY used to code-smells and development patterns. I want to learn what code-...

.Net vs SSIS: What should SSIS be used for?

If I have the option of using .Net and can do data transformations just fine in .Net, when would I need SSIS? Is there a certain task that SSIS would be better for? Are the added benefits of transparency worth it? Is it just what I am more comfortable with? What are the best practices for determining this? ...

ITunes SDK: Loading shared music

I've been messing with the iTunes SDK under .NET 3.5 with C#, but I have not found a way to load a shared music library from another computer on the network. Does anyone know how I can access shared music from the iTunes SDK? If this is not possible, then can anyone suggest alternatives? ...

Guaranteeing that a .NET WCF Service can be consumed by a Java client

I am creating a WCF Service that will be consumed by both .NET and Java client applications. We do not have any Java experience in the team, so are looking for guidelines or rules to follow to ensure that we do not accidentally include any types in our WCF Service interface or do anything else that would preclude it from being consumed ...

how to best wait for a filelock to release

I have an application where i sometimes need to read from file being written to and as a result being locked. As I have understood from other questions i should catch the IOException and retry until i can read. But my question is how do i know for certain that the file is locked and that it is not another IOExcetpion that occurs. ...

Using app.config with a class library

Frequently I need to create a .Net class library that requires an app.config for things such as database connection strings. However, these settings must be in the calling application's app.config or web.config. If I want to distribute the DLL across multiple applications it becomes a pain to have to keep copying these settings in the...

Inject different object to constructor with StructureMap for certain case

I have IRepository<T> , and implementation SqlRepository<T>. SqlRepository has DataContext parameter in constructor. SM configuration looks like this: x.ForRequestedType(typeof(IRepository<>)) .TheDefaultIsConcreteType(typeof(SqlRepository<>)); x.ForRequestedType<DataContext>().CacheBy(InstanceScope.Hybrid) .TheDefault.Is.Constructe...

Asp.net "Global" variables

I'm writing a page in ASP.NET and am having problems following the cycle of initialization on postbacks: I have (something akin to) the following: public partial class MyClass : System.Web.UI.Page { String myString = "default"; protected void Page_Init(object o, EventArgs e) { myString = Request["passedString"]; ...

EventBinding in a codebehind generated DataTemplate

Hi there, lets begin with the scenario: I have an ItemsControl inside a UserControl. In this ItemsControl I have a dynamicly created DataTemplate which is created and added in codebehind. As there doesn't seem to be a nice way to create a DataTemplate in codebehind I had to programmatically generate the xaml code for my DataTemplate in...

Is there a .NET control out there to emulate the Word 2007 selection toolbar?

I'd like to have a toolbar similar to the hover toolbar in Word 2007 (see picture) show up when I highlight text. Does this control exist (free or otherwise) or am I S.O.L. to hack it together myself? Thanks! If anyone has any tips on how to put this together that would be appreciated as well. I don't need the fade-in/out effects th...

.NET implementation (libraries) of elliptic curve cryptography

Please can you suggest any implementation of elliptical curve cryptography to be used on .NET platform? Also if you have used them, can you tell me the recommended curves that should be used? [EDIT] As @FatCat mentioned, its implementation is available in .NET framework 3.5 but that is only available on windows vista. Can you please s...

Using WebClient in C# is there a way to get the URL of a site after being redirected?

Using the WebClient class I can get the title of a website easily enough: WebClient x = new WebClient(); string source = x.DownloadString(s); string title = Regex.Match(source, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value; I want to store the URL and the page title. Ho...

Should “Action” delegate be refactored out into a new method?

I have a following method private void SetProcessDocumentStatus(string status) { var setStatusWith = new Action<string>( statusValue => processDocumentStatusLabel.Text = statusValue); if (processDocumentStatusLabel.InvokeRequired) processDocumentStatusLabel.Invoke( (MethodI...

VSS or SVN for a .Net Project?

At work, one of the head managers asked me to research on what could be the benefits of changing the current source control server (Visual Source Safe) of my project to SVN. I really don't have anything against SVN, actually I kind of dig it, but in my humble opinion, change to SVN will not bring any significant benefits to the project...

Encoding £ in SMS message sent via Gateway not working correctly

Hi, I'm having trouble with an SMS message I am sending using a provider called Cymba. Basically I'm posting the message over to them as per their specifications URL encoded. However when the message is sent to my phone the £ appears with an A in front i.e. £A Now C# strings are Unicode by default, so I switched to ASCII encoding and...

Is there a place that outlines causes of generic .NET error messages?

The specific error that I'm getting is a System.ArgumentException with a message of "Value does not fall within the expected range". I'd like to know specifically what could cause this error (I suspect some kind of overflow), but I'd also like to know if there's a place where these sort of generic .NET messages and their causes are list...