Revert "json property set for generated classes"

This commit is contained in:
adiviness 2016-10-20 14:39:07 -07:00 коммит произвёл GitHub
Родитель 751451d8dd
Коммит 76894abd69
8 изменённых файлов: 7 добавлений и 118 удалений

Просмотреть файл

@ -114,18 +114,13 @@
<None Include="..\winsdkfb_testing_key.pfx">
<Link>winsdkfb_testing_key.pfx</Link>
</None>
<None Include="data.json" />
<None Include="FBCSObjectImplementation.ttinclude" />
<None Include="FBPhoto.tt" />
<None Include="FBObject.tt" />
<None Include="FBSuccess.tt" />
<None Include="FBTestUser.tt" />
<None Include="packages.config" />
<Content Include="TestData\testJsonPropertySet.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\testJsonPropertySetNoBuiltInFields.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Utility.ttinclude" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -1,11 +0,0 @@
{
"name": "test_user",
"test_boolean": false,
"test_num": 4,
"test_string": "hello_world",
"test_array": [ 2, 3, 5, 7, 11 ],
"test_object": {
"a": "b",
"c": "d"
}
}

Просмотреть файл

@ -1,10 +0,0 @@
{
"test_boolean": false,
"test_num": 4,
"test_string": "hello_world",
"test_array": [ 2, 3, 5, 7, 11 ],
"test_object": {
"a": "b",
"c": "d"
}
}

Просмотреть файл

@ -15,7 +15,6 @@
//******************************************************************************
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -701,49 +700,5 @@ namespace FBWinStoreCsTests
Assert.IsFalse(likes.HasPrevious);
// test with next but no previous
}
[TestMethod]
public async Task testJsonPropertySet()
{
StorageFolder installedLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder jsonFolder = await installedLocation.GetFolderAsync("TestData");
StorageFile jsonTestFile = await jsonFolder.GetFileAsync("testJsonPropertySet.json");
string text = await FileIO.ReadTextAsync(jsonTestFile);
FBUser testUser = (FBUser)FBUser.FromJson(text);
// member variable
Assert.AreEqual(testUser.Name, "test_user");
Assert.IsFalse(testUser.Fields.ContainsKey("name"));
// boolean field
Assert.IsTrue(testUser.Fields.ContainsKey("test_boolean"));
Assert.AreEqual(testUser.Fields["test_boolean"], "false");
// num field
Assert.IsTrue(testUser.Fields.ContainsKey("test_num"));
Assert.AreEqual(testUser.Fields["test_num"], "4");
// string field
Assert.IsTrue(testUser.Fields.ContainsKey("test_string"));
Assert.AreEqual(testUser.Fields["test_string"], "hello_world");
// array field
Assert.IsTrue(testUser.Fields.ContainsKey("test_array"));
Assert.AreEqual(testUser.Fields["test_array"], "[2,3,5,7,11]");
// object field
Assert.IsTrue(testUser.Fields.ContainsKey("test_object"));
Assert.AreEqual(testUser.Fields["test_object"], @"{""a"":""b"",""c"":""d""}");
}
[TestMethod]
public async Task testJsonPropertySetNoBuiltInFields()
{
StorageFolder installedLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder jsonFolder = await installedLocation.GetFolderAsync("TestData");
StorageFile jsonTestFile = await jsonFolder.GetFileAsync("testJsonPropertySetNoBuiltInFields.json");
string text = await FileIO.ReadTextAsync(jsonTestFile);
FBUser testUser = (FBUser)FBUser.FromJson(text);
Assert.AreNotEqual(testUser, null);
}
}
}

Просмотреть файл

Просмотреть файл

@ -89,10 +89,6 @@ namespace winsdkfb
Platform::String^ JsonText
);
property Windows::Foundation::Collections::PropertySet^ Fields
{
Windows::Foundation::Collections::PropertySet^ get();
}
<#
foreach (XmlNode child in rootNode.SelectNodes("property"))
@ -133,7 +129,6 @@ namespace winsdkfb
<#
}
#>
Windows::Foundation::Collections::PropertySet^ _fields;
};
}
}

Просмотреть файл

@ -38,7 +38,7 @@ using namespace winsdkfb::Graph;
using namespace Platform;
using namespace Windows::Data::Json;
using namespace Windows::Foundation::Collections;
<#
<#
if (bindable)
{
#>
@ -86,13 +86,9 @@ using namespace Windows::UI::Xaml::Data;
}
#>
{
_fields = ref new PropertySet();
;
}
PropertySet^ <#= className #>::Fields::get()
{
return _fields;
}
<#
for (int i = 0; i < props.Count; i++)
{
@ -122,7 +118,7 @@ void <#= className #>::<#= propName #>::set(<#= rtType #> value)
}
#>
Object^ <#= className #>::FromJson(
String^ JsonText
String^ JsonText
)
{
<#= className #>^ result = ref new <#= className #>;
@ -182,38 +178,11 @@ Object^ <#= className #>::FromJson(
<#
}
#>
else
{
String^ value = nullptr;
switch (it->Current->Value->ValueType)
{
case JsonValueType::Boolean:
value = it->Current->Value->GetBoolean().ToString();
break;
case JsonValueType::Number:
value = it->Current->Value->GetNumber().ToString();
break;
case JsonValueType::String:
value = it->Current->Value->GetString();
break;
case JsonValueType::Array:
case JsonValueType::Object:
value = it->Current->Value->Stringify();
break;
}
if (value)
{
result->_fields->Insert(key, value);
found++;
}
}
}
if (!found)
{
// No field names matched any known properties for this class.
// No field names matched any known properties for this class.
// Even if it *is* an object of our type, it's not useful.
result = nullptr;
}
@ -221,7 +190,7 @@ Object^ <#= className #>::FromJson(
}
return result;
}
<#
<#
if (bindable)
{
#>
@ -231,7 +200,7 @@ void <#= className #>::NotifyPropertyChanged(
)
{
CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(
Windows::UI::Core::CoreDispatcherPriority::Normal,
Windows::UI::Core::CoreDispatcherPriority::Normal,
ref new Windows::UI::Core::DispatchedHandler([this, prop]()
{
PropertyChangedEventArgs^ args = ref new PropertyChangedEventArgs(prop);

Просмотреть файл

@ -98,10 +98,6 @@
<None Include="..\..\FBWinStoreCsTests\FBCSObjectImplementation.ttinclude">
<Link>FBCSObjectImplementation.ttinclude</Link>
</None>
<Content Include="..\..\FBWinStoreCsTests\TestData\testJsonPropertySet.json">
<Link>TestData\testJsonPropertySet.json</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="..\..\FBWinStoreCsTests\Utility.ttinclude">
<Link>Utility.ttinclude</Link>
</None>