.net

How do I match part of a string only if it is not preceded by certain characters?

I've created the following regex pattern in an attempt to match a string 6 characters in length ending in either "PRI" or "SEC", unless the string = "SIGSEC". For example, I want to match ABCPRI, XYZPRI, ABCSEC and XYZSEC, but not SIGSEC. (\w{3}PRI$|[^SIG].*SEC$) It is very close and sort of works (if I pass in "SINSEC", it returns a ...

How to read from a memory mapped I/O port in .Net?

Can standard pointers in .Net do this? Or does one need to resort to P/invoke? Note that I'm not talking about object references; I'm talking about actual C# pointers in unsafe code. ...

MonthCalendar control selection range with EnableVisualStyles?

I'm using the MonthCalendar control and want to programmatically select a date range. When I do so the control doesn't paint properly if Application.EnableVisualStyles() has been called. This is a known issue according to MSDN. Using the MonthCalendar with visual styles enabled will cause a selection range for the MonthCalendar ...

Feed paper on POS Printer C#

I've been trying to programatically feed the paper on a pos printer (Epson TM-U220D). The problem I have is that the last line of the document don't get printed, instead, it is printed as the first line of the next document printed. I tried POS for .NET sending the "ESC|flF" command, also tried to send the raw esc/pos command using the s...

Need help choosing a name for an interface

I'm refactoring a number of classes in an application to use interfaces instead of base classes. Here's the interfaces I created so far: ICarryable implemented by all Item objects IActable implemented by all Actor objects IUseable implemented by some Item sub-classes IWieldable implemented by some Item sub-classes You can see the...

DataGridView locked on a inherited UserControl

I have a UserControl with some predefined controls (groupbox,button,datagridview) on it, these controls are marked as protected and the components variable is also marked as protected. I then want to inherit from this base UserControl to another UserControl, however the DataGridView is always locked in the designer. I suspect it may ha...

Prevent Visual Studio from automatically creating "Mixed Platforms" solution configuration

How do I prevent Visual Studio 2008 from automatically creating the "Mixed Platforms" and "Any CPU" solution configurations? We have "Win32" and "x64" configurations and a developer needs to choose between them. However, as soon as anyone makes any changes to the solution VS automatically creates "Mixed Platforms" and it seems to be the ...

Are .NET applications immune from classic pointer errors?

Does some article or proof exist that .NET applications are immune to low level errors? I'm talking about the classic pointer errors we can see in a C++ application, memory overflow, problems from the Intel DEP and so on. I'm talking about .NET applications that do not use "unsafe" code, from what is my experience in this case only pr...

Combining two interfaces into one

As I mention in an earlier question, I'm refactoring a project I'm working on. Right now, everything depends on everything else. Everything is separated into namespaces I created early on, but I don't think my method of separtion was very good. I'm trying to eliminate cases where an object depends on another object in a different namespa...

How to Forcefully Rollback a Setup from Custom Actions?

I am creating a installer in .NET and using custom actions for controlling installation. Now there is certain conditions which I need to check and based on those I have to continue install OR rollback the installation. How can I forcefully rollback the Setup from custom actions? ...

Adding functonality to Linq-to-SQL objects to perform common selections

In a previous question I asked how to make "Computed properties" in a linq to sql object. The answer supplied there was sufficient for that specific case but now I've hit a similar snag in another case. I have a database with Items that have to pass through a number of Steps. I want to have a function in my database that retrieves the C...

Best Practice for Loading Object from Serialized XML in C#

Greetings, I have a particular object which can be constructed from a file, as such: public class ConfigObj { public ConfigObj(string loadPath) { //load object using .Net's supplied Serialization library //resulting in a ConfigObj object ConfigObj deserializedObj = VoodooLoadFunction(loadpath); ...

C#/.NET: Detect whether program is being run as a service or a console application.

I have a C#/.NET program that can run both as a console application and as a service. Currently I give it a command-line option to start as a console application, but I would like to avoid that. Is it possible to programmatically detect whether my program is being started as a service? If it was pure Win32, I could try starting as a s...

nHibernate, can I map to a table that doesn't have an row-per-object mapping?

I have a database that contains a table that looks a bit like this: PropertyId, EntityId, Value PropertyId and EntityId are a combined primary key. Every Entity is spread over a couple of rows where every row contains a single property of the entity. I have no control over this database so I'll have to work with it. Is it possible to ...

How do i specify a bold version of the theme's default font?

Hi Guys, I'm having problems with cross theme compatibility in windows forms. If you don't set the font for a control on a windows form, it will use the system font with correct typeface and size. If you want to make the font bold, it hard codes in the rest of the system font values for the current theme you're programming with. For ...

How to use a different assembly name for different configurations?

In Visual Studio 2008 (and others) when creating a .NET or silverlight application if you look at your project properties, it seems like you can only have one assembly name - across all configurations. I would like to compile my application as: MyAppDebug - in debug mode and just MyApp - in release mode Does anyone know if this is poss...

Set Locale of a SQL Server 2005

By default the SQL Server comes with the Langauge set to "English (United States)", setting the date format to mm/dd/yy instead of the date format I want it in, which is Australian and has a date format such as dd/mm/yy. Is there an option in the Server Management Studio / Configuration tools where I can set the locale of the SQL Server...

How do I display only certain columns from a data table?

Hi guys... I'm using a web service that returns a dataset. in this dataset there are 5 table, let's say table A, B, C, D, E. I use table A. So DataTable dt = new DataTable() dt = dataset.Table["A"] Now in this datatable there are columns a1,a2,a3,a4,a5,a6,a7. Let's say I only want to get columns a3 and a4 then bind it to my datagr...

Forcibly rollback an installer in c# setup projects.

Hi, I have created a custom action dll.I just want to check if a product with same name exists(Done).If yes tell the user to uninstall the product by throwing a InstallException.However if the products are installed in same directory the Install state of the prev product is removed & the install state of new product is copied in the bas...

WeakReference Bug ?

[TestMethod] public void Memory() { var wr = new WeakReference("aaabbb"); Assert.IsTrue(wr.IsAlive); GC.Collect(); GC.Collect(); GC.Collect(); GC.Collect(); GC.Collect(); Assert.IsFalse(wr.IsAlive); //<-- fails here } It's .NET 3.5 SP1 Can anyone can tell me why this test fails? Edit: Thanks stusmith ...