Update Shorthand?
-
Is there a shorthand for updating an object? Something like an initializer?
var item = new FooViewModel { id = "test", name = "test" };
Something like that but instead:
Record myRecord = Context.RecordRepository.GetById(1234);
myRecord {
id = 123,
name = "blah"
}Cheers, --EA
-
Is there a shorthand for updating an object? Something like an initializer?
var item = new FooViewModel { id = "test", name = "test" };
Something like that but instead:
Record myRecord = Context.RecordRepository.GetById(1234);
myRecord {
id = 123,
name = "blah"
}Cheers, --EA
No, there isn't.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Is there a shorthand for updating an object? Something like an initializer?
var item = new FooViewModel { id = "test", name = "test" };
Something like that but instead:
Record myRecord = Context.RecordRepository.GetById(1234);
myRecord {
id = 123,
name = "blah"
}Cheers, --EA
The best you can do is try and using LINQ to fetch and update records in the same line. However, what you are tyring to do is not directly possible.
Apps - Color Analyzer | Arctic | XKCD | Sound Meter | Speed Dial
-
Is there a shorthand for updating an object? Something like an initializer?
var item = new FooViewModel { id = "test", name = "test" };
Something like that but instead:
Record myRecord = Context.RecordRepository.GetById(1234);
myRecord {
id = 123,
name = "blah"
}Cheers, --EA
In VB.net its called "WITH" C# dont have this trick... But, you can use this:
/// /// C# implementation of Visual Basics With statement
///
public static void With(this T _object, Action _action)
{
_action(_object);
}Usage:
LongInstanceOfPersonVariableName.With(x => {
x.AgeIntVar = 21;
x.NameStrVar = "John";
x.NameStrVar += " Smith";
//etc..
});from http://stackoverflow.com/a/5964848[^] I dont think its the best solution... But... It may work.