public void GetCustomAttribute4()
        {
            IEnumerable <Attribute> attributes = CustomAttributeExtensions.GetCustomAttributes(s_typeTestClass.GetTypeInfo(), typeof(MyAttribute_AllowMultiple_Inherited));

            Assert.Equal(2, attributes.Count());

            attributes = CustomAttributeExtensions.GetCustomAttributes(s_typeTestClass.GetTypeInfo(), typeof(SecurityCriticalAttribute));
            Assert.Equal(0, attributes.Count());

            AssertExtensions.Throws <ArgumentException>(null, () =>
            {
                attributes = CustomAttributeExtensions.GetCustomAttributes(s_typeTestClass.GetTypeInfo(), typeof(String));
            });

            Assert.Throws <ArgumentNullException>(() =>
            {
                attributes = CustomAttributeExtensions.GetCustomAttributes(s_typeTestClass.GetTypeInfo(), null);
            });
        }
示例#2
0
        public static List <Tuple <int, string> > GetEnumToString <T>() where T : struct
        {
            List <Tuple <int, string> > list = new List <Tuple <int, string> >();
            Type type = typeof(T);

            type.GetFields().Where(t => t.FieldType == type).ToList().ForEach(t =>
            {
                DescriptionAttribute customAttribute = CustomAttributeExtensions.GetCustomAttribute <DescriptionAttribute>(t);
                if (customAttribute != null && !string.IsNullOrEmpty(customAttribute.Description))
                {
                    list.Add(new Tuple <int, string>((int)t.GetValue(null), customAttribute.Description));
                }
                else
                {
                    list.Add(new Tuple <int, string>((int)t.GetValue(null), t.Name));
                }
            });
            return(list);
        }
示例#3
0
        public SqliteSchemaBuilder()
        {
            var type = typeof(T);

            var tableAttribute = type.GetCustomAttribute <SqliteTableAttribute>();

            if (tableAttribute == null)
            {
                throw new ArgumentException("Given type does not have the SqliteTable attribute");
            }

            TableName = tableAttribute.Name;

            var columns = (from property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)
                           let columnAttribute =
                               CustomAttributeExtensions.GetCustomAttribute <SqliteColumnAttribute>((MemberInfo)property)
                               let keyAttribute = property.GetCustomAttribute <SqliteKeyAttribute>()
                                                  where columnAttribute != null
                                                  select new
            {
                property,
                columnAttribute,
                keyAttribute
            }).ToList();

            if (columns.Count == 0)
            {
                throw new ArgumentException("Given type does not have any SqliteColumn attributes");
            }

            Keys = (from column in columns
                    where column.keyAttribute != null
                    select column.columnAttribute.ResolveName(column.property)).ToList();

            Columns = (from column in columns
                       select new
            {
                column.property.Name,
                Value = new Tuple <SqliteColumnAttribute, PropertyInfo>(column.columnAttribute,
                                                                        column.property)
            }).ToDictionary(k => k.Name, v => v.Value);
        }
示例#4
0
        /// <summary>
        /// Determines the collectionname from the specified type.
        /// </summary>
        /// <param name="entitytype">The type of the entity to get the collectionname from.</param>
        /// <returns>Returns the collectionname from the specified type.</returns>
        private static string GetCollectionNameFromType()
        {
            Type   entitytype = typeof(T);
            string collectionname;

            // Check to see if the object (inherited from Entity) has a CollectionName attribute
            var att = CustomAttributeExtensions.GetCustomAttribute <CollectionNameAttribute>(typeof(T).GetTypeInfo().Assembly);

            if (att != null)
            {
                // It does! Return the value specified by the CollectionName attribute
                collectionname = att.Name;
            }
            else
            {
                collectionname = entitytype.Name;
            }

            return(collectionname);
        }
        private void EvaluateValidationAttributes(ParameterInfo parameter, object argument, ModelStateDictionary modelState)
        {
            var validationAttributes = parameter.CustomAttributes;

            foreach (var attributeData in validationAttributes)
            {
                var attributeInstance = CustomAttributeExtensions.GetCustomAttribute(parameter, attributeData.AttributeType);

                var validationAttribute = attributeInstance as ValidationAttribute;

                if (validationAttribute != null)
                {
                    var isValid = validationAttribute.IsValid(argument);
                    if (!isValid)
                    {
                        modelState.AddModelError(parameter.Name, validationAttribute.FormatErrorMessage(parameter.Name));
                    }
                }
            }
        }
