private static void defaultModuleResolver(Module sender, ResolveModuleEventArgs e) { Module result; _modulesCache.TryGetValue(e.ModulePath, out result); e.Module = result; }
public static string ConditionCodeToIcon(int code) { string WeatherIcon = "\xF00D"; WeatherIconMap.TryGetValue(code.ToString(), out WeatherIcon); return(WeatherIcon); }
/// <summary> /// Constructor: A metadata wrapper for different types of /// unique/redundant primary or composite keyed CSV document classes. /// </summary> /// <param name="data">Data from which to derive a key, if any.</param> /// <param name="sampleColumnTypes">A dictionary of column types in the derived type of Record</param> /// <param name="keyIsUniqueIdentifier">Is the primary or composite key a unique identifier? /// <br>(Sometimes they're not.)</br></param> public BasicRecord( StringMap data , TableHeaders sampleColumnTypes , bool keyIsUniqueIdentifier = true) : base() { try { foreach (KeyValuePair <string, string> record in data) { Add(record.Key, record.Value); } recordKey = new KeyStrings(); // TO DO: Decouple from clientETLProcess (should be providable from FileDataRecords). foreach (KeyValuePair <string, (Type colType, bool isKey)> headerData in sampleColumnTypes.Where((x) => x.Value.isKey == true)) { bool success = data.TryGetValue(headerData.Key, out string dataValue); if (success) { recordKey.Add((dataValue ??= data[headerData.Key], headerData.Key)); } else { Log.WriteException("Bad key assignent or unknown failure in TryGetValue."); } } }catch (WarningException err) { Log.Write("ETLProcess threw Warning: " + err.ToString() + "at BasicRecord constructor."); } this.keyIsUniqueIdentifier = keyIsUniqueIdentifier; //this.headers = keyHeaders; }
bool IModuleResolver.TryGetModule(ModuleRequest moduleRequest, out Module result) { var cacheKey = GetCacheKey(moduleRequest); if (_modulesCache.TryGetValue(cacheKey, out result)) { return(true); } if (TryGetModule(moduleRequest, out result)) { _modulesCache.Add(cacheKey, result); return(true); } return(false); }
private void DrawItems() { EditorGUILayout.LabelField("Items", EditorStyles.boldLabel); GUILayout.BeginVertical("box"); { foreach (var pair in registeredItems) { GUILayout.BeginHorizontal("box"); { GUILayout.Label(pair.Key.ToString()); string name; nameMap.TryGetValue(pair.Key, out name); GUILayout.Label(name); } GUILayout.EndHorizontal(); } } GUILayout.EndVertical(); }
// Suppress the deprecation warning for _SetId, since the DB is intended to use it #pragma warning disable 612, 618 public void UpdateDatabase() { if (!defaultItem) { Debug.LogError("Cannot update the database. A default item MUST be assigned."); return; } // Add the default item registeredItems.Remove(0); defaultItem._SetId(this, 0); registeredItems.Add(0, defaultItem); // Add new items var existingValues = registeredItems.Values; foreach (ItemBase newItem in addItems) { // No double registering if (existingValues.Contains(newItem)) { continue; } newItem._SetId(this, idCounter); registeredItems.Add(idCounter, newItem); idCounter++; } addItems.Clear(); //Remap missing items that have been filled out // // Remove missing items/ids List <uint> missingValues = new List <uint>(10); foreach (var pair in registeredItems) { if (!pair.Value) { missingValues.Add(pair.Key); } } foreach (uint key in missingValues) { registeredItems.Remove(key); } // Add the missing items' ids for remapping foreach (uint id in missingValues) { string name = "Unknown"; nameMap.TryGetValue(id, out name); missingIds.Add(id); missingNameMap.Add(id, name); } // Regenerate name map nameMap.Clear(); foreach (var pair in registeredItems) { nameMap.Add(pair.Key, pair.Value.GetName()); } }
internal protected override JSValue GetProperty(JSValue key, bool forWrite, PropertyScope memberScope) { if (_members == null) { fillMembers(); } if (memberScope == PropertyScope.Super || key._valueType == JSValueType.Symbol) { return(base.GetProperty(key, forWrite, memberScope)); } forWrite &= (_attributes & JSValueAttributesInternal.Immutable) == 0; string name = key.ToString(); JSValue r = null; if (_fields.TryGetValue(name, out r)) { if (!r.Exists && !forWrite) { var t = base.GetProperty(key, false, memberScope); if (t.Exists) { r.Assign(t); r._valueType = t._valueType; } } if (forWrite && r.NeedClone) { _fields[name] = r = r.CloneImpl(false); } return(r); } IList <MemberInfo> m = null; _members.TryGetValue(name, out m); if (m == null || m.Count == 0) { JSValue property; var protoInstanceAsJs = PrototypeInstance as JSValue; if (protoInstanceAsJs != null) { property = protoInstanceAsJs.GetProperty(key, forWrite && !_indexersSupported, memberScope); } else { property = base.GetProperty(key, forWrite && !_indexersSupported, memberScope); } if (!_indexersSupported) { return(property); } if (property.Exists) { if (forWrite) { if ((property._attributes & (JSValueAttributesInternal.SystemObject & JSValueAttributesInternal.ReadOnly)) == JSValueAttributesInternal.SystemObject) { if (protoInstanceAsJs != null) { property = protoInstanceAsJs.GetProperty(key, true, memberScope); } else { property = base.GetProperty(key, true, memberScope); } } } return(property); } if (forWrite) { return(new JSValue { _valueType = JSValueType.Property, _oValue = new PropertyPair(null, _indexerProperty.setter.bind(new Arguments { null, key })) }); } else { return(new JSValue { _valueType = JSValueType.Property, _oValue = new PropertyPair(_indexerProperty.getter.bind(new Arguments { null, key }), null) }); } } var result = proxyMember(forWrite, m); _fields[name] = result; return(result); }
private void fillMembers() { lock (this) { if (_members != null) { return; } var tempMembers = new StringMap <IList <MemberInfo> >(); string prewName = null; IList <MemberInfo> temp = null; bool instanceAttribute = false; #if (PORTABLE || NETCORE) var members = _hostedType.GetTypeInfo().DeclaredMembers .Union(_hostedType.GetRuntimeMethods()) .Union(_hostedType.GetRuntimeProperties()) .Union(_hostedType.GetRuntimeFields()) .Union(_hostedType.GetRuntimeEvents()).ToArray(); #else var members = _hostedType.GetMembers(); #endif for (int i = 0; i < members.Length; i++) { var member = members[i]; if (member.IsDefined(typeof(HiddenAttribute), false)) { continue; } instanceAttribute = member.IsDefined(typeof(InstanceMemberAttribute), false); if (!IsInstancePrototype && instanceAttribute) { continue; } var property = member as PropertyInfo; if (property != null) { if ((property.GetSetMethod(true) ?? property.GetGetMethod(true)).IsStatic != !(IsInstancePrototype ^ instanceAttribute)) { continue; } if ((property.GetSetMethod(true) == null || !property.GetSetMethod(true).IsPublic) && (property.GetGetMethod(true) == null || !property.GetGetMethod(true).IsPublic)) { continue; } var parentProperty = property; while (parentProperty != null && parentProperty.DeclaringType != typeof(object) && ((property.GetGetMethod() ?? property.GetSetMethod()).Attributes & MethodAttributes.NewSlot) == 0) { property = parentProperty; #if (PORTABLE || NETCORE) parentProperty = property.DeclaringType.GetTypeInfo().BaseType?.GetRuntimeProperty(property.Name); #else parentProperty = property.DeclaringType.GetTypeInfo().BaseType?.GetProperty(property.Name, BindingFlags.Public | BindingFlags.Instance); #endif } member = property; } if (member is EventInfo && (!(member as EventInfo).GetAddMethod(true).IsPublic || (member as EventInfo).GetAddMethod(true).IsStatic != !IsInstancePrototype)) { continue; } if (member is FieldInfo && (!(member as FieldInfo).IsPublic || (member as FieldInfo).IsStatic != !IsInstancePrototype)) { continue; } #if (PORTABLE || NETCORE) if ((members[i] is TypeInfo) && !(members[i] as TypeInfo).IsPublic) { continue; } #else if (member is Type && !(member as Type).IsPublic && !(member as Type).IsNestedPublic) { continue; } #endif var method = member as MethodBase; if (method != null) { if (method.IsStatic != !(IsInstancePrototype ^ instanceAttribute)) { continue; } if (!method.IsPublic) { continue; } if (method.DeclaringType == typeof(object) && member.Name == "GetType") { continue; } if (method is ConstructorInfo) { continue; } var parameterTypes = method.GetParameters().Select(x => x.ParameterType).ToArray(); if (parameterTypes.Any(x => x.IsByRef)) { continue; } if (method.IsVirtual && (method.Attributes & MethodAttributes.NewSlot) == 0) { var parentMethod = method; while (parentMethod != null && parentMethod.DeclaringType != typeof(object) && (method.Attributes & MethodAttributes.NewSlot) == 0) { method = parentMethod; #if (PORTABLE || NETCORE) parentMethod = method.DeclaringType.GetTypeInfo().BaseType?.GetMethod(method.Name, parameterTypes); #else parentMethod = method.DeclaringType.BaseType?.GetMethod(method.Name, BindingFlags.Public | BindingFlags.Instance, null, parameterTypes, null); #endif } } member = method; } var membername = member.Name; if (member.IsDefined(typeof(JavaScriptNameAttribute), false)) { var nameOverrideAttribute = member.GetCustomAttributes(typeof(JavaScriptNameAttribute), false).ToArray(); membername = (nameOverrideAttribute[0] as JavaScriptNameAttribute).Name; } else { membername = membername[0] == '.' ? membername : membername.Contains(".") ? membername.Substring(membername.LastIndexOf('.') + 1) : membername; #if (PORTABLE || NETCORE) if (members[i] is TypeInfo && membername.Contains("`")) #else if (member is Type && membername.Contains('`')) #endif { membername = membername.Substring(0, membername.IndexOf('`')); } } if (prewName != membername) { if (temp != null && temp.Count > 1) { var type = temp[0].DeclaringType; for (var j = 1; j < temp.Count; j++) { if (type != temp[j].DeclaringType && type.IsAssignableFrom(temp[j].DeclaringType)) { type = temp[j].DeclaringType; } } int offset = 0; for (var j = 1; j < temp.Count; j++) { if (!type.IsAssignableFrom(temp[j].DeclaringType)) { temp.RemoveAt(j--); tempMembers.Remove(prewName + "$" + (++offset + j)); } } if (temp.Count == 1) { tempMembers.Remove(prewName + "$0"); } } if (!tempMembers.TryGetValue(membername, out temp)) { tempMembers[membername] = temp = new List <MemberInfo>(); } prewName = membername; } if (membername.StartsWith("@@")) { if (_symbols == null) { _symbols = new Dictionary <Symbol, JSValue>(); } _symbols.Add(Symbol.@for(membername.Substring(2)), proxyMember(false, new[] { member })); } else { if (temp.Count == 1) { tempMembers.Add(membername + "$0", new[] { temp[0] }); } temp.Add(member); if (temp.Count != 1) { tempMembers.Add(membername + "$" + (temp.Count - 1), new[] { member }); } } } _members = tempMembers; if (IsInstancePrototype) { if (typeof(IIterable).IsAssignableFrom(_hostedType)) { IList <MemberInfo> iterator = null; if (_members.TryGetValue("iterator", out iterator)) { if (_symbols == null) { _symbols = new Dictionary <Symbol, JSValue>(); } _symbols.Add(Symbol.iterator, proxyMember(false, iterator)); _members.Remove("iterator"); } } #if NET40 var toStringTag = _hostedType.GetCustomAttribute <ToStringTagAttribute>(); #else var toStringTag = _hostedType.GetTypeInfo().GetCustomAttribute <ToStringTagAttribute>(); #endif if (toStringTag != null) { if (_symbols == null) { _symbols = new Dictionary <Symbol, JSValue>(); } _symbols.Add(Symbol.toStringTag, toStringTag.Tag); } } if (_indexersSupported) { IList <MemberInfo> getter = null; IList <MemberInfo> setter = null; _members.TryGetValue("get_Item", out getter); _members.TryGetValue("set_Item", out setter); if (getter != null || setter != null) { _indexerProperty = new PropertyPair(); if (getter != null) { _indexerProperty.getter = (Function)proxyMember(false, getter); _fields["get_Item"] = _indexerProperty.getter; } if (setter != null) { _indexerProperty.setter = (Function)proxyMember(false, setter); _fields["set_Item"] = _indexerProperty.setter; } } else { _indexersSupported = false; } } } }