Is it possible to take an existing type and create an anonymous type from it with additional properties? Example (in VB)
Public Class Person Public Name As String Public Age As Integer End Class Dim p As New Person With {.Name = "James", .Age = 100} Dim n = New With {.ShoeSize = 10}
I want the second object (n) to clone all the properties of p, and then add a new property (ShoeSize).
Is it possible?
Many thanks
James
There is no syntax in C #. You will need to create an anonymous type with all properties.
If you need to do this regularly, modifying my extensions listed in here can save some typing.
, string.Join(", " , from p in ps select "." + p.Name + " = " + VarName + "." + p.Name), .
string.Join(", " , from p in ps select "." + p.Name + " = " + VarName + "." + p.Name)
OP: p.AllFieldsVb("p") ".Name = p.Name, .Age = p.Age".
p.AllFieldsVb("p")
".Name = p.Name, .Age = p.Age"
Source: https://habr.com/ru/post/1702466/More articles:Can Silverlight be used in ActiveX Control? - silverlightHow to change date format in Eclipse editor templates? - eclipseMoodle / Joomla / JFusion - the best platform for the development of e-learning, communication and information portal? - joomlaHow to read xls diagram in java? - javaHow to record and play macros in Eclipse 3.5? - macrosWPF Level Management - controlsExtension of an existing (anonymous) type in the selected request - .netRefactoring this Python code to iterate over a container - pythonCalling a web service from a Windows service - c #https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1702471/need-simple-example-of-wpf-binding-objects-to-listbox-with-linq&usg=ALkJrhjdYszlsZEzM5MmdFLnHECU-ZDIXQAll Articles