/// <summary> /// Initializes a new instance of the <see cref="SharedMemberInfo"/>. /// </summary> /// <param name="declaringType">The <see cref="SharedTypeInfo"/> of the declaring type.</param> /// <param name="member">The member which is represented.</param> internal SharedMemberInfo(SharedTypeInfo declaringType, MemberInfo member) { if (member == null) { throw new ArgumentNullException(nameof(member)); } DeclaringType = declaringType ?? throw new ArgumentNullException(nameof(declaringType)); if (declaringType.Type != member.DeclaringType.GetTypeInfo()) { throw new ArgumentException("declaringType must match member declaring type"); } Name = member.Name; }
/// <summary> /// Initializes a new instance of the <see cref="SharedValueMemberInfo"/>. /// </summary> /// <param name="reflectionManager">The <see cref="SharedReflectionManager"/> used for the reflection.</param> /// <param name="declaringType">The <see cref="SharedTypeInfo"/> of the declaring type.</param> /// <param name="member">The member which is represented.</param> /// <param name="valueType">The type of the value hold by the member.</param> /// <param name="canWrite">Specifies if the member can be written.</param> internal SharedValueMemberInfo(SharedReflectionManager reflectionManager, SharedTypeInfo declaringType, MemberInfo member, Type valueType, Boolean canWrite, Object defaultValue) : base(declaringType, member) { if (reflectionManager == null) { throw new ArgumentNullException(nameof(reflectionManager)); } if (valueType == null) { throw new ArgumentNullException(nameof(valueType)); } CanWrite = canWrite; ValueType = reflectionManager.GetInfo(valueType.GetTypeInfo()); _DefaultValue = ((member.GetCustomAttribute <DefaultValueAttribute>() is DefaultValueAttribute defaultAttribute) ? defaultAttribute.Value : defaultValue) ?? (ValueType.IsValueType ? Activator.CreateInstance(valueType) : null); }
/// <summary> /// Gets a <see cref="SharedTypeInfo"/> for the specified <see cref="TypeInfo"/>. /// </summary> /// <param name="type">The <see cref="TypeInfo"/> to get the <see cref="SharedTypeInfo"/> for.</param> /// <returns>The <see cref="SharedTypeInfo"/> for the specified type.</returns> public SharedTypeInfo GetInfo(TypeInfo type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (!_RegisteredType.TryGetValue(type, out SharedTypeInfo sharedType)) { lock (_RegisteredType) { if (!_RegisteredType.TryGetValue(type, out sharedType)) { _RegisteredType.TryAdd(type, sharedType = new SharedTypeInfo(this, _SharedAction, type)); } } } return(sharedType); }
/// <summary> /// Tries to find a property in the current and all base types. /// </summary> /// <param name="name">The unique name of the property.</param> /// <param name="property">The property to search for.</param> /// <returns>True if the property could be found; otherwise false.</returns> public Boolean TryGetProperty(String name, out SharedPropertyInfo property) { if (name == null) { throw new ArgumentNullException(nameof(name)); } // Wait until the parser is done WaitUntilReady(_ObjectParseCompletion); SharedTypeInfo current = this; while (!current._DeclaredPropertiesLookup.TryGetValue(name, out property) && current.BaseType != null) { current = current.BaseType; // Wait until the parser is done WaitUntilReady(current._ObjectParseCompletion); } return(property != null); }
public SharedPropertyInfo(SharedReflectionManager reflectionManager, SharedTypeInfo declaringType, PropertyInfo property, DependencyProperty dependencyProperty, Object defaultValueSample) : base(reflectionManager, declaringType, property, dependencyProperty?.PropertyType.AsType() ?? property.PropertyType, CanWriteProperty(property, dependencyProperty), SampleDefault(property, dependencyProperty, defaultValueSample)) { DependencyProperty = dependencyProperty; _Property = property; }
/// <summary> /// Registers a <see cref="SharedTypeInfo"/> in the <see cref="SharedReflectionManager"/>. /// </summary> /// <param name="typeInfo">The <see cref="SharedTypeInfo"/> to register.</param> void Register(SharedTypeInfo typeInfo) => _RegisteredType[typeInfo.Type] = typeInfo;