Exemple #1
0
        public override string ToString()
        {
            if (!_isDefaultPropertyAttributeInit)
            {
                if (ClassInfo.FindAttributeInfo(typeof(DefaultPropertyAttribute)) is DefaultPropertyAttribute attrib)
                {
                    _defaultPropertyMemberInfo = ClassInfo.FindMember(attrib.Name);
                }
                _isDefaultPropertyAttributeInit = true;
            }
            object obj = _defaultPropertyMemberInfo?.GetValue(this);

            if (obj != null)
            {
                return(obj.ToString());
            }
            if (!_isDefaultPropertyAttributeInit)
            {
                string defaultPropertyName         = string.Empty;
                var    xafDefaultPropertyAttribute = XafTypesInfo.Instance.FindTypeInfo(GetType()).FindAttribute <XafDefaultPropertyAttribute>();
                if (xafDefaultPropertyAttribute != null)
                {
                    defaultPropertyName = xafDefaultPropertyAttribute.Name;
                }
                else
                {
                    var defaultPropertyAttribute = XafTypesInfo.Instance.FindTypeInfo(GetType()).FindAttribute <DefaultPropertyAttribute>();
                    if (defaultPropertyAttribute != null)
                    {
                        defaultPropertyName = defaultPropertyAttribute.Name;
                    }
                }
                if (!string.IsNullOrEmpty(defaultPropertyName))
                {
                    _defaultPropertyMemberInfo = ClassInfo.FindMember(defaultPropertyName);
                }
                _isDefaultPropertyAttributeInit = true;
            }
            obj = _defaultPropertyMemberInfo?.GetValue(this);
            return(obj?.ToString() ?? base.ToString());
        }
Exemple #2
0
 public override string ToString()
 {
     if (!_isDefaultPropertyAttributeInit)
     {
         var attrib = ClassInfo.FindAttributeInfo(typeof(DefaultPropertyAttribute)) as DefaultPropertyAttribute;
         if (attrib != null)
         {
             _defaultPropertyMemberInfo = ClassInfo.FindMember(attrib.Name);
         }
         _isDefaultPropertyAttributeInit = true;
     }
     if (_defaultPropertyMemberInfo != null)
     {
         object obj = _defaultPropertyMemberInfo.GetValue(this);
         if (obj != null)
         {
             return(obj.ToString());
         }
     }
     return(base.ToString());
 }