示例#6
0
        /// <summary>
        ///     Retrieves or creates the store item for the given type
        /// </summary>
        /// <param name="type">The type whose store item is needed.  It cannot be null</param>
        /// <returns>The type store item.  It will not be null.</returns>
        private TypeStoreItem GetTypeStoreItem(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            lock (_typeStoreItems)
            {
                TypeStoreItem item = null;
                if (!_typeStoreItems.TryGetValue(type, out item))
                {
                    // use CustomAttributeExtensions.GetCustomAttributes() to get inherited attributes as well as direct ones
                    var attributes = CustomAttributeExtensions.GetCustomAttributes(type.GetTypeInfo(), true);
                    item = new TypeStoreItem(type, attributes);
                    _typeStoreItems[type] = item;
                }
                return(item);
            }
        }
示例#7
0
        /// <summary>
        /// Gets test extensions from a given assembly.
        /// </summary>
        /// <param name="assembly">Assembly to check for test extension availability</param>
        /// <param name="pluginInfos">Test extensions collection to add to.</param>
        /// <typeparam name="TPluginInfo">
        /// Type of Test Plugin Information.
        /// </typeparam>
        /// <typeparam name="TExtension">
        /// Type of Extensions.
        /// </typeparam>
        private void GetTestExtensionsFromAssembly <TPluginInfo, TExtension>(Assembly assembly, Dictionary <string, TPluginInfo> pluginInfos) where TPluginInfo : TestPluginInformation
        {
            Debug.Assert(assembly != null, "null assembly");
            Debug.Assert(pluginInfos != null, "null pluginInfos");
            IEnumerable <Type> types;
            Type extension = typeof(TExtension);

            try
            {
                var customAttribute = CustomAttributeExtensions.GetCustomAttribute(assembly, typeof(TypesToLoadAttribute)) as TypesToLoadAttribute;
                if (customAttribute != null)
                {
                    types = customAttribute.Types;
                }
                else
                {
                    types = assembly.GetTypes().Where(type => type.GetTypeInfo().IsClass&& !type.GetTypeInfo().IsAbstract);
                }
            }
            catch (ReflectionTypeLoadException e)
            {
                EqtTrace.Warning("TestPluginDiscoverer: Failed to get types from assembly '{0}'.  Skipping test extension scan for this assembly.  Error: {1}", assembly.FullName, e.ToString());

                if (e.LoaderExceptions != null)
                {
                    foreach (var ex in e.LoaderExceptions)
                    {
                        EqtTrace.Warning("LoaderExceptions: {0}", ex);
                    }
                }
                return;
            }

            if (types != null && types.Any())
            {
                foreach (var type in types)
                {
                    GetTestExtensionFromType(type, extension, pluginInfos);
                }
            }
        }
