protected override void OnCreate() { base.OnCreate(); m_ForeignBanks = new Dictionary <int, PatternBank>(); m_Exchanges = new Dictionary <long, PatternBankExchange>(); LocalBank = new PatternBank(0); m_ForeignBanks[0] = LocalBank; }
internal static void ObjRegister(object holder, PatternBank bank) { var type = holder.GetType(); var fields = type.GetFields ( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance ); foreach (var field in fields) { if (field.FieldType != typeof(PatternIdent) && field.FieldType != typeof(PatternResult)) { continue; } var nv = field.GetCustomAttribute <PatternAttribute>(); var nameAttribute = field.GetCustomAttribute <PatternNameAttribute>(); var versionAttribute = field.GetCustomAttribute <PatternVersionAttribute>(); var pattern = new PatternIdent { Name = nv?.Name ?? nameAttribute?.Value }; if (string.IsNullOrEmpty(pattern.Name)) { pattern.Name = $"{type.Namespace}:{type.Name}.{field.Name}"; } if (nv != null) { pattern.Version = nv.Version; } else if (versionAttribute != null) { pattern.Version = versionAttribute.Value; } var result = bank.Register(pattern); if (field.FieldType == typeof(PatternIdent)) { field.SetValue(holder, pattern); } else { field.SetValue(holder, result); } } }