.net

Calculate the bounding box of a GDI+ drawing for bitmap export

I have a .NET Windows.Forms diagram editor that can export its diagrams as bitmaps. It also comes with a command line utility that just converts diagrams to bitmap images. I don't want to scale the diagram to a given bitmap size; instead, I want to size the bitmap based on the diagram's bounding box. I can easily determine it after dra...

What ways can I ensure that a string property is of a particular length?

I've created some classes that will be used to provide data to stored procedures in my database. The varchar parameters in the stored procs have length specifications (e.g. varchar(6) and I'd like to validate the length of all string properties before passing them on to the stored procedures. Is there a simple, declarative way to do th...

How to specify public key in RSACryptoServiceProvider .NET class

Hello everybody. I need to sign an xml-doc with digital signature. I know that there is a way to do this in .NET but i cannot understand how to specify my own puplic key in RSACryptoServiceProvider. I need for the public key based on the special keyword. How can i do this? Help me please. ...

C#/.NET/WPF: Obtaining subsets from LINQ, rather than the IEnumerable

I have some trivial code that looks like this: SortedDictionary<String, long> d = new SortedDictionary<String, long>(); // d is then populated with an expensive time-consuming process ListBox lb = new ListBox(); lb.ItemsSource = d; // THIS WORKS GREAT Now what I'd like to do is dynamically show a ...

Meaning of () => Operator in C#, if it exists

Hello everybody, I read this interesting line here, in an answer by Jon Skeet. The interesting line is this, where he advocated using a delegate: Log.Info("I did something: {0}", () => action.GenerateDescription()); Question is, what is this ()=> operator, I wonder? I tried Googling it but since it's made of symbols Google couldn't b...

How do I use sturcturemap to pass two different implementations of a single interface into a constructor?

I have a constructor that take two interfaces, they are the same interface, but need to be different implementations: public class Foo { public Foo(IBar publicData, IBar privateData) { } } What I'd like to happen is that structuremap would pass in a concrete implementation of IBar as class PublicData and class PrivateData ...

Marshalling between C# and C++, and the Juggling of Responsibilities

Hello everybody, what if I had a native C++ function in which, depending on the result of the function, the responsibility of deleting a certain pointer (delete[]) differs between the caller and the function. I would of course check for the return value and act accordingly in C++. Question is, what if the function was marshalled between...

Visual Studio: Check out file when building project

I have a post build event that combines my JavaScript files and outputs to Production.js, however if Production.js is not checked out, the build fails. Is it possible to automatically check Production.js out when a project is built? [Edit] If possible using a post-build event, does anyone know how to do this? I am using Visual Studio...

.NET Garbage Collection (GC) Tuning

Hello, I have situation when GC has not time to delete free objects, how to tune GC or may be are there best practices for tunning GC ? Thanks. code reads big document into memory and processes it, so in one of method presents loop where doing process of this document. If I stopped in this loop(in debug mode) or add GC.Collect() ...

Use reflection to get attribute of a property via method called from the setter

Note: This is a follow-up to an answer on a previous question. I'm decorating a property's setter with an Attribute called TestMaxStringLength that's used in method called from the setter for validation. The property currently looks like this: public string CompanyName { get { return this._CompanyName; } [Tes...

Wix heat.exe with project harvesting type

Hi, I'm using the lastest version of Wix 3.5 and I'm trying to generate a fragment file using heat.exe. The command line is : "%WIX%\bin\heat.exe" project "MyProj.csproj" -pog Binaries -pog Content -suid -directoryid INSTALLLOCATION -ag -template fragment -out "Files.wxs" The prolem I'm having is that the assemblies my project is dep...

What is in a DLL and how does it work? - 12 questions on DLL's

I'm always referencing DLL's in my C# code but they have remained somewhat of a mystery which I would like to clarify. This is a sort of brain dump of questions regarding DLL's I understand a DLL is a dynamically linked library which I understand means that at run time another program can access this library to get "functionality". Howe...

Why you need partial methods in c#? Can events be used to achieve the same goal?

I was reading the book "Apress Pro LINQ: Language Integrated Query in C#" and I came across partial methods, but I really don't understand what is the need for them. I think the examples in the book (properties before and after change) can be implemented using events. So any explanation? ...

how can I replace the deprecated SoapFormatter?

I have a legacy app that uses SoapFormatter to persist a graph of objects (maybe 50 different classes). I want to move away from using this as it is deprecated, and increasingly hard to continue to support deserializing from old files as the classes change. I want to use DataContractSerializer going forward. Does anyone have any suggest...

C#: A way to copy xml comments from a set of APIs to another similar set of APIs?

Suppose in Visual Studio I have a new project which contains some of the same APIs from an older project, and I would like to copy the xml documentation over to the new one. Is there a way I can do this without manually copy-pasting them one by one? Thanks! ...

Why does System.Numerics.BigInteger not have a Parse method in Silverlight 4.0, but does in .Net 4.0?

I've come across a weird discrepancy between BigIntegers used by .Net 4.0 and Silverlight 4.0; In .Net, BigInteger has a Parse and TryParse method where as in the Silverlight version, it does not have either of these. If you look at the .Net version of System.Numerics in Reflector, you also see that when you disassemble the code, every ...

string .IndexOf with startIndex

when you use a startIndex in a IndoexOf method if not match is found does it return -1 or your startIndex? I ran this in my code and want to make sure what I got is right. ...

POCO design question

Can/Should my POCO's encompass multiple Databases if applicable? The reason I ask is that I am in the process of refactoring a legacy Enterprise App that was built in stages. Unfortunately, each stage had it's own separate DB (at least they are all on the same SQL instance). Because of this I can easily see where a typical Business ...

Is a Java package the equivalent of a .Net assembly?

I am a .Net developer starting Java development for Android and would like to know if it's correct to think of Java packages like .Net assemblies. Thanks! ...

Use Elmah with twitter and its mandatory oauth authentication?

Since Twitter won't use basic authentication (login, password) anymore, I'm converting my app to using twitter with oauth authentication. In my code this was ok, but I also use Elmah to tweet the errors on a specific twitter account. But it seems Elmah only works with basic authentication. Is it true? Any workaround? Thanks ...