| 1 | #Region "Microsoft.VisualBasic::a4ac39b554ee308d53f58010efa121b0, Microsoft.VisualBasic.Core\Scripting\MetaData\MetaAPI.vb" |
| 2 | |
| 3 | ' Author: |
| 4 | ' |
| 5 | ' asuka (amethyst.asuka@gcmodeller.org) |
| 6 | ' xie (genetics@smrucc.org) |
| 7 | ' xieguigang (xie.guigang@live.com) |
| 8 | ' |
| 9 | ' Copyright (c) 2018 GPL3 Licensed |
| 10 | ' |
| 11 | ' |
| 12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
| 13 | ' |
| 14 | ' |
| 15 | ' This program is free software: you can redistribute it and/or modify |
| 16 | ' it under the terms of the GNU General Public License as published by |
| 17 | ' the Free Software Foundation, either version 3 of the License, or |
| 18 | ' (at your option) any later version. |
| 19 | ' |
| 20 | ' This program is distributed in the hope that it will be useful, |
| 21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | ' GNU General Public License for more details. |
| 24 | ' |
| 25 | ' You should have received a copy of the GNU General Public License |
| 26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 27 | |
| 28 | |
| 29 | |
| 30 | ' /********************************************************************************/ |
| 31 | |
| 32 | ' Summaries: |
| 33 | |
| 34 | ' Module MetaAPI |
| 35 | ' |
| 36 | ' Properties: TypeInfo |
| 37 | ' |
| 38 | ' Function: (+2 Overloads) GetCLIMod, GetEntry |
| 39 | ' |
| 40 | ' |
| 41 | ' /********************************************************************************/ |
| 42 | |
| 43 | #End Region |
| 44 | |
| 45 | Imports System.Reflection |
| 46 | Imports System.Runtime.CompilerServices |
| 47 | |
| 48 | Namespace Scripting.MetaData |
| 49 | |
| 50 | Public Module MetaAPI |
| 51 | |
| 52 | ''' <summary> |
| 53 | ''' <see cref="PackageAttribute"/> |
| 54 | ''' </summary> |
| 55 | ''' <returns></returns> |
| 56 | Public ReadOnly Property TypeInfo As Type = GetType(PackageAttribute) |
| 57 | |
| 58 | <Extension> Public Function GetCLIMod(assm As Assembly) As Type |
| 59 | Dim types As Type() = assm.GetTypes |
| 60 | Dim LQuery = (From type As Type In types |
| 61 | Let attrs As Object() = type.GetCustomAttributes(PackageAttribute.TypeInfo, inherit:=True) |
| 62 | Where Not attrs.IsNullOrEmpty |
| 63 | Let attr = DirectCast(attrs(Scan0), PackageAttribute) |
| 64 | Select attr, type) |
| 65 | Dim GetCLI = (From x In LQuery |
| 66 | Where x.attr.Category = APICategories.CLI_MAN |
| 67 | Select x.type).FirstOrDefault |
| 68 | Return GetCLI |
| 69 | End Function |
| 70 | |
| 71 | Public Function GetCLIMod(path As String) As Type |
| 72 | Try |
| 73 | Dim assm As Assembly = Assembly.LoadFile(path) |
| 74 | Return assm.GetCLIMod |
| 75 | Catch ex As Exception |
| 76 | ex = New Exception(path.ToFileURL, ex) |
| 77 | Call App.LogException(ex) |
| 78 | #If DEBUG Then |
| 79 | Call ex.PrintException |
| 80 | #End If |
| 81 | Return Nothing |
| 82 | End Try |
| 83 | End Function |
| 84 | |
| 85 | ''' <summary> |
| 86 | ''' 获取定义在类型定义上面的命名空间的标记信息 |
| 87 | ''' </summary> |
| 88 | ''' <param name="type"></param> |
| 89 | ''' <returns></returns> |
| 90 | Public Function GetEntry(type As Type) As PackageAttribute |
| 91 | #If NET_40 = 0 Then |
| 92 | Dim attrs = type.GetCustomAttributes(Of PackageAttribute)(inherit:=True) |
| 93 | Return attrs.FirstOrDefault |
| 94 | #Else |
| 95 | Throw New NotSupportedException |
| 96 | #End If |
| 97 | End Function |
| 98 | End Module |
| 99 | End Namespace |