Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Discussions

Richard Anthony Hein Richard.Hein Stay on Target
  • Share ASP.NET Session with Classic ASP

    They wouldn't SELL it?  What??  Perplexed  Why on Earth not??

  • is 'new ​object().​property' or 'new ​object().​method()' a good idea?

    ScanIAm wrote:
    
    Exactly, and I'm fine with that, now, but it doesn't 'feel' right.  That's my own cross to bear Smiley

    string s = "bob";
    if(s!=null)
       Console.WriteLine(bob.Length);

    just seems safer.




    Sorry, that's just not making sense; maybe you need to come up with a better example, but I can't see it.  s can never be null here ... even if it was you'd sure as hell WANT an exception to be thrown, because it's exceptional ... you don't want to hide this kind of exception.

  • What do you consider the better practice...

    ScanIAm wrote:
    

    This is true, but if you are running out of screen realestate, the braces take up extra lines that aren't needed and might make the function harder to read.

    In this, simple case, it's not a big deal, but if you are validating a few supplied parameters, it's a space saver.  e.g.:

    if(param1==null)
       throw new ArgumentNullException(...);
    if(!param1.IsWithinRange())
       throw new ArgumentOutOfRangeException(...);
    etc.


    I like doing this, too, but some folks don't like it:


    foreach(MyNestedType mnt in listofMyNestedTypes)
        if(mnt!=null)
           if(mnt.subobject!=null)
             if(mnt.subobject.subsubobject!=null)
                if(mnt.subobject.subobject.valueType==3)
                  doSomething();


    That function would be 10 lines longer if we put in braces




    Just for the fun of it, I tried out a recursive way of going through nested objects to find the value ... if you made these functions (SelfApplicable, Fix and Y) extension methods then you'd only have to write one line for any nested object in the future Big Smile:

    listofMyNestedTypes.ForEach(mnt => DoSomething(Fix(find => x => x != null && x.valueType == 3 ? x : find(x.subobject))(mnt).valueType));

    Here's my test program:

    class Program {
       delegate T SelfApplicable<T>(SelfApplicable<T> self);
       
    static void DoSomething(int x) {
          
    Console.WriteLine("x = " + x);
       
    }

    static void Main(string[] args) {

    List<MyNestedType> listofMyNestedTypes = new List<MyNestedType> {
       
    new MyNestedType
          
    valueType = 1, 
          
    subobject = new MyNestedType
                                     
    valueType = 2,
                                     
    subobject = new MyNestedType() { 
                                                             
    valueType = 3,
                                                             
    subobject = null
                                                             
    }
                                     
    }
                           
    }
        
    };

    SelfApplicable<Func<Func<Func<MyNestedType, MyNestedType>, Func<MyNestedType, MyNestedType>>, Func<MyNestedType, MyNestedType>>> Y = y => f => x => f(y(y)(f))(x);

    Func<Func<Func<MyNestedType, MyNestedType>, Func<MyNestedType, MyNestedType>>, Func<MyNestedType, MyNestedType>> Fix = Y(Y);

    listofMyNestedTypes.ForEach(mnt => DoSomething(Fix(find => x => x != null && x.valueType == 3 ? x : find(x.subobject))(mnt).valueType));

    Console.Read();

    }
    }

    class MyNestedType {
       public MyNestedType subobject;
       
    public int valueType;
    }

    EDIT:  I had to change the code to deal with a list that didn't have a value of 3 for any valueType, so now it's really ugly.  Anyone got a better way?

    List<MyNestedType> listofMyNestedTypes = new List<MyNestedType> {

    new MyNestedType {

    valueType = 1,

    subobject = new MyNestedType {

    valueType = 2,

    subobject = new MyNestedType() {

    valueType = 3,

    subobject = null

    }

    }

    },

    new MyNestedType {

    valueType = 4,

    subobject = new MyNestedType {

    valueType = 5,

    subobject = new MyNestedType() {

    valueType = 6,

    subobject = new MyNestedType()

    }

    }

    }

    };

    SelfApplicable<Func<Func<Func<MyNestedType, MyNestedType>, Func<MyNestedType, MyNestedType>>, Func<MyNestedType, MyNestedType>>> Y = y => f => x => f(y(y)(f))(x);

    Func<Func<Func<MyNestedType, MyNestedType>, Func<MyNestedType, MyNestedType>>, Func<MyNestedType, MyNestedType>> Fix = Y(Y);

    listofMyNestedTypes.Select(mnt => Fix(find => x => x != null && x.valueType != 3 ? find(x.subobject) : x)(mnt)).Where(mnt => mnt != null).ToList().ForEach(mnt => DoSomething(mnt.valueType));

  • What do you consider the better practice...

    [quote user="ScanIAm"]

    Rossj wrote:
    

    Add this to your class and change MyObject for your class name ..

    public static implicit operator bool(MyObject obj)
    {
        return obj != null;
    }

    Kinda cool!  I didn't think to do that.  It won't really help for already defined types, but it could work.


    You could make an extension method that worked pretty much the same way, like Exists().

  • Doing the same thing for multiple exception types

    You could make ShowErrorMessage() overloaded, accepting the types of exceptions you want.

  • What would you do if everything fails (what's your plan B)?

    Busk with my guitar, and make guitars, and possibly teach lessons.

  • Share ASP.NET Session with Classic ASP

    phreaks wrote:
    Does anyone know of a product that will facilitate the sharing of Classic ASP and ASP.NET sessions ?


    Yes, StateStitch - http://www.consonica.com/StateStitch.aspx; I've used it and it's simple and effective, dealing with complex types that you'd have to mess with if you wrote your own.

  • Hi, I'm Chris and I am a VB.NET developer !

    Although I prefer to use C# for most of the code I write, there are times when VB.NET seems better.  For example VB.NET has a lot of templates for that save time, versus C#, which is more of a tooling issue than anything (i.e. in VB.NET 2005 you have options for automagically generating code to handle single-instance applications and so on).  Late-binding is very helpful when doing a lot of COM Interop, so you can skip adding all the optional Reflection.Missing parameters that are required by C#, but not VB.NET.

    I think that I can write in VB.NET and C# equally well, however, and really having any bias against one or the other is more of a reflection of the ignorance of the person who think VB.NET is somehow "weaker" or "a toy" compared to C#, because it's completely irrelevant in the big scheme of things aside from the forementioned benefits of late-binding and VS templates, and the forthcoming XML literals and dynamic features of VB.NET.

    Making a UI in VB.NET in the future with XML literals and dynamicism is going to make it a lot easier to write than it currently is without those features. 

  • Let's get ​philosophic​al....

    If the many-worlds, or infinite-worlds which seems more appropriate, theory of quantum physics is correct, then in some reality the machine imagined never gets turned off, and so never dies, thus being immortal.  Also, in some reality, you lived a perfect life and so has society and together have managed to perfect the health and healing of the body thus gaining immortality.  And in some reality, eventually, some society will find a way to merge all those realities into one in which the "perfect" reality is chosen by all the "imperfect" realities as being the one in which they would prefer to dwell, and in that "perfect" reality the society may choose to not only merge with all other realities, but to resurrect the dead in those alternate realities by means such as reviving them from genes left over, and from the electromagnetic signatures left over from their thought patterns, resurrect their memories and thoughts throughout all time.

    LOL - so you know, anything's possible.  Only one of the many realities has to be able and choose to do this to save all.  Wink

  • C#:How do you kill an application when all you have is the GUID?

    lagu26537 wrote:
    Also the network technician told me the exe is probably svchost.exe. Now I need to unload a dll which I think I know the name of from svchost.exe. How do you do that?


    If it's always the same dll, then you can find out which host it's in by using Component Services/Computer/My Computer/DCOM and finding your GUID, take a look at the properties, etc....

    If svchost is your host, is it a Windows Service?  Then you just kill the service, using System.ServiceProcess.ServiceController.