region using System Collections Generic using System Linq endregion na

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
#region
using System.Collections.Generic;
using System.Linq;
#endregion
namespace ScriptSDK
{
public class CoreObject
{
internal Dictionary<CoreAttribut, object> _datatable;
public CoreMode Mode
{
get { return GetValue<CoreMode>(CoreAttribut.CoreMode); }
set { SetValue(CoreAttribut.CoreMode, value); }
}
protected void SetValue<T>(CoreAttribut attrib, T value)
{
if (_datatable.ContainsKey(attrib))
_datatable[attrib] = value;
}
protected T GetValue<T>(CoreAttribut attrib)
{
if (attrib.Equals(CoreAttribut.CoreMode))
return (T) _datatable[attrib];
if (!_datatable.ContainsKey(attrib))
return (T) GetRawValue(attrib);
if (Mode.Equals(CoreMode.Auto))
_datatable[attrib] = GetRawValue(attrib);
return (T) _datatable[attrib];
}
protected virtual object GetRawValue(CoreAttribut attrib)
{
switch (attrib)
{
case CoreAttribut.CoreMode:
return CoreMode.Auto;
}
return new object();
}
public void Update()
{
if (!Mode.Equals(CoreMode.Auto))
return;
var a = _datatable.Keys.ToList();
foreach (var o in a)
{
var k = o;
if (!k.Equals(CoreAttribut.CoreMode))
SetValue(k, GetRawValue(k));
}
}
protected void Register(CoreAttribut attrib)
{
if (!_datatable.ContainsKey(attrib))
_datatable.Add(attrib, new object());
}
protected void Register<T>(CoreAttribut attrib, T value)
{
Register(attrib);
SetValue(attrib, value);
}
public T Clone<T>() where T : CoreObject
{
const CoreAttribut att = CoreAttribut.CoreMode;
var val = GetValue<CoreMode>(att);
if (val.Equals(CoreMode.Auto))
Mode = CoreMode.Clone;
var obj = CreateInstance();
foreach (var o in _datatable.Keys)
{
var k = o;
obj._datatable[k] = _datatable[k];
}
if (val.Equals(CoreMode.Auto))
Mode = CoreMode.Auto;
return (T) obj;
}
protected virtual CoreObject CreateInstance()
{
return new CoreObject();
}
public override string ToString()
{
return "";
}
public CoreObject()
{
_datatable = new Dictionary<CoreAttribut, object>();
Register(CoreAttribut.CoreMode, CoreMode.Auto);
}
}
}