本文整理汇总了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;
}
示例2: CustomAttributeData_NamedArguments
public static void CustomAttributeData_NamedArguments(CustomAttributeData customAttributeData)
{
String attributeTypeName = customAttributeData.AttributeTypeNameString();
if (attributeTypeName == null)
return;
ReflectionEventSource.Log.CustomAttributeData_NamedArguments(attributeTypeName);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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;
}
示例10: Translate
public static string Translate(Attribute a, CustomAttributeData d, Type context)
{
if (a is EcoElementAttribute)
return TranslateEcoElementAttribute((EcoElementAttribute)a);
else
return d.ToString();
}
示例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);
}
示例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();
}
}
示例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>();
}
示例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;
}
示例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");
}