| 1 | #Region "Microsoft.VisualBasic::8f5dc2d2723bf368ee62ccf0148ba17d, Microsoft.VisualBasic.Core\ComponentModel\DataSource\DefaultAttribute.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 | ' Class DefaultAttribute |
| 35 | ' |
| 36 | ' Constructor: (+1 Overloads) Sub New |
| 37 | ' Function: GetDefaultAttribute, GetDefaultValues, ToString |
| 38 | ' |
| 39 | ' |
| 40 | ' /********************************************************************************/ |
| 41 | |
| 42 | #End Region |
| 43 | |
| 44 | Imports System.ComponentModel |
| 45 | Imports System.Reflection |
| 46 | Imports System.Runtime.CompilerServices |
| 47 | Imports Microsoft.VisualBasic.Scripting |
| 48 | |
| 49 | Namespace ComponentModel.DataSourceModel |
| 50 | |
| 51 | ''' <summary> |
| 52 | ''' Property default value |
| 53 | ''' </summary> |
| 54 | <AttributeUsage(AttributeTargets.Property, AllowMultiple:=False, Inherited:=True)> |
| 55 | Public Class DefaultAttribute : Inherits DefaultValueAttribute |
| 56 | |
| 57 | Sub New(value As Object) |
| 58 | Call MyBase.New(value) |
| 59 | End Sub |
| 60 | |
| 61 | Public Overrides Function ToString() As String |
| 62 | Return InputHandler.ToString(Value) |
| 63 | End Function |
| 64 | |
| 65 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
| 66 | Public Shared Function GetDefaultValues(type As Type) As Dictionary(Of String, Object) |
| 67 | Return type.Schema(PropertyAccess.Readable, PublicProperty, nonIndex:=True) _ |
| 68 | .ToDictionary(Function(p) p.Value.Name, |
| 69 | Function(p) |
| 70 | Return GetDefaultAttribute(p.Value)?.Value |
| 71 | End Function) |
| 72 | End Function |
| 73 | |
| 74 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
| 75 | Public Shared Function GetDefaultAttribute([property] As PropertyInfo) As DefaultValueAttribute |
| 76 | Return [property] _ |
| 77 | .GetCustomAttributes(Of DefaultValueAttribute)(inherit:=True) _ |
| 78 | .FirstOrDefault |
| 79 | End Function |
| 80 | End Class |
| 81 | End Namespace |