public void TestGetFragmentDataType() { ClassPartDataType ResultType = ClassPartDataType.Empty; ResultType = ElementsFinder.GetFragmentDataType("\"Property\" : 1.0"); Assert.Equal(ClassPartDataType.Double, ResultType); ResultType = ElementsFinder.GetFragmentDataType("\"Property\" : 1"); Assert.Equal(ClassPartDataType.Int, ResultType); ResultType = ElementsFinder.GetFragmentDataType("\"Property\" : \"String\""); Assert.Equal(ClassPartDataType.String, ResultType); ResultType = ElementsFinder.GetFragmentDataType("\"Property\" : { }"); Assert.Equal(ClassPartDataType.Object, ResultType); ResultType = ElementsFinder.GetFragmentDataType("\"Property\" :"); Assert.Equal(ClassPartDataType.Empty, ResultType); }
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); }