How do I make the properties of an anonymous type dynamically change from the user input? - vb.net

If I Have The following code:
Dim L = From item in _list
Group item By item.Name
Select New With {.Property = Name}
The problem is:
I want to generate a grid based on this grouping, the grouping is specified by the user, so the .Property will be a column name that user specified as the grouping property already I made the Group By depend on the user in my original code, but I could not make the .Property dependent so if the user specify to group the list by Name I want the .Property to be .Name
So, I want to make the .Property determined, any help please?

The fields of anonymous types must be defined at compile-time, so there's not a way to dynamically add fields at run-time. Besides, you wouldn't know what fields are available at compile-time, so you wouldn't to be able to write any code against them.
I would say you should use a different structure to represent the data. A Dictionary is the first type that comes to mind.

Related

How can I get all of the properties related to one node type?

I have a node Country. I know that this node has some properties, but I don't know which. I mean, I know since I've take a look at model. Here is what I've found in documentation:
Country
name: String
iso_2_code: String
iso_3_code: String
region: String
sub.region: String
I know that if I run
MATCH (c:Country)
RETURN c.iso_2_code
I'll get result for one specific property. Is there a query that would as a result return me something like: name, iso_2_code, iso_3_code, region, sub.region?
If I didn't have access to the model how could I list all of the properties that are attached to some node type?
Answering more from a Cypher or openCypher perspective than for a specific implementation. Using the air-routes dataset. There are three things to consider.
Firstly if you know the properties you want, as you mentioned, you can just ask for them explicitly.
MATCH (a:airport {icao:'KDFW'})
RETURN a.city, a.desc
However, if you want all properties, but do not want to list them all, you can just do:
MATCH (a:airport {icao:'KDFW'})
RETURN properties(a)
If you just want the property keys:
MATCH (a:airport {icao:'KDFW'})
RETURN keys(properties(a))
Lastly, if you want the properties plus the label and ID information you can just do:
MATCH (a:airport {icao:'KDFW'})
RETURN a

Make a custom field as a range - like "Price" is as default in Bigcommerce

Hi I am new in Bigcommerce can I make any custom field or field as a Range and filter data base on that range.
Depending on what functionality you're needing from this custom field, you may be able to use it for the 'price range'. The value type is string, so this does not accept an array of multiple values, you can see this in our API reference documentation. If you're just needing to use custom fields to render the text on a template or so, this could work, but if you're needing more functionality from it, it'd be best to use something else.

Is it possible to test if two types are of the same unknown inheritance in VB.net?

Is it possible to dynamically identify the closest common hierarchy or inheritance of two or more unknown typed objects? In other words, I'd like to test if, say, Integer and String have a common hierarchy, without knowing the objects I'm testing are going to be an Integer and String due to user selection. I found a C++ question posted that seems similar to my issue here: Check if two types are of the same template
However, I'm not familiar with any VB.net equivalents of the answers posted there, and online translators simply provide an error when I attempt to translate them. So is this even possible in VB.net in the first place?
The closest to this action that I know of is the .IsAssignableFrom() function, but in my case I don't know what the parent class/interface/whatever is to test against in the first place. the above function is the only thing even remotely related to this issue that pops up on any search I do.
The context I need this is in the Revit API; I'm trying to see if user selected elements have a similar hierarchy/inheritance that is not the Object Type, and if so to allow an action, otherwise, give a warning dialog box.
EDIT: Due to the nature of the Revit API and the desired effects of my command, the users of my plugin could select anything in the model, and I'm not able to determine which of the MANY common ancestors I could be looking for to compare using IsAssignableFrom. I could test for the (I think universal) common ancestor of Element type, but I don't want to allow users to run the command if you select a wall and an element tag. I need to find the common ancestors of the user-selected elements and confirm that the closest common ancestor is below Element type in hierarchy.
For example, the room tag element in the API has a hierarchy sort of like this:
Object -> Element -> SpatialElementTag -> RoomTag
There may be more intermediate inheritances, but I'm not going to track them down in the API documentation. And then each element may have a slightly different ancestry. IsAssignableFrom would be great if I knew the base ancestry I wanted to test for.
TnTinMn's answer gives me the type of solution I'm looking for.
The Type.BaseType Property returns:
The Type from which the current Type directly inherits, or null if the current Type represents the Object class or an interface.
Using this information, it is possible to define an iterator to enumerate the inheritance tree.
Private Iterator Function SelfAndAncestors(srcType As Type) As IEnumerable(Of Type)
Do Until srcType Is Nothing
Yield srcType
srcType = srcType.BaseType
Loop
End Function
Now you can use the Enumerable.Intersect Method to find all common types in the inheritance between two ancestry enumerations and return the first common ancestry type.
Dim t1 As Type = GetType(Form)
Dim t2 As Type = GetType(UserControl)
Dim highestCommonAncestor As Type = Enumerable.Intersect(SelfAndAncestors(t1), SelfAndAncestors(t2)).First()
For this case, the highest common ancestor is ContainerControl.

Check whether the given object is a list?

How can we check whether the given object is a list or other type
in velocity. In that list i have another list which i need to iterate again.
I also have another data in the parent list which i want to print while iterating parent list. But the problem is the child list object also get printing with actual data. So i want to print the data by checking whether its list or not. Any help is much appreciated.
Before you get any remarks on using too much logic in templates, try this reflection based approach :
velocity (test instanceof)

How do I use a GtkComboBox with objects, as opposed to strings?

The usual use for a combo box is to let it display options to the user, and then you get an OBJECT out of it. In Win32, you do it by using the CB_SETITEMDATA and CB_GETITEMDATA messages, casting between int and object pointers. In XAML, you set up a data template and the item in the list IS the object.
What is the Correct way to get this effect with a GtkComboBox?
GtkComboBox normally uses a GtkListStore as the underlaying model.
You need to create one with an extra column for the object you want to store and as you insert new items in the combo's model you also need to provide the object you want to associate with that row/item.