Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate source for Resources.resx #542

Merged
merged 2 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,162 +1,164 @@
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports Microsoft.CodeAnalysis

Friend Module ObjectInfoHelper
'Helpers that use Reflection to return details pertaining to an object including
'its type + the types, names and values of properties on this object.
Namespace Roslyn.SyntaxVisualizer.DgmlHelper
Friend Module ObjectInfoHelper
'Helpers that use Reflection to return details pertaining to an object including
'its type + the types, names and values of properties on this object.

#Region "GetObjectInfo"
Friend Function GetObjectInfo(nodeOrToken As SyntaxNodeOrToken) As ObjectInfo
Dim info As ObjectInfo = Nothing
Friend Function GetObjectInfo(nodeOrToken As SyntaxNodeOrToken) As ObjectInfo
Dim info As ObjectInfo = Nothing

If nodeOrToken.IsNode Then
info = GetObjectInfo(nodeOrToken.AsNode)
Else
info = GetObjectInfo(nodeOrToken.AsToken)
End If
If nodeOrToken.IsNode Then
info = GetObjectInfo(nodeOrToken.AsNode)
Else
info = GetObjectInfo(nodeOrToken.AsToken)
End If

Return info
End Function
Return info
End Function

Friend Function GetObjectInfo(node As SyntaxNode) As ObjectInfo
Dim type = node.GetType()
Friend Function GetObjectInfo(node As SyntaxNode) As ObjectInfo
Dim type = node.GetType()

