-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
3,093 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtReflection_Convert", "ExtReflection_Convert\ExtReflection_Convert.csproj", "{1ECBD465-0D12-4E77-BD6E-FDAE456D9143}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1ECBD465-0D12-4E77-BD6E-FDAE456D9143}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1ECBD465-0D12-4E77-BD6E-FDAE456D9143}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1ECBD465-0D12-4E77-BD6E-FDAE456D9143}.Debug|x86.ActiveCfg = Debug|x86 | ||
{1ECBD465-0D12-4E77-BD6E-FDAE456D9143}.Debug|x86.Build.0 = Debug|x86 | ||
{1ECBD465-0D12-4E77-BD6E-FDAE456D9143}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1ECBD465-0D12-4E77-BD6E-FDAE456D9143}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{1ECBD465-0D12-4E77-BD6E-FDAE456D9143}.Release|x86.ActiveCfg = Release|x86 | ||
{1ECBD465-0D12-4E77-BD6E-FDAE456D9143}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Reflection; | ||
|
||
namespace BackRoom | ||
{ | ||
public class Magnifier<T, V> | ||
// where T : class | ||
where V : class | ||
{ | ||
protected Magnifier() { } | ||
//public class TConvert : Magnifier<TConvert, object> | ||
private static V _Parent; | ||
public V Parent | ||
{ | ||
get { return _Parent; } | ||
protected internal set { _Parent = value; } | ||
} | ||
private static T _Lens; | ||
public static T GetLens(V obj)//установка линзы (статический Parent) и возврат себя | ||
{ | ||
if (_Lens == null) | ||
{ | ||
ConstructorInfo ee = typeof(T).GetConstructor( | ||
BindingFlags.Instance | BindingFlags.NonPublic| BindingFlags.Public, null, new Type[0], new ParameterModifier[0]); | ||
|
||
_Lens = (T)typeof(T).GetConstructor( | ||
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, new Type[0], new ParameterModifier[0]).Invoke(null); | ||
} | ||
|
||
if (!object.ReferenceEquals(_Lens.GetType().GetProperty("Parent").GetValue(_Lens, null), obj)) | ||
_Lens.GetType().GetProperty("Parent").SetValue(_Lens, obj, null); | ||
return _Lens; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Collections; | ||
namespace BackRoom | ||
{ | ||
public class TMapper<T> : Singleton<T> where T : class | ||
{ | ||
protected TMapper(){ } | ||
private static Dictionary<string, Dictionary<object, SortedList<string, object>>> MapperList = new Dictionary<string, Dictionary<object, SortedList<string, object>>>(); | ||
//private Dictionary<object, List<object>> Childs = new Dictionary<object, List<object>>(); | ||
#region Work_Mapper | ||
protected Dictionary<object, SortedList<string, object>> add_Mapper(string MapperName) | ||
{ | ||
Dictionary<object, SortedList<string, object>> AddDic = new Dictionary<object, SortedList<string, object>>(); | ||
MapperList.Add(MapperName, AddDic); | ||
return AddDic; | ||
} | ||
protected Dictionary<object, SortedList<string, object>> Get_Mapper(string MapperName) | ||
{ | ||
Dictionary<object, SortedList<string, object>> Mapper; | ||
if (!MapperList.TryGetValue(MapperName, out Mapper)) Mapper = add_Mapper(MapperName); | ||
return Mapper; | ||
} | ||
protected bool Check_Mapper(string MapperName) | ||
{ | ||
return MapperList.ContainsKey(MapperName); | ||
} | ||
protected bool Delete_Mapper(string MapperName, bool DeleteifNullOnly = false) | ||
{ | ||
bool Result = false; | ||
if (DeleteifNullOnly) | ||
{ | ||
Dictionary<object, SortedList<string, object>> Mapper; | ||
if (MapperList.TryGetValue(MapperName, out Mapper)) | ||
{ | ||
if (Mapper.Count == 0) Result = MapperList.Remove(MapperName); | ||
} | ||
} | ||
else | ||
{ | ||
Result = MapperList.Remove(MapperName); | ||
} | ||
return Result; | ||
} | ||
#endregion | ||
|
||
#region Work_LinkertoObjects | ||
private SortedList<string, object> add_LinkertoObjects(Dictionary<object, SortedList<string, object>> Mapper, object MainObject) | ||
{ | ||
SortedList<string, object> LinkertoObjects = new SortedList<string, object>(); | ||
Mapper.Add(MainObject, LinkertoObjects); | ||
return LinkertoObjects; | ||
} | ||
protected SortedList<string, object> add_LinkertoObjects(string MapperName, object MainObject) | ||
{ | ||
Dictionary<object, SortedList<string, object>> Mapper = Get_Mapper(MapperName); | ||
return add_LinkertoObjects(Mapper, MainObject); | ||
} | ||
SortedList<string, object> Get_LinkertoObjects(string MapperName, object MainObject) | ||
{ | ||
SortedList<string, object> LinkertoObjects=null; | ||
Dictionary<object, SortedList<string, object>> Mapper = Get_Mapper(MapperName); | ||
if (!((Mapper.Count > 0) && (Mapper.TryGetValue(MainObject, out LinkertoObjects)))) LinkertoObjects = add_LinkertoObjects(Mapper, MainObject); | ||
return LinkertoObjects; | ||
} | ||
protected bool Check_LinkertoObjects(string MapperName, object MainObject) | ||
{ | ||
bool Result = false; | ||
Dictionary<object, SortedList<string, object>> Mapper = null; | ||
if (MapperList.TryGetValue(MapperName, out Mapper)) | ||
{ | ||
if ((Mapper.Count > 0) && Mapper.ContainsKey(MainObject)) Result = true; | ||
} | ||
return Result; | ||
} | ||
protected bool Delete_LinkertoObjects(string MapperName, object MainObject, bool DeleteifNullOnly = false, bool DeleteParentifNull = false) | ||
{ | ||
bool Result = false; | ||
Dictionary<object, SortedList<string, object>> Mapper; | ||
if (MapperList.TryGetValue(MapperName, out Mapper)) | ||
{ | ||
|
||
if (DeleteifNullOnly) | ||
{ | ||
SortedList<string, object> LinkertoObjects = null; | ||
if ((Mapper.Count > 0) && Mapper.TryGetValue(MainObject, out LinkertoObjects)) | ||
{ | ||
if (LinkertoObjects.Count == 0) Result = Mapper.Remove(MainObject); | ||
} | ||
} | ||
else | ||
{ | ||
if (Mapper.Count > 0) Result = Mapper.Remove(MainObject); | ||
} | ||
if (DeleteParentifNull) | ||
{ | ||
if (Mapper.Count == 0) MapperList.Remove(MapperName); | ||
} | ||
} | ||
return Result; | ||
} | ||
#endregion | ||
#region Work_LinkedObject | ||
private void add_LinkedtObject(SortedList<string, object> LinkertoObjects,string NameLinkedObject, object LinkedObject) | ||
{ | ||
LinkertoObjects.Add(NameLinkedObject, LinkedObject); | ||
} | ||
protected bool add_LinkedObject(string MapperName, object MainObject, string NameLinkedObject, object LinkedObject, bool Replace = false) | ||
{ | ||
bool Result = true; | ||
SortedList<string, object> LinkertoObjects = Get_LinkertoObjects(MapperName, MainObject); | ||
if (!LinkertoObjects.ContainsKey(NameLinkedObject)) | ||
{ | ||
add_LinkedtObject(LinkertoObjects, NameLinkedObject, LinkedObject); | ||
} | ||
else if (Replace) | ||
{ | ||
LinkertoObjects.Remove(NameLinkedObject); | ||
add_LinkedtObject(LinkertoObjects, NameLinkedObject, LinkedObject); | ||
} | ||
else | ||
{ | ||
Result = false; | ||
} | ||
return Result; | ||
} | ||
protected object Get_LinkedObject(string MapperName, object MainObject, string NameLinkedObject, out bool Result) | ||
{ | ||
Result = false; object LinkedObject = null; | ||
Dictionary<object, SortedList<string, object>> Mapper = null; | ||
if (MapperList.TryGetValue(MapperName, out Mapper)) | ||
{ | ||
SortedList<string, object> LinkertoObjects = null; | ||
if (Mapper.TryGetValue(MainObject, out LinkertoObjects)) | ||
{ | ||
if (LinkertoObjects.TryGetValue(NameLinkedObject, out LinkedObject)) Result = true; | ||
} | ||
} | ||
return LinkedObject; | ||
} | ||
protected object Get_LinkedObject(string MapperName, object MainObject, string NameLinkedObject) | ||
{ | ||
bool Result; | ||
return Get_LinkedObject(MapperName, MainObject, NameLinkedObject, out Result); | ||
} | ||
protected bool Check_LinkedObject(string MapperName, object MainObject, string NameLinkedObject) | ||
{ | ||
bool Result = false; | ||
Dictionary<object, SortedList<string, object>> Mapper = null; | ||
if (MapperList.TryGetValue(MapperName, out Mapper)) | ||
{ | ||
SortedList<string, object> LinkertoObjects = null; | ||
if ((Mapper.Count > 0) && Mapper.TryGetValue(MainObject, out LinkertoObjects)) | ||
{ | ||
if (LinkertoObjects.ContainsKey(NameLinkedObject)) Result = true; | ||
} | ||
} | ||
return Result; | ||
} | ||
protected bool Delete_LinkedObject(string MapperName, object MainObject, string NameLinkedObject, bool DeleteParentifNull = false) | ||
{ | ||
bool Result = false; | ||
Dictionary<object, SortedList<string, object>> Mapper; | ||
if (MapperList.TryGetValue(MapperName, out Mapper)) | ||
{ | ||
SortedList<string, object> LinkertoObjects = null; | ||
if ((Mapper.Count > 0) && Mapper.TryGetValue(MainObject, out LinkertoObjects)) | ||
{ | ||
if (LinkertoObjects.Count > 0) Result = LinkertoObjects.Remove(NameLinkedObject); | ||
if (DeleteParentifNull) | ||
{ | ||
if (LinkertoObjects.Count == 0) Mapper.Remove(MainObject); | ||
if (Mapper.Count == 0) MapperList.Remove(MapperName); | ||
} | ||
} | ||
} | ||
return Result; | ||
} | ||
#endregion | ||
|
||
public int GarbageCollector() | ||
{ | ||
// MapperList.SelectMany(a => a.Value).Where(b => b.Value.Count==0).Select(b =>b.Key).ToList(). | ||
int Result = 0; | ||
foreach (var MapperPair in MapperList) | ||
{ | ||
var NullableMainObject = MapperPair.Value.Where(LinkertoObjectsPair => LinkertoObjectsPair.Value.Count == 0).Select(LinkertoObjectsPair => LinkertoObjectsPair.Key); | ||
Result = Result + NullableMainObject.Count(); | ||
NullableMainObject.ToList().ForEach(MainObject => MapperPair.Value.Remove(MainObject)); | ||
} | ||
var NullableMapperName = MapperList.Where(MapperPair => MapperPair.Value.Count == 0).Select(MapperPair => MapperPair.Key); | ||
Result = Result + NullableMapperName.Count(); | ||
NullableMapperName.ToList().ForEach(MapperName => MapperList.Remove(MapperName)); | ||
return Result; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Reflection; | ||
using System.Diagnostics; | ||
using System.ComponentModel; | ||
|
||
namespace BackRoom | ||
{ | ||
class ParentChildren : TMapper<ParentChildren> | ||
{ | ||
private const string kParentPullName = "Parent"; | ||
private const string kParentName = kParentPullName; | ||
private const string kChildPullName = "Children"; | ||
protected static ExtParentChildren Extensio = new ExtParentChildren(); | ||
|
||
// protected partial class ExtParentChildren : ParentChildren | ||
// { internal ExtParentChildren() { } } | ||
|
||
private ParentChildren() | ||
{ | ||
this.add_Mapper(kParentPullName); | ||
this.add_Mapper(kChildPullName); | ||
} | ||
|
||
public void Add_Children(object Parent, string ChildName, object Child) | ||
{ | ||
this.add_LinkedObject(kParentPullName, Parent, ChildName, Child, true); | ||
this.add_LinkedObject(kChildPullName, Child, kParentName, Parent, true); | ||
} | ||
public object Get_Parent(object Child) | ||
{ | ||
return this.Get_LinkedObject(kChildPullName, Child, kParentName); | ||
} | ||
public object Get_Child(object Parent, string ChildName) | ||
{ | ||
return this.Get_LinkedObject(kParentPullName, Parent, ChildName); | ||
} | ||
public bool Delete_Link(object Parent, string ChildName) | ||
{ | ||
object Child = Get_Child(Parent, ChildName); | ||
return this.Delete_LinkedObject(kParentPullName, Parent, ChildName, true) && | ||
this.Delete_LinkertoObjects(kChildPullName, Child, false, true); | ||
} | ||
} | ||
public partial class ExtParentChildren | ||
{ | ||
// protected void InitGenericFunctionMap() | ||
// { } | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Reflection; | ||
|
||
namespace BackRoom | ||
{ | ||
public class Singleton<T> where T : class | ||
{ | ||
//protected Singleton() { } | ||
private sealed class SingletonCreator<S> where S : class | ||
{ | ||
private static readonly S instance= (S)typeof(S).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, | ||
null,new Type[0],new ParameterModifier[0]).Invoke(null); | ||
public static S CreatorInstance | ||
{ | ||
get { return instance; } | ||
} | ||
} | ||
|
||
public static T Instance | ||
{ | ||
get {return SingletonCreator<T>.CreatorInstance; } | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.