public static IEnumerable <string> GetPropertyValues(object ruleInfo, PropertyInfo propertyInfo, Action <string> emitError, LintDictionaryReference dictionaryReference = LintDictionaryReference.None) { var type = propertyInfo.PropertyType; if (type == typeof(string)) { return new[] { (string)propertyInfo.GetValue(ruleInfo) } } ; if (typeof(IEnumerable).IsAssignableFrom(type)) { return((IEnumerable <string>)propertyInfo.GetValue(ruleInfo)); } if (type == typeof(BooleanExpression) || type == typeof(IntegerExpression)) { var expr = (VariableExpression)propertyInfo.GetValue(ruleInfo); return(expr != null ? expr.Variables : Enumerable.Empty <string>()); } if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary <,>)) { // Use an intermediate list to cover the unlikely case where both keys and values are lintable var dictionaryValues = new List <string>(); if (dictionaryReference.HasFlag(LintDictionaryReference.Keys) && type.GenericTypeArguments[0] == typeof(string)) { dictionaryValues.AddRange((IEnumerable <string>)((IDictionary)propertyInfo.GetValue(ruleInfo)).Keys); } if (dictionaryReference.HasFlag(LintDictionaryReference.Values) && type.GenericTypeArguments[1] == typeof(string)) { dictionaryValues.AddRange((IEnumerable <string>)((IDictionary)propertyInfo.GetValue(ruleInfo)).Values); } if (dictionaryReference.HasFlag(LintDictionaryReference.Values) && type.GenericTypeArguments[1] == typeof(IEnumerable <string>)) { foreach (var row in (IEnumerable <IEnumerable <string> >)((IDictionary)propertyInfo.GetValue(ruleInfo)).Values) { dictionaryValues.AddRange(row); } } return(dictionaryValues); } var supportedTypes = new[] { "string", "IEnumerable<string>", "Dictionary<string, T> (LintDictionaryReference.Keys)", "Dictionary<T, string> (LintDictionaryReference.Values)", "Dictionary<T, IEnumerable<string>> (LintDictionaryReference.Values)", "BooleanExpression", "IntegerExpression" }; throw new InvalidOperationException("Bad type for reference on {0}.{1}. Supported types: {2}" .F(ruleInfo.GetType().Name, propertyInfo.Name, supportedTypes.JoinWith(", "))); } }
public SequenceReferenceAttribute(string imageReference = null, bool prefix = false, bool allowNullImage = false, LintDictionaryReference dictionaryReference = LintDictionaryReference.None) { ImageReference = imageReference; Prefix = prefix; AllowNullImage = allowNullImage; DictionaryReference = dictionaryReference; }
public CursorReferenceAttribute(LintDictionaryReference dictionaryReference = LintDictionaryReference.None) { DictionaryReference = dictionaryReference; }
public ActorReferenceAttribute(Type requiredTrait = null, LintDictionaryReference dictionaryReference = LintDictionaryReference.None) { RequiredTraits = requiredTrait != null ? new[] { requiredTrait } : new Type[0]; DictionaryReference = dictionaryReference; }
public ActorReferenceAttribute(Type[] requiredTraits, LintDictionaryReference dictionaryReference = LintDictionaryReference.None) { RequiredTraits = requiredTraits; DictionaryReference = dictionaryReference; }
public ActorReferenceAttribute(Type requiredTrait = null, LintDictionaryReference dictionaryReference = LintDictionaryReference.None) { RequiredTraits = requiredTrait != null ? new[] { requiredTrait } : Array.Empty <Type>(); DictionaryReference = dictionaryReference; }