示例#8
0
        public static List <Tuple <int, string> > GetStrings <T>() where T : struct
        {
            List <Tuple <int, string> > list = new List <Tuple <int, string> >();
            Type type = typeof(T);

            (from t in type.GetFields()
             where t.FieldType == type
             select t).ToList().ForEach((Action <FieldInfo>) delegate(FieldInfo t)
            {
                DescriptionAttribute customAttribute = CustomAttributeExtensions.GetCustomAttribute <DescriptionAttribute>((MemberInfo)t);
                if (customAttribute != null && !string.IsNullOrEmpty(customAttribute.Description))
                {
                    list.Add(new Tuple <int, string>((int)t.GetValue(null), customAttribute.Description));
                }
                else
                {
                    list.Add(new Tuple <int, string>((int)t.GetValue(null), t.Name));
                }
            });
            return(list);
        }
        private static bool IsValidDescriptionField(string descriptionValue, FieldInfo field)
        {
#if NET_CORE
            var descriptionAttribute = CustomAttributeExtensions.GetCustomAttribute(field, typeof(LanguageAttribute));
#else
            var descriptionAttribute = Attribute.GetCustomAttribute(field, typeof(LanguageAttribute));
#endif

            if (descriptionAttribute == null)
            {
                return(false);
            }

            var attribute = ((LanguageAttribute)descriptionAttribute);
            if (!attribute.HasMultipleCodes)
            {
                return(attribute.Code == descriptionValue);
            }

            return(attribute.Codes.Any(x => x == descriptionValue));
        }
        public void GetCustomAttributeOfT()
        {
            Assembly  thisAsm = typeof(GetCustomAttributes_Assembly).GetTypeInfo().Assembly;
            Attribute attribute;

            attribute = CustomAttributeExtensions.GetCustomAttribute <SecurityCriticalAttribute>(thisAsm);
            Assert.Null(attribute);

            AssertExtensions.Throws <ArgumentException>(null, () =>
            {
                CustomAttributeExtensions.GetCustomAttributes(thisAsm, typeof(string));
            });

            attribute = CustomAttributeExtensions.GetCustomAttribute <MyAttribute_Single>(thisAsm);
            Assert.Equal("System.Reflection.Tests.MyAttribute_Single single", attribute.ToString());

            Assert.Throws <AmbiguousMatchException>(() =>
            {
                attribute = CustomAttributeExtensions.GetCustomAttribute <Attribute>(thisAsm);
            });
        }
        public void SetCustomAttribute_CustomAttributeBuilder()
        {
            TypeBuilder        type        = Helpers.DynamicType(TypeAttributes.Public);
            ConstructorBuilder constructor = type.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[0]);
            ILGenerator        ilGenerator = constructor.GetILGenerator();

            ilGenerator.Emit(OpCodes.Ldarg_1);

            ConstructorInfo        attributeConstructor = typeof(IntAllAttribute).GetConstructor(new Type[] { typeof(int) });
            CustomAttributeBuilder attributeBuilder     = new CustomAttributeBuilder(attributeConstructor, new object[] { 2 });

            constructor.SetCustomAttribute(attributeBuilder);
            Type createdType = type.CreateType();

            ConstructorInfo createdConstructor = createdType.GetConstructor(new Type[0]);

            Attribute[] customAttributes = (Attribute[])CustomAttributeExtensions.GetCustomAttributes(createdConstructor, true).ToArray();

            Assert.Equal(1, customAttributes.Length);
            Assert.Equal(2, ((IntAllAttribute)customAttributes[0])._i);
        }
        public void GetCustomAttributeSingle()
        {
            Attribute attribute = CustomAttributeExtensions.GetCustomAttribute(s_typeTestClass.GetTypeInfo(), typeof(MyAttribute_Single_M));

            Assert.NotNull(attribute);

            Assert.Throws <AmbiguousMatchException>(() =>
            {
                attribute = CustomAttributeExtensions.GetCustomAttribute(s_typeTestClass.GetTypeInfo(), typeof(MyAttribute_AllowMultiple_Inherited));
            });

            Assert.Throws <ArgumentException>(() =>
            {
                attribute = CustomAttributeExtensions.GetCustomAttribute(s_typeTestClass.GetTypeInfo(), typeof(String));
            });

            Assert.Throws <ArgumentNullException>(() =>
            {
                attribute = CustomAttributeExtensions.GetCustomAttribute(s_typeTestClass.GetTypeInfo(), null);
            });
        }
        private static bool HasIndexablePropertyOnLeft <Key>(Expression leftSide, BTreeBase <Key, Key> sourceCollection, DataMember dataMember, out MemberExpression theMember)
#if WINDOWS_PHONE
            where Key : new()
#endif
        {
            theMember = null;
            MemberExpression mex = leftSide as MemberExpression;

            if (leftSide.NodeType == ExpressionType.Convert)
            {
                UnaryExpression convert = leftSide as UnaryExpression;
                mex = convert.Operand as MemberExpression;
            }
            if (leftSide.NodeType == ExpressionType.Call)
            {
                MethodCallExpression call = leftSide as MethodCallExpression;
                if (call.Method.Name == "CompareString")
                {
                    mex = call.Arguments[0] as MemberExpression;
                }
            }
            else if (mex == null)
            {
                return(false);
            }
            else
            {
                theMember = mex;
                if (dataMember.Field.Name == mex.Member.Name)
                {
                    return(true);
                }
                FieldAccessor accessor = CustomAttributeExtensions.GetCustomAttribute <FieldAccessor>(theMember.Member, true);
                if (accessor != null)
                {
                    return(dataMember.Field.Name == accessor.FieldName);
                }
            }
            return(false);
        }
示例#14
0
        public T DecodeTopics <T>(object[] topics, string data) where T : new()
        {
            var type   = typeof(T);
            var result = new T();

            var properties  = GetPropertiesWithParameterAttributes(type.GetTypeInfo().DeclaredProperties.ToArray());
            var topicNumber = 0;

            foreach (var topic in topics)
            {
                //skip the first one as it is the signature
                if (topicNumber > 0)
                {
                    var property  = properties.FirstOrDefault(x => CustomAttributeExtensions.GetCustomAttribute <ParameterAttribute>((MemberInfo)x).Order == topicNumber);
                    var attribute = CustomAttributeExtensions.GetCustomAttribute <ParameterAttribute>(property);
                    //skip dynamic types as the topic value is the sha3 keccak
                    if (!attribute.Parameter.ABIType.IsDynamic())
                    {
                        result = DecodeAttributes(topic.ToString(), result, property);
                    }
                    else
                    {
                        if (property.PropertyType != typeof(string))
                        {
                            throw new Exception(
                                      "Indexed Dynamic Types (string, arrays) value is the Keccak SHA3 of the value, the property type of " +
                                      property.Name + "should be a string");
                        }

                        property.SetValue(result, topic.ToString());
                    }
                }
                topicNumber = topicNumber + 1;
            }

            var dataProperties = properties.Where(x => x.GetCustomAttribute <ParameterAttribute>().Order >= topicNumber);

            result = DecodeAttributes(data, result, dataProperties.ToArray());
            return(result);
        }
示例#15
0
        public IEnumerable <App> Create()
        {
            foreach (var component in ComponentRepository.GetAll())
            {
                foreach (var type in AppTypeProvider.GetTypes(component))
                {
                    var attribute = CustomAttributeExtensions.GetCustomAttribute <AppAttribute>(type);

                    var translationAttribute = CustomAttributeExtensions.GetCustomAttribute <TranslationsAttribute>(type);
                    var translations         = translationAttribute != null?TranslationRepositoryCreator.Create(component.Id + "/" + translationAttribute.Path) : new EmptyTranslationRepository();

                    yield return(new App(
                                     attribute.Id,
                                     component,
                                     scripts: ScriptCreator.Create(component.Id, type),
                                     styles: StyleCreator.Create(component.Id, type),
                                     resources: ResourceCreator.Create(component.Id, type),
                                     translations: translations
                                     ));
                }
            }
        }
示例#16
0
        public static void InvokeAutoRegister()
        {
            var factoryTypes = typeof(AutoResisterRendererResourceFactories).GetNestedTypes(BindingFlags.Public);

            foreach (var factoryType in factoryTypes)
            {
#if !UNITY_EDITOR && (ENABLE_DOTNET || (UNITY_WINRT && !ENABLE_IL2CPP))
                if (!factoryType.GetTypeInfo().IsSubclassOf(typeof(RendererResourceFactory)))
                {
#else
                if (!factoryType.IsSubclassOf(typeof(RendererResourceFactory)))
                {
#endif
                    UnityEngine.Debug.LogError("[CRIWARE] internal logic error. " + factoryType.Name + " is required to be a subclass of RendererResourceFactory.");
                    continue;
                }
#if !UNITY_EDITOR && (ENABLE_DOTNET || (UNITY_WINRT && !ENABLE_IL2CPP))
                var priorityAttribute = (RendererResourceFactoryPriorityAttribute)CustomAttributeExtensions.GetCustomAttribute(
                    factoryType.GetTypeInfo(),
                    typeof(RendererResourceFactoryPriorityAttribute)
                    );
#else
                var priorityAttribute = (RendererResourceFactoryPriorityAttribute)System.Attribute.GetCustomAttribute(
                    factoryType,
                    typeof(RendererResourceFactoryPriorityAttribute)
                    );
#endif
                if (priorityAttribute == null)
                {
                    UnityEngine.Debug.LogError("[CRIWARE] internal logic error. need priority attribute. (" + factoryType.Name + ")");
                    continue;
                }
                RendererResourceFactory.RegisterFactory(
                    (RendererResourceFactory)System.Activator.CreateInstance(factoryType),
                    priorityAttribute.priority
                    );
            }
        }
    }
