English 中文(简体)
向通用名单发送某种类型的困难
原标题:Difficulties sending a type to a generic list

我不想在装上该页时使用通用清单。 我有一套从名单上继承的财产。 使用这种收集方法的用户控制不了解使用哪类数据(目标)。 因此,当该页装满时,我通过依赖性财产向用户控制传递。 这种方法的目的是:

Private Shared Sub OnObjectTypeChanged(ByVal obj As DependencyObject, ByVal args As DependencyPropertyChangedEventArgs)
    Dim objectType As Type = TryCast(args.NewValue, Type)
    Dim aList As List(Of PropertyData) = New TypePropertyCollection(Of objectType)
End Sub

我可以ces地从活动成果中检索这种类型,将其放在一个变量上。 当我造就一种新的类型物色时,我想将这种类型列入通用清单,但是,它说的是标语的定型号,尽管这只是上述线。

任何建议?

Edit

职业类别

Public Sub New()
    Dim properties = New List(Of PropertyInfo)(GetType(T).GetProperties(BindingFlags.Public Or BindingFlags.Instance))
    For Each propertyToCheck In properties
        Dim descriptionAttribute = propertyToCheck.GetCustomAttributes(GetType(DescriptionAttribute), True)
        If Not descriptionAttribute Is Nothing AndAlso descriptionAttribute.Length > 0 Then
            Add(New PropertyData() With {.Description = DirectCast(descriptionAttribute(0), DescriptionAttribute).Description, .PropertyName = propertyToCheck.Name})
        Else
            Add(New PropertyData() With {.Description = propertyToCheck.Name, .PropertyName = propertyToCheck.Name})
        End If
    Next
End Sub

To use this collection, I m creating a new class which inherits from the typcollection:

Public Class CustomerTypePropertyCollection
    Inherits TypePropertyCollection(Of Person)
End Class

我不能这样做,因为个人(我指这里的人,以方便)在这种解决办法中不为人所知。 还应当能够收集其他已知或不知道的类型。 因此,我想通过该物体的类型,并以这种方式使用。

问题回答
Dim aList As List(Of PropertyData) = New TypePropertyCollection(Of Type)

之所以出现这一错误,是因为你试图制造一种类型的物体类型,物体类型是具有某种类型变量的名称。 你们需要的是类型类型,而不是变量名称的类型。 如果还有其他问题,请回我。





相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签