本文整理汇总了C#中PropertyBag.Get方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyBag.Get方法的具体用法?C# PropertyBag.Get怎么用?C# PropertyBag.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyBag
的用法示例。
在下文中一共展示了PropertyBag.Get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoLoadState
/// <summary>
/// Loads the <see cref="FormState"/> of a particular <paramref name="form"/> from the <paramref name="context"/>.
/// </summary>
/// <param name="context">The <see cref="IMansionWebContext"/>.</param>
/// <param name="form">The <see cref="Form"/> for which to load the state.</param>
/// <returns>Returns the loaded <see cref="FormState"/>.</returns>
protected override FormState DoLoadState(IMansionWebContext context, Form form)
{
// get the GET and POST propertybags
var getProperties = context.Stack.Peek<IPropertyBag>("Get");
var postProperties = context.Stack.Peek<IPropertyBag>("Post");
var fieldProperties = new PropertyBag();
var formProperties = new PropertyBag();
var action = string.Empty;
// if the form has more than one step, try to load the state
var stateLossDetected = false;
if (form.Steps.Count > 1)
{
// try to load the state
string stateString;
var stateKey = form.Prefix + "state";
if (!postProperties.TryGet(context, stateKey, out stateString) || string.IsNullOrEmpty(stateString))
stateString = getProperties.Get<string>(context, stateKey, null);
// dehydrate the field properties, if there is state
if (!string.IsNullOrEmpty(stateString))
{
// dehydrate the field properties
var dehydratedFieldProperties = context.Nucleus.ResolveSingle<IConversionService>().Convert<IPropertyBag>(context, stateString);
// merge them with the current properties
fieldProperties.Merge(dehydratedFieldProperties);
}
else
stateLossDetected = true;
}
// load the properties from the data source
foreach (var candidate in postProperties.Where(candidate => candidate.Key.StartsWith(form.Prefix, StringComparison.OrdinalIgnoreCase)))
{
// check for field property
if (candidate.Key.StartsWith(form.FieldPrefix, StringComparison.OrdinalIgnoreCase))
fieldProperties.Add(candidate.Key.Substring(form.FieldPrefix.Length), candidate.Value);
// check for action property
else if (candidate.Key.StartsWith(form.ActionPrefix, StringComparison.OrdinalIgnoreCase))
action = candidate.Value.ToString();
else
formProperties.Add(candidate.Key.Substring(form.Prefix.Length), candidate.Value);
}
// determine the current step
var currentStepId = formProperties.Get(context, "current-step", getProperties.Get(context, form.Prefix + "current-step", 0));
var currentStep = form.Steps.ElementAtOrDefault(currentStepId) ?? form.Steps.First();
// always go to the first step on multi step forms when the state has been lost
if (form.Steps.Count > 1 && stateLossDetected)
currentStep = form.Steps.First();
// determine the next set
var nextStep = form.Steps.ElementAtOrDefault(currentStepId + 1) ?? form.Steps.Last();
// create the state
return new FormState {
FieldProperties = fieldProperties,
FormInstanceProperties = formProperties,
DataSource = dataSource,
CurrentAction = action,
IsPostback = !string.IsNullOrEmpty(action) || formProperties.Count > 0,
CurrentStep = currentStep,
NextStep = nextStep
};
}