示例#17
0
        public ActionTransform(IContext context = null) : base(context, "string")
        {
            if (IsMissingContext())
            {
                return;
            }

            if (IsMissing(Context.Operation.Property))
            {
                return;
            }

#if NETS10
            _props = typeof(Action).GetRuntimeProperties().Where(prop => CustomAttributeExtensions.GetCustomAttribute((MemberInfo)prop, typeof(CfgAttribute), (bool)true) != null).Select(prop => prop.Name).ToArray();
#else
            _props = typeof(Action).GetProperties().Where(prop => prop.GetCustomAttributes(typeof(CfgAttribute), true).FirstOrDefault() != null).Select(prop => prop.Name).ToArray();
#endif

            var set = new HashSet <string>(_props, StringComparer.OrdinalIgnoreCase);

            if (!set.Contains(Context.Operation.Property))
            {
                Error($"The action property {Context.Operation.Property} is not allowed.  The allowed properties are {(string.Join(", ", _props))}.");
                Run = false;
                return;
            }

            Context.Operation.Property = set.First(s => s.Equals(Context.Operation.Property, StringComparison.OrdinalIgnoreCase));

            if (Context.Operation.Index < Context.Process.Actions.Count)
            {
                _action = Context.Process.Actions[Context.Operation.Index];
            }
            else
            {
                Run = false;
                Context.Error($"action index {Context.Operation.Index} is out of bounds");
            }
        }
示例#18
0
        private string GetRuntimeVersionNumber()
        {
            // Get version number that is used in the deployment folder
            Assembly runtimeAssembly = typeof(ArcGISRuntimeEnvironment).GetTypeInfo().Assembly;

            var sdkVersion = string.Empty;
            var attr       = CustomAttributeExtensions.GetCustomAttribute <AssemblyFileVersionAttribute>(runtimeAssembly);

            if (attr != null)
            {
                var      version  = attr.Version;
                string[] versions = attr.Version.Split(new[] { '.' });

                // Ensure that we only look maximum of 3 part version number ie. 10.2.4
                int partCount = 3;
                if (versions.Count() < 3)
                {
                    partCount = versions.Count();
                }

                for (var i = 0; i < partCount; i++)
                {
                    if (string.IsNullOrEmpty(sdkVersion))
                    {
                        sdkVersion = versions[i];
                    }
                    else
                    {
                        sdkVersion += "." + versions[i];
                    }
                }
            }
            else
            {
                throw new Exception("Cannot read version number from ArcGIS Runtime");
            }

            return(sdkVersion);
        }
示例#19
0
        public static List <Tuple <int, string> > GetEnumToString(this Type enumType)
        {
            if (!enumType.GetTypeInfo().IsEnum)
            {
                throw new Exception("The type is not Enum");
            }
            List <Tuple <int, string> > list = new List <Tuple <int, string> >();

            enumType.GetFields().Where(t => t.FieldType == enumType).ToList().ForEach(t =>
            {
                DescriptionAttribute customAttribute = CustomAttributeExtensions.GetCustomAttribute <DescriptionAttribute>(t);
                if (customAttribute != null && !string.IsNullOrEmpty(customAttribute.Description))
                {
                    list.Add(new Tuple <int, string>((int)t.GetValue(null), customAttribute.Description));
                }
                else
                {
                    list.Add(new Tuple <int, string>((int)t.GetValue(null), t.Name));
                }
            });
            return(list);
        }
