/// <summary> /// Determines whether the IP address is in the same subnet as the /// specified IP address. /// </summary> /// <param name="address">The IPAddress instance this is being called /// for.</param> /// <param name="other">The IP address to determine whether it is in the same /// subnet.</param> /// <param name="netmask">The subnetmask to apply.</param> /// <returns>true if both IP address are located in the same subnet; Otherwise /// false.</returns> /// <exception cref="ArgumentNullException">The other parameter or the netmask /// parameter is null.</exception> /// <exception cref="ArgumentException">The netmask and IP address must be /// of the same address family.</exception> /// <remarks>This is an extension method for the IPAddress class.</remarks> public static bool InSameSubnet(this IPAddress address, IPAddress other, IPAddress netmask) { other.ThrowIfNull("other"); netmask.ThrowIfNull("netmask"); return address.And(netmask).Equals(other.And(netmask)); }
public static RequestBuilder WithContent(this RequestBuilder requestBuilder, object data) { var serializedData = JsonConvert.SerializeObject(data); requestBuilder .And(x => x.Content = new StringContent(serializedData, Encoding.UTF8, "application/json")); return requestBuilder; }
public static ReqlExpr BetterAnd(this RethinkDB r, params object[] exprs) { switch (exprs.Length) { // Make sure we have at least one expression. case 0: throw new ArgumentException("At least one expression is required.", nameof(exprs)); // If we only have one expression, no need to do anything. case 1: return (ReqlExpr)exprs[0]; // Otherwise, combine using the builtin And. default: return r.And(exprs); } }
public static void And(this ITestRunner testRunner, string text, string multilineTextArg) { testRunner.And(text, multilineTextArg, null); }
public static void And(this ITestRunner testRunner, string text) { testRunner.And(text, null, null); }
/// <summary> /// Alternating returns a predicate which returns true, then false, then true, and so forth. /// </summary> /// <param name="predicate">The initial predicate.</param> /// <param name="initialState">The initial state of the alternating selector.</param> /// <returns>The relevant selector.</returns> public static Func<Session, bool> Alternating(this Func<Session, bool> predicate, bool initialState = true) { return predicate.And(Selectors.Alternating(initialState)); }
/// <summary> /// IfHostNameContains returns a predicate which returns true if the hostname contains the given substring. /// </summary> /// <param name="predicate">The initial predicate.</param> /// <param name="hostNameSubstring">The substring for which to search.</param> /// <returns>The relevant selector.</returns> public static Func<Session, bool> IfHostNameContains(this Func<Session, bool> predicate, string hostNameSubstring) { return predicate.And(Selectors.IfHostNameContains(hostNameSubstring)); }
/// <summary> /// IfUrlContains returns a predicate which returns true if the URL contains the given substring of a URL. /// </summary> /// <param name="predicate">The initial predicate.</param> /// <param name="urlSubstring">The substring for which to search.</param> /// <returns>The relevant selector.</returns> public static Func<Session, bool> IfUrlContains(this Func<Session, bool> predicate, string urlSubstring) { return predicate.And(Selectors.IfUrlContains(urlSubstring)); }
/// <summary> /// IfUrlEquals returns a predicate which returns true if the URL in the session matches the given URL. /// </summary> /// <param name="predicate">The initial predicate.</param> /// <param name="urlToMatch">The URL to match.</param> /// <returns>The relevant selector.</returns> public static Func<Session, bool> IfUrlEquals(this Func<Session, bool> predicate, string urlToMatch) { return predicate.And(Selectors.IfUrlEquals(urlToMatch)); }
/// <summary> /// IfDelete returns a selector that adds a test for the GET verb. /// </summary> /// <param name="predicate">The initial predicate.</param> /// <returns>The relevant selector.</returns> public static Func<Session, bool> IfDelete(this Func<Session, bool> predicate) { return predicate.And(Selectors.IfDelete()); }
/// <summary> /// SkipNSessions returns a predicate which always returns true after n invocations. /// </summary> /// <param name="predicate">The initial predicate.</param> /// <param name="n">How many sessions to skip.</param> /// <returns>The relevant selector.</returns> public static Func<Session, bool> SkipNSessions(this Func<Session, bool> predicate, int n) { return predicate.And(Selectors.SkipNSessions(n)); }
/// <summary> /// 直接添加某个查询条件。 /// 如果没有相应的 And 连接符,则自动添加。 /// </summary> /// <param name="query">The query.</param> /// <param name="property">The property.</param> /// <param name="propertyOwner">The property owner.</param> /// <returns></returns> public static IPropertyQueryValue AddConstrain(this IPropertyQuery query, IManagedProperty property, Type propertyOwner = null) { if (query.HasWhere && query.IsCompleted) query.And(); return query.Constrain(property, propertyOwner); }
/// <summary> /// 直接添加某个 Sql 查询条件。 /// 如果没有相应的 And 连接符,则自动添加。 /// </summary> /// <param name="query">The query.</param> /// <param name="formatSql">The format SQL.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public static IPropertyQuery AddConstrainSql(this IPropertyQuery query, string formatSql, params object[] parameters) { if (query.HasWhere && query.IsCompleted) query.And(); return query.ConstrainSql(formatSql, parameters); }
/// <summary> /// Retuns true if the ip address is one of the following /// IANA-reserved private IPv4 network ranges (from http://en.wikipedia.org/wiki/IP_address) /// Start End /// 10.0.0.0 10.255.255.255 /// 172.16.0.0 172.31.255.255 /// 192.168.0.0 192.168.255.255 /// </summary> /// <returns></returns> public static bool IsOnIntranet(this System.Net.IPAddress ipAddress) { if (emptyIpv4.Equals(ipAddress)) { return false; } bool onIntranet = System.Net.IPAddress.IsLoopback(ipAddress); if (false == onIntranet) { //Handle IPv6 by getting the IPv4 Mapped Address. if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) { onIntranet = System.Net.IPAddress.Equals(ipAddress, ipAddress.And(intranetMask1v6)); //10.255.255.255 onIntranet = onIntranet || System.Net.IPAddress.Equals(ipAddress, ipAddress.And(intranetMask4v6)); ////192.168.255.255 onIntranet = onIntranet || (intranetMask2v4.Equals(ipAddress.And(intranetMask2v6)) && System.Net.IPAddress.Equals(ipAddress, ipAddress.And(intranetMask3v6))); } else if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { onIntranet = System.Net.IPAddress.Equals(ipAddress, ipAddress.And(intranetMask1v4)); //10.255.255.255 onIntranet = onIntranet || System.Net.IPAddress.Equals(ipAddress, ipAddress.And(intranetMask4v4)); ////192.168.255.255 onIntranet = onIntranet || (intranetMask2v4.Equals(ipAddress.And(intranetMask2v4)) && System.Net.IPAddress.Equals(ipAddress, ipAddress.And(intranetMask3v4))); } else throw new System.NotSupportedException("Only InterNetwork and InterNetworkV6 Address Families are supported."); } return onIntranet; }