Re: Passing property Accesor as Function`
Brady Kelly <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.clr |
|---|---|
| Message-ID | <[email protected]> |
Richard, I'm idealistically trying to find a way of choosing the correct type conversion based on the type of the property. Like I said, it was really a hypothetical issue; I'm going to use PropertyInfo objects and attributes in production. > -----Original Message----- > From: Discussion of development on the .NET platform using any managed > language [mailto:[email protected]] On Behalf Of Richard > Blewett > Sent: 19 November 2007 04:05 PM > To: [email protected] > Subject: Re: [DOTNET-CLR] Passing property Accesor as Function` > > What I don't understand is why your method doesn't simple return the > data > instead of trying to pass a property by reference. I assume there is > some > underlying issue that isn't obvious from the code > > Regards > > Richard Blewett - DevelopMentor > > > -----Original Message----- > > From: Discussion of development on the .NET platform using any > managed > > language [mailto:[email protected]] On Behalf Of Brady > > Kelly > > Sent: 19 November 2007 06:22 > > To: [email protected] > > Subject: [DOTNET-CLR] Passing property Accesor as Function` > > > > Warning: This is a purely academic and speculative post. > > > > > > > > This has suddenly become a real 'would like to have' feature in the > > project > > I'm currently working on. I know this isn't possible in standard C#, > > but > > I'm trying to find a hammer with the right weight and shape to beat > > this > > into some semblance of working. What I would like to achieve is > > something > > like this, in the commented line: > > > > > > > > public class PersonForm > > > > { > > > > System.Windows.Forms.TextBox textRate = new TextBox(); > > > > public void BuildPerson(Person person) > > > > { > > > > Person pers = new Person(); > > > > pers.HourlyRate = textRate.Text.Length == 0 ? (double?) > > null : > > double.Parse(textRate.Text); > > > > // SetPropertyFromText(pers.HourlyRate, textRate.Text) > > > > } > > > > } > > > > > > > > My SetPropertyFromText should take the pers.HourlyRate as a delegate > > parameter, not as a double?, determine the correct type conversion > > based on > > the type of the pers.HourlyRate, and set the property to the > converted > > object value. > > > > > > > > I can easily use a property name as my property parameter for > > SetPropertyFromText, but then I lose compile time checks. Our > > generated > > DAL, nettiers, provides, for each entity, an Enum with all the column > > properties for each entity, and I think this is about as close as > I've > > seen > > to what I want, but not quite there. > > > > > > > > Any ideas on the matter? > > > > > > > > > > =================================== > > This list is hosted by DevelopMentor. http://www.develop.com > > > > View archives and manage your subscription(s) at > > http://discuss.develop.com > > =================================== > This list is hosted by DevelopMentor. http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com