Exemple #1
0
        public bool Test(EventKey evt, InheritMap map)
        {
            // method name matches type regex?
            if (!String.IsNullOrEmpty(type) && !Helper.CompareOptionalRegex(evt.TypeKey.Fullname, type))
            {
                return(false);
            }

            if (MethodTester.CheckMemberVisibility(attrib, typeAttrib, GetEventMethodAttributes(evt.Event), evt.DeclaringType))
            {
                return(false);
            }

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

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

            return(true);
        }
Exemple #2
0
        public bool Test(PropertyKey prop, InheritMap map)
        {
            // method name matches type regex?
            if (!String.IsNullOrEmpty(type) && !Helper.CompareOptionalRegex(prop.TypeKey.Fullname, type))
            {
                return(false);
            }

            // method visibility matches
            if (MethodTester.CheckMemberVisibility(attrib, typeAttrib, GetPropertyMethodAttributes(prop.Property), prop.DeclaringType))
            {
                return(false);
            }

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

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

            return(true);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #5
0
        public bool Test(EventKey evt)
        {
            if (Helper.CompareOptionalRegex(evt.TypeKey.Fullname, type) && MethodTester.CheckMethodVisibility(attrib, evt.AddMethodAttributes))
            {
                if (name != null)
                {
                    return(Helper.CompareOptionalRegex(evt.Name, name));
                }
                else
                {
                    return(nameRx.IsMatch(evt.Name));
                }
            }

            return(false);
        }
Exemple #6
0
        public bool Test(string ns, InheritMap map)
        {
            // regex matches
            if (nameRx != null && !nameRx.IsMatch(ns))
            {
                return(false);
            }

            // name matches
            if (!string.IsNullOrEmpty(name) && !Helper.CompareOptionalRegex(ns, name))
            {
                return(false);
            }

            return(true);
        }
Exemple #7
0
        public bool Test(PropertyKey prop)
        {
            if (Helper.CompareOptionalRegex(prop.TypeKey.Fullname, type) && MethodTester.CheckMethodVisibility(attrib, prop.GetterMethodAttributes))
            {
                if (name != null)
                {
                    return(Helper.CompareOptionalRegex(prop.Name, name));
                }
                else
                {
                    return(nameRx.IsMatch(prop.Name));
                }
            }

            return(false);
        }
Exemple #8
0
        public bool Test(PropertyKey prop, InheritMap map)
        {
            if (Helper.CompareOptionalRegex(prop.TypeKey.Fullname, type) && !MethodTester.CheckMemberVisibility(attrib, typeAttrib, prop.GetterMethodAttributes, prop.DeclaringType))
            {
                if (name != null)
                {
                    return(Helper.CompareOptionalRegex(prop.Name, name));
                }
                else
                {
                    return(nameRx.IsMatch(prop.Name));
                }
            }

            return(false);
        }
Exemple #9
0
        public bool Test(EventKey evt, InheritMap map)
        {
            if (Helper.CompareOptionalRegex(evt.TypeKey.Fullname, type) && !MethodTester.CheckMemberVisibility(attrib, typeAttrib, evt.AddMethodAttributes, evt.DeclaringType))
            {
                if (name != null)
                {
                    return(Helper.CompareOptionalRegex(evt.Name, name));
                }
                else
                {
                    return(nameRx.IsMatch(evt.Name));
                }
            }

            return(false);
        }
Exemple #10
0
        public bool Test(FieldKey field)
        {
            // It's not very clean to use CheckMethodVisibility() from MethodTester. But we don't want duplicate code either.
            if (Helper.CompareOptionalRegex(field.TypeKey.Fullname, type) && MethodTester.CheckMethodVisibility(attrib, (MethodAttributes)field.FieldAttributes))
            {
                if (name != null)
                {
                    return(Helper.CompareOptionalRegex(field.Name, name));
                }
                else
                {
                    return(nameRx.IsMatch(field.Name));
                }
            }

            return(false);
        }
Exemple #11
0
        public bool Test(TypeKey type)
        {
            if (!string.IsNullOrEmpty(attrib))
            {
                if (string.Equals(attrib, "public", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (!MethodTester.IsTypePublic(type.TypeDefinition))
                    {
                        return(false);
                    }
                }
                else
                {
                    throw new ApplicationException(string.Format("'{0}' is not valid for the 'attrib' value of the SkipType element. Only 'public' is supported by now.", attrib));
                }
            }

            return(Helper.CompareOptionalRegex(type.Fullname, name));
        }
Exemple #12
0
        public bool Test(MethodKey method)
        {
            if (key != null)
            {
                return(method == key);
            }

            if (Helper.CompareOptionalRegex(method.TypeKey.Fullname, type) && CheckMethodVisibility(this.attrib, method.MethodAttributes))
            {
                if (name != null)
                {
                    return(Helper.CompareOptionalRegex(method.Name, name));
                }
                else
                {
                    return(nameRx.IsMatch(method.Name));
                }
            }

            return(false);
        }
Exemple #13
0
 public bool Test(TypeKey type)
 {
     return(Helper.CompareOptionalRegex(type.Fullname.Replace("/", "."), name));            //nested classes contain "/"
 }
 public bool Test(string ns)
 {
     return(Helper.CompareOptionalRegex(ns, name));
 }
Exemple #15
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);
        }