示例#20
0
        public static void Configure(ConfigurationBuilder builder)
        {
            var componentViewModelTypes = typeof(ReinforcedTypingsConfiguration).Assembly.GetTypes()
                                          .Where(t => CustomAttributeExtensions.GetCustomAttribute <TsInterfaceAttribute>(t) != null)
                                          .Concat(ExternalTypes());

            foreach (var componentViewModelType in componentViewModelTypes)
            {
                builder.ExportAsInterfaces(new [] { componentViewModelType }, b =>
                {
                    b.AutoI(false);
                    b.WithAllMethods(m => m.Ignore())
                    .WithAllProperties();

                    var fileName = componentViewModelType.IsGenericType ?
                                   componentViewModelType.Name.Substring(0, componentViewModelType.Name.IndexOf('`')) :
                                   componentViewModelType.Name;

                    b.ExportTo(string.Join(
                                   Path.DirectorySeparatorChar.ToString(),
                                   componentViewModelType.Namespace.Split('.').Skip(2).Concat(new [] { $"{fileName}.csharp.ts" })));
                });
            }

            var enumTypes = typeof(ReinforcedTypingsConfiguration).Assembly.GetTypes()
                            .Where(t => t.GetCustomAttribute <TsEnumAttribute>() != null)
                            .Concat(ExternalEnums());

            foreach (var enumType in enumTypes)
            {
                builder.ExportAsEnums(new [] { enumType }, b =>
                {
                    b.ExportTo(string.Join(
                                   Path.DirectorySeparatorChar.ToString(),
                                   enumType.Namespace.Split('.').Skip(2).Concat(new [] { $"{enumType.Name}.csharp.ts" })));
                });
            }
        }
        public void GetCustomAttribute_General_NoInherit()
        {
            Type          type = typeof(TestClass_P);
            MethodInfo    miWithoutAttributes = type.GetTypeInfo().GetDeclaredMethod("methodWithoutAttribute");
            ParameterInfo piWithoutAttributes = miWithoutAttributes.GetParameters()[0];

            MethodInfo    miWithAttributes = type.GetTypeInfo().GetDeclaredMethod("methodWithAttribute");
            ParameterInfo piWithAttributes = miWithAttributes.GetParameters()[0];

            IEnumerable <Attribute> attributes;


            attributes = CustomAttributeExtensions.GetCustomAttributes(piWithoutAttributes, false);
            Assert.Equal(0, attributes.Count());

            attributes = CustomAttributeExtensions.GetCustomAttributes(piWithAttributes, false);
            Assert.Equal(5, attributes.Count());
            Assert.Equal(1, attributes.Count(attr => attr.ToString().Equals("System.Reflection.Tests.MyAttribute_Single_P single", StringComparison.Ordinal)));
            Assert.Equal(1, attributes.Count(attr => attr.ToString().Equals("System.Reflection.Tests.MyAttribute_AllowMultiple_P multiple1", StringComparison.Ordinal)));
            Assert.Equal(1, attributes.Count(attr => attr.ToString().Equals("System.Reflection.Tests.MyAttribute_AllowMultiple_P multiple2", StringComparison.Ordinal)));
            Assert.Equal(1, attributes.Count(attr => attr.ToString().Equals("System.Reflection.Tests.MyAttribute_Single_Inherited_P single", StringComparison.Ordinal)));
            Assert.Equal(1, attributes.Count(attr => attr.ToString().Equals("System.Reflection.Tests.MyAttribute_AllowMultiple_Inherited_P multiple", StringComparison.Ordinal)));
        }
示例#22
0
        public T DecodeTopics <T>(object[] topics, string data) where T : new()
        {
            var type   = typeof(T);
            var result = new T();

            var properties  = GetPropertiesWithParameterAttributes(type.GetProperties());
            var topicNumber = 0;

            foreach (var topic in topics)
            {
                //skip the first one as it is the signature
                if (topicNumber > 0)
                {
                    var property = properties.FirstOrDefault(x => CustomAttributeExtensions.GetCustomAttribute <ParameterAttribute>((MemberInfo)x).Order == topicNumber);
                    result = DecodeAttributes(topic.ToString(), result, property);
                }
                topicNumber = topicNumber + 1;
            }

            var dataProperties = properties.Where(x => x.GetCustomAttribute <ParameterAttribute>().Order >= topicNumber);

            result = DecodeAttributes(data, result, dataProperties.ToArray());
            return(result);
        }
