Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

Mirko1980

@Mirko1980
About
Posts
265
Topics
3
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Linq - Remove Object From Collection
    M Mirko1980

    I've further elaborated the idea above, using an extension method:

    // Base interfaces for a node
    public interface INode
    where T : INode // A child is the same class as the parent
    {
    Guid Id { get; set; }
    List Children { get; set; }
    }

    // Static class containing Extension Methods
    public static class NodeExtensions
    {
    // Recursively removes a node by its id
    public static void Remove(this INode node, Guid id)
    where T : INode
    {
    // List that will contains the nodes to be removed
    // Can't remove nodes directly in the foreach loop
    // (will throw "Collection was modified; enumeration operation may not execute.")
    List toRemove = new List();

        if (node.Children == null)
            return; // No childrens, exit
    
        foreach (var child in node.Children)
        {
            if (child.Id == id)
                toRemove.Add(child); // The node has to be removed
            else
                child.Remove(id); // Recursion here
        }
    
        // Removes all found nodes
        foreach (var child in toRemove)
            node.Children.Remove(child);
    }
    

    }

    C# csharp linq question

  • Formatting a DateTime object/String to only show yyyy/mm/dd [modified]
    M Mirko1980

    You could also use the short date format specifier:

    ToString("d")

    C# question

  • Get the ancestor nodes from XML
    M Mirko1980

    Remember when I told you to use int level = book.Select("ancestor::Entity").Count to get the level of a node? What ancestor::Entity does is returning the list of all the ancestor Entity nodes, you just have to avoid using Count. If you need the token value, you just have to subsequently select Token, like this: ancestor::Entity/Token. To understand what you can do with XPath, I strongly suggest you to read here.

    C# tutorial business xml announcement learning

  • LINQ JOIN
    M Mirko1980

    Here you go:

    var query = from item in A.Union(B)
    group item by item.Name into grp
    select new { Name = grp.Key, N = grp.Sum(t => t.N) };

    modified on Wednesday, July 20, 2011 10:46 AM

    C# csharp linq

  • get parent and level of the xml node from XPathNavigator
    M Mirko1980

    For the parent, it seems you are selecting a not-leaf node (I'd say an 'Entity' node), so, using value, you are getting the full content of that node, all descendants included. If you want a string value, you must select a Token or a Description. For the level, I forgot you can't use scalar function in XPath when selecting nodes. You can simply use Select and then Count the result: int level = book.Select("ancestor::Entity").Count;

    C# tutorial business xml question announcement

  • get parent and level of the xml node from XPathNavigator
    M Mirko1980

    For the parent node, you can use .. to navigate upward the xml tree (like as it where a directory). Using your Example, string parent = book.SelectSingleNode("../Token").Value; will get you the parent token of the current entity. For the depth, you could try to count the number of entity parent nodes, like this: string level = book.SelectSingleNode("count(ancestor::Entity)").Value; I don't know if that will give you a 0-based or a 1-based value, you will have to do some tests.

    C# tutorial business xml question announcement

  • Searching XML file
    M Mirko1980

    Use // to search in any level into your XML. The following XPath will give you what you want: //Entity[contains(./Description, 'Company')]/Token

    C# xml tutorial algorithms business announcement

  • WCF Service Browsable through any Web Browser
    M Mirko1980

    Here for a complete tutorial.

    C# wcf question csharp com help

  • Odd Google results, or just me?
    M Mirko1980

    This is what wikipedia says about Order of Operations: There exist differing conventions concerning the unary operator - (usually read "minus"). In written or printed mathematics, the expression -3² is interpreted to mean -(3²) = -9, but in some applications and programming languages, notably the application Microsoft Office Excel and the programming language bc, unary operators have a higher priority than binary operators, that is, the unary minus (negation) has higher precedence than exponentiation, so in those languages -3² will be interpreted as (-3)² = 9. [1] In any case where there is a possibility that the notation might be misinterpreted, it is advisable to use brackets to clarify which interpretation is intended.

    modified on Friday, June 3, 2011 8:56 AM

    The Lounge database question

  • Odd Google results, or just me?
    M Mirko1980

    Actually, Google is right. sqrt(-1^2) = sqrt(-(1^2)) = sqrt(-1*1) = sqrt(-1) = i sqrt(-i^2) = sqrt(-(i^2)) = sqrt(-1*-1) = sqrt(1) = 1

    The Lounge database question

  • abstarct class basic question [modified]
    M Mirko1980

    I said that at the end of my post. I agree you are losing many advatages of polymorphism, but, at least, you can reuse the Create login in multple classes.

    C# csharp linq tutorial question lounge

  • abstarct class basic question [modified]
    M Mirko1980

    You can use generics like this:

    abstract class b<T> where T: b, new()
    {
    ...
    public T Create() { return new T(); }
    }

    class D1 : b<D1>
    {
    ...
    }
    class D2 : b<D2>
    {
    ...
    }

    So, you can do:

    D1 myClassD1 = new D1();
    D1 newClassD1 = D1.Create();

    But, you can't do anymore:

    b myClassAb = new D1;
    D1 newClassAb = myClassAb.Create();

    because you'd have to specify the generic type for class b.

    C# csharp linq tutorial question lounge

  • C# COM Interop
    M Mirko1980

    You have to play a bit with interfaces. Look here for a sample.

    C# com csharp help tutorial

  • FxCop Performance Warning CA1822
    M Mirko1980

    Don't worry too much about that, it's only a warning. If a non-static method don't use any instance-level method or property, FxCop tells you that there are no reasons that method should not be static, and suggest you to make it static. But, if that method is part of an interface implementation (or exposed publicly and alraedy used from other methods), there ARE reasons that should not be static, so you should ignore the warning. If you want, you can use the SuppressMessage attribute to avoid getting the warning for specific methods.

    C# performance help question

  • Parallel.For Issue
    M Mirko1980

    Since it seems you are already using .NET 4, you can give a look to the new Thread-safe collections.

    C# csharp visual-studio data-structures help question

  • Please tell me why this simple shutdown application isn't working
    M Mirko1980

    After a quick search I found this Often people try to code complex soluting when the OS already give them the option...

    C# csharp linq question workspace

  • Please tell me why this simple shutdown application isn't working
    M Mirko1980

    You are missing System.Diagnostics.Process.Start(shutDownBlocker);

    C# csharp linq question workspace

  • Removing duplicates / extracting unique vals from String array
    M Mirko1980

    Talking about efficiency, I read somewere on MSDN that, for generating a list of unique elements, the more efficient way is to use an HashSet (as PIEBALDconsult already said) instead of the Distinct extension method. Something like this:

    var query = string.Join(",", arr) // join to make one string
    .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) // split to array
    .Select(t => t.Trim()); // trim each entry

    var set = new Hashset<string>

    foreach (string item in query)
    set.Add(item); // add items to the hash set, this ensure unique

    string[] vals = set.ToArray(); // back to array

    C# question docker data-structures

  • windows service
    M Mirko1980

    You said "I have now developed a simple console app based on the example". So I thought that you had put the WCF service on a separate Console Application. If you have already put the WCF service into the Windows service, you should be able to browse it from IE on the url you specified when coding it (the example I gave you uses http://localhost:8080/hello). You have only to add a service reference to your WCF service in the Silverlight application so that it can communicate with the Windows service.

    C# question csharp wcf data-structures

  • windows service
    M Mirko1980

    Now you have a Windows service (that is actually a console application) that manages your queue, and a console application that exposes a WCF service. What you have to do is to put the two things together: include the code of the new console app into the code of your Window Service and make sure that both reference the same queue instance. Then, when you start the Windows service, it will also expose the WCF service that you can call from Silverlight.

    C# question csharp wcf data-structures
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups