コード例 #1
0
        private static AttemptTuple <object> CheckValueMatchesType(object value, HiveIdValueTypes type)
        {
            Mandate.ParameterNotNull(value, "value");

            switch (type)
            {
            case HiveIdValueTypes.Uri:
                Uri uri;
                return(new AttemptTuple <object>(Uri.TryCreate(HiveId.HiveEntityUriDecode(value.ToString()), UriKind.RelativeOrAbsolute, out uri), uri));

            case HiveIdValueTypes.Guid:
                Guid ignoredResult;
                return(new AttemptTuple <object>(Guid.TryParse(value.ToString(), out ignoredResult), ignoredResult));

            case HiveIdValueTypes.Int32:
                Int32 ignoredInt;
                return(new AttemptTuple <object>(Int32.TryParse(value.ToString(), out ignoredInt), ignoredInt));

            default:
                return(new AttemptTuple <object>(true, value.ToString()));
            }
        }
コード例 #2
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);
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HiveIdValue"/> struct from a string value.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <remarks></remarks>
 public HiveIdValue(string value)
 {
     _type     = HiveIdValueTypes.String;
     _value    = value;
     _isSystem = false;
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HiveIdValue"/> struct from a <see cref="Guid"/> value.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <remarks></remarks>
 public HiveIdValue(Guid value)
 {
     _type     = HiveIdValueTypes.Guid;
     _value    = value;
     _isSystem = null;
 }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HiveIdValue"/> struct from an integer value.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <remarks></remarks>
 public HiveIdValue(int value)
 {
     _type     = HiveIdValueTypes.Int32;
     _value    = value;
     _isSystem = false;
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HiveIdValue"/> struct from a string value.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <remarks></remarks>
 public HiveIdValue(Uri value)
 {
     _type     = HiveIdValueTypes.Uri;
     _value    = value;
     _isSystem = false;
 }
コード例 #7
0
ファイル: HiveIdTest.cs プロジェクト: paulsuart/rebelcmsxu5
        public void Ctor_AsString_FullValue(string input, string expectedUriSafe, string expectedAsUri, HiveIdValueTypes expectedType, bool shouldThrow)
        {
            HiveId hiveId = HiveId.Empty;

            if (shouldThrow)
            {
                Assert.Throws<FormatException>(() => hiveId = new HiveId(input));
                return;
            }
            else
                hiveId = new HiveId(input);

            Assert.AreEqual(expectedType, hiveId.Value.Type);
            Assert.AreEqual(expectedUriSafe, hiveId.ToString(HiveIdFormatStyle.UriSafe));
            Assert.AreEqual(expectedAsUri, hiveId.ToString(HiveIdFormatStyle.AsUri));
        }
コード例 #8
0
        public void Ctor_AsString_FullValue(string input, string expectedUriSafe, string expectedAsUri, HiveIdValueTypes expectedType, bool shouldThrow)
        {
            HiveId hiveId = HiveId.Empty;

            if (shouldThrow)
            {
                Assert.Throws <FormatException>(() => hiveId = new HiveId(input));
                return;
            }
            else
            {
                hiveId = new HiveId(input);
            }

            Assert.AreEqual(expectedType, hiveId.Value.Type);
            Assert.AreEqual(expectedUriSafe, hiveId.ToString(HiveIdFormatStyle.UriSafe));
            Assert.AreEqual(expectedAsUri, hiveId.ToString(HiveIdFormatStyle.AsUri));
        }