Esempio n. 1
0
 public static bool IsAnonymous(this System.Reflection.TypeInfo type)
 {
     return(type.Namespace == null &&
            type.IsSealed &&
            (type.Name.StartsWith("<>f__AnonymousType", StringComparison.Ordinal) ||
             type.Name.StartsWith("<>__AnonType", StringComparison.Ordinal) ||
             type.Name.StartsWith("VB$AnonymousType_", StringComparison.Ordinal)) &&
            type.IsDefined(typeof(CompilerGeneratedAttribute), false));
 }
 private bool IsDispatcherHandler(TypeInfo typeInfo)
 {
     return typeInfo.IsDefined(typeof(DispatcherHandlerAttribute))
            && typeInfo.IsClass
            && typeInfo.IsPublic
            && !typeInfo.IsAbstract
            && !typeInfo.IsGenericTypeDefinition
            && !typeInfo.ContainsGenericParameters;
 }
        /// <summary>
        /// Returns <c>true</c> if the <paramref name="typeInfo"/> is a controller. Otherwise <c>false</c>.
        /// </summary>
        /// <param name="typeInfo">The <see cref="TypeInfo"/>.</param>
        /// <param name="candidateAssemblies">The set of candidate assemblies.</param>
        /// <returns><c>true</c> if the <paramref name="typeInfo"/> is a controller. Otherwise <c>false</c>.</returns>
        protected internal virtual bool IsController(
            TypeInfo typeInfo,
            ISet<Assembly> candidateAssemblies)
        {
            if (typeInfo == null)
            {
                throw new ArgumentNullException(nameof(typeInfo));
            }

            if (candidateAssemblies == null)
            {
                throw new ArgumentNullException(nameof(candidateAssemblies));
            }

            if (!typeInfo.IsClass)
            {
                return false;
            }
            if (typeInfo.IsAbstract)
            {
                return false;
            }
            // We only consider public top-level classes as controllers. IsPublic returns false for nested
            // classes, regardless of visibility modifiers
            if (!typeInfo.IsPublic)
            {
                return false;
            }
            if (typeInfo.ContainsGenericParameters)
            {
                return false;
            }
            if (!typeInfo.Name.EndsWith(ControllerTypeName, StringComparison.OrdinalIgnoreCase) &&
                !DerivesFromController(typeInfo, candidateAssemblies))
            {
                return false;
            }
            if (typeInfo.IsDefined(typeof(NonControllerAttribute)))
            {
                return false;
            }

            return true;
        }
        public static bool IsComponent(TypeInfo typeInfo)
        {
            if (typeInfo == null)
            {
                throw new ArgumentNullException(nameof(typeInfo));
            }

            if (!typeInfo.IsClass ||
                !typeInfo.IsPublic ||
                typeInfo.IsAbstract ||
                typeInfo.ContainsGenericParameters)
            {
                return false;
            }

            return
                typeInfo.Name.EndsWith(ViewComponentSuffix, StringComparison.OrdinalIgnoreCase) ||
                typeInfo.IsDefined(typeof(ViewComponentAttribute));
        }
Esempio n. 5
0
 public void AllPublicTypesShouldBeAnnotatedWithPublicAPIAttribute(TypeInfo type)
 {
     Assert.True(type.IsDefined(typeof(PublicAPIAttribute), true));
 }
        internal static HarshEntityMetadata Create(HarshEntityMetadataRepository repository, TypeInfo typeInfo)
        {
            if (repository == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(repository));
            }

            if (typeInfo == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(typeInfo));
            }

            if (typeInfo.IsDefined(typeof(ContentTypeAttribute), inherit: false))
            {
                return new HarshEntityMetadataContentType(repository, typeInfo);
            }

            throw new NotImplementedException("TODO: more entity types to come :)");
        }