System.Linq.Dynamic.ExpressionParser.GetTypeName C# (CSharp) Method

GetTypeName() private static method

private static GetTypeName ( Type type ) : string
type Type
return string
		private static string GetTypeName(Type type)
		{
			var baseType = GetNonNullableType(type);

			var displayName = baseType.GetCustomAttribute<ComponentModel.DisplayNameAttribute>();
			var result = displayName.HasValue && !displayName.Value.DisplayName.IsNullOrEmpty()
				? displayName.Value.DisplayName
				: baseType.Name;
			if (type != baseType) result += '?';
			return result;
		}

Usage Example

Esempio n. 1
0
            protected override Expression VisitMember(MemberExpression m)
            {
                if (!this.isInProjection)
                {
                    if (m.Member.MemberType == MemberTypes.Property)
                    {
                        PropertyDescriptor pd = TypeDescriptor.GetProperties(m.Member.DeclaringType)[m.Member.Name];

                        // Let properties for which no PropertyDescriptors exist go through. This happens when we
                        // deal with structs.
                        bool requiresValidation = !(pd == null && m.Member.DeclaringType.IsValueType);
                        if (requiresValidation && !this.IsVisible(pd))
                        {
                            if (!PostProcessor.IsProjectionPath(m))
                            {
                                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.UnknownPropertyOrField, pd.Name, ExpressionParser.GetTypeName(pd.ComponentType)));
                            }
                            else
                            {
                                this.isInProjection = true;
                                Expression expr = base.VisitMember(m);
                                this.isInProjection = false;
                                return(expr);
                            }
                        }
                    }
                }

                return(base.VisitMember(m));
            }
ExpressionParser