System.Net.EndpointPermission.MatchWildcard C# (CSharp) Method

MatchWildcard() private method

private MatchWildcard ( string str ) : bool
str string
return bool
        internal bool MatchWildcard(string str) {

            string [] wcPieces = hostname.Split(DotSeparator);
            string [] strPieces = str.Split(DotSeparator);

            if ((strPieces.Length != 4) || (wcPieces.Length != 4)) {
                return false;
            }
            for (int i = 0; i < 4; i++) {
                if ((strPieces[i] != wcPieces[i]) && (wcPieces[i] != "*")) {
                    return false;
                }
            }
            return true;
        }

Usage Example

        internal bool MatchAddress(EndpointPermission e)
        {
            // For Asp.Net config we made it valid empty string in a hostname,
            // but it will match to nothing.
            if (this.Hostname.Length == 0 || e.Hostname.Length == 0)
            {
                return(false);
            }

            //
            // This is a fix for INADDR_ANY in Bind()
            // if this.Hostname == "0.0.0.0" then it matches only to e.Hostname="*.*.*.*"
            //
            // The reason is to not pass "0.0.0.0" into Resolve()
            if (this.Hostname.Equals("0.0.0.0"))
            {
                if (e.Hostname.Equals("*.*.*.*") || e.Hostname.Equals("0.0.0.0"))
                {
                    return(true);
                }
                return(false);
            }

            if (IsDns && e.IsDns)
            {
                return(String.Compare(hostname, e.hostname, StringComparison.OrdinalIgnoreCase) == 0);
            }
            Resolve();
            e.Resolve();


            if (((address == null) && !wildcard) || ((e.address == null) && !e.wildcard))
            {
                return(false);
            }

            //
            // try matching IP addresses against other wildcard address(es) or
            // wildcard
            //

            if (this.wildcard && !e.wildcard)
            {
                return(false);                           // as a wildcard I cannot be subset of a host.
            }
            else if (e.wildcard)
            {
                if (this.wildcard)
                {
                    // check against my _wildcard_
                    if (MatchWildcard(e.hostname))
                    {
                        return(true);
                    }
                }
                else
                {
                    // check against my _addresses_
                    for (int i = 0; i < address.Length; ++i)
                    {
                        if (e.MatchWildcard(address[i].ToString()))
                        {
                            return(true);
                        }
                    }
                }
            }
            else
            {
                //both are _not_ wildcards
                for (int i = 0; i < address.Length; ++i)
                {
                    for (int j = 0; j < e.address.Length; ++j)
                    {
                        if (address[i].Equals(e.address[j]))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
All Usage Examples Of System.Net.EndpointPermission::MatchWildcard