public static EntityKindAttribute GetAttribute(Type type) { var attr = TryGetAttribute(type); if (attr == null) throw new InvalidOperationException("{0} does not define an EntityKindAttribute".Formato(type.TypeName())); return attr; }
internal static string NoRegistrationForTypeFound(Type serviceType, bool containerHasRegistrations, bool containerHasRelatedOneToOneMapping, bool containerHasRelatedCollectionMapping, Type[] skippedDecorators) => string.Format(CultureInfo.InvariantCulture, "No registration for type {0} could be found.{1}{2}{3}{4}", serviceType.TypeName(), ContainerHasNoRegistrationsAddition(containerHasRegistrations), DidYouMeanToCallGetInstanceInstead(containerHasRelatedOneToOneMapping, serviceType), DidYouMeanToCallGetAllInstancesInstead(containerHasRelatedCollectionMapping, serviceType), NoteThatSkippedDecoratorsWereFound(serviceType, skippedDecorators));
public ExtensionToken(QueryToken parent, string key, Type type, bool isProjection, string unit, string format, Implementations? implementations, string isAllowed, PropertyRoute propertyRoute) : base(parent) { var shouldHaveImplementations = typeof(IEntity).IsAssignableFrom((isProjection ? type.ElementType() : type).CleanType()); if (shouldHaveImplementations && implementations == null) throw new ArgumentException("Extension token '{0}' (of type {1}) registered on type {2} has no implementations".FormatWith(key, type.TypeName(), parent.Type.CleanType().TypeName())); this.key= key; this.type = type; this.isProjection = isProjection; this.unit = unit; this.format = format; this.implementations = implementations; this.isAllowed = isAllowed; this.propertyRoute = propertyRoute; }
private static string DidYouMeanToCallGetAllInstancesInstead(bool hasCollection, Type serviceType) => hasCollection ? string.Format(CultureInfo.InvariantCulture, " There is, however, a registration for {0}; Did you mean to call " + "GetAllInstances<{1}>() or depend on {0}?", typeof(IEnumerable<>).MakeGenericType(serviceType).TypeName(), serviceType.TypeName()) : string.Empty;
internal static string OpenGenericTypesCanNotBeResolved(Type serviceType) => string.Format(CultureInfo.InvariantCulture, "The request for type {0} is invalid because it is an open generic type: it is only " + "possible to instantiate instances of closed generic types. A generic type is closed if " + "all of its type parameters have been substituted with types that are recognized by the " + "compiler.", serviceType.TypeName());
public void PrintType(string prefix, Type ty) { Contract.Requires(prefix != null); Contract.Requires(ty != null); string s = ty.TypeName(null, true); if (s != "?" && !s.StartsWith("_")) { wr.Write("{0}{1}", prefix, s); } }
internal static string DelegateForTypeReturnedNull(Type serviceType) => string.Format(CultureInfo.InvariantCulture, "The registered delegate for type {0} returned null.", serviceType.TypeName());
public static Exception ArgumentNullException(Type argumentType, string argumentName) { return new ArgumentNullException(argumentName, $"The argument '{argumentName}' of type '{argumentType.TypeName()}' is null. Are you missing an [AutoInit] attribute?"); }
public readonly Expression CustomToStr; //Not readonly public LiteReferenceExpression(Type type, Expression reference, Expression customToStr) : base(DbExpressionType.LiteReference, type) { Type cleanType = Lite.Extract(type); if (cleanType != reference.Type) throw new ArgumentException("The type {0} is not the Lite version of {1}".Formato(type.TypeName(), reference.Type.TypeName())); this.Reference = reference; this.CustomToStr = customToStr; }
internal static string AnOverlappingRegistrationExists(Type openGenericServiceType, Type overlappingImplementationType, bool isExistingRegistrationConditional, Type implementationTypeOfNewRegistration, bool isNewRegistrationConditional) { string solution = "Either remove one of the registrations or make them both conditional."; if (isExistingRegistrationConditional && isNewRegistrationConditional && overlappingImplementationType == implementationTypeOfNewRegistration) { solution = "You can merge both registrations into a single conditional registration and combine " + "both predicates into one single predicate."; } return string.Format(CultureInfo.InvariantCulture, "There is already a {0}registration for {1} (with implementation {2}) that " + "overlaps with the {3}registration for {4} that you are trying to make. This new " + "registration would cause ambiguity, because both registrations would be used for the " + "same closed service types. {5}", isExistingRegistrationConditional ? "conditional " : string.Empty, openGenericServiceType.TypeName(), overlappingImplementationType.TypeName(), isNewRegistrationConditional ? "conditional " : string.Empty, implementationTypeOfNewRegistration.TypeName(), solution); }
public void PrintType(string prefix, Type ty) { Contract.Requires(prefix != null); Contract.Requires(ty != null); if (DafnyOptions.O.DafnyPrintResolvedFile != null) { ty = ty.Normalize(); } string s = ty.TypeName(null, true); if (!(ty is TypeProxy) && !s.StartsWith("_")) { wr.Write("{0}{1}", prefix, s); } }
internal static string RegistrationForClosedServiceTypeOverlapsWithOpenGenericRegistration( Type closedServiceType, Type overlappingGenericImplementationType) => string.Format(CultureInfo.InvariantCulture, "There is already an open generic registration for {0} (with implementation {1}) that " + "overlaps with the registration of {2} that you are trying to make. If your intention is " + "to use {1} as fallback registration, please instead call: " + "{5}(typeof({3}), typeof({4}), c => !c.Handled).", closedServiceType.GetGenericTypeDefinition().TypeName(), overlappingGenericImplementationType.TypeName(), closedServiceType.TypeName(), CSharpFriendlyName(closedServiceType.GetGenericTypeDefinition()), CSharpFriendlyName(overlappingGenericImplementationType), nameof(Container.RegisterConditional));
internal static string ErrorWhileBuildingDelegateFromExpression(Type serviceType, Expression expression, Exception exception) => string.Format(CultureInfo.InvariantCulture, "Error occurred while trying to build a delegate for type {0} using the expression \"{1}\". " + "{2}", serviceType.TypeName(), expression, exception.Message);
internal static string ServiceTypeCannotBeAPartiallyClosedType(Type openGenericServiceType, string serviceTypeParamName, string implementationTypeParamName) => string.Format(CultureInfo.InvariantCulture, "The supplied type '{0}' is a partially-closed generic type, which is not supported as " + "value of the {1} parameter. Instead, please supply the open generic type '{2}' and make " + "the type supplied to the {3} parameter partially-closed instead.", openGenericServiceType.TypeName(), serviceTypeParamName, CSharpFriendlyName(openGenericServiceType.GetGenericTypeDefinition()), implementationTypeParamName);
internal static string ServiceTypeCannotBeAPartiallyClosedType(Type openGenericServiceType) => string.Format(CultureInfo.InvariantCulture, "The supplied type '{0}' is a partially-closed generic type, which is not supported by " + "this method. Please supply the open generic type '{1}' instead.", openGenericServiceType.TypeName(), CSharpFriendlyName(openGenericServiceType.GetGenericTypeDefinition()));
internal static string TypeFactoryReturnedIncompatibleType(Type serviceType, Type implementationType) => string.Format(CultureInfo.InvariantCulture, "The registered type factory returned type {0} which does not implement {1}.", implementationType.TypeName(), serviceType.TypeName());
static Type GetEntityType(string typeStr, Type objectType) { var type = ReflectionServer.TypesByName.Value.GetOrThrow(typeStr); if (type.IsEnum) type = EnumEntity.Generate(type); if (!objectType.IsAssignableFrom(type)) throw new JsonSerializationException($"Type '{type.Name}' is not assignable to '{objectType.TypeName()}'"); return type; }
internal static string MultipleApplicableRegistrationsFound(Type serviceType, Tuple<Type, Type, InstanceProducer>[] overlappingRegistrations) => string.Format(CultureInfo.InvariantCulture, "Multiple applicable registrations found for {0}. The applicable registrations are {1}. " + "If your goal is to make one registration a fallback in case another registration is not " + "applicable, make the fallback registration last using RegisterConditional and make sure " + "the supplied predicate returns false in case the Handled property is true.", serviceType.TypeName(), overlappingRegistrations.Select(BuildRegistrationName).ToCommaSeparatedText());
public static FixTokenResult FixValue(Replacements replacements, Type type, ref string valueString, bool allowRemoveToken, bool isList) { object val; string error = FilterValueConverter.TryParse(valueString, type, out val, isList); if (error == null) return FixTokenResult.Nothing; if (isList && valueString.Contains('|')) { List<string> changes = new List<string>(); foreach (var str in valueString.Split('|')) { string s = str; var result = FixValue(replacements, type, ref s, allowRemoveToken, false); if (result == FixTokenResult.DeleteEntity || result == FixTokenResult.SkipEntity || result == FixTokenResult.RemoveToken) return result; changes.Add(s); } valueString = changes.ToString("|"); return FixTokenResult.Fix; } if (type.IsLite()) { var m = Lite.ParseRegex.Match(valueString); if (m.Success) { var typeString = m.Groups["type"].Value; if (!TypeLogic.NameToType.ContainsKey(typeString)) { string newTypeString = AskTypeReplacement(replacements, typeString); if (newTypeString.HasText()) { valueString = valueString.Replace(typeString, newTypeString); return FixTokenResult.Fix; } } } } if (Replacements.AutoReplacement != null) { Replacements.Selection? sel = Replacements.AutoReplacement(valueString, null); if (sel != null && sel.Value.NewValue != null) { valueString = sel.Value.NewValue; return FixTokenResult.Fix; } } SafeConsole.WriteLineColor(ConsoleColor.White, "Value '{0}' not convertible to {1}.".FormatWith(valueString, type.TypeName())); SafeConsole.WriteLineColor(ConsoleColor.Yellow, "- s: Skip entity"); if (allowRemoveToken) SafeConsole.WriteLineColor(ConsoleColor.DarkRed, "- r: Remove token"); SafeConsole.WriteLineColor(ConsoleColor.Red, "- d: Delete entity"); SafeConsole.WriteLineColor(ConsoleColor.Green, "- freeText: New value"); string answer = Console.ReadLine(); if (answer == null) throw new InvalidOperationException("Impossible to synchronize interactively without Console"); string a = answer.ToLower(); if (a == "s") return FixTokenResult.SkipEntity; if (allowRemoveToken && a == "r") return FixTokenResult.RemoveToken; if (a == "d") return FixTokenResult.DeleteEntity; valueString = answer; return FixTokenResult.Fix; }
private static string NonGenericTypeAlreadyRegistered(Type serviceType, bool existingRegistrationIsConditional) { return string.Format(CultureInfo.InvariantCulture, "Type {0} has already been registered as {1} registration. For non-generic types, " + "conditional and unconditional registrations can't be mixed.", serviceType.TypeName(), existingRegistrationIsConditional ? "conditional" : "unconditional"); }
public static EntityKindAttribute TryGetAttribute(Type type) { return dictionary.GetOrAdd(type, t => { if (!t.IsIEntity()) throw new InvalidOperationException("{0} should be a non-abstrat Entity".FormatWith(type.TypeName())); return t.GetCustomAttribute<EntityKindAttribute>(true); }); }
internal static string DelegateForTypeThrewAnException(Type serviceType) => string.Format(CultureInfo.InvariantCulture, "The registered delegate for type {0} threw an exception.", serviceType.TypeName());
internal static string ImplementationTypeFactoryReturnedNull(Type serviceType) => string.Format(CultureInfo.InvariantCulture, "The implementation type factory delegate that was registered for service type {0} returned null.", serviceType.TypeName());
protected virtual string WriteQuery(Type type) { if (ShouldWriteSimpleQuery(type)) return null; string typeName = type.TypeName(); var v = GetVariableName(type); StringBuilder sb = new StringBuilder(); sb.AppendLine("dqm.RegisterQuery(typeof({0}), () =>".FormatWith(typeName)); sb.AppendLine(" from {0} in Database.Query<{1}>()".FormatWith(v, typeName)); sb.AppendLine(" select " + WriteQueryConstructor(type, v) + ");"); return sb.ToString(); }
// ----------------------------- PrintType ----------------------------- public void PrintType(Type ty) { Contract.Requires(ty != null); wr.Write(ty.TypeName(null, true)); }
internal static string TheServiceIsRequestedOutsideTheContextOfAScopedLifestyle(Type serviceType, ScopedLifestyle lifestyle) => string.Format(CultureInfo.InvariantCulture, "The {0} is registered as '{1}' lifestyle, but the instance is requested outside the " + "context of a {1}.", serviceType.TypeName(), lifestyle.Name);
protected virtual string WriteInclude(Type type) { var ops = GetOperationsSymbols(type); var save = ops.SingleOrDefaultEx(o => GetOperationType(o) == OperationType.Execute && IsSave(o)); var delete = ops.SingleOrDefaultEx(o => GetOperationType(o) == OperationType.Delete); var p = ShouldWriteSimpleQuery(type) ? GetVariableName(type) : null; return new[] { "sb.Include<" + type.TypeName() + ">()", save != null && ShouldWriteSimpleOperations(save) ? (" .WithSave(" + save.Symbol.ToString() + ")") : null, delete != null && ShouldWriteSimpleOperations(delete) ? (" .WithDelete(" + delete.Symbol.ToString() + ")") : null, p == null ? null : $" .WithQuery(dqm, {p} => {WriteQueryConstructor(type, p)})" }.NotNull().ToString("\r\n") + ";"; }
internal static string TheTypeReturnedFromTheFactoryShouldNotBeOpenGeneric( Type serviceType, Type implementationType) => string.Format(CultureInfo.InvariantCulture, "The registered type factory returned open generic type {0} while the registered service " + "type {1} is not generic, making it impossible for a closed generic type to be constructed.", implementationType.TypeName(), serviceType.TypeName());
private static string SuppliedTypeIsNotGenericExplainingAlternatives(Type type, string registeringElement) => string.Format(CultureInfo.InvariantCulture, "This method only supports open generic types. " + "If you meant to register all available implementations of {0}, call " + "{2}(typeof({0}), IEnumerable<{1}>) instead.", type.TypeName(), registeringElement, nameof(Container.RegisterCollection));
internal static string UnregisteredTypeEventArgsRegisterDelegateThrewAnException(Type serviceType, Exception exception) => string.Format(CultureInfo.InvariantCulture, "The delegate that was registered for service type {0} using the {2}.{3}(Func<object>) " + "method threw an exception. {1}", serviceType.TypeName(), exception.Message, nameof(UnregisteredTypeEventArgs), nameof(UnregisteredTypeEventArgs.Register));