.net

Show a GUID in 36 letters format

Hi. GUID is big random number show in a HEX basis. I want to show this number in a shorter format, lets say that based on the all letters and numbers. That is a 36 basis. Lets say that: 2f1e4fc0-81fd-11da-9156-00036a0f876a will become as 3jEl9x6eZi. Is there any 'ready' algorithm for this in .Net? it need to be bidirectional. Edit:...

How to force a C# root namespace throughout project files for when none is coded?

I want to force a root namespace on the contents of any .cs source files that don't have their contents wrapped in an explicit namespace. In other words I want to keep classes and other namespace-level structures out of the default namespace. (Working inside a Windows .NET environment with Visual Studio) In the following example, I want...

good book about C# object model.

Or, should I put it "the .NET object model"? I am looking for a book just like Stanley Lippman's "Inside the C++ Object Model", and my favourite language is C#. Anyone got a recommendation? Thanks in advance. ...

Can this linq statement be refactored to return an IQueryable instead?

Hi folks, i have the following linq extension method, which returns an IEnumerable. This means, that this piece of code ends up hitting the DB, before the rest of the linq statement has been finished. Is it possible to refactor this so it returns an IQueryable instead? public static IEnumerable<TSource> WhereIf<TSource> (this IEnu...

Error running edmgen on entity framework ssdl, csdl and msl files

I have created a Entity Framework mapping based on the book "Microsoft Entity Framework in Action". The OrderIT DB is available for download from the link. I am on VS 2010 RC and this is my first serious try of EF. But I keep getting an error "Object reference not set to an instance of an object. Model.edmx" I have broken the...

How to iterate through Dictionary and change values?

Dictionary<string,double> myDict = new Dictionary(); //... foreach (KeyValuePair<string,double> kvp in myDict) { kvp.Value = Math.Round(kvp.Value, 3); } I get an error: "Property or indexer 'System.Collections.Generic.KeyValuePair.Value' cannot be assigned to -- it is read only." How can I iterate through myDict and change values?...

.NET Regular Expressions - Finding, Replace

I have a string containing address and a phone number (US format; (xxx) xxx-xxxx). E.g., 1243 K. Beverly Bld. # 223 Los Angeles, CA 41124 (213) 314-3221 This is a single string, I need to extract phone number out of it using regex. I could have used string tokens, but there are chances that some invalid data is also concatenated with ...

How to handle and organize DTOs for different context ?

When using simple DTOs in various scenarios I have frequently run into the same kind of problem and I always wondered whether there's a better way to deal with it. The thing is, I have a business object, e.g. Asset which has a bunch of properties, child objects and calculated fields, some of them expensive to calculate in sense of time,...

How to get list of locales in .Net

I would like to give user option to select text file locale. Is there some class in .net that keeps list of available locales? Now, I am planning to make my own list class from MSDN page: Language Identifier Constants and Strings, but it would be nicer if there is something already in .net. Here is MSDN article on CultureInfo.GetCu...

What is the Include(..) method not getting found, on my IObjectSet object, in this Entity Framework code?

Hi folks, i'm trying to eager load some child entity, and when I try to add the Include() method, i'm getting a compiler error (ie. it can't find it). er ... can anyone help me out on this one, please? ...

Sock shows inconsistent/impossible results after repeat use

Hey all, I am trying to determine the status of some servers over the course of time. Here is my code: static void Main(string[] args) { byte[] readstream = new byte[100]; byte[] sendstream = Encoding.ASCII.GetBytes("PLAYER_JOINED"); string[] IPs = new string[] { "24.15.169.211", "69.198.255.121", "219.79.24...

Change the XML Serializer's element name of an array element

I have a class which is generated from an XML file via the XSD.exe tool. The class I have contains an array with elements. Until recently, rendering the whole document from a fully instantiated business object was possible, however due to the size, we now need to render the documents array elements to a stream so that we don't run out ...

Why is this code throwing an ArgumentNullException?

I use this code pattern all over and only in this particular property an ArgumentNullException is thrown when trying to assign a value to it (ie invoking the setter). The object being null is the isLoggedInLock,so it seems that it has not been instantiated before the setter is called. Wat is wrong?? EDIT: I commented out the OnPropertyCh...

Gaussian filter with Brahma

I am trying to write a gaussian filter with Brahma with the DirectX provider, but I get a "The generated HLSL was invalid." exception. Has anyone written anything similar? Could you tell me if my approach is ok? The code I have written so far is : var provider = new ComputationProvider(); var data = new DataParallelArray2D<float>(provid...

Working With ODP.NET Asynchronously

Hay, My system needs to execute several major SQL`s (on Oracle DB) using the same connection (asynchronous). What`s the best practice for this issue? 1. open single connection and execute every SQL statement on different thread (does it thread safe?) 2. create new connection and “open + close” it for every SQL statement Thanks, Hec ...

Drag & Drop from Form to Windows; get drop destination

I have been developing an app in VB.NET which requires a control object (for example, a ListViewItem) to be dragged out of the form, and to a user-specified location (for example, on the desktop, or in a folder). However, The file that is intended to be 'copied', as the 'ListViewItem' represents, does not yet exist. It needs to be downl...

Which is Efficient StringBuilder or CommaDelimitedStringCollection

Hi, I am creating a CSV file and I am using StringBuilder at the moment I come to a new Class "CommaDelimitedStringCollection". Can anyone tell me which is betterto use to write the file data. also what do you think of using TextWriter. Thanks ...

Accessing a property in a Datagrid in C#

I am loading the output of a database query to a DataGrid. myAdapter.Fill(ds,"AllInfo"); dataGridSearchOutput.DataSource = ds.Tables["AllInfo"].DefaultView; It will fillup the data grid control with multiple records. Suppose the primary key of the data record is "ID". Now I want to generate report. To do that I need to select an item...

Help with some mocking

Hi, I was trying to mock an interface and I got the next expection: System.TypeLoadException: System.TypeLoadException: Signature of the body and declaration in a method implementation do not match I figured out later that my problem was a function that I have defined in my interface: IList<T> GetAll<T>() where T : class, new(); ...

Dynamically Create C# Properties From Database Columns

Hello, I don't know if this can be done in C#/.NET 2.0 but I want to be able to add a sql call to a method and build the properties based off the call. So, it would be something like this: QueryResult result = QueryDataTable.Query("SELECT ...", "DataConnection"); int someVar = result.SomeTableId; So, above the SomeTableId property wo...