public static SetEntityKeyValue ( Object entity, String entityKeyName ) : System.Guid | ||
entity | Object | An object instance. |
entityKeyName | String | The property name. |
return | System.Guid |
public static Guid SetEntityKeyValue(Object entity, String entityKeyName)
{
PropertyInfo property = null;
Object objId = GetPropertyValue(entity, entityKeyName, out property);
Guid entityId = Guid.Empty;
if ( property != null && property.PropertyType.IsAssignableFrom(typeof(Guid)) )
{
if ( Guid.Empty.Equals(objId) && property.CanWrite )
{
entityId = Guid.NewGuid();
property.SetValue(entity, entityId, null);
}
}
return entityId;
}