Ejemplo n.º 1
0
        internal static Exception AssociatedObjectNotFound(object key, Type type, ProjectionObject projectionObject)
        {
            var message = string.Format
            (
                "Associated object not found for key '{0}' in {1}.  Expected type: {2}",
                key,
                projectionObject.ToString(),
                type.GetPrettyName(qualified: true)
            );

            return new KeyNotFoundException(message);
        }
Ejemplo n.º 2
0
        // TODO: 'trait' instead of 'attribute'?
        internal static Exception AttributeConflict(ProjectionType projectionType, Type attributeType)
        {
            var message = string.Format
            (
                "Conflicting '{0}' attributes inherited by type {1}.  " +
                "Override the attribute, or use inheritance directives to resolve the conflict.",
                attributeType.GetPrettyName(false).RemoveSuffix(AttributeSuffix),
                projectionType.UnderlyingType.GetPrettyName(true)
            );

            return new ProjectionException(message);
        }
        public static Type[] GetGenericTypesFor(this Type type, Type genericTypeDefinition)
        {
            Type[] foundTypes = findGenericTypesForDefinition(type, genericTypeDefinition);

            if (foundTypes.Length == 0)
            {
                throw new ArgumentException(
                    string.Format(
                                     "The type '{0}' is not a generic type of {1}.",
                                     type.GetPrettyName(),
                                     genericTypeDefinition.GetPrettyName()),
                    "type");
            }

            return foundTypes;
        }
        private static void printExample(Type type, Type genTypeDef)
        {
            bool isOfGenericType = type.IsOfGenericType(genTypeDef);

            Console.WriteLine("Is {0} an {1}? {2}",
                              type.GetPrettyName(),
                              genTypeDef.GetPrettyName(),
                              isOfGenericType ? "yes." : "no.");

            if (isOfGenericType)
            {
                Console.WriteLine("If it is, what are the type parameters? "
                                  + type.GetGenericArgumentsFor(genTypeDef)
                                        .Select(_ => _.GetPrettyName())
                                        .JoinStringsWith(", "));
            }
        }
        public static Type GetGenericTypeFor(this Type type, Type genericTypeDefinition)
        {
            Type[] foundTypes = GetGenericTypesFor(type, genericTypeDefinition);

            if (foundTypes.Length > 1)
            {
                throw new ArgumentException(
                    string.Format(
                                     "The type '{0}' has multiple implementations of {1}:{2}",
                                     type.GetPrettyName(),
                                     genericTypeDefinition.GetPrettyName(),
                                     string.Join(", ", foundTypes.Select(t => t.GetPrettyName()).ToArray())
                                     ),
                    "type");
            }

            return foundTypes[0];
        }
Ejemplo n.º 6
0
 public static string GetName(Type type) {
   object[] attribs = type.GetCustomAttributes(typeof(ItemAttribute), false);
   if (attribs.Length > 0) {
     string name = ((ItemAttribute)attribs[0]).Name;
     if (type.IsGenericType) {
       name += "<";
       Type[] typeParams = type.GetGenericArguments();
       if (typeParams.Length > 0) {
         name += GetName(typeParams[0]);
         for (int i = 1; i < typeParams.Length; i++)
           name += ", " + GetName(typeParams[i]);
       }
       name += ">";
     }
     return name;
   } else {
     return type.GetPrettyName();
   }
 }
        protected override void RegisterType(Type type)
        {
            base.RegisterType(type);

            if (BindingServiceProvider.DisableConverterAutoRegistration)
                return;
            if (!typeof(IValueConverter).IsAssignableFrom(type) || !type.IsPublicNonAbstractClass())
                return;
            var constructor = type.GetConstructor(Empty.Array<Type>());
            if (constructor == null || !constructor.IsPublic)
                return;
            var converter = (IValueConverter)constructor.Invoke(Empty.Array<object>());
            BindingServiceProvider.ResourceResolver.AddConverter(new ValueConverterWrapper(converter), type, true);
            ServiceProvider.BootstrapCodeBuilder?.Append(nameof(DataBindingModule), $"{typeof(BindingExtensions).FullName}.AddConverter(resolver, new {typeof(ValueConverterWrapper).FullName}(new {type.GetPrettyName()}()), typeof({type.GetPrettyName()}, true);");
            if (Tracer.TraceInformation)
                Tracer.Info("The {0} converter is registered.", type);
        }
Ejemplo n.º 8
0
        private static MessageTypeLogInfo CreateLogger(Type messageType)
        {
            var logger = LogManager.GetLogger(messageType);
            var hasToStringOverride = HasToStringOverride(messageType);

            return new MessageTypeLogInfo(logger, hasToStringOverride, messageType.GetPrettyName());
        }
Ejemplo n.º 9
0
 internal static Exception UnsupportedCollectionType(Type type)
 {
     var message = string.Format
     (
         "Unsupported collection type: {0}",
         type.GetPrettyName(true)
     );
     return new NotSupportedException(message);
 }
Ejemplo n.º 10
0
 internal static Exception TraitSpecCreateFailed(Type type, Exception innerException)
 {
     var message = string.Format
     (
         "Failed to create trait spec instance: {0}",
         type.GetPrettyName(true)
     );
     return new TraitSpecException(message, innerException);
 }
Ejemplo n.º 11
0
        // TODO: 'trait' instead of 'attribute'?
        internal static Exception InvalidOverride(string name, Type declaringType, ProjectionProperty newProperty)
        {
            var message = string.Format
            (
                "Invalid 'Override' attribute on property {0}.{1}.  " +
                "The specified base property was not found: {2}.{3}.",
                newProperty.DeclaringType.UnderlyingType.GetPrettyName(true),
                newProperty.Name,
                declaringType.GetPrettyName(true),
                name
            );

            return new ProjectionException(message);
        }
        protected virtual void RegisterType(Type type)
        {
            if (_isLoaded)
                return;
            var isConverter = typeof(IBindingValueConverter).IsAssignableFrom(type);
            var isTemplate = typeof(IDataTemplateSelector).IsAssignableFrom(type);

            if ((!isConverter && !isTemplate) || !type.IsPublicNonAbstractClass())
                return;

            if (BindingServiceProvider.DisableConverterAutoRegistration && isConverter)
                return;
            if (BindingServiceProvider.DisableDataTemplateSelectorAutoRegistration && isTemplate)
                return;

            var constructor = type.GetConstructor(Empty.Array<Type>());
            if (constructor == null || !constructor.IsPublic)
                return;

            var value = constructor.Invoke(Empty.Array<object>());
            if (isTemplate)
            {
                BindingServiceProvider.ResourceResolver.AddObject(type.Name, value, true);
                ServiceProvider.BootstrapCodeBuilder?.Append(nameof(DataBindingModule), $"{typeof(BindingExtensions).FullName}.AddObject(resolver, \"{type.Name}\", new {type.GetPrettyName()}(), true);");
            }
            else
            {
                BindingServiceProvider.ResourceResolver.AddConverter((IBindingValueConverter)value, type, true);
                ServiceProvider.BootstrapCodeBuilder?.Append(nameof(DataBindingModule), $"{typeof(BindingExtensions).FullName}.AddConverter(resolver, new {type.GetPrettyName()}(), typeof({type.GetPrettyName()}), true);");
            }

            if (Tracer.TraceInformation)
                Tracer.Info("The {0} is registered.", type);
        }
 public AggregateRootNotFoundException(Type aggregateRootType, string id)
     : base(string.Format("Could not find aggregate root of type {0} with ID {1}", aggregateRootType.GetPrettyName(), id))
 {
 }