/// <summary> /// Tries to find a disassembled entity, given a disassembled target. /// </summary> /// <param name="disassemblyTarget">The disassembly target.</param> /// <returns></returns> public DisassembledEntity FindDisassembledEntity(DisassemblyTarget disassemblyTarget) { // If there's no target, we can't find anything. if (disassemblyTarget == null) { return(null); } switch (disassemblyTarget.TargetType) { case DisassemblyTargetType.Class: // Find the class with the given name. return(AllClasses.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName)); case DisassemblyTargetType.Enumeration: // Find the enumeration with the given name. return(AllEnumerations.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName)); case DisassemblyTargetType.Method: // Find the entity with the given name. return(AllMethods.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName)); case DisassemblyTargetType.Property: // Find the entity with the given name. return(AllProperties.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName)); case DisassemblyTargetType.Field: // Find the entity with the given name. return(AllFields.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName)); case DisassemblyTargetType.Structure: // Find the structure with the given name. return(AllStructures.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName)); case DisassemblyTargetType.Interface: // Find the structure with the given name. return(AllInterfaces.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName)); case DisassemblyTargetType.Event: // Find the structure with the given name. return(AllEvents.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName)); case DisassemblyTargetType.Delegate: // Find the structure with the given name. return(AllDelegates.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName)); default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Finds the name of the property by column. /// </summary> /// <param name="columnName">Name of the column.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">columnName</exception> public Property FindPropertyByColumnName(string columnName) { if (columnName == null) { throw new ArgumentNullException(nameof(columnName)); } return(AllProperties.FirstOrDefault(c => columnName.Equals(c.ColumnName))); }
/// <summary> /// Creates a new instance of the <see cref="TypeCacheResolver"/> class. /// </summary> /// <param name="type">Type of the cached properties.</param> /// <param name="nameMatchResolver">Name match resolver.</param> /// <param name="dynamicType">Whether the cached type is dynamic.</param> /// <param name="dynamicContainerName">Dynamic container name.</param> public TypeCacheResolver(Type type, INameMatchResolver nameMatchResolver, bool dynamicType = false, string dynamicContainerName = "DynamicProperties") { _nameMatchResolver = nameMatchResolver; Type = type; DerivedTypes = type.DerivedTypes().ToList(); IsDynamicType = dynamicType; DynamicPropertiesName = dynamicContainerName; TypeInfo = type.GetTypeInfo(); AllProperties = type.GetAllProperties().ToList(); DeclaredProperties = type.GetDeclaredProperties().ToList(); AllFields = type.GetAllFields().ToList(); DeclaredFields = type.GetDeclaredFields().ToList(); MappedName = type.GetMappedName(); MappedProperties = type.GetMappedProperties().ToList(); MappedPropertiesWithNames = type.GetMappedPropertiesWithNames().ToList(); IsAnonymousType = type.IsAnonymousType(); AnnotationsProperty = AllProperties.FirstOrDefault(x => x.PropertyType == typeof(ODataEntryAnnotations)); }
private void InitLogicalDeleted() { var statusProperty = SqlProperties.FirstOrDefault(x => x.PropertyInfo.GetCustomAttributes <StatusAttribute>().Any()); if (statusProperty == null) { return; } StatusPropertyName = statusProperty.ColumnName; if (statusProperty.PropertyInfo.PropertyType.IsBool()) { var deleteProperty = AllProperties.FirstOrDefault(p => p.GetCustomAttributes <DeletedAttribute>().Any()); if (deleteProperty == null) { return; } LogicalDelete = true; LogicalDeleteValue = 1; // true } else if (statusProperty.PropertyInfo.PropertyType.IsEnum()) { var deleteOption = statusProperty.PropertyInfo.PropertyType.GetFields().FirstOrDefault(f => f.GetCustomAttribute <DeletedAttribute>() != null); if (deleteOption == null) { return; } var enumValue = Enum.Parse(statusProperty.PropertyInfo.PropertyType, deleteOption.Name); if (enumValue != null) { LogicalDeleteValue = Convert.ChangeType(enumValue, Enum.GetUnderlyingType(statusProperty.PropertyInfo.PropertyType)); } LogicalDelete = true; } }
private PropertyDescriptor FindPropertyDescriptor(ColumnId columnId) { return(AllProperties.FirstOrDefault(pd => Equals(columnId, ColumnId.GetColumnId(pd)))); }