.net

How do you Read the value of an attribute in a Method

I need to be able to read the value of my attribute from within my Method, how can I do it? [MyAttribute("Hello World")] public int MyMethod() { //Need to read the MyAttribute attribute and get its value } ...

[MSIL] Variable comparison

Hi, The following C#-snippet: var x = 1; var y = 1; if (x == y) Console.Write("True"); Generates this MSIL: .locals init ( [0] int32 x, [1] int32 y, [2] bool CS$4$0000) L_0000: nop L_0001: ldc.i4.1 L_0002: stloc.0 L_0003: ldc.i4.1 L_0004: stloc.1 L_0005: ldloc.0 L_0006: ldloc.1 L_0007: ...

How to define a ref-type variable from a assembly loaded at runtime?

I want to define a ref type variable, like this: SomeType v=null; and this "SomeType" is defined in another assembly which is loaded at runtime with Assembly asm=AppDomain.CurrentDomain.Load(...); I know how to create an object of "SomeType", just do as below: Object=asm.CreateInstance(...); but how to just define a ref-type va...

Can i exclude a word in my pattern?

I know i can do something like ab[^c]+def which should match ab_blah_hi_blah_def but is there a way to do something like ab(^hi)+def which will exclude the word hi causeing ab_blah_hi_blah_def to fail? but not ab_blah_h_i_blah_def ...

What does "<<" mean in C#?

Basically the questions in the title. I'm looking at the MVC 2 source code: [Flags] public enum HttpVerbs { Get = 1 << 0, Post = 1 << 1, Put = 1 << 2, Delete = 1 << 3, Head = 1 << 4 } and I'm just curious as to what "<<" does. ...

Is there a way to move old log files, from a log4net RollingLogFileAppender into a different folder?

Hello, I have a rolling file appender configured with this: <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <file value="appname" /> <appendToFile value="true" /> <rollingStyle value="Composite" /> <datePattern value="'.'yyyyMMdd'.log'" /> <maxSizeRollBackups value="30" /> <maximumFileSi...

Using Linq to Sql, does not update, but does not throw exception

Running .net 2008, asp.net, Linq to sql, sql server 2008 express Foo f = db.Foo.First(x => x.ID == id); f.IsValid = true; db.SubmitChanges(); I have a very basic table, which has several fields, and no FK constraints. None of the data saves when I call .SubmitChanges(), but no error is thrown. Any ideas? Not using any explicit tran...

NHibernate cache/deletion problem?

I am using NHibernate and have a cache region specified in my NHibernate configuration: <cache region="HalfHour" expiration="1800" priority="3" /> I have an entity definition (UserDefinedGroup) which is set to use this cache region in read-write mode: <class name="UserDefinedGroup" table="Message_Groups"> <cache region="HalfHour"...

How to get previous day using datetime.

I want to set a DateTime property to previous day at 00:00:00. I don't know why DateTime.AddDays(-1) isn't working. Or why DateTime.AddTicks(-1) isn't working. First should this work? I have 2 objects. Each object have DateTime fields ValidFrom, ValidTo. EDIT: After coming home from work I tried to get the same behavior as my business...

Preview a .NET color

The VS debugger gives me: _Color = "{Name=ff000040, ARGB=(255, 0, 0, 64)}" how can I "see" what color is? I tried a html page: <html> <div style="background: rgba(255, 0, 0, 64);">________<div> <h1 style="background-color: ff000040">hello</h1> </html> doesn't work. ...

What are 3 kinds of Binding Contexts for?

I know that there are 3 different binding contexts or load contexts: Load LoadFrom LoadNeither What are load contexts? What are they for? Why make the assembly loading so complicated? In "LoadNeither", "neither" of what? Thanks in advance... --------------- Following are some useful quotations I recently found --------------------...

Can someone provide an easy explanation of how 'Full Fences' are implemented in .Net using Threading.MemoryBarrier?

I'm clear on the usage of MemoryBarrier, but not on what happens behind the scenes in the runtime. Can anyone give a good explanation of what goes on? ...

Add space between items in a WPF/Silverlight ListBox without space above first or below last

Is there a standard/best way to space items in a WPF ListBox, such that there is space between consecutive items, but not above the first or below the last? To me, the most obvious way to add spacing is to modify the ItemTemplate to include space above, below, or both above and below each item. This, of course, means that there will be ...

Managed .NET Equivalent to CreateFile & WriteFile from WinBase (kernel32.dll)

I am working with a legacy file format. The file is created using unmanaged C++ that utilizes the WinBase.h CreateFile() & WriteFile() functions (found in the kernel32.dll). I have been using P/Invoke interop to access these native functions like so: [DllImport("kernel32.dll")] public static extern bool WriteFile( In...

ReaderWriterLockSlim question.

There are lots written about the ReaderWriterLockSlim class which allows multiple read and a single write. All of these (at least that I had found) tell how to use it without much explanation why and how it works. The standard code sample is: lock.EnterUpgradeableReadLock(); try { if (test if write is required) { lock.Enter...

ASP.Net 2.0 Web application cannot find specified module.

Recently my ASP.NET application quit working. It is local to my machine. It quit working after installing and uninstalling some third party developer tools. (I believe) I emptied out my directory and started adding modules until I narrowed it down to a managed C++ dll. When I load the dll into Dependency Walker it says that "c:\windows...

When can a == b be false and a.Equals(b) true?

I ran into this situation today. I have an object which I'm testing for equality; the Create() method returns a subclass implementation of MyObject. MyObject a = MyObject.Create(); MyObject b = MyObject.Create(); a == b; // is false a.Equals(b); // is true Note I have also over-ridden Equals() in the subclass implementation, which...

switching from EnterpriseLibrary.Validation to Microsoft.Practices.EnterpriseLibrary.Validation.Validators to System.ComponentModel.DataAnnotations

I'm moving some code from Microsoft.Practices.EnterpriseLibrary.Validation.Validators to System.ComponentModel.DataAnnotations, and have come across a more complex validator that I am having trouble in changing it to DataAnnotations, anyone got any pointers on how I can convert this? [NotNullValidator] [DomainValidator("M", "F", "A", Me...

Using URL Routing for Web Forms with .ashx files

I am developing a .NET 3.5 Web Forms based website that uses URL Routing. So far I have created a few routes and I have had no issue. I now have a .ashx file that is going to handle sending .pdf files from a table in SQL Server to the website when someone clicks on a link. Normally when I create a Handler it would look like this: ret...

How do I "Fire and forget" a WinForms Form?

What's a good technique to create a WinForms Form instance, display it (non-modally) but not have to keep a reference around to it? Normally, as soon as the variable goes out of scope, the form is closed: var form = new SuperDuperForm(); form.Show(); // Form has probably been closed instantly I don't want to have to keep track of ins...