private static string Get1CTypeName(Type type) { if (type == typeof(string)) { return("СТРОКА"); } if (type == typeof(bool)) { return("БУЛЕВО"); } if (type == typeof(int) || type == typeof(uint) || type == typeof(byte) || type == typeof(long) || type == typeof(ulong) || type == typeof(double) || type == typeof(float) || type == typeof(decimal)) { return("ЧИСЛО"); } if (type == typeof(DateTime) || type == typeof(DateTime?)) { return("ДАТА"); } var name = ConfigurationName.GetOrNull(type); if (name.HasValue) { return(name.Value.Fullname); } const string messageFormat = "can't detect 1C type for [{0}]"; throw new InvalidOperationException(string.Format(messageFormat, type.Name)); }
private static string GetTypePresentation(Type type) { if (type == typeof(string)) { return("Строка"); } if (type.IsClass) { var scope = ConfigurationName.GetOrNull(type); if (scope != null) { var presentation = ObjectPresentation.OfClass(type); return(string.IsNullOrEmpty(presentation) ? Synonym.OfClass(type) : presentation); } } if (type == typeof(bool)) { return("Булево"); } if (type == typeof(DateTime)) { return("Дата"); } if (type == typeof(Guid)) { return("УникальныйИдентификатор"); } if (type == typeof(int) || type == typeof(long) || type == typeof(decimal) || type == typeof(byte) || type == typeof(sbyte) || type == typeof(short) || type == typeof(ushort) || type == typeof(uint) || type == typeof(ulong) || type == typeof(float) || type == typeof(double)) { return("Число"); } var underlyingType = Nullable.GetUnderlyingType(type); if (underlyingType != null) { return(GetTypePresentation(underlyingType)); } const string messageFormat = "can't get ПРЕДСТАВЛЕНИЕ for [typeof({0})]"; throw new NotSupportedException(string.Format(messageFormat, type.FormatName())); }
protected override Expression VisitConstant(ConstantExpression node) { var value = node.Value; var type = node.Type; var comparand = binaryExpressionMappings.GetOrDefault(node); if (comparand != null) { if (type == typeof(object) && comparand.Type != typeof(object)) { type = comparand.Type; } if (comparand.NodeType == ExpressionType.Convert) { type = ((UnaryExpression)comparand).Operand.Type; } } type = Nullable.GetUnderlyingType(type) ?? type; if (value == null) { var name = ConfigurationName.GetOrNull(type); if (name == null) { filterBuilder.Append("NULL"); } else { filterBuilder.AppendFormat("ЗНАЧЕНИЕ({0}.ПустаяСсылка)", name.Value.Fullname); } } else if (value.GetType().FullName == "System.RuntimeType") { var valueType = (Type)value; filterBuilder.Append("ТИП("); filterBuilder.Append(Get1CTypeName(valueType)); filterBuilder.Append(")"); } else { var xMember = comparand as MemberExpression; if (value is Guid && xMember != null && xMember.Member.Name == EntityHelpers.idPropertyName) { value = new ConvertUniqueIdentifierCmd { entityType = xMember.Member.DeclaringType == queryBuilder.QueryType ? queryBuilder.SourceType : xMember.Member.DeclaringType, id = (Guid)value } } ; else if (type.IsEnum) { value = new ConvertEnumCmd { enumType = type, valueIndex = (int)value } } ; else if (value is Abstract1CEntity) { value = ((Abstract1CEntity)value).Controller.ValueSource.GetBackingStorage(); } var parameterName = queryBuilder.AddParameter(value); filterBuilder.Append('&'); filterBuilder.Append(parameterName); } return(node); }