Last active
June 6, 2018 20:42
-
-
Save johanlindfors/8af7c647600c4b31df3eb06fbb0d96af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace winsdkfb | |
{ | |
namespace Graph | |
{ | |
struct FBCursors : winrt::implements<FBCursors, winrt::Windows::Foundation::IInspectable > | |
{ | |
hstring After() { return _after; } | |
void After(hstring const& value) { _after = value; } | |
hstring Before() { return _before; } | |
void Before(hstring const& value) { _before = value; } | |
static winrt::Windows::Foundation::IInspectable FromJson(hstring const& JsonText) | |
{ | |
auto result = make_self<FBCursors>(); | |
int found = 0; | |
JsonValue val{ nullptr }; | |
if (JsonValue::TryParse(JsonText, val)) | |
{ | |
if (val.ValueType() == JsonValueType::Object) | |
{ | |
JsonObject obj = val.GetObject(); | |
IIterator<IKeyValuePair<hstring, IJsonValue>> it{ nullptr }; | |
for (it = obj.First(); it.HasCurrent(); it.MoveNext()) | |
{ | |
hstring key = it.Current().Key(); | |
if (key == L"after") | |
{ | |
found++; | |
result->After(it.Current().Value().GetString()); | |
} | |
else if (key == L"before") | |
{ | |
found++; | |
result->Before(it.Current().Value().GetString()); | |
} | |
} | |
} | |
} | |
return result.as<winrt::Windows::Foundation::IInspectable>(); | |
} | |
private: | |
hstring _after; | |
hstring _before; | |
}; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace winsdkfb | |
{ | |
namespace Graph | |
{ | |
public ref class FBCursors sealed | |
{ | |
public: | |
property Platform::String^ After | |
{ | |
Platform::String^ get() { return _after; } | |
void set(Platform::String^ value) { _after = value; } | |
} | |
property Platform::String^ Before | |
{ | |
Platform::String^ get() { return _before; } | |
void set(Platform::String^ value) { _before = value; } | |
} | |
static Object^ FBCursors::FromJson(String^ JsonText) | |
{ | |
FBCursors^ result = ref new FBCursors; | |
int found = 0; | |
JsonValue^ val = nullptr; | |
if (JsonValue::TryParse(JsonText, &val)) | |
{ | |
if (val->ValueType == JsonValueType::Object) | |
{ | |
JsonObject^ obj = val->GetObject(); | |
IIterator<IKeyValuePair<String^, IJsonValue^>^>^ it = nullptr; | |
for (it = obj->First(); it->HasCurrent; it->MoveNext()) | |
{ | |
String^ key = it->Current->Key; | |
if (!String::CompareOrdinal(key, L"after")) | |
{ | |
found++; | |
result->After = it->Current->Value->GetString(); | |
} | |
else if (!String::CompareOrdinal(key, L"before")) | |
{ | |
found++; | |
result->Before = it->Current->Value->GetString(); | |
} | |
} | |
if (!found) | |
{ | |
// 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; | |
} | |
} | |
} | |
return result; | |
} | |
private: | |
FBCursors::FBCursors( | |
) : | |
_after(nullptr), | |
_before(nullptr) | |
{ | |
; | |
} | |
Platform::String^ _after; | |
Platform::String^ _before; | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment