This commit is contained in:
@@ -4574,6 +4574,9 @@ namespace DynamORM
|
||||
/// <returns>Converted object.</returns>
|
||||
public static dynamic ToDynamic(this object o)
|
||||
{
|
||||
if (o == null)
|
||||
return null;
|
||||
|
||||
Type ot = o.GetType();
|
||||
|
||||
if (ot == typeof(DynamicExpando) || ot == typeof(ExpandoObject))
|
||||
@@ -13592,7 +13595,11 @@ namespace DynamORM
|
||||
|
||||
private Func<object> CreateCreator()
|
||||
{
|
||||
if (Type.GetConstructor(Type.EmptyTypes) != null)
|
||||
var c = Type.GetConstructor(Type.EmptyTypes);
|
||||
if (c == null)
|
||||
c = Type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
|
||||
|
||||
if (c != null)
|
||||
return Expression.Lambda<Func<object>>(Expression.New(Type)).Compile();
|
||||
|
||||
return null;
|
||||
@@ -13830,8 +13837,15 @@ namespace DynamORM
|
||||
public virtual DynamicEntityState GetDynamicEntityState() { return _dynamicEntityState; }
|
||||
|
||||
/// <summary>Sets the state of the dynamic entity.</summary>
|
||||
/// <remarks>Using this method will reset modified fields list.</remarks>
|
||||
/// <param name="state">The state.</param>
|
||||
public virtual void SetDynamicEntityState(DynamicEntityState state) { _dynamicEntityState = state; }
|
||||
public virtual void SetDynamicEntityState(DynamicEntityState state)
|
||||
{
|
||||
_dynamicEntityState = state;
|
||||
|
||||
if (_changedFields != null)
|
||||
_changedFields.Clear();
|
||||
}
|
||||
|
||||
/// <summary>Called when object property is changing.</summary>
|
||||
/// <param name="propertyName">Name of the property.</param>
|
||||
@@ -13874,8 +13888,11 @@ namespace DynamORM
|
||||
return Insert(database);
|
||||
|
||||
case DynamicEntityState.Existing:
|
||||
if (IsModified())
|
||||
return Update(database);
|
||||
|
||||
return true;
|
||||
|
||||
case DynamicEntityState.ToBeDeleted:
|
||||
return Delete(database);
|
||||
|
||||
@@ -13884,6 +13901,16 @@ namespace DynamORM
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Determines whether this instance is in existing state and fields was modified since this state was set modified.</summary>
|
||||
/// <returns>Returns <c>true</c> if this instance is modified; otherwise, <c>false</c>.</returns>
|
||||
public virtual bool IsModified()
|
||||
{
|
||||
if (GetDynamicEntityState() != DynamicEntityState.Existing)
|
||||
return false;
|
||||
|
||||
return _changedFields != null && _changedFields.Any();
|
||||
}
|
||||
|
||||
#region Insert/Update/Delete
|
||||
|
||||
/// <summary>Inserts this object to database.</summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace AmalgamationTool
|
||||
{
|
||||
@@ -24,12 +25,30 @@ namespace AmalgamationTool
|
||||
|
||||
// Deal with usings
|
||||
foreach (var u in content.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)
|
||||
.Where(l => l.TrimEnd().StartsWith("using "))
|
||||
.Where(l => l.Trim().StartsWith("using "))
|
||||
.Select(l => l.Trim()))
|
||||
if (!usings.Contains(u))
|
||||
usings.Add(u);
|
||||
|
||||
// Extract namespace
|
||||
|
||||
//if (args.Length > 2)
|
||||
//{
|
||||
// var tcontent = Regex.Replace(content, @"^\s*using\s+.*\s*;$", string.Empty);
|
||||
// tcontent = Regex.Replace(content, @"^\s*namespace\s+.*\s*", string.Empty).Trim();
|
||||
|
||||
// var ns = Regex.Match(content, @"^\s*namespace\s+(?<ns>.*)\s*");
|
||||
|
||||
// if (ns.Success)
|
||||
// {
|
||||
// if (!classes.ContainsKey(ns.Groups["ns"].Value))
|
||||
// classes.Add(ns.Groups["ns"].Value, new List<string>());
|
||||
|
||||
// classes[ns.Groups["ns"].Value].Add(tcontent);
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
{
|
||||
var nstart = content.IndexOf("namespace ") + "namespace ".Length;
|
||||
var bbrace = content.IndexOf("{", nstart);
|
||||
var nlen = bbrace - nstart;
|
||||
@@ -46,6 +65,7 @@ namespace AmalgamationTool
|
||||
sb.AppendLine();
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -60,6 +80,7 @@ namespace AmalgamationTool
|
||||
// Cut content as class/enum
|
||||
classes[ns].Add(content.Substring(bbrace + 1, ebrace - bbrace - 1));
|
||||
}
|
||||
}
|
||||
|
||||
usings.Sort();
|
||||
|
||||
@@ -88,12 +109,14 @@ namespace AmalgamationTool
|
||||
|
||||
private static void FillClassesAndNamespacesIddented(Dictionary<string, List<string>> classes, StringBuilder sb)
|
||||
{
|
||||
foreach (var n in classes.Where(nc => nc.Key.Split('.').Count() == 1))
|
||||
var min = classes.Min(k => k.Key.Split('.').Count());
|
||||
|
||||
foreach (var n in classes.Where(nc => nc.Key.Split('.').Count() == min))
|
||||
{
|
||||
sb.AppendFormat("namespace {0}{1}{{", n.Key, Environment.NewLine);
|
||||
n.Value.ForEach(c => sb.Append(c));
|
||||
|
||||
SubNamespaces(classes, n.Key, sb, 1);
|
||||
SubNamespaces(classes, n.Key, sb, min);
|
||||
|
||||
sb.AppendLine("}");
|
||||
sb.AppendLine(string.Empty);
|
||||
|
||||
@@ -108,7 +108,11 @@ namespace DynamORM.Mapper
|
||||
|
||||
private Func<object> CreateCreator()
|
||||
{
|
||||
if (Type.GetConstructor(Type.EmptyTypes) != null)
|
||||
var c = Type.GetConstructor(Type.EmptyTypes);
|
||||
if (c == null)
|
||||
c = Type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
|
||||
|
||||
if (c != null)
|
||||
return Expression.Lambda<Func<object>>(Expression.New(Type)).Compile();
|
||||
|
||||
return null;
|
||||
|
||||
@@ -21,8 +21,15 @@ namespace DynamORM.Objects
|
||||
public virtual DynamicEntityState GetDynamicEntityState() { return _dynamicEntityState; }
|
||||
|
||||
/// <summary>Sets the state of the dynamic entity.</summary>
|
||||
/// <remarks>Using this method will reset modified fields list.</remarks>
|
||||
/// <param name="state">The state.</param>
|
||||
public virtual void SetDynamicEntityState(DynamicEntityState state) { _dynamicEntityState = state; }
|
||||
public virtual void SetDynamicEntityState(DynamicEntityState state)
|
||||
{
|
||||
_dynamicEntityState = state;
|
||||
|
||||
if (_changedFields != null)
|
||||
_changedFields.Clear();
|
||||
}
|
||||
|
||||
/// <summary>Called when object property is changing.</summary>
|
||||
/// <param name="propertyName">Name of the property.</param>
|
||||
@@ -65,8 +72,11 @@ namespace DynamORM.Objects
|
||||
return Insert(database);
|
||||
|
||||
case DynamicEntityState.Existing:
|
||||
if (IsModified())
|
||||
return Update(database);
|
||||
|
||||
return true;
|
||||
|
||||
case DynamicEntityState.ToBeDeleted:
|
||||
return Delete(database);
|
||||
|
||||
@@ -75,6 +85,16 @@ namespace DynamORM.Objects
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Determines whether this instance is in existing state and fields was modified since this state was set modified.</summary>
|
||||
/// <returns>Returns <c>true</c> if this instance is modified; otherwise, <c>false</c>.</returns>
|
||||
public virtual bool IsModified()
|
||||
{
|
||||
if (GetDynamicEntityState() != DynamicEntityState.Existing)
|
||||
return false;
|
||||
|
||||
return _changedFields != null && _changedFields.Any();
|
||||
}
|
||||
|
||||
#region Insert/Update/Delete
|
||||
|
||||
/// <summary>Inserts this object to database.</summary>
|
||||
|
||||
Reference in New Issue
Block a user