Shaolinq.Persistence.TypeDescriptor.GetRelatedProperty C# (CSharp) Method

GetRelatedProperty() public method

public GetRelatedProperty ( Type type ) : PropertyDescriptor
type System.Type
return PropertyDescriptor
		public PropertyDescriptor GetRelatedProperty(Type type)
		{
			PropertyDescriptor retval;

			if (!this.relatedPropertiesByType.TryGetValue(type, out retval))
			{
				Func<PropertyDescriptor, bool> isForType = delegate(PropertyDescriptor c)
				{
					if (type.IsAssignableFrom(c.PropertyType))
					{
						return true;
					}

					if (c.PropertyType.IsGenericType && typeof(RelatedDataAccessObjects<>).IsAssignableFromIgnoreGenericParameters(c.PropertyType.GetGenericTypeDefinition()))
					{
						if (c.PropertyType.GetGenericArguments()[0] == type)
						{
							return true;
						}
					}

					return false;
				};

				retval = this.RelationshipRelatedProperties.FirstOrDefault(isForType);

				if (retval == null)
				{
					throw new InvalidOperationException($"Unable to find related property for type '{type.Name}' on type '{this.Type.Name}'");
				}

				this.relatedPropertiesByType[type] = retval;
			}

			return retval;
		}