I am trying to write a single macro method in Kentico (v8.2.x or v9.0) that caches accordingly and provides POCO with several public members.
Debugging in Visual Studio, I see that the request is working fine, and the object instance is returned exactly the way I want. In addition, checking the cached items using the Kentico Debug application also shows that all POCO instance data is cached as expected.
However, when I call the macro, I am apparently able to read the string representation of the object.
This is a macro that extends the type of CurrentUserInfo , so I'm trying to call it like this:
{% CurrentUser.ClientStatus() %}
But attempts to extract any of the attached properties failed.
I am sure that I just could not do something (for example, correctly register these properties). But from the documentation I saw a lot of things that could be. For instance:
- Named source
- Named Callback Source
- Anonymous source
- Or register them as separate fields somehow
Here is the macro itself:
/// <summary> /// A class containing custom user-extension macros. /// </summary> [assembly: RegisterExtension(typeof(CustomUserMacros), typeof(CurrentUserInfo))] public class CustomUserMacros : MacroMethodContainer { /// <summary> /// Retrieves data regarding user client. /// </summary> /// <param name="context">The context.</param> /// <param name="parameters">The parameters.</param> /// <returns>Data regarding user client information.</returns> [MacroMethod(typeof(ClientInfo), "Retrieves client info.", 1)] [MacroMethodParam(0, "user", typeof(CurrentUserInfo), "The user.")] public static object ClientStatus( EvaluationContext context, params object[] parameters) { ClientInfo retVal = null; if (parameters != null && parameters.Length > 0 && parameters[0].GetType() == typeof(CurrentUserInfo)) { var siteName = SiteContext.CurrentSiteName; var userGuid = ((CurrentUserInfo)parameters[0]).UserGUID; var uInfo = UserInfoProvider.GetUserInfoByGUID(userGuid); retVal = CacheHelper.Cache( cs => new ClientInfo(uInfo, siteName), new CacheSettings( 60, typeof(CustomUserMacros), "ClientStatus", userGuid)); } return retVal; } }
And the ClientInfo class is pretty simple:
public class ClientInfo { public string Summary { get; private set; } public CustomTableItem ClientRecord { get; private set; } public IEnumerable<string> MediaPaths { get; private set; } public ClientInfo(UserInfo userInfo, string siteCodeName) {
What is the easiest way for me to access properties like the following?
{% CurrentUser.ClientStatus().ClientRecord["< Column Name >"] %}