/// <summary> /// 获取单例对象 /// </summary> /// <param name="serviceProvider"></param> /// <param name="record"></param> /// <returns></returns> internal object GetSingleton(IServiceProvider serviceProvider, TypeRecord record) { if (record.BuildFlag) { var obj = record.GetInstacne(serviceProvider); if (singleton.Contains(record.ID) == false) { objects.Add(new ObjectContainer(obj, ServiceLifetime.Singleton)); } return(obj); } else { var key = GenerateTempKey(serviceProvider, record, record.ImplementationType); if (singleton.Contains(key)) { return(objects.First(p => p.ID == key).Instance); } else { var obj = record.GetInstacne(serviceProvider); this.singleton.Add(key); this.objects.Add(new ObjectContainer(obj, ServiceLifetime.Singleton, key)); return(obj); } } }
/// <summary> /// 获取多例对象 /// </summary> /// <param name="serviceProvider"></param> /// <param name="record"></param> /// <returns></returns> internal object GetTransient(IServiceProvider serviceProvider, TypeRecord record) { var obj = record.CallFactory(serviceProvider); this.objects.Add(new ObjectContainer(obj, ServiceLifetime.Transient, serviceProvider.GetScope())); return(obj); }
/// <summary> /// Creates a list of fields based on <see cref="TagRecord"/>.<see cref="TagRecord.FieldList"/>. /// </summary> private List <PdbTypeField> EnumerateFields() { List <PdbTypeField> fields = new List <PdbTypeField>(); foreach (TypeRecord field in EnumerateFieldList()) { if (field is DataMemberRecord dataMemberRecord) { // Check if this field is stored as bits. TypeIndex typeIndex = dataMemberRecord.Type; if (!typeIndex.IsSimple) { TypeRecord fieldType = Pdb.PdbFile.TpiStream[typeIndex]; if (fieldType is BitFieldRecord bitFieldRecord) { fields.Add(new PdbTypeBitField(this, dataMemberRecord, bitFieldRecord)); continue; } } // Add it as regular field. fields.Add(new PdbTypeField(this, dataMemberRecord)); } } return(fields); }
internal List <TypeRecord> GetAllImplementationTypes(Type serviceType, Type[] genericParms) { var records = this.relations.GetAll(serviceType); var list = new List <TypeRecord>(); foreach (var record in records) { if (record.ImplementationType.IsGenericType && record.ImplementationType.ContainsGenericParameters == true) { Type newType = null; if (genericParms == null) { newType = record.ImplementationType.MakeGenericType(serviceType.GetGenericArguments()); } else { newType = record.ImplementationType.MakeGenericType(genericParms); } var newRec = new TypeRecord(record.Lifetime, serviceType, newType, null, _ => _.CreateInstance(newType), buildFlag: false, id: record.ID); list.Insert(0, newRec); } else { list.Insert(0, record); } } return(list); }
public static int AddEvent(TypeRecord type_record, string name) { int index = LastEventIndex(type_record) + type_record.TypeEventCount; type_record.Events.Add(new KeyValuePair<string, int>(name, index)); type_record.TypeEventCount += 1; return index; }
public MethodRecord(int id, TypeRecord type, GenericInstRecord ginst, string name, string sig, int param_count) : base(id) { Type = type; GenericInst = ginst; Name = name; Signature = sig; ParamCount = param_count; }
public void Save() { BigEndianBinaryWriter TROPUSRWriter = new BigEndianBinaryWriter(new FileStream(path + "TROPUSR.DAT", FileMode.Open)); TROPUSRWriter.Write(header.StructToBytes()); TypeRecord account_id_Record = typeRecordTable[2]; TROPUSRWriter.BaseStream.Position = account_id_Record.Offset + 32; // 空行 TROPUSRWriter.Write(account_id.ToCharArray()); // 帳號 TypeRecord trophy_id_Record = typeRecordTable[3]; TROPUSRWriter.BaseStream.Position = trophy_id_Record.Offset + 16; TROPUSRWriter.Write(trophy_id.ToCharArray()); // 獎杯ID TROPUSRWriter.BaseStream.Position = trophy_id_Record.Offset + 80; //TROPUSRWriter.Write(AchievementRate[0]); // 完成度 //TROPUSRWriter.Write(AchievementRate[1]); // 完成度 //TROPUSRWriter.Write(AchievementRate[2]); // 完成度 //TROPUSRWriter.Write(AchievementRate[3]); // 完成度 TypeRecord TrophyType_Record = typeRecordTable[4]; TROPUSRWriter.BaseStream.Position = TrophyType_Record.Offset; foreach (TrophyType type in trophyTypeTable) { TROPUSRWriter.BaseStream.Position += 16; TROPUSRWriter.Write(type.StructToBytes()); } TypeRecord trophyListInfo_Record = typeRecordTable[5]; TROPUSRWriter.BaseStream.Position = trophyListInfo_Record.Offset + 16; TROPUSRWriter.Write(trophyListInfo.StructToBytes()); TypeRecord TrophyTimeInfo_Record = typeRecordTable[6]; TROPUSRWriter.BaseStream.Position = TrophyTimeInfo_Record.Offset; foreach (TrophyTimeInfo time in trophyTimeInfoTable) { TROPUSRWriter.BaseStream.Position += 16; TROPUSRWriter.Write(time.StructToBytes()); } TypeRecord unknowType7_Record = typeRecordTable[7]; TROPUSRWriter.BaseStream.Position = unknowType7_Record.Offset + 16; TROPUSRWriter.Write(unknowType7.StructToBytes()); TROPUSRWriter.Flush(); TROPUSRWriter.Close(); }
/// <summary> /// 存储临时对象 /// </summary> /// <param name="serviceProvider"></param> /// <param name="record"></param> /// <param name="obj"></param> /// <param name="newType"></param> /// <returns></returns> private object SaveTempObject(IServiceProvider serviceProvider, TypeRecord record, object obj = null, Type newType = null) { if (record.Lifetime == ServiceLifetime.Singleton) { var key = GenerateTempKey(serviceProvider, record, obj?.GetType() ?? newType); if (this.singleton.Contains(key)) { return(this.objects.First(_ => _.ID == key).Instance); } else { this.singleton.Add(key); this.objects.Add(new ObjectContainer(obj, ServiceLifetime.Singleton, key)); return(obj); } } else if (record.Lifetime == ServiceLifetime.Scoped) { var key = GenerateTempKey(serviceProvider, record, newType); if (this.scopedKeys.Contains(key) == false) { scopedKeys.Add(key); if (scoped.TryAdd(key, obj)) { return(obj); } else { scoped.TryGetValue(key, out obj); return(obj); } } else { if (scoped.TryGetValue(key, out obj)) { return(obj); } else { return(null); } } } else if (record.Lifetime == ServiceLifetime.Transient) { this.objects.Add(new ObjectContainer(obj, ServiceLifetime.Transient, serviceProvider.GetScope())); return(obj); } else { throw new NotSupportedException("Doesn't Support ServiceLifetime"); } }
public PropertyRecord(Context context, TypeRecord typeRecord, CachedProperty prop) : this(context, typeRecord) { DeclaringTypeId = prop.DeclaringTypeId; PropertyTag = prop.Tag; EncodeTag = EncodePropertyTag(DeclaringTypeId, PropertyTag); DataType = prop.DataType; PropertyType = prop.PropertyType; Property = prop; Name = prop.Name; }
//public FinanceGraphicRecord GraphicRecord { get; set; } /// <summary> /// Základní konstruktor s povinnými údaji /// </summary> /// <param name="price">Utracená / získaná částka</param> /// <param name="name">Název transakce</param> /// <param name="date">Datum uskutečnění transakce</param> /// <param name="type">Výdaj / příjem</param> /// <param name="category">Kategorie výdaje</param> public FinanceRecord(int price, string name, DateTime date, TypeRecord type, Category category , TypeBalance balance) { Price = price; Name = name; Date = date; TypeRecord = type; Category = category; TypeBalance = balance; ID = Id; Id++; }
/// <summary> /// Remove dead entries from the data for the given source. Returns true if /// some entries were actually removed. /// </summary> protected override bool Purge(object source, object data, bool purgeAll) { TypeRecord typeRecord = (TypeRecord)data; bool foundDirt = typeRecord.Purge(purgeAll); if (!purgeAll && typeRecord.IsEmpty) { Remove(typeRecord.Type); } return(foundDirt); }
public override string GetIdentifer(TypeRecord caller, AnalysisEnvironment environment) { // the record index is set, which means the type is successfully registered and // is allocated with an index already. if (this.Symbol == "matrix" && (!this.IsFilledGeneric)) { return("matrix"); } if (ClrTypeRecordIndex != -1) { return("<" + ClrTypeRecordIndex + ">"); } Interop.AnonymousTypeRecord.RegistryCount++; this.ClrTypeRecordIndex = Interop.AnonymousTypeRecord.RegistryCount; Interop.AnonymousTypeRecord.IdentiferRegistry.Add(this.ClrTypeRecordIndex, "(undefined)"); string genericName = ""; if (this.Symbol.StartsWith("matrix(") || this.Symbol.Trim() == "matrix") { genericName = "matrix"; } else { genericName = "[" + this.clrType.FullName + "]"; } List <string> typeParams = new List <string>(); if (this.IsFilledGeneric && this.IsClrFilling) { foreach (var item in this.GenericParameters) { typeParams.Add("[" + item.FullName + "]"); } } else if (this.IsFilledGeneric) { foreach (var item in GenericTypeRecords) { typeParams.Add(item.GetIdentifer(this, environment)); } } typeParams.Sort(); this.Identifer = genericName + "(" + typeParams.JoinString(",") + ")"; Interop.AnonymousTypeRecord.IdentiferRegistry[ClrTypeRecordIndex] = this.Identifer; return("<" + this.ClrTypeRecordIndex + ">"); }
/// <summary> /// Initializes a new instance of the <see cref="PdbSymbol"/> class. /// </summary> /// <param name="module">Module that contains this symbol.</param> /// <param name="id">Type identifier.</param> /// <param name="typeRecord">Type record that represents this symbol.</param> public PdbSymbol(PdbModule module, uint id, TypeRecord typeRecord) : base(module) { PdbModule = module; Id = id; this.typeRecord = typeRecord; if (typeRecord is ClassRecord classRecord) { Initialize(classRecord); } else if (typeRecord is UnionRecord unionRecord) { Initialize(unionRecord); } else if (typeRecord is EnumRecord enumRecord) { Initialize(enumRecord); } else if (typeRecord is BaseClassRecord baseClassRecord) { Initialize(baseClassRecord); } else if (typeRecord is VirtualBaseClassRecord virtualBaseClassRecord) { Initialize(virtualBaseClassRecord); } else if (typeRecord is PointerRecord pointerRecord) { Initialize(pointerRecord); } else if (typeRecord is ProcedureRecord procedureRecord) { Initialize(procedureRecord); } else if (typeRecord is ArrayRecord arrayRecord) { Initialize(arrayRecord); } else if (typeRecord is ModifierRecord modifierRecord) { Initialize(modifierRecord); } else if (typeRecord is MemberFunctionRecord memberFunctionRecord) { Initialize(memberFunctionRecord); } else { throw new NotImplementedException($"Unexpected type record: {typeRecord.Kind}"); } }
/// <summary> /// 生成泛型对象 /// </summary> /// <param name="serviceProvider"></param> /// <param name="outRecord"></param> /// <param name="newType"></param> /// <returns></returns> internal object GetMakedGeneric(IServiceProvider serviceProvider, TypeRecord outRecord, Type newType) { var key = GenerateTempKey(serviceProvider, outRecord, newType); if (ContainsTempKey(outRecord.Lifetime, key)) { return(this.SaveTempObject(serviceProvider, outRecord, newType: newType)); } else { var obj = serviceProvider.CreateInstance(newType); return(this.SaveTempObject(serviceProvider, outRecord, obj: obj)); } }
internal void Traverse(Instance instance) { if (!instance.Archivable || (instance is Workspace && !IncludeWorkspace)) { return; } TypeRecord record; var typeId = instance.GetType().GetCustomAttribute <TypeIdAttribute>()?.Id; if (!typeId.HasValue) { return; } var type = Types[typeId.Value]; if (!TypeRecords.TryGetValue(type, out record)) { record = new TypeRecord(this, type); TypeRecords.Add(type, record); TotalTypes++; } var context = record.Context; if (!context.AddObject(instance)) { return; } instance.BeforeSerialization(context); foreach (var prop in type.Properties) { if (typeof(Instance).IsAssignableFrom(prop.PropertyType)) { var inst = (Instance)prop.Get.FastDynamicInvoke(instance); if (inst != null && inst.IsDescendantOf(Root)) { Traverse(inst); } } } foreach (var child in instance.Children) { Traverse(child); } }
/// <summary> /// 生成临时对象Key /// </summary> /// <param name="serviceProvider"></param> /// <param name="record"></param> /// <param name="newType"></param> /// <returns></returns> private string GenerateTempKey(IServiceProvider serviceProvider, TypeRecord record, Type newType) { if (record.Lifetime == ServiceLifetime.Singleton) { return(record.ID + newType.GetHashCode()); } else if (record.Lifetime == ServiceLifetime.Scoped) { return(record.ID + serviceProvider.GetScopedID() + newType.GetHashCode()); } else { return(string.Empty); } }
private PdbType[] EnumerateArguments() { TypeRecord typeRecord = Pdb.PdbFile.TpiStream[ProcedureRecord.ArgumentList]; if (typeRecord is ArgumentListRecord argumentList) { PdbType[] arguments = new PdbType[argumentList.Arguments.Length]; for (int i = 0; i < arguments.Length; i++) { arguments[i] = Pdb[argumentList.Arguments[i]]; } return(arguments); } return(new PdbType[0]); }
/// <summary> /// Gets all <see cref="TypeRecord"/> entries associated with the specified <see cref="TypeLeafKind"/>. /// </summary> /// <param name="kind">Type record kind.</param> private TypeRecord[] GetTypesByKind(TypeLeafKind kind) { List <TypeRecord> records = new List <TypeRecord>(); for (int i = 0; i < references.Count; i++) { if (references[i].Kind == kind) { TypeRecord record = typesCache[i]; if (record != null) { records.Add(record); } } } return(records.ToArray()); }
private object CallRecord(TypeRecord record) { if (record.Lifetime == ServiceLifetime.Singleton) { return(this.GetSingleton(record)); } else if (record.Lifetime == ServiceLifetime.Scoped) { return(this.GetScoped(record)); } else if (record.Lifetime == ServiceLifetime.Transient) { return(this.GetTransient(record)); } else { throw new NotSupportedException($"Unsupported ServiceLifetime {record.Lifetime}"); } }
public void Save() { using (var fileStream = new FileStream(Path.Combine(path, TROPUSR_FILE_NAME), FileMode.Open)) using (var TROPUSRWriter = new BigEndianBinaryWriter(fileStream)) { TROPUSRWriter.Write(header.StructToBytes()); TypeRecord account_id_Record = typeRecordTable[2]; TROPUSRWriter.BaseStream.Position = account_id_Record.Offset + 32; // 空行 TROPUSRWriter.Write(this.account_id); // 帳號 TypeRecord trophy_id_Record = typeRecordTable[3]; TROPUSRWriter.BaseStream.Position = trophy_id_Record.Offset + 16; TROPUSRWriter.Write(trophy_id.ToCharArray()); // 獎杯ID TROPUSRWriter.BaseStream.Position = trophy_id_Record.Offset + 80; TypeRecord TrophyType_Record = typeRecordTable[4]; TROPUSRWriter.BaseStream.Position = TrophyType_Record.Offset; foreach (TrophyType type in trophyTypeTable) { TROPUSRWriter.BaseStream.Position += 16; TROPUSRWriter.Write(type.StructToBytes()); } TypeRecord trophyListInfo_Record = typeRecordTable[5]; TROPUSRWriter.BaseStream.Position = trophyListInfo_Record.Offset + 16; TROPUSRWriter.Write(trophyListInfo.StructToBytes()); TypeRecord TrophyTimeInfo_Record = typeRecordTable[6]; TROPUSRWriter.BaseStream.Position = TrophyTimeInfo_Record.Offset; foreach (TrophyTimeInfo time in trophyTimeInfoTable) { TROPUSRWriter.BaseStream.Position += 16; TROPUSRWriter.Write(time.StructToBytes()); } TypeRecord unknowType7_Record = typeRecordTable[7]; TROPUSRWriter.BaseStream.Position = unknowType7_Record.Offset + 16; TROPUSRWriter.Write(unknowType7.StructToBytes()); TROPUSRWriter.Flush(); TROPUSRWriter.Close(); } }
private static IEnumerable <TypeRecord> GetBaseClasses(PdbFile pdb, ClassRecord classRecord) { if (classRecord.DerivationList != TypeIndex.None) { TypeRecord baseClasses = pdb.TpiStream[classRecord.DerivationList]; throw new System.NotImplementedException(); } else if (classRecord.FieldList != TypeIndex.None) { foreach (TypeRecord field in EnumerateFieldList(pdb, classRecord.FieldList)) { if (field is BaseClassRecord || field is VirtualBaseClassRecord) { yield return(field); } } } }
public static IType TypeMap(Func <int, TypeVar, IType> onVar, int c, IType t) { IType Walk(int c, IType t) { return(t switch { TypeVar v => onVar(c, v), TypeId i => i, TypeString ts => ts, TypeUnit u => u, TypeRecord r => new TypeRecord(r.Variants.Select(p => (p.Item1, Walk(c, p.Item2)))), TypeFloat f => f, TypeBool b => b, TypeNat n => n, TypeArrow a => new TypeArrow(Walk(c, a.From), Walk(c, a.To)), TypeVariant tv => new TypeVariant(tv.Variants.Select(p => (p.Item1, Walk(c, p.Item2)))), _ => throw new InvalidOperationException() }); }
/// <summary> /// Obrácený type EnumValidator - na základě zadaných Enums vytvoří pole ID daných prvků /// </summary> /// <param name="type">Type transakce Výdaj - Příjem</param> /// <param name="category">Kategorie výdajů</param> /// <param name="balance">Typ zůstatku Bankovní účet - Hotovost</param> /// <returns>[Typ transakce, Kategorie, Typ zůstatku pro platbu]</returns> public int[] EnumValidatorReverse(TypeRecord type, Category category, TypeBalance balance) { int[] ids = new int[3]; if ((int)category >= 0 && (int)category <= 6) { ids[0] = (int)category; } else { ids[0] = 7; } if (type == TypeRecord.Costs) { ids[1] = 0; } else if (type == TypeRecord.Income) { ids[1] = 1; } else { ids[1] = -1; } if (balance == TypeBalance.BankAccount) { ids[2] = 0; } else if (balance == TypeBalance.Cash) { ids[2] = 1; } else { ids[2] = -1; } return(ids); }
// Remove a handler to the named property (empty means "any property") private void PrivateRemoveHandler(Type type, EventHandler <PropertyChangedEventArgs> handler, string propertyName) { Debug.Assert(handler != null && type != null && propertyName != null, "Handler, type, and propertyName of event cannot be null"); using (WriteLock) { TypeRecord tr = (TypeRecord)this[type]; if (tr != null) { tr.RemoveHandler(handler, propertyName); if (tr.IsEmpty) { tr.StopListening(); Remove(tr.Type); } } } }
/// <summary> /// Gets user type base classes. /// </summary> protected override IEnumerable <Symbol> GetBaseClasses() { if (typeRecord is ClassRecord classRecord) { if (classRecord.DerivationList != TypeIndex.None) { TypeRecord baseClasses = PdbModule.PdbFile.TpiStream[classRecord.DerivationList]; throw new NotImplementedException(); } else if (classRecord.FieldList != TypeIndex.None) { foreach (TypeRecord field in EnumerateFieldList(classRecord.FieldList)) { if (field is BaseClassRecord || field is VirtualBaseClassRecord) { yield return(PdbModule.GetSymbol(field)); } } } } }
/// <summary> /// Initializes a new instance of the <see cref="PdbSymbolField"/> class. /// </summary> /// <param name="parentType">The parent type.</param> /// <param name="record">Data member type record.</param> public PdbSymbolField(PdbSymbol parentType, DataMemberRecord record) : base(parentType) { Name = record.Name; DataKind = DIA.DataKind.Member; Offset = (int)record.FieldOffset; TypeRecord typeRecord = !record.Type.IsSimple ? parentType.PdbModule.PdbFile.TpiStream[record.Type] : null; if (typeRecord is BitFieldRecord bitFieldRecord) { LocationType = DIA.LocationType.BitField; BitPosition = bitFieldRecord.BitOffset; BitSize = bitFieldRecord.BitSize; Type = parentType.PdbModule.GetSymbol(bitFieldRecord.Type); } else { LocationType = DIA.LocationType.ThisRel; Type = parentType.PdbModule.GetSymbol(record.Type); Size = Type.Size; } }
/// <summary> /// 获取域单例对象 /// </summary> /// <param name="serviceProvider"></param> /// <param name="record"></param> /// <returns></returns> internal object GetScoped(IServiceProvider serviceProvider, TypeRecord record) { var key = string.Empty; if (record.BuildFlag) { key = serviceProvider.GetScopedID() + record.ID; } else { key = GenerateTempKey(serviceProvider, record, record.ImplementationType); } if (scopedKeys.Contains(key) == false) { var obj = record.GetObject(serviceProvider); scopedKeys.Add(key); this.objects.Add(new ObjectContainer(obj, record.Lifetime, serviceProvider.GetScope())); if (scoped.TryAdd(key, obj)) { return(obj); } else { scoped.TryGetValue(key, out obj); return(obj); } } else { if (scoped.TryGetValue(key, out var obj)) { return(obj); } else { return(null); } } }
// // Private Methods // // PropertyChanged is a special case - we superimpose per-property granularity // on top of this event, by keeping separate lists of listeners for // each property. // Add a listener to the named property (empty means "any property") private void PrivateAddHandler(Type type, EventHandler <PropertyChangedEventArgs> handler, string propertyName) { Debug.Assert(handler != null && type != null && propertyName != null, "Handler, type, and propertyName of event cannot be null"); using (WriteLock) { TypeRecord tr = (TypeRecord)this[type]; if (tr == null) { // no entry in the hashtable - add a new one tr = new TypeRecord(type, this); this[type] = tr; // listen for the desired events tr.StartListening(); } tr.AddHandler(handler, propertyName); } }
/// <summary> /// Enumerates type records from field list type index. /// </summary> /// <param name="fieldListIndex">Type index of the field list type record.</param> private IEnumerable <TypeRecord> EnumerateFieldList(TypeIndex fieldListIndex) { while (fieldListIndex != TypeIndex.None) { TypeIndex nextFieldListIndex = TypeIndex.None; TypeRecord fieldList = PdbModule.PdbFile.TpiStream[fieldListIndex]; if (fieldList is FieldListRecord fieldListRecord) { foreach (TypeRecord field in fieldListRecord.Fields) { if (field is ListContinuationRecord listContinuation) { nextFieldListIndex = listContinuation.ContinuationIndex; } else { yield return(field); } } } fieldListIndex = nextFieldListIndex; } }
// event handler for PropertyChanged event private void OnStaticPropertyChanged(TypeRecord typeRecord, PropertyChangedEventArgs args) { ListenerList list; // get the list of listeners using (ReadLock) { list = typeRecord.GetListenerList(args.PropertyName); // mark the list "in use", even outside the read lock, // so that any writers will know not to modify it (they'll // modify a clone intead). list.BeginUse(); } // deliver the event, being sure to undo the effect of BeginUse(). try { DeliverEventToList(null, args, list); } finally { list.EndUse(); } // if we calculated an AllListeners list, we should now try to store // it in the dictionary so it can be used in the future. This must be // done under a WriteLock - which is why we didn't do it immediately. if (list == typeRecord.ProposedAllListenersList) { using (WriteLock) { typeRecord.StoreAllListenersList((ListenerList <PropertyChangedEventArgs>)list); } } }
private static int LastEventIndex(TypeRecord type_record) { int index = 0; TypeRecord parent = type_record.ParentType; while(parent != null) { index += parent.TypeEventCount; parent = parent.ParentType; } return index; }
public PropertyRecord(string propertyName, TypeRecord owner, ListenerList<PropertyChangedEventArgs> list) { _propertyName = propertyName; _typeRecord = owner; _list = list; }
object AddTypeWithoutNamespace (Type t, Hashtable ht) { TreeIter iter; //Console.WriteLine ("add type {0}", t.FullName); if (!IsVisible (t)) return null; //Console.WriteLine ("try type {0}", t.FullName); if (ht [t] != null) return (TreeIter) ht [t]; //Console.WriteLine ("new line {0}", t.FullName); iter = new TreeIter (); if (t.BaseType == null) // FIXME? || t.BaseType.Assembly != assembly) typeStore.Append (out iter); else typeStore.Append (out iter, (TreeIter) AddTypeWithoutNamespace (t.BaseType, ht)); TypeRecord tr = new TypeRecord (t); typeStore.SetValue (iter, 0, new GLib.Value (tr.Label)); typeStore.SetValue (iter, 1, new GLib.Value (t.FullName)); typeStore.SetValue (iter, 2, new GLib.Value (tr.Icon)); ht [t] = iter; return iter; }
object AddTypeWithNamespace (Type t, Hashtable ht) { //Console.WriteLine ("add type {0}", t.FullName); if (!IsVisible (t)) return null; //Console.WriteLine ("try type {0}", t.FullName); if (ht [t] != null) return (TreeIter) ht [t]; //Console.WriteLine ("new line {0}", t.FullName); TreeIter iter = new TreeIter (); if (t.BaseType != null /* FIXME? && t.BaseType.Assembly == assembly */ && t.BaseType.Namespace == t.Namespace) typeStore.Append (out iter, (TreeIter) AddTypeWithNamespace (t.BaseType, ht)); else { if (t.Namespace != null && t.Namespace != "") typeStore.Append (out iter, NamespaceIter (t.Namespace, ht)); else typeStore.Append (out iter); } TypeRecord tr = new TypeRecord (t); typeStore.SetValue (iter, 0, new GLib.Value (tr.Label)); typeStore.SetValue (iter, 1, new GLib.Value (t.FullName)); typeStore.SetValue (iter, 2, new GLib.Value (tr.Icon)); ht [t] = iter; return iter; }
public BaseObject() { m_type_record = TypeManager.GetRecord(GetType()); }
private static TypeRecord AddRecord(Type type) { if(type == null) throw new ArgumentNullException("type"); TypeRecord record = new TypeRecord(null); record.TypeEventCount = 0; record.CLRType = type; if(type != typeof(Lucid.BaseObject)) { record.ParentType = GetRecord(type.BaseType); if(record.ParentType.ChildTypes == null) record.ParentType.ChildTypes = new List<TypeRecord>(); record.ParentType.ChildTypes.Add(record); record.Events = record.ParentType.Events; } else { record.Events = new EventTable(); return record; } //Split /* if( ) { record.Events = new EventTable(); foreach(KeyValuePair<string, int> event_record in record.ParentType.Events) record.Events.Add(event_record); } */ List<FieldInfo> fields = new List<FieldInfo>(); foreach(FieldInfo field in type.GetFields()) { object[] attrs = field.GetCustomAttributes(false); foreach(Attribute attr in attrs) { if(attr.GetType() == typeof(EventAttribute)) { //TODO: readonly too if(field.IsPublic && field.IsStatic && field.Name.EndsWith("Event") && field.FieldType == typeof(int)) fields.Add(field); else throw new System.NotSupportedException(String.Format("Field \"{0}.{1}\" is fail.", type, field.Name)); } } } if(fields.Count > 0) { if(record.ParentType.ChildTypes.Count > 1) { record.Events = new EventTable(); for(int i = 0, j = LastEventIndex(record); i < j; i++) record.Events.Add(record.ParentType.Events[i]); } foreach(FieldInfo field in fields) { int index = AddEvent(record, field.Name); field.SetValue(null, index); } } /* Console.WriteLine("{0} [{1}]", type, record.ParentType.CLRType); foreach(KeyValuePair<string, int> event_record in record.Events) Console.WriteLine("\t{0} = {1}", event_record.Key, event_record.Value); */ return record; }
// // Private Methods // // PropertyChanged is a special case - we superimpose per-property granularity // on top of this event, by keeping separate lists of listeners for // each property. // Add a listener to the named property (empty means "any property") private void PrivateAddHandler(Type type, EventHandler<PropertyChangedEventArgs> handler, string propertyName) { Debug.Assert(handler != null && type != null && propertyName != null, "Handler, type, and propertyName of event cannot be null"); using (WriteLock) { TypeRecord tr = (TypeRecord)this[type]; if (tr == null) { // no entry in the hashtable - add a new one tr = new TypeRecord(type, this); this[type] = tr; // listen for the desired events tr.StartListening(); } tr.AddHandler(handler, propertyName); } }
public PropertyRecord(string propertyName, TypeRecord owner) : this(propertyName, owner, new ListenerList<PropertyChangedEventArgs>()) { }
private object GetTransient(TypeRecord record) { return(ObjectContainer.GetTransient(this, record)); }
// event handler for PropertyChanged event private void OnStaticPropertyChanged(TypeRecord typeRecord, PropertyChangedEventArgs args) { ListenerList list; // get the list of listeners using (ReadLock) { list = typeRecord.GetListenerList(args.PropertyName); // mark the list "in use", even outside the read lock, // so that any writers will know not to modify it (they'll // modify a clone intead). list.BeginUse(); } // deliver the event, being sure to undo the effect of BeginUse(). try { DeliverEventToList(null, args, list); } finally { list.EndUse(); } // if we calculated an AllListeners list, we should now try to store // it in the dictionary so it can be used in the future. This must be // done under a WriteLock - which is why we didn't do it immediately. if (list == typeRecord.ProposedAllListenersList) { using (WriteLock) { typeRecord.StoreAllListenersList((ListenerList<PropertyChangedEventArgs>)list); } } }