public IEnumerable <(string, AssertInstanceReference)> Items()
        {
            var enumer   = Value as System.Collections.IEnumerable;
            var declared = ActualType.GetCollectionElementType();
            int idx      = 0;

            foreach (var enumeration in enumer)
            {
                var instance = new AssertInstanceReference(
                    enumeration,
                    declared,
                    IdentifierName($"r{IterationDepth}_{idx}"),
                    $"item #{idx} of {Path}",
                    Usings)

                {
                    AssertionName  = AssertionName,
                    IterationDepth = this.IterationDepth + 1
                };

                yield return($"r{IterationDepth}_{idx}", instance);

                idx++;
            }
        }
Exemple #2
0
        protected virtual MemberInfo[] GetDefaultMembers()
        {
            MemberInfo[] miarr = ActualType.GetDefaultMembers();

            if (this.IsInterface && GetInterfaces() != null)
            {
                System.Collections.Generic.List <MemberInfo> memlist =
                    new System.Collections.Generic.List <MemberInfo>();
                if (miarr != null)
                {
                    memlist.AddRange(miarr);
                }
                foreach (ExternalType type in GetInterfaces())
                {
                    miarr = type.GetDefaultMembers();
                    if (miarr != null)
                    {
                        memlist.AddRange(miarr);
                    }
                }

                miarr = memlist.ToArray();
            }

            return(miarr);
        }
        public IEnumerable <AssertInstanceReference> Properties()
        {
            var props = ActualType
                        .GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.FlattenHierarchy)
                        .Where(x => x.CanRead);

            var anon = ActualType.IsAnonymousType();

            foreach (var prop in props)
            {
                var value = prop.GetValue(Value);

                if (ValidationGenerator.ForbiddenTypes.Any(x => x.IsAssignableFrom(prop.PropertyType)))
                {
                    continue;
                }

                if (prop.GetCustomAttribute <NoValidateAttribute>() != null)
                {
                    continue;
                }

                ExpressionSyntax expression =
                    anon ? (ExpressionSyntax)AnonymousProperty(Expression, prop, Usings) : RegularProperty(Expression, prop)
                ;
                yield return(new AssertInstanceReference(value, prop.PropertyType,
                                                         expression, $"{prop.Name} of {Path}", Usings)
                {
                    AssertionName = AssertionName
                });
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AxisBase"/> class.
 /// </summary>
 public AxisBase()
 {
     this.MLabels      = new List <string>();
     this.MLabelValues = new List <double>();
     this.ActualType   = ActualType.Double;
     GetStyles();
 }
 public AxisBase()
 {
     this.m_Labels      = new List <string>();
     this.m_labelValues = new List <double>();
     this.ActualType    = ActualType.Double;
     GetStyles();
     this.StringFormat = string.Empty;
 }
Exemple #6
0
        public IType[] GetTypeConstraints()
        {
            return(Util.ArrayUtil.ConvertAll <Type, IType>(
#if DNXCORE50
                       ActualType.GetTypeInfo().GetGenericParameterConstraints(),
#else
                       ActualType.GetGenericParameterConstraints(),
#endif
                       _provider.Map));
        }
Exemple #7
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (id != null ? id.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ActualType != null ? ActualType.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ViewType != null ? ViewType.GetHashCode() : 0);
         return(hashCode);
     }
 }
 private IdentifierNameSyntax ComputerEnumTypeName()
 {
     //Some enums are nested. To support serializing them we need to consider
     //that they may be nested and fully qualify them.
     if (ActualType.ContainingType == null)
     {
         return(IdentifierName(ActualType.Name));
     }
     else
     {
         return(IdentifierName(ActualType.ToFullName()));                //non fully qualified, because of global::
     }
 }
 public AssertInstanceReference(object value, Type declaredType, ExpressionSyntax expression, string path, HashSet <string> usings)
 {
     Value        = value;
     DeclaredType = declaredType;
     Expression   = expression;
     if (value != null)
     {
         ActualType = value.GetType();
         if (DeclaredType != ActualType && !ActualType.IsAssignableFrom(DeclaredType) && DeclaredType != typeof(Type))
         {
             Expression = Cast(expression, ActualType, usings);
         }
     }
     else
     {
         ActualType = null;
     }
     Path   = path;
     Usings = usings;
 }
        public IEnumerable <AssertInstanceReference> Dictionary()
        {
            var enumer     = Value as System.Collections.IDictionary;
            var declaredKv = ActualType.GetDictionaryParameters();

            foreach (var key in enumer.Keys)
            {
                var value    = enumer[key];
                var instance = new AssertInstanceReference(
                    value,
                    declaredKv.Item1,
                    Bracket(Expression, declaredKv.Item1, key),
                    $"value for {key} in {Path}",
                    Usings)

                {
                    AssertionName  = AssertionName,
                    IterationDepth = this.IterationDepth + 1
                };

                yield return(instance);
            }
        }
Exemple #11
0
 private string ComputeTypeToSerializeTo()
 {
     if (Member.HasAttributeExact <EnumSizeAttribute>())
     {
         PrimitiveSizeType sizeType = EnumSizeAttribute.Parse(Member.GetAttributeExact <EnumSizeAttribute>().ConstructorArguments.First().ToCSharpString());
         return(sizeType.ToString());
     }
     else
     {
         //This is hacky but covers the case that enum array types can use this emitter.
         if (ActualType.IsEnumType())
         {
             return(ActualType.GetEnumUnderlyingType().Name);
         }
         else if (ActualType is IArrayTypeSymbol arraySymbol)
         {
             return(arraySymbol.ElementType.GetEnumUnderlyingType().Name);
         }
         else
         {
             throw new NotSupportedException($"Type: {ActualType.Name} cannot emit enum serialization.");
         }
     }
 }
Exemple #12
0
 public IType[] GetTypeConstraints()
 {
     return(Array.ConvertAll <Type, IType>(
                ActualType.GetGenericParameterConstraints(),
                _provider.Map));
 }
Exemple #13
0
 public IType[] GetTypeConstraints()
 {
     return(Array.ConvertAll <Type, IType>(
                ActualType.GetGenericParameterConstraints(),
                _typeSystemServices.Map));
 }
Exemple #14
0
 public override bool Assignable(TigerType tigerType)
 {
     return(ActualType.Assignable(tigerType));
 }
        public override object Instantiate(CompactBinaryReader reader)
        {
            int length = reader.ReadInt32();

            return(Array.CreateInstance(ActualType.GetElementType(), length));
        }
Exemple #16
0
 public override string ToString()
 {
     return(base.ToString() + $"Invalid type: expected {ExpectedTypesList} but got {ActualType.ToString().ToLower()}.");
 }
Exemple #17
0
 public override string ToString()
 {
     return(ActualType.ToString());
 }
 public Array CreateInstance(int len)
 {
     return(Array.CreateInstance(ActualType.GetElementType(), len));
 }
Exemple #19
0
 protected virtual MemberInfo[] GetDefaultMembers()
 {
     return(ActualType.GetDefaultMembers());
 }