Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DependencyProperty"/> class.
 /// </summary>
 /// <param name="declaringType">The type which declares the property.</param>
 /// <param name="ownerType">The type which can own this property.</param>
 /// <param name="propertyType">The type of the property.</param>
 /// <param name="name">The name of the property.</param>
 /// <param name="defaultBindingMode">The default <see cref="BindingMode"/> for this property.</param>
 /// <param name="isAttachement">Specifies if the property is a attachement.</param>
 /// <param name="createValueCallback">The default value of the property.</param>
 /// <param name="coerceValueCallback">The callback for coercing the value.</param>
 /// <param name="validationCallback">The validation callback of the value.</param>
 /// <param name="changingCallback">The changing callback of the property.</param>
 /// <param name="changedCallback">The changed callback of the property.</param>
 internal DependencyProperty(TypeInfo declaringType, String name, BindingMode defaultBindingMode, Boolean isAttachement, CreateValueDelegate <TOwner, TProperty> createValueCallback, CoerceValueDelegate <TOwner, TProperty> coerceValueCallback, PropertyValidationDelegate <TOwner, TProperty> validationCallback, PropertyChangingDelegate <TOwner, TProperty> changingCallback, PropertyChangedDelegate <TOwner, TProperty> changedCallback)
     : base(declaringType, Reflection.TypeOf <TOwner> .TypeInfo, name, defaultBindingMode, isAttachement, false)
 {
     _CreateValueCallback = createValueCallback;
     _CoerceValueCallback = coerceValueCallback;
     _ValidationCallback  = validationCallback;
     _ChangingCallback    = changingCallback;
     _ChangedCallback     = changedCallback;
 }
Ejemplo n.º 2
0
 public TValue AddIfNotExists(TKey key, CreateValueDelegate del) => m_RwLock.AcquireWriterLock(() =>
 {
     if (m_Dictionary.ContainsKey(key))
     {
         throw new KeyAlreadyExistsException("Key \"" + key.ToString() + "\" already exists");
     }
     TValue res = del();
     m_Dictionary.Add(key, res);
     return(res);
 });
Ejemplo n.º 3
0
 public TValue GetOrAddIfNotExists(TKey key, CreateValueDelegate del) => m_RwLock.AcquireReaderLock(() =>
 {
     try
     {
         return(m_Dictionary[key]);
     }
     catch (KeyNotFoundException)
     {
         return(m_RwLock.UpgradeToWriterLock(() =>
         {
             if (m_Dictionary.ContainsKey(key))
             {
                 return m_Dictionary[key];
             }
             return m_Dictionary[key] = del();
         }));
     }
 });
Ejemplo n.º 4
0
 public TValue GetOrAddIfNotExists(TKey key, CreateValueDelegate del) => m_RwLock.AcquireReaderLock(() =>
 {
     TValue value;
     if (m_Dictionary.TryGetValue(key, out value))
     {
         return(value);
     }
     else
     {
         return(m_RwLock.UpgradeToWriterLock(() =>
         {
             if (m_Dictionary.TryGetValue(key, out value))
             {
                 return value;
             }
             return m_Dictionary[key] = del();
         }));
     }
 });
Ejemplo n.º 5
0
 private static Expression GetModuleValue(string Module, string Key, CreateValueDelegate CreateValue)
 {
     ConcurrentDictionary<string, Expression> moduleCache = GetModule(Module, (CreateValue != null));
     if (moduleCache != null)
     {
         Expression expression;
         if (moduleCache.TryGetValue(Key, out expression))
         {
             return expression;
         }
         if (CreateValue != null)
         {
             expression = CreateValue();
             Expression oldExpression;
             if (moduleCache.TryGetValue(Key, out oldExpression))
                 moduleCache.TryUpdate(Key, expression, oldExpression);
             else
                 moduleCache.TryAdd(Key, expression);
             return expression;
         }
     }
     return null;
 }
 public static DependencyPropertyKey <TProperty> CreateReadonlyAttachment <TDeclarer, TOwner, TProperty>(String name, CreateValueDelegate <TOwner, TProperty> defaultValueFactory, BindingMode bindingMode = BindingMode.Default, PropertyValidationDelegate <TOwner, TProperty> validation = null, PropertyChangingDelegate <TOwner, TProperty> propertyChanging = null, PropertyChangedDelegate <TOwner, TProperty> propertyChanged = null, CoerceValueDelegate <TOwner, TProperty> coerceValue = null)
     where TOwner : class, IDependencyObject
 {
     ValidatePropertyName(name);
     new DependencyProperty <TProperty, TOwner>(TypeOf <TDeclarer> .TypeInfo, name, bindingMode, true, defaultValueFactory, coerceValue, validation, propertyChanging, propertyChanged, out DependencyPropertyKey <TProperty> key);
     return(key);
 }
 public static DependencyPropertyKey <TProperty> CreateReadonly <TDeclarer, TProperty>(Expression <Func <TDeclarer, TProperty> > getter, CreateValueDelegate <TDeclarer, TProperty> defaultValueFactory, BindingMode bindingMode = BindingMode.Default, PropertyValidationDelegate <TDeclarer, TProperty> validation = null, PropertyChangingDelegate <TDeclarer, TProperty> propertyChanging = null, PropertyChangedDelegate <TDeclarer, TProperty> propertyChanged = null, CoerceValueDelegate <TDeclarer, TProperty> coerceValue = null)
     where TDeclarer : class, IDependencyObject
 {
     new DependencyProperty <TProperty, TDeclarer>(TypeOf <TDeclarer> .TypeInfo, GetPropertyName <TDeclarer, TProperty>(getter), bindingMode, true, defaultValueFactory, coerceValue, validation, propertyChanging, propertyChanged, out DependencyPropertyKey <TProperty> key);
     return(key);
 }
Ejemplo n.º 8
0
 public static Expression GetValue(string Module, string Key, CreateValueDelegate CreateValue)
 {
     return GetModuleValue(Module, Key, CreateValue);
 }
Ejemplo n.º 9
0
 public RwLockedSortedDictionaryAutoAdd(IDictionary <TKey, TValue> dictionary, IComparer <TKey> comparer, CreateValueDelegate autoAddDelegate)
     : base(dictionary, comparer)
 {
     m_AutoAddDelegate = autoAddDelegate;
 }
Ejemplo n.º 10
0
 public RwLockedSortedDictionaryAutoAdd(IDictionary <TKey, TValue> dictionary, CreateValueDelegate autoAddDelegate)
     : base(dictionary)
 {
     m_AutoAddDelegate = autoAddDelegate;
 }
Ejemplo n.º 11
0
 public RwLockedSortedDictionaryAutoAdd(CreateValueDelegate autoAddDelegate)
 {
     m_AutoAddDelegate = autoAddDelegate;
 }
Ejemplo n.º 12
0
 public RwLockedDictionaryAutoAdd(int capacity, IEqualityComparer <TKey> comparer, CreateValueDelegate autoAddDelegate)
     : base(capacity, comparer)
 {
     m_AutoAddDelegate = autoAddDelegate;
 }
Ejemplo n.º 13
0
 public RwLockedDictionaryAutoAdd(int capacity, CreateValueDelegate autoAddDelegate)
     : base(capacity)
 {
     m_AutoAddDelegate = autoAddDelegate;
 }