当前位置: 首页>>代码示例>>C#>>正文


C# Reflection.CustomAttributeData类代码示例

本文整理汇总了C#中System.Reflection.CustomAttributeData的典型用法代码示例。如果您正苦于以下问题:C# CustomAttributeData类的具体用法?C# CustomAttributeData怎么用?C# CustomAttributeData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CustomAttributeData类属于System.Reflection命名空间,在下文中一共展示了CustomAttributeData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ForeignKey

 public ForeignKey(CustomAttributeData data)
 {
     TableName = (string)data.ConstructorArguments[0].Value;
     ColumnName = (string)data.ConstructorArguments[1].Value;
     FullName = TableName + "." + ColumnName;
     Index = (int)data.ConstructorArguments[2].Value;
 }
开发者ID:agglerithm,项目名称:DataBus,代码行数:7,代码来源:ForeignKey.cs

示例2: CustomAttributeData_NamedArguments

 public static void CustomAttributeData_NamedArguments(CustomAttributeData customAttributeData)
 {
     String attributeTypeName = customAttributeData.AttributeTypeNameString();
     if (attributeTypeName == null)
         return;
     ReflectionEventSource.Log.CustomAttributeData_NamedArguments(attributeTypeName);
 }
开发者ID:tijoytom,项目名称:corert,代码行数:7,代码来源:ReflectionTrace.Public.Events.cs

