Exemple #1
0
        public static bool IsConditionalMethodExcluded(ParseContext parseContext, MethodBase mb, SourceSpan loc)
        {
            var excluded = _analyzedMethodExcluded[mb];

            if (excluded != null)
            {
                return(excluded == True ? true : false);
            }

            var conditionalAttributes = mb
                                        .GetCustomAttributes(TypeManager.PredefinedAttributes.Conditional, true)
                                        .Cast <ConditionalAttribute>();

            if (!conditionalAttributes.Any())
            {
                _analyzedMethodExcluded.Add(mb, False);
                return(false);
            }

            if (conditionalAttributes.Any(a => parseContext.LanguageContext.IsConditionalDefined(a.ConditionString)))
            {
                _analyzedMethodExcluded.Add(mb, False);
                return(false);
            }

            _analyzedMethodExcluded.Add(mb, True);
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Returns instance of ObsoleteAttribute when member is obsolete
        /// </summary>
        public static ObsoleteAttribute GetMemberObsoleteAttribute(MemberInfo mi)
        {
            var typeObsolete = _analyzedMemberObsolete[mi];

            if (typeObsolete == False)
            {
                return(null);
            }

            if (typeObsolete != null)
            {
                return((ObsoleteAttribute)typeObsolete);
            }

            if ((mi.DeclaringType is TypeBuilder) || TypeManager.IsGenericType(mi.DeclaringType))
            {
                return(null);
            }

            var obsoleteAttribute = Attribute.GetCustomAttribute(
                mi,
                TypeManager.PredefinedAttributes.Obsolete,
                false) as ObsoleteAttribute;

            _analyzedMemberObsolete.Add(mi, obsoleteAttribute ?? False);

            return(obsoleteAttribute);
        }
Exemple #3
0
        /// <summary>
        ///   Lookup a TypeHandle instance for the given type.  If the type doesn't have
        ///   a TypeHandle yet, a new instance of it is created.  This static method
        ///   ensures that we'll only have one TypeHandle instance per type.
        /// </summary>
        private static TypeHandle GetTypeHandle(Type t)
        {
            var handle = (TypeHandle)_typeHash[t];

            if (handle != null)
            {
                return(handle);
            }

            handle = new TypeHandle(t);
            _typeHash.Add(t, handle);
            return(handle);
        }
Exemple #4
0
        /// <summary>
        /// Returns IFixedBuffer implementation if field is fixed buffer else null.
        /// </summary>
        public static IFixedBuffer GetFixedBuffer(FieldInfo fi)
        {
            // Fixed buffer helper type is generated as value type
            if (TypeManager.IsReferenceType(fi.FieldType))
            {
                return(null);
            }

            if (TypeManager.GetConstant(fi) != null)
            {
                return(null);
            }

            var o = _fixedBufferCache[fi];

            if (o == null)
            {
                var fixedBufferAttribute = TypeManager.PredefinedAttributes.FixedBuffer;

                if (!fi.IsDefined(fixedBufferAttribute, false))
                {
                    _fixedBufferCache.Add(fi, False);
                    return(null);
                }

                IFixedBuffer iff = new FixedFieldExternal(fi);
                _fixedBufferCache.Add(fi, iff);
                return(iff);
            }

            if (o == False)
            {
                return(null);
            }

            return((IFixedBuffer)o);
        }
Exemple #5
0
        /// <summary>
        /// This method tests the CLS compliance of external types. It doesn't test type visibility.
        /// </summary>
        public static bool IsClsCompliant(Type type)
        {
            if (type == null)
            {
                return(true);
            }

            var typeCompliance = _analyzedTypes[type];

            if (typeCompliance != null)
            {
                return(typeCompliance == True);
            }

            if (type.IsPointer)
            {
                _analyzedTypes.Add(type, False);
                return(false);
            }

            bool result;

            if (type.IsArray)
            {
                result = IsClsCompliant(type);
            }
            else if (TypeManager.IsNullableType(type))
            {
                result = IsClsCompliant(type.GetGenericArguments()[0]);
            }
            else
            {
                result = AnalyzeTypeCompliance(type);
            }
            _analyzedTypes.Add(type, result ? True : False);
            return(result);
        }