示例#23
0
        private static string GetDisplayNameForProperty(Type containerType, string propertyName)
        {
            var property = containerType.GetRuntimeProperties()
                           .SingleOrDefault(
                prop =>
                IsPublic(prop) &&
                string.Equals(propertyName, prop.Name, StringComparison.OrdinalIgnoreCase));

            if (property == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                                          SR.Common_PropertyNotFound, containerType.FullName, propertyName));
            }

            var attributes = CustomAttributeExtensions.GetCustomAttributes(property, true);
            var display    = attributes.OfType <DisplayAttribute>().FirstOrDefault();

            if (display != null)
            {
                return(display.GetName());
            }

            return(propertyName);
        }
示例#24
0
        /// <summary>
        /// Get available attributes on test method
        /// </summary>
        /// <param name="methodInfo"></param>
        /// <returns></returns>
        private IList <Type> GetAvailableAttributes(MethodInfo methodInfo)
        {
            IList <Type> attributeTypes = new List <Type>();

            IEnumerable <Attribute> attributes = CustomAttributeExtensions.GetCustomAttributes(methodInfo, false);

            if (attributes.Count() != 0)
            {
                foreach (Attribute attribute in attributes)
                {
                    Type attributeType = attribute.GetType();
                    if (attributeType == typeof(TestInfoAttribute))
                    {
                        attributeTypes.Add(attributeType);
                    }
                    else if (attributeType == typeof(ExecuteAttribute))
                    {
                        attributeTypes.Add(attributeType);
                    }
                    else if (attributeType == typeof(TestOrderAttribute))
                    {
                        attributeTypes.Add(attributeType);
                    }
                    else if (attributeType == typeof(DependentAttribute))
                    {
                        attributeTypes.Add(attributeType);
                    }
                    else if (attributeType == typeof(RetryByAttribute))
                    {
                        attributeTypes.Add(attributeType);
                    }
                }
            }

            return(attributeTypes);
        }
示例#25
0
        public ScriptTransform(IContext context = null) : base(context, "string")
        {
            if (IsMissingContext())
            {
                return;
            }

            if (IsMissing(Context.Operation.Name))
            {
                return;
            }

            if (IsMissing(Context.Operation.Property))
            {
                return;
            }

#if NETS10
            _props = typeof(Script).GetRuntimeProperties().Where(prop => CustomAttributeExtensions.GetCustomAttribute((MemberInfo)prop, typeof(CfgAttribute), (bool)true) != null).Select(prop => prop.Name).ToArray();
#else
            _props = typeof(Script).GetProperties().Where(prop => prop.GetCustomAttributes(typeof(CfgAttribute), true).FirstOrDefault() != null).Select(prop => prop.Name).ToArray();
#endif

            var set = new HashSet <string>(_props, StringComparer.OrdinalIgnoreCase);

            if (!set.Contains(Context.Operation.Property))
            {
                Error($"The script property {Context.Operation.Property} is not allowed.  The allowed properties are {(string.Join(", ", _props))}.");
                Run = false;
                return;
            }

            Context.Operation.Property = set.First(s => s.Equals(Context.Operation.Property, StringComparison.OrdinalIgnoreCase));

            _parameter = Context.Process.Scripts.First(c => c.Name.Equals(Context.Operation.Name, StringComparison.OrdinalIgnoreCase));
        }
示例#26
0
 public sealed override object[] GetCustomAttributes(bool inherit) => CustomAttributeExtensions.GetCustomAttributes(this, inherit: false).ToArray();  // Desktop compat: for events, this form of the api ignores "inherit"
示例#27
0
 public sealed override object[] GetCustomAttributes(bool inherit) => CustomAttributeExtensions.GetCustomAttributes(this, inherit).ToArray();
示例#28
0
 public sealed override object[] GetCustomAttributes(bool inherit) => CustomAttributeExtensions.GetCustomAttributes(this).ToArray();  // inherit is meaningless for Assemblies
        public void GetCustomAttributeT_Multiple_NoInheirit()
        {
            var attributes = CustomAttributeExtensions.GetCustomAttributes <MyAttribute_AllowMultiple_Inherited>(s_typeTestClass.GetTypeInfo(), false);

            Assert.Equal(1, attributes.Count());
        }
        public void GetCustomAttributeOfT_Single_NotInherited()
        {
            Attribute attribute = CustomAttributeExtensions.GetCustomAttribute <MyAttribute_Single_Inherited>(s_typeTestClass.GetTypeInfo(), false);

            Assert.Null(attribute);
        }