private static T GetProperty <T>(Expression <Func <T> > property, Func <T> getter) { string name = property.GetMemberName(); lock (Properties) { if (!Properties.ContainsKey(name)) { Properties[name] = CSharp.Try(getter); } return((T)Properties[name]); } }
public static bool TryConvertIPv4(IPAddress ipAddress, out uint address) { if (ipAddress.AddressFamily == AddressFamily.InterNetwork) { byte[] bytes = CSharp.Try(() => ipAddress.MapToIPv4().GetAddressBytes()); if (bytes?.Length == 4) { address = BitConverter.ToUInt32(bytes.Reverse().ToArray(), 0); return(true); } } address = 0; return(false); }
public static bool TryConvertIPv6(IPAddress ipAddress, out byte[] address) { if (ipAddress.AddressFamily == AddressFamily.InterNetworkV6) { byte[] bytes = CSharp.Try(() => ipAddress.GetAddressBytes()); if (bytes?.Length == 16) { address = bytes; return(true); } } address = null; return(false); }
/// <summary> /// Validates a <see cref="string" /> that is a path. /// </summary> /// <param name="str">The <see cref="string" /> to be validated.</param> /// <returns> /// <see langword="true" />, if validation of <paramref name="str" /> succeeded; /// otherwise, <see langword="false" />. /// </returns> public static bool Path(string str) { return(str != null && CSharp.Try(() => new FileIOPermission(FileIOPermissionAccess.Read, new[] { str }).Demand())); }
/// <summary> /// Validates a <see cref="string" /> that is a path. /// </summary> /// <param name="str">The <see cref="string" /> to be validated.</param> /// <returns> /// <see langword="true" />, if validation of <paramref name="str" /> succeeded; /// otherwise, <see langword="false" />. /// </returns> public static bool Path(string str) { return(str != null && CSharp.Try(() => new FileIOPermission(FileIOPermissionAccess.Read, SingletonCollection.Array(str)).Demand())); }