Example #1
0
        /// <summary>
        /// Check arguments of custom attribute.
        /// </summary>
        /// <param name="attributeArgs">The list of custom attribute arguments (types).</param>
        private void CheckCustomAttributes(IEnumerable <CustomAttributeArgument> attributeArgs)
        {
            IMetadataScope forwardedFrom;

            foreach (CustomAttributeArgument customAttributeArgument in attributeArgs)
            {
                TypeDefinition typeDefinition = customAttributeArgument.Value is TypeReference
                    ? (customAttributeArgument.Value as TypeReference).Resolve(out forwardedFrom)
                    : customAttributeArgument.Type.Resolve(out forwardedFrom);

                _sharedData.RemoveFromCandidates(forwardedFrom);

                if (typeDefinition != null && !_sharedData.IsUsedTypeExists(typeDefinition.AssemblyQualifiedName()))
                {
                    _sharedData.RemoveFromCandidates(typeDefinition.Scope);
                    if (!_sharedData.HasCandidateReferences)
                    {
                        return;
                    }

                    _sharedData.AddToUsedTypes(typeDefinition.AssemblyQualifiedName());
                    _interfaceCheckHelper.Check(typeDefinition, _sharedData);
                }
            }
        }
Example #2
0
        private void ResolveTypeReference(TypeReference paramTypeRef, CheckerSharedData sharedData)
        {
            var typeRef = GetNativeTypeOfTypeReference(paramTypeRef);

            if (typeRef == null || typeRef.IsGenericParameter)
            {
                return;
            }

            IMetadataScope forwardedFrom;
            var            typeDef = typeRef.Resolve(out forwardedFrom);

            sharedData.RemoveFromCandidates(forwardedFrom);
            if (typeDef != null && !sharedData.IsUsedTypeExists(typeDef.AssemblyQualifiedName()))
            {
                sharedData.RemoveFromCandidates(typeDef.Scope);

                _classCheckHeper.Check(typeDef, sharedData);
                _interfaceCheckHelper.Check(typeDef, sharedData);
            }
            else if (typeDef == null)
            {
                sharedData.AddToUsedTypes(typeRef.AssemblyQualifiedName());
                sharedData.RemoveFromCandidates(typeRef.Scope);
            }

            // check generic parameters of the type.
            if (typeRef is GenericInstanceType && ((GenericInstanceType)typeRef).HasGenericArguments)
            {
                var genericType = ((GenericInstanceType)typeRef);
                foreach (var genericArg in genericType.GenericArguments)
                {
                    ResolveTypeReference(genericArg, sharedData);
                }
            }
        }