private Dictionary <int, Type> DiscoverEnumTypes(Type[] types) { if (types == null) { return(null); } var lookup = new Dictionary <int, Type>(); foreach (var type in types) { var attribute = type.GetCustomAttributes(typeof(PartitionEnumAttribute), false) .OfType <PartitionEnumAttribute>() .FirstOrDefault(); if (attribute == null) { throw new InvalidOperationException(type + " is not attributed with PartitionEnumAttribute"); } var typeNameHash = DJB.Compute(attribute.TypeName); var typeIndex = this._Partition.TypeDefinitionEntries.FindIndex(td => td.NameHash == typeNameHash); if (typeIndex >= 0) { var typeDefinition = this._Partition.TypeDefinitionEntries[typeIndex]; if ((attribute.Options & PartitionEnumOptions.Validate) != 0) { ValidateEnumType(type, typeDefinition); } lookup.Add(typeIndex, type); } } return(lookup); }
public IEnumerable <dynamic> GetObjectsOfType(params string[] typeNames) { if (typeNames == null || typeNames.Length == 0) { yield break; } foreach (var typeName in typeNames) { var typeNameHash = DJB.Compute(typeName); var typeIndex = this._Partition.TypeDefinitionEntries.FindIndex(tde => tde.NameHash == typeNameHash); if (typeIndex < 0) { continue; } foreach (var derivedTypeIndex in this.GetClassHierarchy(typeIndex)) { int index = derivedTypeIndex; foreach (var obj in this._Instances.Where(i => i.Type.Index == index).Select(i => i.ToObject())) { yield return(obj); } } } }
public bool HasMember(string name) { var nameHash = DJB.Compute(name); var fieldIndex = Array.FindIndex(this._Type.Fields, fd => fd.NameHash == nameHash); return(fieldIndex >= 0); }
public IEnumerable <dynamic> GetObjectsOfSpecificType(string typeName) { if (string.IsNullOrEmpty(typeName) == true) { throw new ArgumentNullException("typeName"); } var typeNameHash = DJB.Compute(typeName); var typeIndex = this._Partition.TypeDefinitionEntries.FindIndex(tde => tde.NameHash == typeNameHash); if (typeIndex < 0) { throw new ArgumentException("could not find type '" + typeName + "' in partition", "typeName"); } return(this._Instances.Where(i => i.Type.Index == typeIndex).Select(i => i.ToObject())); }
public bool TryGetMember(GetMemberBinder binder, out object result) { if (this._FieldCache.ContainsKey(binder.Name) == true) { result = this._FieldCache[binder.Name]; return(true); } var nameHash = DJB.Compute(binder.Name); var fieldIndex = Array.FindIndex(this._Type.Fields, fd => fd.NameHash == nameHash); if (fieldIndex < 0) { result = null; return(false); } var field = this._Type.Fields[fieldIndex]; #if DEBUG_READING try #endif { result = this._Reader.ReadField(this._DataOffset, field); } #if DEBUG_READING catch (Exception e) { result = e; return(true); } #endif this._FieldCache.Add(binder.Name, result); return(true); }
public static uint GetNameHash(string name) { return(DJB.Compute(name)); }
public MemoryStream LoadResource(string name, string type) { return(LoadResource(name, (int)DJB.Compute(type))); }