Inherits() public method

public Inherits ( Mono.Cecil.TypeDefinition type, string interfaceFullName ) : bool
type Mono.Cecil.TypeDefinition
interfaceFullName string
return bool
Esempio n. 1
0
        public bool Test(TypeKey type, InheritMap map)
        {
            if (!string.IsNullOrEmpty(attrib))
            {
                if (string.Equals(attrib, "public", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (!type.TypeDefinition.IsTypePublic())
                    {
                        return(false);
                    }
                }
                else
                {
                    throw new ObfuscarException(string.Format(
                                                    "'{0}' is not valid for the 'attrib' value of the SkipType element. Only 'public' is supported by now.",
                                                    attrib));
                }
            }

            // type's regex matches
            if (nameRx != null && !nameRx.IsMatch(type.Fullname))
            {
                return(false);
            }

            // type's name matches
            if (!string.IsNullOrEmpty(name) && !Helper.CompareOptionalRegex(type.Fullname, name))
            {
                return(false);
            }

            if (isSerializable.HasValue)
            {
                if (isSerializable != type.TypeDefinition.IsSerializable)
                {
                    return(false);
                }
            }

            if (isStatic.HasValue)
            {
                if (isStatic != (type.TypeDefinition.IsSealed && type.TypeDefinition.IsAbstract))
                {
                    return(false);
                }
            }

            if (!string.IsNullOrEmpty(inherits))
            {
                if (!map.Inherits(type.TypeDefinition, inherits))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 2
0
        public bool Test(MethodKey method, InheritMap map)
        {
            if (key != null)
            {
                return(method == key);
            }

            // method name matches type regex?
            if (!String.IsNullOrEmpty(type) && !Helper.CompareOptionalRegex(method.TypeKey.Fullname, type))
            {
                return(false);
            }

            // method visibility matches
            if (CheckMemberVisibility(this.attrib, typeAttrib, method.MethodAttributes, method.DeclaringType))
            {
                return(false);
            }

            // method's name matches
            if (nameRx != null && !nameRx.IsMatch(method.Name))
            {
                return(false);
            }

            // method's name matches
            if (!string.IsNullOrEmpty(name) && !Helper.CompareOptionalRegex(method.Name, name))
            {
                return(false);
            }

            // check is method's static flag matches.
            if (isStatic.HasValue)
            {
                bool methodIsStatic = (method.MethodAttributes & MethodAttributes.Static) == MethodAttributes.Static;

                if (isStatic != methodIsStatic)
                {
                    return(false);
                }
            }

            // finally does method's type inherit?
            if (!string.IsNullOrEmpty(inherits))
            {
                if (!map.Inherits(method.DeclaringType, inherits))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 3
0
        public bool Test(FieldKey field, InheritMap map)
        {
            if (!string.IsNullOrEmpty(decorator))
            {
                var match = false;

                foreach (var typeField in field.TypeKey.TypeDefinition.Fields)
                {
                    if (typeField.Name != field.Name)
                    {
                        continue;
                    }

                    if (!typeField.HasCustomAttributes)
                    {
                        return(false);
                    }

                    foreach (var customAttr in typeField.CustomAttributes)
                    {
                        if (customAttr.AttributeType.FullName == decorator)
                        {
                            match = true;
                            break;
                        }
                    }
                }

                if (!match)
                {
                    return(false);
                }
            }

            if (!string.IsNullOrEmpty(type) && !Helper.CompareOptionalRegex(field.TypeKey.Fullname, type))
            {
                return(false);
            }

            // It's not very clean to use CheckMethodVisibility() from MethodTester. But we don't want duplicate code either.
            if (MethodTester.CheckMemberVisibility(attrib, typeAttrib, (MethodAttributes)field.FieldAttributes,
                                                   field.DeclaringType))
            {
                return(false);
            }

            if (nameRx != null && !nameRx.IsMatch(field.Name))
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(name) && !Helper.CompareOptionalRegex(field.Name, name))
            {
                return(false);
            }

            if (isStatic.HasValue)
            {
                bool fieldIsStatic = (field.FieldAttributes & FieldAttributes.Static) == FieldAttributes.Static;

                if (isStatic.Value != fieldIsStatic)
                {
                    return(false);
                }
            }

            if (isSerializable.HasValue)
            {
                if (isSerializable.Value && ((field.FieldAttributes & FieldAttributes.NotSerialized) ==
                                             FieldAttributes.NotSerialized))
                {
                    return(false);
                }

                bool fieldIsPublic        = (field.FieldAttributes & FieldAttributes.Public) == FieldAttributes.Public;
                bool parentIsSerializable = field.DeclaringType.IsSerializable;

                if (isSerializable != (fieldIsPublic && parentIsSerializable))
                {
                    return(false);
                }
            }

            // finally does method's type inherit?
            if (!string.IsNullOrEmpty(inherits))
            {
                if (!map.Inherits(field.DeclaringType, inherits))
                {
                    return(false);
                }
            }

            return(true);
        }