Exemplo n.º 1
0
        public static HiveIdValue ConvertIntToGuid(int value)
        {
            Mandate.ParameterCondition(value != 0, "id");

            string template = Guid.Empty.ToString("N");
            bool   isSystem = false;

            if (value < 0)
            {
                // Reset it
                value = value * -1;
                // Add a prefix to the generated Guid
                template = 1 + template.Substring(1);

                //because it is negative we will deem it a system Uri
                isSystem = true;
            }
            string number = value.ToString();
            string guid   = template.Substring(0, template.Length - number.Length) + number;

            return(new HiveIdValue(Guid.Parse(guid))
            {
                IsSystem = isSystem
            });
        }
Exemplo n.º 2
0
        ///<summary>
        ///</summary>
        ///<param name="id"></param>
        ///<returns></returns>
        public static HiveEntityUri ConvertIntToGuid(int id)
        {
            Mandate.ParameterCondition(id != 0, "id");

            string template = Guid.Empty.ToString("N");
            bool   isSystem = false;

            if (id < 0)
            {
                // Reset it
                id = id * -1;
                // Add a prefix to the generated Guid
                template = 1 + template.Substring(1);

                //because it is negative we will deem it a system Uri
                isSystem = true;
            }
            string number = id.ToString();
            string guid   = template.Substring(0, template.Length - number.Length) + number;

            var hId = new HiveEntityUri(Guid.Parse(guid))
            {
                _isSystem = isSystem
            };

            return(hId);
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value == null)
            {
                return(null);
            }
            if (culture == null)
            {
                culture = Thread.CurrentThread.CurrentCulture;
            }

            Mandate.ParameterCondition(value.GetType() == typeof(string), "value");

            return(new LocalizedString((string)value));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Tries to create a <see cref="HiveIdValue"/> given the provided value and type.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static AttemptTuple <HiveIdValue> TryCreate(object value, HiveIdValueTypes type)
        {
            var potentialValue = CheckValueMatchesType(value, type);

            Mandate.ParameterCondition(potentialValue.Success, "type");

            switch (type)
            {
            case HiveIdValueTypes.Uri:
                return(new AttemptTuple <HiveIdValue>(true, new HiveIdValue((Uri)potentialValue.Result)));

            case HiveIdValueTypes.Guid:
                return(new AttemptTuple <HiveIdValue>(true, new HiveIdValue((Guid)potentialValue.Result)));

            case HiveIdValueTypes.Int32:
                return(new AttemptTuple <HiveIdValue>(true, new HiveIdValue((int)potentialValue.Result)));

            case HiveIdValueTypes.String:
                return(new AttemptTuple <HiveIdValue>(true, new HiveIdValue((string)potentialValue.Result)));
            }

            return(AttemptTuple <HiveIdValue> .False);
        }