public AbstractAccessor GetAccessorType(Type type, IPropertyInfo property) { WeakReference accessorR = typeToAccessorMap.Get(type, property.Name); AbstractAccessor accessor = accessorR != null ? (AbstractAccessor)accessorR.Target : null; if (accessor != null) { return(accessor); } Object writeLock = this.writeLock; lock (writeLock) { // concurrent thread might have been faster accessorR = typeToAccessorMap.Get(type, property.Name); accessor = accessorR != null ? (AbstractAccessor)accessorR.Target : null; if (accessor != null) { return(accessor); } Type enhancedType = GetAccessorTypeIntern(type, property); if (enhancedType == typeof(AbstractAccessor)) { throw new Exception("Must never happen. No enhancement for " + typeof(AbstractAccessor) + " has been done"); } ConstructorInfo constructor = enhancedType.GetConstructor(new Type[] { typeof(Type), typeof(String) }); accessor = (AbstractAccessor)constructor.Invoke(new Object[] { type, property }); typeToAccessorMap.Put(type, property.Name, new WeakReference(accessor)); return(accessor); } }
public void RegisterXmlType(Type type, String name, String namespaceString) { ParamChecker.AssertParamNotNull(type, "type"); ParamChecker.AssertParamNotNull(name, "name"); if (namespaceString == null) { namespaceString = String.Empty; } XmlTypeKey xmlTypeKey = new XmlTypeKey(); xmlTypeKey.Name = name; xmlTypeKey.Namespace = namespaceString; writeLock.Lock(); try { Type typeToSet = type; Type existingType = xmlTypeToClassMap.Get(name, namespaceString); if (existingType != null) { if (type.IsAssignableFrom(existingType)) { // Nothing else to to } else if (existingType.IsAssignableFrom(type)) { typeToSet = existingType; } else if (typeof(IList <>).Equals(existingType) && typeof(ObservableCollection <>).Equals(type)) { // Workaround for C# since the two collections are not assignable to eachother. typeToSet = existingType; } else { throw new Exception("Error while registering '" + type.FullName + "': Unassignable type '" + existingType.FullName + "' already registered for: Name='" + name + "' Namespace='" + namespaceString + "'"); } } xmlTypeToClassMap.Put(name, namespaceString, typeToSet); IList <XmlTypeKey> xmlTypeKeys = DictionaryExtension.ValueOrDefault(classToXmlTypeMap, type); if (xmlTypeKeys == null) { xmlTypeKeys = new List <XmlTypeKey>(); classToXmlTypeMap.Add(type, xmlTypeKeys); } xmlTypeKeys.Add(xmlTypeKey); } finally { writeLock.Unlock(); } }
public ICacheMapEntryFactory GetCacheMapEntryType(Type entityType, sbyte idIndex) { if (BytecodeEnhancer == null) { return(ci); } ICacheMapEntryFactory factory = typeToConstructorMap.Get(entityType, idIndex); if (factory != null) { return(factory); } Lock writeLock = this.writeLock; writeLock.Lock(); try { // concurrent thread might have been faster factory = typeToConstructorMap.Get(entityType, idIndex); if (factory != null) { return(factory); } try { Type enhancedType = BytecodeEnhancer.GetEnhancedType(typeof(CacheMapEntry), new CacheMapEntryEnhancementHint(entityType, idIndex)); if (enhancedType == typeof(CacheMapEntry)) { // Nothing has been enhanced factory = ci; } else { factory = AccessorTypeProvider.GetConstructorType <ICacheMapEntryFactory>(enhancedType); } } catch (Exception e) { if (Log.WarnEnabled) { Log.Warn(e); } // something serious happened during enhancement: continue with a fallback factory = ci; } typeToConstructorMap.Put(entityType, idIndex, factory); return(factory); } finally { writeLock.Unlock(); } }
protected IObjRefStoreFactory BuildDelegate(Type entityType, int idIndex) { lock (writeLock) { IObjRefStoreFactory objRefConstructorDelegate = constructorDelegateMap.Get(entityType, idIndex); if (objRefConstructorDelegate != null) { return(objRefConstructorDelegate); } Type enhancedType = BytecodeEnhancer.GetEnhancedType(typeof(ObjRefStore), new ObjRefStoreEnhancementHint(entityType, idIndex)); objRefConstructorDelegate = AccessorTypeProvider.GetConstructorType <IObjRefStoreFactory>(enhancedType); constructorDelegateMap.Put(entityType, idIndex, objRefConstructorDelegate); return(objRefConstructorDelegate); } }
public IGarbageProxyConstructor <T> CreateGarbageProxyConstructor <T>(params Type[] additionalInterfaceTypes) { Object writeLock = this.writeLock; lock (writeLock) { IGarbageProxyConstructor gpContructor = interfaceTypesToConstructorMap.Get(typeof(T), additionalInterfaceTypes); if (gpContructor != null) { return((IGarbageProxyConstructor <T>)gpContructor); } Type gpType = LoadClass(typeof(GCProxy), typeof(T), additionalInterfaceTypes); gpContructor = AccessorTypeProvider.GetConstructorType <IGarbageProxyConstructor <T> >(gpType); interfaceTypesToConstructorMap.Put(typeof(T), additionalInterfaceTypes, gpContructor); return((IGarbageProxyConstructor <T>)gpContructor); } }