internal void Validate(Type implementationType) { this.FillPropertyChain(implementationType, true); PropertyInfo property = PropertyChain.Last(); foreach (Type implementedInterface in new Type[] { property.PropertyType }.Concat(property.PropertyType.GetInterfaces())) { if (implementedInterface.IsGenericType && (implementedInterface.GetGenericTypeDefinition() == typeof(ICollection <>))) { this.CollectionElementType = implementedInterface.GetGenericArguments()[0]; this.CollectionType = PropertyCollectionType.GenericCollection; break; } } if (this.CollectionType == PropertyCollectionType.None) { throw new ConfigurationErrorsException( "Implementation type '{0}' collection property '{1}' of type '{2}' is not supported.".FormatInvariant(implementationType, this.PropertyName, property.PropertyType), this.ElementInformation.Source, this.ElementInformation.LineNumber); } }
//public TypeVisualProperty() //{ //} public TypeVisualProperty(string name, string type, PropertyAttribute attribute, PropertyCollectionType collectionType, string collectionKey) { this.name = name; this.type = type; this.attribute = attribute; this.collectionType = collectionType; this.collectionKey = collectionKey; }
//public TypeVisualProperty() //{ //} public TypeVisualProperty(string name, string type, PropertyAttribute attribute, PropertyCollectionType collectionType, string collectionKey) { this.name = name; this.type = type; this.attribute = attribute; this.collectionType = collectionType; this.collectionKey = collectionKey; }
/// <summary> /// This ctor should be used by anything that emits code. Emit limiters are always emitted /// as int types regardless of the wire type and as such a check will be made for the /// parameter being bound before use. The check for all other parameters is done based on /// whether they could be a nullable value type. /// </summary> /// <param name="propertyInfo"></param> /// <param name="parent"></param> /// <param name="propertyTypeName"></param> /// <param name="documentationSource"></param> /// <param name="collectionType"></param> /// <param name="genericCollectionTypes"></param> public SimplePropertyInfo(PropertyInfo propertyInfo, SimplePropertyInfo parent, string propertyTypeName, XmlDocument documentationSource, PropertyCollectionType collectionType, Type[] genericCollectionTypes) { BaseProperty = propertyInfo; Name = propertyInfo.Name; PropertyType = propertyInfo.PropertyType; PropertyTypeName = propertyTypeName; DeclaringType = propertyInfo.DeclaringType; DeprecationMessage = propertyInfo.GetCustomAttributes(typeof(ObsoleteAttribute), false).Cast <ObsoleteAttribute>().FirstOrDefault()?.Message; dynamic awsPropertyAttribute = propertyInfo.GetCustomAttributes().Where(attribute => attribute.GetType().FullName == "Amazon.Runtime.Internal.AWSPropertyAttribute").SingleOrDefault(); if (awsPropertyAttribute != null) { IsRequired = awsPropertyAttribute?.Required; MinValue = awsPropertyAttribute.IsMinSet ? awsPropertyAttribute.Min : null; MaxValue = awsPropertyAttribute.IsMaxSet ? awsPropertyAttribute.Max : null; } CollectionType = collectionType; GenericCollectionTypes = genericCollectionTypes; Parent = parent; Children = new List <SimplePropertyInfo>(); IsReadWrite = propertyInfo.CanRead && propertyInfo.CanWrite; DocumentationSource = documentationSource; IsMemoryStreamType = typeof(System.IO.MemoryStream).IsAssignableFrom(PropertyType); IsStreamType = typeof(System.IO.Stream).IsAssignableFrom(PropertyType); IsDocumentType = PropertyType.FullName == "Amazon.Runtime.Documents.Document"; UseParameterValueOnlyIfBound = IsNullableValueType(propertyInfo.PropertyType); // if analysing properties on a cmdlet for help purposes, extract // the Parameter, AWSRequiredParameter and Alias attributes info PsParameterAttribute = propertyInfo.GetCustomAttributes(typeof(ParameterAttribute), false) as ParameterAttribute[]; PsAliasAttribute = propertyInfo.GetCustomAttributes(typeof(AliasAttribute), false).SingleOrDefault() as AliasAttribute; IsRequiredForParameterSets = GetRequiredHelpDescription(propertyInfo); IsConstrainedToSet = PropertyType.BaseType != null && PropertyType.BaseType.FullName.Equals(ConstantClassBaseTypeName, StringComparison.Ordinal); }
/// <summary> /// Recursively fills the units dictionary with a TypeVisualisationUnit of the Guid - typeNodeId. /// </summary> /// <param name="typeNodeId"></param> /// <param name="units"></param> /// <param name="ignoreTypeNames"></param> private void GetTypeVisualUnitsRecursive(Guid typeNodeId, IDictionary <String, TypeVisualUnit> units, ICollection <string> ignoreTypeNames) { TypeVisualUnit unit = null; string typeName = null; ICollection <TypeVisualProperty> scalarProperties = new List <TypeVisualProperty>(); ICollection <TypeVisualProperty> nonScalarProperties = new List <TypeVisualProperty>(); if (!typeNodeId.Equals(Guid.Empty)) { var typeNode = provider.GetNode(typeNodeId, NodeAccess.Read); typeName = TypeVisualUtilities.GetTypeNameFromAssemblyName((string)typeNode.Data); if (!ignoreTypeNames.Contains(typeName)) { ignoreTypeNames.Add(typeName); foreach (var edge in typeNode.Edges.Values) { if (edge.Data.Semantic.Equals(EdgeType.Property)) { //setting name and type bool isScalar; var nodeProperty = provider.GetNode(edge.ToNodeId, NodeAccess.Read); var nodePropertyType = provider.GetNode(nodeProperty.Edges.Values[0].ToNodeId, NodeAccess.Read); string propertyTypeName = TypeVisualUtilities.GetTypeNameFromAssemblyName((string)nodePropertyType.Data); string collectionKey, collectionValue; PropertyCollectionType collectionType = TypeVisualUtilities.CheckIfCollectionOrDictionary(propertyTypeName, out collectionKey, out collectionValue); //checking if property is a collection and if property is scalar. if (collectionType != PropertyCollectionType.NotACollection) { if (!typesService.IsSupportedScalarTypeName(collectionValue)) { Guid genericArgumentTypeId = GetIdFromTypeName(collectionValue); if (!genericArgumentTypeId.Equals(Guid.Empty)) { //ignoreTypeNames.Add(typeName); GetTypeVisualUnitsRecursive(genericArgumentTypeId, units, ignoreTypeNames); } isScalar = false; } else { isScalar = true; } propertyTypeName = collectionValue; } else if (!typesService.IsSupportedScalarTypeName(propertyTypeName)) { //ignoreTypeNames.Add(typeName); GetTypeVisualUnitsRecursive(nodeProperty.Edges.Values[0].ToNodeId, units, ignoreTypeNames); isScalar = false; } else { isScalar = true; } //setting additional property attributes bool isImmutable, isPrimaryKey; PropertyAttribute propAttribute; isImmutable = edge.Data.Flags.Equals(EdgeFlags.Permanent); isPrimaryKey = nodeProperty.Values.ContainsKey(Constants.TypeMemberPrimaryKeyId); if (isImmutable && isPrimaryKey) { propAttribute = PropertyAttribute.PrimaryKeyAndImmutableProperty; } else if (isImmutable) { propAttribute = PropertyAttribute.ImmutableProperty; } else if (isPrimaryKey) { propAttribute = PropertyAttribute.PrimaryKeyProperty; } else { propAttribute = PropertyAttribute.None; } //adding the property to either scalar or non-scalar lists. TypeVisualProperty property = new TypeVisualProperty((string)nodeProperty.Data, propertyTypeName, propAttribute, collectionType, collectionKey); if (isScalar) { scalarProperties.Add(property); } else { nonScalarProperties.Add(property); } } else if (edge.Data.Semantic.Equals(EdgeType.Contains)) { var nodeProperty = provider.GetNode(edge.ToNodeId, NodeAccess.Read); TypeVisualProperty property = new TypeVisualProperty((string)nodeProperty.Data, TypeVisualProperty.EnumType, PropertyAttribute.None, PropertyCollectionType.NotACollection, ""); scalarProperties.Add(property); } } unit = new TypeVisualUnit(typeName, scalarProperties, nonScalarProperties); units.Add(unit.Name, unit); } } }