public void Initialize(ILibraryInitializer initializer) { Libraries = new Dictionary <int, ActionLibrary>(); Functions = new Dictionary <string, IFunction>(); BuiltInVariables = new List <string>(); InstanceVariables = new List <string>(); Constants = new Dictionary <string, Value>(); InstanceFactory = initializer.CreateInstanceFactory(this); PerformEvent = initializer.PerformEvent; Resources = Resources ?? new ResourceContext(this); if (initializer != null) { // Build the list of functions foreach (var mi in initializer.FunctionLibraries.SelectMany( t => t.GetMethods(BindingFlags.Public | BindingFlags.Static)) .Where(mi => mi.GetCustomAttributes(typeof(GmlFunctionAttribute), false) .Any()) ) { var fn = (GmlFunctionAttribute)mi.GetCustomAttributes(typeof(GmlFunctionAttribute), false).Single(); string name = string.IsNullOrEmpty(fn.Name) ? mi.Name : fn.Name; Functions.Add(name, initializer.TransformFunction(mi, name)); } // Add built-in variables (InstanceVariables as List <string>).AddRange(initializer.InstanceVariables); (BuiltInVariables as List <string>).AddRange(initializer.GlobalVariables); // Add constants foreach (var c in initializer.Constants) { Constants.Add(c.Key, c.Value); } } }
public void Initialize(ILibraryInitializer initializer) { Libraries = new Dictionary<int, ActionLibrary>(); Functions = new Dictionary<string, IFunction>(); BuiltInVariables = new List<string>(); InstanceVariables = new List<string>(); Constants = new Dictionary<string, Value>(); InstanceFactory = initializer.CreateInstanceFactory(this); PerformEvent = initializer.PerformEvent; Resources = Resources ?? new ResourceContext(this); if (initializer != null) { // Build the list of functions foreach (var mi in initializer.FunctionLibraries.SelectMany( t => t.GetMethods(BindingFlags.Public | BindingFlags.Static)) .Where(mi => mi.GetCustomAttributes(typeof(GmlFunctionAttribute), false) .Any()) ) { var fn = (GmlFunctionAttribute)mi.GetCustomAttributes(typeof(GmlFunctionAttribute), false).Single(); string name = string.IsNullOrEmpty(fn.Name) ? mi.Name : fn.Name; Functions.Add(name, initializer.TransformFunction(mi, name)); } // Add built-in variables (InstanceVariables as List<string>).AddRange(initializer.InstanceVariables); (BuiltInVariables as List<string>).AddRange(initializer.GlobalVariables); // Add constants foreach (var c in initializer.Constants) Constants.Add(c.Key, c.Value); } }
public LibraryContext(ILibraryInitializer initializer) { Initialize(initializer); }