Как использовать отражение для получения значений параметров по умолчанию - PullRequest
0 голосов
/ 09 января 2020

Я пытаюсь определить значение параметров по умолчанию и получаю странную ошибку.

При вызове info.HasDefaultValue

я получаю приведенный ниже erorr * Кто-нибудь знает как это сделать?

    Public Sub New(ByVal factory As DefinitionFactory, ByVal info As ParameterInfo)
        m_factory = factory
        Try
            If info.HasDefaultValue Then
                Me.DefaultValue = info.DefaultValue.GetType().FullName
            End If

            Me.HasDefaultValue = info.HasDefaultValue

        Catch ioe As InvalidOperationException

        End Try
End Sub

Ошибка:

System.InvalidOperationException
  HResult=0x80131509
  Message=It is illegal to reflect on the custom attributes of a Type loaded via ReflectionOnlyGetType (see Assembly.ReflectionOnly) -- use CustomAttributeData instead.
  Source=mscorlib
  StackTrace:
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeParameterInfo parameter, RuntimeType caType)
   at System.Reflection.RuntimeParameterInfo.GetDefaultValueInternal(Boolean raw)
   at System.Reflection.RuntimeParameterInfo.get_HasDefaultValue()
   at DefinitionParameter..ctor(DefinitionFactory factory, ParameterInfo info) in G:\Dev\FrozenElephant\APIcodeDB\ApiCodeModel\DefinitionParameter.vb:line 69
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...