コード例 #1
0
        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]);
            }
        }
コード例 #2
0
ファイル: GeoIPHelper.cs プロジェクト: vasiliyph/bytecode-api
        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);
        }
コード例 #3
0
ファイル: GeoIPHelper.cs プロジェクト: vasiliyph/bytecode-api
        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);
        }
コード例 #4
0
 /// <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()));
 }
コード例 #5
0
ファイル: Validate.cs プロジェクト: vasiliyph/bytecode-api
 /// <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()));
 }