public void TestGetFragmentValue() { Assert.Equal(1D, (double)ElementsFinder.GetFragmentValue("\"Property\" : 1.0")); Assert.Equal(1, (int)ElementsFinder.GetFragmentValue("\"Property\" : 1")); Assert.Equal("String", (string)ElementsFinder.GetFragmentValue("\"Property\" : \"String\"")); Assert.Equal(new double[] { 1, 2, 3 }, (double[])ElementsFinder.GetFragmentValue("\"Property\" : [1.0, 2.0, 3.0]")); Assert.Equal(new int[] { 1, 2, 3 }, (int[])ElementsFinder.GetFragmentValue("\"Property\" : [1, 2, 3]")); List <IClassPart> TestObject = new List <IClassPart>(); TestObject.Add(ClassPart.Create(ClassPartType.Property, ClassPartDataType.Double, "\"InnerProperty\" : 1.0 ", "InnerProperty", 1.0D)); Assert.Equal(TestObject.GetType(), ElementsFinder.GetFragmentValue("\"Property\" : { \"InnerProperty\" : 1.0 }").GetType()); }
public IDecompositor Go() { int strIndex = 0; if (!string.IsNullOrEmpty(JSONInput)) { if (ElementsFinder.StartAndStopExist(JSONInput)) { for (;;) { var index = ElementsFinder.GetNextPropertyIndex(JSONInput, strIndex); if (index == -1) { IsComplited = false; break; } var NextPropertyFragment = ElementsFinder.GetPropertyFragment(JSONInput, index); if (!string.IsNullOrEmpty(NextPropertyFragment)) { strIndex = index + NextPropertyFragment.Length; } else { IsComplited = false; break; } var PropertyName = ElementsFinder.GetFragmentName(NextPropertyFragment); var PropertyDataType = ElementsFinder.GetFragmentDataType(NextPropertyFragment); var PropertyType = ElementsFinder.GetFragmentType(NextPropertyFragment); var ProperyValue = ElementsFinder.GetFragmentValue(NextPropertyFragment); _Parts.Add(ClassPart.Create(PropertyType, PropertyDataType, NextPropertyFragment, PropertyName, ProperyValue)); } } } else { IsComplited = false; } return(this); }