Dim properties = type.GetProperties(System.Reflection.BindingFlags.Instance Or
Dim properties = type.GetProperties(System.Reflection.BindingFlags.Instance Or
System.Reflection.BindingFlags.Public)
Dim propertyInfos = (From p In properties Where IsSimpleProperty(p)
Select GetPropertyInfo(p, node)).ToList()
Dim propertyInfos = (From p In properties Where IsSimpleProperty(p)
Select GetPropertyInfo(p, node)).ToList()

Return New ObjectInfo(type.Name, propertyInfos)
End Function
Return New ObjectInfo(type.Name, propertyInfos)
End Function

Friend Function GetObjectInfo(token As SyntaxToken) As ObjectInfo
Dim type = token.GetType()
Friend Function GetObjectInfo(token As SyntaxToken) As ObjectInfo
Dim type = token.GetType()

Dim properties = type.GetProperties(System.Reflection.BindingFlags.Instance Or
Dim properties = type.GetProperties(System.Reflection.BindingFlags.Instance Or
System.Reflection.BindingFlags.Public)
Dim propertyInfos = (From p In properties Where IsSimpleProperty(p)
Select GetPropertyInfo(p, token)).ToList()
Dim propertyInfos = (From p In properties Where IsSimpleProperty(p)
Select GetPropertyInfo(p, token)).ToList()

Return New ObjectInfo(type.Name, propertyInfos)
End Function
Return New ObjectInfo(type.Name, propertyInfos)
End Function

Friend Function GetObjectInfo(trivia As SyntaxTrivia) As ObjectInfo
Dim type = trivia.GetType()
Friend Function GetObjectInfo(trivia As SyntaxTrivia) As ObjectInfo
Dim type = trivia.GetType()

Dim properties = type.GetProperties(System.Reflection.BindingFlags.Instance Or
Dim properties = type.GetProperties(System.Reflection.BindingFlags.Instance Or
System.Reflection.BindingFlags.Public)
Dim propertyInfos = (From p In properties Where IsSimpleProperty(p)
Select GetPropertyInfo(p, trivia)).ToList()
Return New ObjectInfo(type.Name, propertyInfos)
End Function
Dim propertyInfos = (From p In properties Where IsSimpleProperty(p)
Select GetPropertyInfo(p, trivia)).ToList()
Return New ObjectInfo(type.Name, propertyInfos)
End Function
#End Region

#Region "GetPropertyInfo"
Private Function IsSimpleProperty(prop As System.Reflection.PropertyInfo) As Boolean
Dim type = prop.PropertyType
If type Is GetType(Char) OrElse
type Is GetType(Boolean) OrElse
type Is GetType(Short) OrElse
type Is GetType(UShort) OrElse
type Is GetType(Integer) OrElse
type Is GetType(UInteger) OrElse
type Is GetType(Long) OrElse
type Is GetType(ULong) OrElse
type Is GetType(Single) OrElse
type Is GetType(Double) OrElse
type Is GetType(Date) OrElse
type Is GetType(Decimal) OrElse
type Is GetType(String) OrElse
type.IsEnum Then
Return True
Else
Return False
End If
End Function

'Only called if IsSimpleProperty returns true.
Private Function GetPropertyInfo(prop As System.Reflection.PropertyInfo,
node As SyntaxNode) As ObjectInfo.PropertyInfo
Return New ObjectInfo.PropertyInfo(prop.Name, prop.PropertyType,
prop.GetValue(node, Nothing))
End Function

'Only called if IsSimpleProperty returns true.
Private Function GetPropertyInfo(prop As System.Reflection.PropertyInfo,
token As SyntaxToken) As ObjectInfo.PropertyInfo
Return New ObjectInfo.PropertyInfo(prop.Name, prop.PropertyType,
prop.GetValue(token, Nothing))
End Function

'Only called if IsSimpleProperty returns true.
Private Function GetPropertyInfo(prop As System.Reflection.PropertyInfo,
trivia As SyntaxTrivia) As ObjectInfo.PropertyInfo
Return New ObjectInfo.PropertyInfo(prop.Name, prop.PropertyType,
prop.GetValue(trivia, Nothing))
End Function
#End Region
End Module

'Encapsulates details pertaining to an object including its type + the types, names
'and values of properties on this object.
Friend Class ObjectInfo
Private ReadOnly _typeName As String
Private ReadOnly _propertyInfos As IEnumerable(Of PropertyInfo)
Private Shared ReadOnly s_emptyPropertyInfos As IEnumerable(Of PropertyInfo) = Array.Empty(Of PropertyInfo)

Friend ReadOnly Property TypeName As String
Get
Return _typeName
End Get
End Property

Friend ReadOnly Property PropertyInfos As IEnumerable(Of PropertyInfo)
Get
If _propertyInfos Is Nothing Then
Return s_emptyPropertyInfos
Private Function IsSimpleProperty(prop As System.Reflection.PropertyInfo) As Boolean
Dim type = prop.PropertyType
If type Is GetType(Char) OrElse
type Is GetType(Boolean) OrElse
type Is GetType(Short) OrElse
type Is GetType(UShort) OrElse
type Is GetType(Integer) OrElse
type Is GetType(UInteger) OrElse
type Is GetType(Long) OrElse
type Is GetType(ULong) OrElse
type Is GetType(Single) OrElse
type Is GetType(Double) OrElse
type Is GetType(Date) OrElse
type Is GetType(Decimal) OrElse
type Is GetType(String) OrElse
type.IsEnum Then
Return True
Else
Return _propertyInfos
Return False
End If
End Get
End Property

Friend Sub New(typeName As String, propertyInfos As IEnumerable(Of PropertyInfo))
_typeName = typeName
_propertyInfos = propertyInfos
End Sub

'Encapsulates the name, type and value of a property on an object.
Friend Class PropertyInfo
Private ReadOnly _name As String
Private ReadOnly _type As Type
Private ReadOnly _value As Object
End Function

'Only called if IsSimpleProperty returns true.
Private Function GetPropertyInfo(prop As System.Reflection.PropertyInfo,
node As SyntaxNode) As ObjectInfo.PropertyInfo
Return New ObjectInfo.PropertyInfo(prop.Name, prop.PropertyType,
prop.GetValue(node, Nothing))
End Function

'Only called if IsSimpleProperty returns true.
Private Function GetPropertyInfo(prop As System.Reflection.PropertyInfo,
token As SyntaxToken) As ObjectInfo.PropertyInfo
Return New ObjectInfo.PropertyInfo(prop.Name, prop.PropertyType,
prop.GetValue(token, Nothing))
End Function

'Only called if IsSimpleProperty returns true.
Private Function GetPropertyInfo(prop As System.Reflection.PropertyInfo,
trivia As SyntaxTrivia) As ObjectInfo.PropertyInfo
Return New ObjectInfo.PropertyInfo(prop.Name, prop.PropertyType,
prop.GetValue(trivia, Nothing))
End Function
#End Region
End Module

Friend ReadOnly Property Name As String
Get
Return _name
End Get
End Property
'Encapsulates details pertaining to an object including its type + the types, names
'and values of properties on this object.
Friend Class ObjectInfo
Private ReadOnly _typeName As String
Private ReadOnly _propertyInfos As IEnumerable(Of PropertyInfo)
Private Shared ReadOnly s_emptyPropertyInfos As IEnumerable(Of PropertyInfo) = Array.Empty(Of PropertyInfo)

Friend ReadOnly Property Type As Type
Friend ReadOnly Property TypeName As String
Get
Return _type
Return _typeName
End Get
End Property

Friend ReadOnly Property Value As Object
Friend ReadOnly Property PropertyInfos As IEnumerable(Of PropertyInfo)
Get
Return _value
If _propertyInfos Is Nothing Then
Return s_emptyPropertyInfos
Else
Return _propertyInfos
End If
End Get
End Property

Friend Sub New(name As String, type As Type, value As Object)
_name = name
_type = type
_value = value
Friend Sub New(typeName As String, propertyInfos As IEnumerable(Of PropertyInfo))
_typeName = typeName
_propertyInfos = propertyInfos
End Sub

'Encapsulates the name, type and value of a property on an object.
Friend Class PropertyInfo
Private ReadOnly _name As String
Private ReadOnly _type As Type
Private ReadOnly _value As Object

Friend ReadOnly Property Name As String
Get
Return _name
End Get
End Property

Friend ReadOnly Property Type As Type
Get
Return _type
End Get
End Property

Friend ReadOnly Property Value As Object
Get
Return _value
End Get
End Property

Friend Sub New(name As String, type As Type, value As Object)
_name = name
_type = type
_value = value
End Sub
End Class
End Class
End Class
End Namespace

This file was deleted.

Loading