示例3: GetCustomAttributeData

 private static string GetCustomAttributeData(CustomAttributeData cad, Type attrType, out Type typeValue, bool allowTypeAlso, bool noArgs, bool zeroArgsAllowed)
 {
     string assemblyQualifiedName = null;
     typeValue = null;
     if (!(cad.Constructor.ReflectedType == attrType))
     {
         return assemblyQualifiedName;
     }
     IList<CustomAttributeTypedArgument> constructorArguments = cad.ConstructorArguments;
     if ((constructorArguments.Count == 1) && !noArgs)
     {
         CustomAttributeTypedArgument argument = constructorArguments[0];
         assemblyQualifiedName = argument.Value as string;
         if (((assemblyQualifiedName == null) && allowTypeAlso) && (argument.ArgumentType == typeof(Type)))
         {
             typeValue = argument.Value as Type;
             assemblyQualifiedName = typeValue.AssemblyQualifiedName;
         }
         if (assemblyQualifiedName == null)
         {
             throw new ArgumentException(System.Xaml.SR.Get("ParserAttributeArgsLow", new object[] { attrType.Name }));
         }
         return assemblyQualifiedName;
     }
     if (constructorArguments.Count != 0)
     {
         throw new ArgumentException(System.Xaml.SR.Get("ParserAttributeArgsHigh", new object[] { attrType.Name }));
     }
     if (!noArgs && !zeroArgsAllowed)
     {
         throw new ArgumentException(System.Xaml.SR.Get("ParserAttributeArgsLow", new object[] { attrType.Name }));
     }
     return string.Empty;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:34,代码来源:ReflectionHelper.cs

示例4: Convert

        public Dictionary<string, object> Convert(string propertyName, CustomAttributeData attr)
        {
            var validations = new Dictionary<string, object>();
            var length = GetConstructorArgumentValue(attr, 0);

            return SetMinLengthAAValidation(propertyName, attr, length);
        }
开发者ID:wald-tq,项目名称:aa-validation-from-server,代码行数:7,代码来源:MinLengthConverter.cs

示例5: Convert

        public Dictionary<string, object> Convert(string propertyName, CustomAttributeData attr)
        {
            var validations = new Dictionary<string, object>();

            var minimum = GetConstructorArgumentValue(attr, 0);
            var maximum = GetConstructorArgumentValue(attr, 1);

            if (!string.IsNullOrWhiteSpace(minimum) && !string.IsNullOrWhiteSpace(maximum))
            {
                validations.Add("min", minimum);

                var displayName = base.GetNamedArgumentValue(propertyName, attr, DataAnnotationConstants.Display);
                if (!string.IsNullOrWhiteSpace(displayName))
                {
                    var msg = GetErrorMessage(propertyName, attr);
                    if (msg != null)
                    {
                        validations.Add("min-msg", msg);
                        validations.Add("max-msg", msg);

                    }
                    validations.Add("max", maximum);
                }
            }
            return validations;
        }
开发者ID:wald-tq,项目名称:aa-validation-from-server,代码行数:26,代码来源:RangeConverter.cs

示例6: GetCustomAttributes

        public static IList<CustomAttributeData> GetCustomAttributes(MemberInfo target)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            IList<CustomAttributeData> cad = GetCustomAttributes(target.Module, target.MetadataToken);

            int pcaCount = 0;
            Attribute[] a = null;
            if (target is RuntimeType)
                a = PseudoCustomAttribute.GetCustomAttributes((RuntimeType)target, typeof(object), false, out pcaCount);
            else if (target is RuntimeMethodInfo)
                a = PseudoCustomAttribute.GetCustomAttributes((RuntimeMethodInfo)target, typeof(object), false, out pcaCount);
            else if (target is RuntimeFieldInfo)
                a = PseudoCustomAttribute.GetCustomAttributes((RuntimeFieldInfo)target, typeof(object), out pcaCount);

            if (pcaCount == 0)
                return cad;

            CustomAttributeData[] pca = new CustomAttributeData[cad.Count + pcaCount];
            cad.CopyTo(pca, pcaCount);
            for (int i = 0; i < pcaCount; i++)
            {
                if (PseudoCustomAttribute.IsSecurityAttribute(a[i].GetType()))
                    continue;

                pca[i] = new CustomAttributeData(a[i]);
            }

            return Array.AsReadOnly(pca);
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:31,代码来源:customattribute.cs

示例7: FormatErrorMessage

        public string FormatErrorMessage(string propertyName, CustomAttributeData attr)
        {
            try
            {
                var message = ErrorMessages[attr.AttributeType.Name];

                var arguments = new List<object>();
                arguments.Add(propertyName);
                if(attr.AttributeType.Name == "StringLengthAttribute")
                {
                    arguments.Add(attr.NamedArguments.Where(x => x.MemberName == "MinimumLength").Select(x => x.TypedValue.Value).First());
                }
                arguments.AddRange(attr.ConstructorArguments.Select(x => x.Value).Cast<object>());

                return String.Format(message, arguments.ToArray());
            }
            catch (KeyNotFoundException)
            {
                try
                {
                    return String.Format(ErrorMessages["Default"], propertyName);
                }
                catch (KeyNotFoundException)
                {
                    return String.Format("{0} incorrect", propertyName);
                }
            }
        }
开发者ID:wald-tq,项目名称:aa-validation-from-server,代码行数:28,代码来源:AttributeErrorMessageFormatter.cs

示例8: GetCommonAttribute

        public CommonAttribute GetCommonAttribute(CustomAttributeData customAttributeData)
        {
            var positionalArguments = customAttributeData.ConstructorArguments.Select(GetCommonPositionalArgument);
              var namedArguments = customAttributeData.NamedArguments.AssertNotNull().Select(GetCommonNamedArgument);

              return new CommonAttribute(GetCommonType(customAttributeData.Constructor.DeclaringType), positionalArguments, namedArguments);
        }
开发者ID:igor-toporet,项目名称:TestFx,代码行数:7,代码来源:IntrospectionUtility.cs

示例9: CreateAttribute

        /// <summary>
        /// This methods creates an attribute instance from the attribute data 
        /// information
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private static Attribute CreateAttribute(CustomAttributeData data)
        {
            var arguments = from arg in data.ConstructorArguments
                            select arg.Value;

            var attribute = data.Constructor.Invoke(arguments.ToArray()) as Attribute;

            if (data.NamedArguments != null)
            {
                foreach (var namedArgument in data.NamedArguments)
                {
                    var propertyInfo = namedArgument.MemberInfo as PropertyInfo;
                    if (propertyInfo != null)
                    {
                        propertyInfo.SetValue(attribute, namedArgument.TypedValue.Value, null);
                    }
                    else
                    {
                        var fieldInfo = namedArgument.MemberInfo as FieldInfo;
                        if (fieldInfo != null)
                        {
                            fieldInfo.SetValue(attribute, namedArgument.TypedValue.Value);
                        }
                    }
                }
            }
            return attribute;
        }
开发者ID:ashokgelal,项目名称:NetSparkle,代码行数:34,代码来源:NetSparkleAssemblyReflectionAccessor.cs

示例10: Translate

 public static string Translate(Attribute a, CustomAttributeData d, Type context)
 {
     if (a is EcoElementAttribute)
         return TranslateEcoElementAttribute((EcoElementAttribute)a);
     else
         return d.ToString();
 }
开发者ID:lukyad,项目名称:Eco,代码行数:7,代码来源:CommonAttributeTranslator.cs

示例11: IsSamplePageByCategory

 public static bool IsSamplePageByCategory(this Page self, CustomAttributeData attr, string category)
 {
     if(attr == null)
     {
         throw new ArgumentNullException("attr");
     }
     return attr.NamedArguments.Any(arg => attr.AttributeType == typeof(SamplePageAttribute) && arg.MemberName == "Category" && arg.TypedValue.Value.ToString() == category);
 }       
开发者ID:ridomin,项目名称:waslibs,代码行数:8,代码来源:PageExtensions.cs

示例12: CustomAttributeInfo

		public CustomAttributeInfo(CustomAttributeData data) {
			attributeType = new QualifiedTypeNameInfo(data.Constructor.DeclaringType);
			constructorArguments = data.Constructor.GetParameters().OrderBy(p => p.Position).Select(p => new KeyValuePair<QualifiedTypeNameInfo, object>(new QualifiedTypeNameInfo(p.ParameterType), GetSimpleValue(data.ConstructorArguments[p.Position].Value))).ToArray();
			if (data.NamedArguments == null) {
				namedArguments = new KeyValuePair<TypeMemberInfo, object>[0];
			} else {
				namedArguments = data.NamedArguments.Select(argument => new KeyValuePair<TypeMemberInfo, object>(new TypeMemberInfo(argument.MemberInfo), GetSimpleValue(argument.TypedValue.Value))).ToArray();
			}
		}
开发者ID:avonwyss,项目名称:bsn-modulestore,代码行数:9,代码来源:CustomAttributeInfo.cs

示例13: Convert

 public Dictionary<string, object> Convert(string propertyName, CustomAttributeData attr)
 {
     var pattern = GetConstructorArgumentValue(attr, 0);
     if (!string.IsNullOrWhiteSpace(pattern))
     {
         return SetRegularExpressionAAValidation(propertyName, attr, pattern);
     }
     return new Dictionary<string, object>();
 }
开发者ID:wald-tq,项目名称:aa-validation-from-server,代码行数:9,代码来源:RegularExpressionConverter.cs

示例14: FileInstallStep

		public FileInstallStep(IManifest manifest, CustomAttributeData rawData) : base(manifest, rawData)
		{
			//[assembly: InstallFile(RepositoryPath = "/Root/Test/asdf.css", ResourcePath = "/res.asdf.css")]
			var repositoryPath = GetParameterValue<string>("RepositoryPath");
			var contentName = ContentManager.Path.GetFileName(repositoryPath);
			var containerPath = ContentManager.Path.GetParentPath(repositoryPath);

			ContainerPath = containerPath;
			ContentName = contentName;
			RawAttachments = "Binary:" + ResourceName;
		}
开发者ID:maxpavlov,项目名称:FlexNet,代码行数:11,代码来源:FileInstallStep.cs

示例15: GetRequiredSpan

        public static TagBuilder GetRequiredSpan(CustomAttributeData cs, MemberInfo member)
        {
            CustomAttributeNamedArgument namedArg = cs.NamedArguments.Where(p => p.MemberName == "ErrorMessage").First();
            string errorMsg = string.Empty;

            if (namedArg != null)
                errorMsg = namedArg.TypedValue.Value.ToString();
            else
                errorMsg = "Please enter " + member.Name.ToLower();

            return GetSpan(errorMsg, member.Name.ToLower(), "required");
        }
开发者ID:nitya1979,项目名称:KanbanBoard,代码行数:12,代码来源:NgHtmlHelper.cs


注:本文中的System.Reflection.CustomAttributeData类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。