Example #1
0
 public override bool Equals(DataViewTypeAttribute other)
 {
     if (other is AlienTypeAttributeAttribute)
     {
         return(RaceId == ((AlienTypeAttributeAttribute)other).RaceId);
     }
     return(false);
 }
Example #2
0
 /// <summary>
 /// Map types with the same key type and the same value type should be equal.
 /// </summary>
 public override bool Equals(DataViewTypeAttribute other)
 {
     if (other is OnnxMapTypeAttribute otherSequence)
     {
         return(_keyType.Equals(otherSequence._keyType) && _valueType.Equals(otherSequence._valueType));
     }
     return(false);
 }
 /// <summary>
 /// Sequence types with the same element type should be equal.
 /// </summary>
 public override bool Equals(DataViewTypeAttribute other)
 {
     if (other is OnnxSequenceTypeAttribute otherSequence)
     {
         return(_elemType.Equals(otherSequence._elemType));
     }
     return(false);
 }
Example #4
0
 /// <summary>
 /// Images with the same width and height should equal.
 /// </summary>
 public override bool Equals(DataViewTypeAttribute other)
 {
     if (other is ImageTypeAttribute otherImage)
     {
         return(Height == otherImage.Height && Width == otherImage.Width);
     }
     return(false);
 }
Example #5
0
        public static IEnumerable <TColumn> GetColumns <TColumn>(object obj, DataViewType viewType, Predicate <TColumn> columnFilter = null)
        {
            switch (obj)
            {
            case null:
                return(Enumerable.Empty <TColumn>());

            case DataTable dt:
                if (columnFilter != null && !typeof(TColumn).Is <DataColumn>())
                {
                    throw new ArgumentException($"Column filter must receive an argument of type '{nameof(DataColumn)}' or a type derived from it.");
                }
                return(DataColumns(dt));

            default:
                if (columnFilter != null && !typeof(TColumn).Is <PropertyInfo>())
                {
                    throw new ArgumentException($"Column filter must receive an argument of type '{nameof(PropertyInfo)}' or a type derived from it.");
                }
                return(Properties());
            }

            IEnumerable <TColumn> DataColumns(DataTable dt)
            {
                IEnumerable <TColumn> columns = columnFilter == null
                                        ? dt.Columns.OfType <TColumn>()
                                        : dt.Columns.OfType <TColumn>()
                                                .Where(c => columnFilter(c));

                foreach (TColumn column in columns)
                {
                    yield return(column);
                }
            }

            IEnumerable <TColumn> Properties()
            {
                Type templateType = obj.AsType();
                IEnumerable <PropertyInfo> properties = templateType.GetProperties(essentialMix.Constants.BF_PUBLIC_INSTANCE)
                                                        .Where(p => !p.HasAttribute <NotMappedAttribute>(true));

                if (viewType != DataViewType.None)
                {
                    properties = properties.Where(p =>
                    {
                        DataViewTypeAttribute dataViewType = p.GetAttribute <DataViewTypeAttribute>(true);
                        return(dataViewType == null || dataViewType.ViewType.FastHasFlag(viewType));
                    });
                }

                IEnumerable <TColumn> propertiesCast = properties.Cast <TColumn>();

                if (columnFilter != null)
                {
                    propertiesCast = propertiesCast.Where(p => columnFilter(p));
                }

                foreach (TColumn column in propertiesCast)
                {
                    yield return(column);
                }
            }
        }