本文整理汇总了C#中DbPropertyValues类的典型用法代码示例。如果您正苦于以下问题:C# DbPropertyValues类的具体用法?C# DbPropertyValues怎么用?C# DbPropertyValues使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbPropertyValues类属于命名空间,在下文中一共展示了DbPropertyValues类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DetectUpdates
/// <summary>
/// Detects any updates on specified entity and tracks them via AlertManager.TrackablePropertyUpdated alert.
/// </summary>
/// <param name="entity">entity</param>
/// <param name="originalValues">original properties values</param>
/// <param name="currentValues">current properties values</param>
/// <param name="properties">properties to track</param>
/// <param name="updateCallback">action to call when update is detected. If it is null it defaults to AlertManager.TrackablePropertyChanged.</param>
/// <remarks>
/// This method would likely be called from <see cref="IModifyHook.OnModify">OnModify</see> implementation to track properties.
/// For tracking enum typed (state) properties see <see cref="DetectStateUpdates">DetectStateUpdates</see> method.
/// </remarks>
public static void DetectUpdates(this IBaseDO entity,
DbPropertyValues originalValues, DbPropertyValues currentValues, PropertyInfo[] properties,
Action<string, object, PropertyInfo> updateCallback = null)
{
if (properties == null || properties.Length == 0)
return;
if (updateCallback == null)
{
updateCallback =
(entityName, idValue, property) =>
AlertManager.TrackablePropertyUpdated(entityName, property.Name, idValue, currentValues[property.Name]);
}
var type = entity.GetType();
var idProperty = type.GetProperty("Id");
var id = idProperty != null ? idProperty.GetValue(entity) : null;
foreach (var property in properties)
{
if (!MiscUtils.AreEqual(originalValues[property.Name], currentValues[property.Name]))
{
string entityName;
if (type.Name.EndsWith("DO", StringComparison.Ordinal))
entityName = type.Name.Remove(type.Name.Length - 2);
else if (type.BaseType != null && type.BaseType.Name.EndsWith("DO", StringComparison.Ordinal))
entityName = type.BaseType.Name.Remove(type.BaseType.Name.Length - 2);
else
entityName = type.Name;
updateCallback(entityName, id, property);
}
}
}
示例2: Non_Generic_DbPropertyValues_uses_ToObject_on_InternalPropertyValues
public void Non_Generic_DbPropertyValues_uses_ToObject_on_InternalPropertyValues()
{
var properties = new Dictionary<string, object> { { "Id", 1 } };
var values = new DbPropertyValues(new TestInternalPropertyValues<FakeTypeWithProps>(properties));
var clone = (FakeTypeWithProps)values.ToObject();
Assert.Equal(1, clone.Id);
}
示例3: OnModify
public override void OnModify(DbPropertyValues originalValues, DbPropertyValues currentValues)
{
base.OnModify(originalValues, currentValues);
var reflectionHelper = new ReflectionHelper<IncidentDO>();
var priorityPropertyName = reflectionHelper.GetPropertyName(i => i.Priority);
if (!MiscUtils.AreEqual(originalValues[priorityPropertyName], currentValues[priorityPropertyName])
&& IsHighPriority)
{
AlertManager.HighPriorityIncidentCreated(Id);
}
}
示例4: PrintPropertyValues
/// <summary>
/// 记录帮助类
/// </summary>
private void PrintPropertyValues(DbPropertyValues values, IEnumerable<string> propertiesToPrint, int indent = 1)
{
foreach (var propertyName in propertiesToPrint)
{
var value = values[propertyName];
if (value is DbPropertyValues)
{
Console.WriteLine("{0}- Complex Property: {1}", string.Empty.PadLeft(indent), propertyName);
var complexPropertyValues = (DbPropertyValues)value;
PrintPropertyValues(complexPropertyValues, complexPropertyValues.PropertyNames, indent + 1);
}
else
{
Console.WriteLine("{0}- {1}: {2}", string.Empty.PadLeft(indent), propertyName, values[propertyName]);
}
}
}
示例5: WritePropertyValues
public static void WritePropertyValues(DbPropertyValues values, int indent = 1)
{
foreach (string propertyName in values.PropertyNames)
{
var value = values[propertyName];
if (value is DbPropertyValues)
{
Console.WriteLine("{0} - Complex Property: {1}",
string.Empty.PadLeft(indent),
propertyName);
WritePropertyValues((DbPropertyValues)value, indent + 1);
}
else
{
Console.WriteLine("{0} - {1}: {2}",
string.Empty.PadLeft(indent),
propertyName,values[propertyName]);
}
}
}
示例6: DetectStateUpdates
/// <summary>
/// Detects any updates on specified entity state properties.
/// </summary>
/// <param name="entity">entity</param>
/// <param name="originalValues">original properties values</param>
/// <param name="currentValues">current properties values</param>
public static void DetectStateUpdates(this IBaseDO entity,
DbPropertyValues originalValues, DbPropertyValues currentValues)
{
var stateProperties = entity.GetStateProperties().ToArray();
if (stateProperties.Length > 0)
{
entity.DetectUpdates(originalValues, currentValues, stateProperties,
(entityName, idValue, stateProperty) =>
{
var stateTemplateType =
ReflectionHelper.ForeignKeyNavitationProperty(entity, stateProperty).
PropertyType;
var stateType =
GetGenericInterface(stateTemplateType, typeof (IStateTemplate<>))
.GetGenericArguments()[0];
var stateName = stateType.Name;
var stateKey = currentValues[stateProperty.Name];
var stateValue = stateKey != null
? stateType.GetFields().Single(f => Equals(f.GetValue(entity), stateKey)).Name
: null;
AlertManager.EntityStateChanged(entityName, idValue, stateName, stateValue);
});
}
}
示例7: Calling_SetValues_with_dictionary_of_derived_type_works
public void Calling_SetValues_with_dictionary_of_derived_type_works()
{
var fromProperties = new Dictionary<string, object>
{
{ "Id", 1 }
};
var fromValues = new DbPropertyValues(new TestInternalPropertyValues<FakeDerivedTypeWithProps>(fromProperties));
var toProperties = new Dictionary<string, object>
{
{ "Id", 0 }
};
var toValues = new DbPropertyValues(new TestInternalPropertyValues<FakeTypeWithProps>(toProperties));
toValues.SetValues(fromValues);
Assert.Equal(1, toValues["Id"]);
}
示例8: Non_Generic_DbPropertyValues_SetValues_with_a_dictionary_works_on_the_underlying_dictionary
public void Non_Generic_DbPropertyValues_SetValues_with_a_dictionary_works_on_the_underlying_dictionary()
{
var fromValues = new DbPropertyValues(CreateSimpleValues());
fromValues["Id"] = 1;
var toValues = new DbPropertyValues(CreateSimpleValues());
toValues.SetValues(fromValues);
Assert.Equal(1, toValues["Id"]);
}
示例9: Attempt_to_copy_values_from_null_dictionary_on_non_generic_DbPropertyValues_throws
public void Attempt_to_copy_values_from_null_dictionary_on_non_generic_DbPropertyValues_throws()
{
var values = new DbPropertyValues(new TestInternalPropertyValues<FakeTypeWithProps>());
Assert.Equal("propertyValues", Assert.Throws<ArgumentNullException>(() => values.SetValues(null)).ParamName);
}
示例10: Calling_SetValues_with_instance_of_derived_type_works
public void Calling_SetValues_with_instance_of_derived_type_works()
{
var properties = new Dictionary<string, object>
{
{ "Id", 0 }
};
var values = new DbPropertyValues(new TestInternalPropertyValues<FakeTypeWithProps>(properties));
values.SetValues(
new FakeDerivedTypeWithProps
{
Id = 1
});
Assert.Equal(1, values["Id"]);
}
示例11: PrintPropertyValues
private static void PrintPropertyValues(DbPropertyValues values)
{
foreach (var propertyName in values.PropertyNames)
{
if (propertyName.ToString().Equals("userpwd"))
Console.WriteLine(" - {0}: {1}", propertyName, values[propertyName]);
}
}
示例12: GetLogContent
//获取要记录的日志内容
private string GetLogContent(DbPropertyValues values, IEnumerable<string> properties)
{
Dictionary<string, string> result = new Dictionary<string, string>();
foreach (var propertyName in properties)
{
var value = values[propertyName];
if (value is DbPropertyValues)
{
var complexPropertyValues = (DbPropertyValues)value;
result.Add(propertyName, GetLogContent(complexPropertyValues, complexPropertyValues.PropertyNames));
}
else
{
result.Add(propertyName, (value ?? "").ToString());
}
}
return result.ToJson();
}
示例13: ResolverConflitos
private static DbPropertyValues ResolverConflitos(DbPropertyValues dbPropertyValues1, DbPropertyValues dbPropertyValues2, DbPropertyValues dbValues)
{
throw new NotImplementedException();
}
示例14: ClientChooses
private void ClientChooses(DbPropertyValues current, DbPropertyValues other, DbPropertyValues resolved)
{
resolved["FirstName"] = other["FirstName"];
resolved["LastName"] = current["LastName"];
}
示例15: Complex_values_cannot_be_set_to_actual_complex_object_instance_in_a_property_dictionary
public void Complex_values_cannot_be_set_to_actual_complex_object_instance_in_a_property_dictionary()
{
var values = new DbPropertyValues(CreateSimpleValues());
Assert.Equal(
Strings.DbPropertyValues_AttemptToSetNonValuesOnComplexProperty,
Assert.Throws<ArgumentException>(() => values["NestedObject"] = new FakeTypeWithProps()).Message);
}