Browsing 7239 questions and answers with Jon Skeet

How can i remove Nodes of Manifest File created with Mage.exe/MageUI.exe without getting trouble with the namespace?

In the Last few Days i tried to .Remove(); some Nodes in a Manifest-File , to specify the Problem i tried to delete the Populated-Files in a Manifest-File with a C# programm. If...
Jon Skeet
people
quotationmark

Okay, it looks like LINQ to XML is getting confused because the namespace is declared twice in the root element - once as the default namespace, and once with an alias of asmv2. The simplest solution is just to remove that attribute. To... more 8/6/2014 4:50:39 PM

people

How do I remove the xmlns="" attribute added to newly created XElement nodes?

When I add new nodes to the root of a node that has a namespace defined, subsequent nodes added all receive xmlns="" attached to to them. This is the code that shows my...
Jon Skeet
people
quotationmark

While I suspect this is a duplicate, I can't easily find it. The problem is that in your desired XML, the ContainerCollection, Container and ContainerNumber elements are in the namespace "someNS" as that is the default inherited from their... more 8/6/2014 3:39:01 PM

people

Equivalent to java packages in C#

I have been looking for a way to make a "package folder" in visual studio express 2013, the way I might do it in java is a "package" I know that I can make whole new projects...
Jon Skeet
people
quotationmark

Just add a new folder - then by default, new classes will be in that namespace. So for example, if you have a project called Foo, and you add a folder called Bar, then you'll end up with: namespace Foo.Bar { } at the top of classes in... more 8/6/2014 12:36:43 PM

people

Remove xmlns attribute in xml so as to get simple plain xml node

I am using the following code var xmlFile = fromConfiguration + @"xyz.xml"; XDocument document = XDocument.Load(xmlFile); var xElement = document.Root; ...
Jon Skeet
people
quotationmark

One of the ancestor elements must be setting a default namespace, e.g. <foo xmlns="http://foo.bar"> <!-- Your element name --> </foo> If you want: <foo xmlns="http://foo.bar"> ... more 8/6/2014 11:38:39 AM

people

Refactor class to avoid writing same pattern in every method

I have a class with a lot of static methods for managing database operations. All methods follow this pattern: try { using(var trans = new TransactionScope()) { ...
Jon Skeet
people
quotationmark

It sounds like you should pass "method body" in as a delegate: public void GiveMeAProperName(Action<DBContext> databaseAction) { try { using(var trans = new TransactionScope()) { using(var context =... more 8/6/2014 9:40:14 AM

people

Setting an Integer from a if then statement

I am trying to get it so if i put a piece of code such as if ((variable1 - variable2) < 0) int variable5 = (variable3 + variable4); but this does not seem to work...
Jon Skeet
people
quotationmark

You're trying to declare a variable as the only statement in an if statement body. That's not allowed, as it would be pointless - the variable would be out of scope immediately afterwards. Either you should declare the variable first: int... more 8/6/2014 9:11:20 AM

people

how to increment epoch time by 5 minutes in Scala or Java

val df = new SimpleDateFormat("MMM dd yyyy HH:mm:ss.SSS zzz") var date1 = new Date() println(date1.getTime) Result: 1407309964324 how can i increment it by 5 minutes?
Jon Skeet
people
quotationmark

Well, 5 minutes is always 300,000 milliseconds, so: long millis = date1.getTime(); millis += 300000; Date date2 = new Date(millis); Or perhaps more readably: long millis = date1.getTime(); millis +=... more 8/6/2014 7:41:58 AM

people

Infinite loop breaks method signature without compilation error

I am wondering why is the following code allowed in Java, without getting compilation error? In my opinion, this code breaks method signature by not returning any String. Could...
Jon Skeet
people
quotationmark

The final } of the method is unreachable - you only get a compilation error if it's possible to get to the end of the method without returning a value. This is more useful for cases where the end of the method is unreachable due to an... more 8/6/2014 7:26:40 AM

people

Threading in Forloop C#

I got a requirement where I need to process two Threads simultaneously in a ForLoop. For Example : private void BtnThreading_Click(object sender, EventArgs e) { for (int i...
Jon Skeet
people
quotationmark

It looks like you don't really need ProcessA to execute in a different thread at all - but you do need to keep track of your previous ProcessB thread. So something like: Thread previousThread = null; for (int i = 0; i < 20; i++) { ... more 8/6/2014 7:08:01 AM

people

Double ternary Integer initiation causes a null pointer

Why is this fine with x being set to null: boolean condition1 = false; Integer x = condition1 ? 1 : null; And this fine with x being set to 2: boolean condition1 = false,...
Jon Skeet
people
quotationmark

(I still think this is a duplicate after you've done a bit of unpacking, but hey...) Expand the one statement into two: // Not exactly the same, but close... Integer tmp = condition2 ? 2 : null; Integer x = condition1 ? 1 : (int)... more 8/6/2014 6:52:42 AM

people