本文整理汇总了C#中Mono.Cecil.CustomAttributeArgument类的典型用法代码示例。如果您正苦于以下问题:C# CustomAttributeArgument类的具体用法?C# CustomAttributeArgument怎么用?C# CustomAttributeArgument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CustomAttributeArgument类属于Mono.Cecil命名空间,在下文中一共展示了CustomAttributeArgument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateExpressionFor
static CodeExpression CreateExpressionFor (CustomAttributeArgument argument)
{
if (IsSystemType (argument.Type))
return new CodeTypeOfExpression (GetCodeTypeReference ((TypeReference) argument.Value));
return new CodePrimitiveExpression (argument.Value);
}
示例2: GetValue
static object GetValue(IProjectContent pc, IEntity member, CustomAttributeArgument argument)
{
if (argument.Value is TypeReference)
return CreateType(pc, member, (TypeReference)argument.Value);
else
return argument.Value;
}
示例3: CopyCustomAttributeArg
private CustomAttributeArgument CopyCustomAttributeArg(CustomAttributeArgument yourArgument)
{
var type = FixTypeReference(yourArgument.Type);
var value = yourArgument.Value;
if (value is CustomAttributeArgument) {
value = CopyCustomAttributeArg((CustomAttributeArgument) value);
} else if (value is TypeReference) {
value = FixTypeReference((TypeReference) value);
}
return new CustomAttributeArgument(type, value);
}
示例4: CopyCustomAttributeNamedArguments
public static void CopyCustomAttributeNamedArguments(Collection<Mono.Cecil.CustomAttributeNamedArgument> source,
Collection<Mono.Cecil.CustomAttributeNamedArgument> target, ReferenceResolver resolver)
{
foreach (var namedArgument in source)
{
var argumentType = resolver.ReferenceType(namedArgument.Argument.Type);
CustomAttributeArgument argument = new CustomAttributeArgument(argumentType, namedArgument.Argument.Value);
target.Add(new Mono.Cecil.CustomAttributeNamedArgument(namedArgument.Name, argument));
}
}
示例5: TryGetPropertyArgument
static bool TryGetPropertyArgument (ICustomAttribute attribute, string name, out CustomAttributeArgument argument)
{
foreach (var namedArg in attribute.Properties) {
if (namedArg.Name == name) {
argument = namedArg.Argument;
return true;
}
}
argument = default (CustomAttributeArgument);
return false;
}
示例6: AddObsoleteAttribute
void AddObsoleteAttribute(AttributeData attributeData, Collection<CustomAttribute> customAttributes)
{
var customAttribute = new CustomAttribute(ObsoleteConstructorReference);
var message = ConvertToMessage(attributeData);
var messageArgument = new CustomAttributeArgument(ModuleDefinition.TypeSystem.String, message);
customAttribute.ConstructorArguments.Add(messageArgument);
var isError = GetIsError(attributeData);
var isErrorArgument = new CustomAttributeArgument(ModuleDefinition.TypeSystem.Boolean, isError);
customAttribute.ConstructorArguments.Add(isErrorArgument);
customAttributes.Add(customAttribute);
}
示例7: AddAttribute
public void AddAttribute(Type attributeType, Type[] ctorParamTypes, object[] paramArguments)
{
var internalAttributeCtor = attributeType.GetConstructor(ctorParamTypes);
var internalAttributeCtorRef = TargetModule.Import(internalAttributeCtor);
var internalAttribute = new CustomAttribute(internalAttributeCtorRef);
for (int i = 0; i < ctorParamTypes.Count(); i++)
{
var paramType = internalAttributeCtorRef.Parameters[i].ParameterType;
var internalAttributeArgument = new CustomAttributeArgument(paramType, paramArguments[i]);
internalAttribute.ConstructorArguments.Add(internalAttributeArgument);
}
TargetModule.Assembly.CustomAttributes.Add(internalAttribute);
}
示例8: AddCustomAttribute
protected void AddCustomAttribute(MethodDefinition methodDefinition, ModuleDefinition moduleWithAttributeType,
CustomAttributeArgument ctorArgument)
{
ArgumentUtility.CheckNotNull ("methodDefinition", methodDefinition);
ArgumentUtility.CheckNotNull ("moduleWithAttributeType", moduleWithAttributeType);
var attributeCtor = MakeCtorAndReference ( methodDefinition.DeclaringType.Module, moduleWithAttributeType);
if (attributeCtor.Parameters.Count != 1)
throw new InvalidOperationException ("There is no custom attribute ctor available that takes one parameter!");
var customAttribute = new CustomAttribute (attributeCtor);
customAttribute.ConstructorArguments.Add (ctorArgument);
if (!methodDefinition.CustomAttributes.Any (att => att.Constructor.FullName == attributeCtor.FullName))
methodDefinition.CustomAttributes.Add (customAttribute);
}
示例9: GetCustomAttributeArgumentReferences
private IEnumerable<ProjectReference> GetCustomAttributeArgumentReferences(
CustomAttributeArgument customAttributeArgument, AuditEntryParameters parameters)
{
TypeDefinition typeDefinition = customAttributeArgument.Value is TypeReference
? (customAttributeArgument.Value as TypeReference).Resolve()
: customAttributeArgument.Type.Resolve();
if (typeDefinition != null && !parameters.IsTypeChecked(typeDefinition))
{
ProjectReference projectReference = parameters.FindProjectReference(typeDefinition.Scope);
if (projectReference != null)
yield return projectReference;
foreach(var pr in
m_interfacesTypeWorker.Execute(typeDefinition, parameters))
yield return pr;
foreach(var pr in
m_classTypeHierarchyWorker.Execute(typeDefinition, parameters))
yield return pr;
parameters.AddToCheckedTypes(typeDefinition);
}
}
示例10: FixCustomAttributeArgument
protected CustomAttributeArgument FixCustomAttributeArgument(ModuleDefinition module, CustomAttributeArgument argument)
{
var value = argument.Value;
if (value is TypeReference)
value = module.Import(value as TypeReference);
if (value is CustomAttributeArgument[])
{
var arguments = value as CustomAttributeArgument[];
for (var i = 0; i < arguments.Length; i++)
arguments[i] = FixCustomAttributeArgument(module, arguments[i]);
}
// Used for wrapped CustomAttributeArgument[]
if (argument.Type.Module == null)
argument.Type = module.TypeSystem.LookupType(argument.Type.Namespace, argument.Type.Name);
return new CustomAttributeArgument(module.Import(argument.Type), value);
}
示例11: FixPlatformVersion
private CustomAttributeArgument FixPlatformVersion(CustomAttributeArgument caa)
{
return new CustomAttributeArgument(FixPlatformVersion(caa.Type), caa.Value);
}
示例12: WriteArrayValues
private void WriteArrayValues(CustomAttributeArgument[] array)
{
for (int i = 0; i < array.Length; i++)
{
if (array[i].Value is bool)
{
WriteBooleanLiteral((bool)array[i].Value);
}
else if (array[i].Value is string)
{
WriteStringLiteral((string)array[i].Value);
}
else if (array[i].Value is CustomAttributeArgument[])
{
WriteArrayValues(array[i].Value as CustomAttributeArgument[]);
}
else
{
WriteLiteral(array[i].Value.ToString());
}
if (i < array.Length - 1)
{
WriteSpace();
}
}
}
开发者ID:juancarlosbaezpozos,项目名称:JustDecompileEngine,代码行数:26,代码来源:IntermediateLanguageAttributeWriter.cs
示例13: MarkIfType
void MarkIfType (CustomAttributeArgument argument)
{
var at = argument.Type;
if (at.IsArray) {
var et = at.GetElementType ();
if (et.Namespace != "System" || et.Name != "Type")
return;
MarkType (et);
if (argument.Value == null)
return;
foreach (var cac in (CustomAttributeArgument[]) argument.Value)
MarkWithResolvedScope ((TypeReference) cac.Value);
} else if (at.Namespace == "System" && at.Name == "Type") {
MarkType (argument.Type);
MarkWithResolvedScope ((TypeReference) argument.Value);
}
}
示例14: ReadConstantValue
public IConstantValue ReadConstantValue(CustomAttributeArgument arg)
{
object value = arg.Value;
if (value is CustomAttributeArgument) {
// Cecil uses this representation for boxed values
arg = (CustomAttributeArgument)value;
value = arg.Value;
}
ITypeReference type = ReadTypeReference(arg.Type);
CustomAttributeArgument[] array = value as CustomAttributeArgument[];
if (array != null) {
// TODO: write unit test for this
// TODO: are multi-dimensional arrays possible as well?
throw new NotImplementedException();
}
TypeReference valueType = value as TypeReference;
if (valueType != null)
value = ReadTypeReference(valueType);
return new SimpleConstantValue(type, value);
}
示例15: ToString
public static string ToString(CustomAttributeArgument argument)
{
return argument.Value.ToString();
}