/// <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="isReadonly">Specifies if the property is readonly and a key is required to write the property.</param> /// <param name="isUsingValueFactory">Specifies if the property is using a value factory for the initial value.</param> /// <param name="isFastProperty">Specifies if the property is accessed in a special behaviour.</param> internal DependencyProperty(TypeInfo declaringType, TypeInfo ownerType, TypeInfo propertyType, String name, BindingMode defaultBindingMode, Boolean isAttachement, Boolean isUsingValueFactory) { if (String.IsNullOrWhiteSpace(name)) { throw new ArgumentException(nameof(name) + "cannot be null, empty or whitespace"); } // TODO : defaultBindingMode -> Enum check DeclaringType = declaringType ?? throw new ArgumentNullException(nameof(declaringType)); PropertyType = propertyType ?? throw new ArgumentNullException(nameof(propertyType)); OwnerType = ownerType ?? throw new ArgumentNullException(nameof(ownerType)); Name = name; DefaultBindingMode = defaultBindingMode; IsAttachement = isAttachement; IsUsingValueFactory = isUsingValueFactory; // Get the DependencyType for the current property and register the property DependencyType = DependencyType.GetDependencyType(declaringType, !isAttachement); DependencyType.Register(this); unchecked { // Precalculate the hash code if the depencency property _HashCode = 17; _HashCode = _HashCode * 23 + DeclaringType.GetHashCode(); _HashCode = _HashCode * 23 + OwnerType.GetHashCode(); _HashCode = _HashCode * 23 + PropertyType.GetHashCode(); _HashCode = _HashCode * 23 + Name.GetHashCode(); } }
/// <summary> /// Gets the <see cref="DependencyType"/> which describes a type. /// </summary> /// <param name="type">The type to get the <see cref="DependencyType"/> for.</param> /// <param name="requiresDependencyType"></param> /// <returns>The <see cref="DependencyType"/> which describes the type.</returns> internal static DependencyType GetDependencyType(TypeInfo type, Boolean requiresDependencyType) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (!TypeLookup.TryGetValue(type, out DependencyType result)) { lock (SyncRoot) { if (!requiresDependencyType || type.ImplementedInterfaces.Contains(typeof(IDependencyObject))) { result = new DependencyType(type); } } } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="DependencyObjectContainer"/> class. /// </summary> /// <param name="representedObject">The <see cref="IDependencyObject"/> type whichs dependency propertys should be represented.</param> public DependencyObjectContainer(IDependencyObject representedObject) { RepresentedObject = representedObject ?? throw new ArgumentNullException(nameof(representedObject)); _DependencyType = DependencyType.GetDependencyType(RepresentedObject.GetType().GetTypeInfo(), true); }
/// <summary> /// Initializes a new instance of the <see cref="DependencyObjectContainer"/> class. /// </summary> internal DependencyObjectContainer() { RepresentedObject = (this as IDependencyObject) ?? throw new NotSupportedException("Object must inherit from IDependencyObject"); _DependencyType = DependencyType.GetDependencyType(RepresentedObject.GetType().GetTypeInfo(), true); }
/// <summary> /// Tests whether the specified type is a subclass of the current type. /// </summary> /// <param name="type">The type to test.</param> /// <returns>True if the type is a subclass of the current class; otherwise false.</returns> internal Boolean IsSubclassOf(DependencyType type) => this == type || (Parent?.IsSubclassOf(type) == true);