Coffeehouse Post

Single Post Permalink

View Thread: C# Extension Properties?
  • User profile image
    koistya

    Property extensions in C# 5.0

    // A product type in this sample has a property Name of type String
    var product = new Product();
    
    // This will print "Product.Name.IsDirty: False"
    Console.WriteLine("Product.Name.IsDurty: {0}", product.Name.IsDirty);
    
    // Now let's try to update product's Name property
    product.Name = "C# 4.0 in a Nutshell";
    
    // And now this will print "Product.Name.IsDirty: True"
    Console.WriteLine("Product.Name.IsDurty: {0}", product.Name.IsDirty);
    
    // Then when you try to save this product in database, it will be easier for
    // Store Repository detect which fields must be saved and which can be skipped
    storeRepository.Add(product);
    storeRepository.SubmitChanges();