本文整理匯總了C#中System.Web.Mvc.ValueProviderResult類的典型用法代碼示例。如果您正苦於以下問題:C# ValueProviderResult類的具體用法?C# ValueProviderResult怎麽用?C# ValueProviderResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ValueProviderResult類屬於System.Web.Mvc命名空間,在下文中一共展示了ValueProviderResult類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetModelValue
internal static object GetModelValue(ValueProviderResult result, Type memberType)
{
var memberMapping = ModelMappingManager.MappingFor(memberType);
var descriptor = new ModelDescriptor(memberMapping);
var value = result.ConvertTo(descriptor.KeyProperty.PropertyType);
return memberMapping.Configuration.Repository().Find(value);
}
示例2: GetValue
public ValueProviderResult GetValue(string key)
{
ValueProviderResult result;
result = new ValueProviderResult(data,
"Id", CultureInfo.CurrentCulture);
return result;
}
示例3: ParseDate
public static DateTime ParseDate(ValueProviderResult value)
{
// Create an array of all supported standard date and time format specifiers.
string[] formats = {"d", "D", "f", "F", "g", "G", "m", "o", "r",
"s", "t", "T", "u", "U", "Y", "dd/MM/yyyy hh:mm:ss", "MM/dd/yyyy hh:mm:ss"};
//
CultureInfo[] cultures = {CultureInfo.CreateSpecificCulture("de-DE"),
CultureInfo.CreateSpecificCulture("en-US"),
CultureInfo.CreateSpecificCulture("he-IL"),
CultureInfo.CreateSpecificCulture("es-ES"),
CultureInfo.CreateSpecificCulture("fr-FR")};
var parsedSuccesfuly = false;
int cultureIndex = 0;
DateTime foundDateTime = DateTime.MinValue;
while (!parsedSuccesfuly && cultureIndex < cultures.Length)
{
parsedSuccesfuly = DateTime.TryParseExact(value.AttemptedValue, formats, cultures[cultureIndex], DateTimeStyles.None, out foundDateTime);
cultureIndex++;
}
if (parsedSuccesfuly)
{
return foundDateTime;
}
throw new FormatException("Could not parse the specified date, culture is not supported");
}
示例4: GetValue
protected virtual ValueProviderResult GetValue(string key)
{
ValueProviderResult res = null;
string val = this._context.HttpContext.Request.Form[key.Replace('.', '[')+']'] as string;
if (val != null)
res = new ValueProviderResult(val, val, CultureInfo.CurrentCulture);
return res;
}
示例5: NHValueProviderResult
/// <summary>
/// </summary>
/// <param name="result"></param>
/// <param name="sessionWrapper"></param>
/// <exception cref="ArgumentNullException"></exception>
public NHValueProviderResult(ValueProviderResult result, SessionWrapper sessionWrapper)
{
_result = result;
_sessionWrapper = sessionWrapper;
AttemptedValue = result.AttemptedValue;
Culture = result.Culture;
RawValue = result.RawValue;
}
示例6: SetModelState
private void SetModelState(ModelBindingContext bindingContext, ValueProviderResult valueProviderResult)
{
ModelState modelState;
if (!bindingContext.ModelState.TryGetValue(bindingContext.ModelName, out modelState))
{
bindingContext.ModelState.Add(bindingContext.ModelName, modelState = new ModelState());
}
modelState.Value = valueProviderResult;
}
示例7: ConvertToCanConvertArraysToSingleElements
public void ConvertToCanConvertArraysToSingleElements() {
// Arrange
ValueProviderResult vpr = new ValueProviderResult(new int[] { 1, 20, 42 }, "", CultureInfo.InvariantCulture);
// Act
string converted = (string)vpr.ConvertTo(typeof(string));
// Assert
Assert.AreEqual("1", converted);
}
示例8: ConvertToCanConvertSingleElementsToSingleElements
public void ConvertToCanConvertSingleElementsToSingleElements() {
// Arrange
ValueProviderResult vpr = new ValueProviderResult(42, "", CultureInfo.InvariantCulture);
// Act
string converted = (string)vpr.ConvertTo(typeof(string));
// Assert
Assert.IsNotNull(converted);
Assert.AreEqual("42", converted);
}
示例9: ConvertToChecksTypeConverterCanConvertFrom
public void ConvertToChecksTypeConverterCanConvertFrom() {
// Arrange
object original = "someValue";
ValueProviderResult vpr = new ValueProviderResult(original, null, CultureInfo.GetCultureInfo("fr-FR"));
// Act
DefaultModelBinderTest.StringContainer returned = (DefaultModelBinderTest.StringContainer)vpr.ConvertTo(typeof(DefaultModelBinderTest.StringContainer));
// Assert
Assert.AreEqual(returned.Value, "someValue (fr-FR)");
}
示例10: GetValue
public ValueProviderResult GetValue(string key)
{
ValueProviderResult result=null;
if (this.dictionary.ContainsKey(key))
{
result = new ValueProviderResult(this.dictionary[key],
this.dictionary[key], CultureInfo.CurrentCulture);
}
return result;
}
示例11: BindMinistryModels
/// <summary>
/// Creates the list of ministries selected by the system users
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
private static List<MinistryModel> BindMinistryModels(ValueProviderResult result)
{
var rawValue = result.RawValue as string[];
if (rawValue == null || rawValue.Length == 0)
{
return null;
}
List<MinistryModel> models = ManageMinistryModelHelper.GetMinistryModels(rawValue);
return models;
}
示例12: GetNonModelValue
internal static object GetNonModelValue(ValueProviderResult result, Type memberType)
{
var innerType = Nullable.GetUnderlyingType(memberType) ?? memberType;
if (innerType.IsEnum)
return Enum.Parse(innerType, result.AttemptedValue);
var value = innerType == typeof(Boolean)
? result.AttemptedValue.Split(',')[0]
: result.AttemptedValue;
return TypeDescriptor.GetConverter(innerType).ConvertFrom(null, CultureInfo.CurrentCulture, value);
}
示例13: GetValue_should_not_throw_exception_when_try_to_convert_value_from_ModelState
public void GetValue_should_not_throw_exception_when_try_to_convert_value_from_ModelState()
{
result = new ValueProviderResult("11/22/2000", "11/22/2000", new CultureInfo("en-US"));
state = new ModelState();
state.Value = result;
viewContext.ViewData.ModelState.Remove("DatePicker1");
viewContext.ViewData.ModelState.Add("DatePicker1", state);
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
Assert.DoesNotThrow(() => datepicker.GetValue(o => (DateTime?)o));
}
示例14: InputComponentExtensionsTests
public InputComponentExtensionsTests()
{
viewContext = TestHelper.CreateViewContext();
datepicker = DatePickerTestHelper.CreateDatePicker(null, viewContext);
datepicker.Name = "DatePicker1";
result = new ValueProviderResult("s", "s", System.Threading.Thread.CurrentThread.CurrentCulture);
state = new ModelState();
state.Value = result;
viewContext.ViewData.ModelState.Add("DatePicker1", state);
currentCulture = CultureInfo.CurrentCulture;
}
示例15: TryGetValue
public static bool TryGetValue(this IValueProvider valueProvider, string key, out ValueProviderResult result)
{
try
{
result = valueProvider.GetValue(key);
return true;
}
catch
{
result = null;
return false;
}
}