本文整理汇总了C#中ICustomAttribute类的典型用法代码示例。如果您正苦于以下问题:C# ICustomAttribute类的具体用法?C# ICustomAttribute怎么用?C# ICustomAttribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ICustomAttribute类属于命名空间,在下文中一共展示了ICustomAttribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Include
public override bool Include(ICustomAttribute attribute)
{
if (_attributeDocIds.Contains(attribute.DocId()))
return false;
return base.Include(attribute);
}
示例2: PrintAttribute
public virtual void PrintAttribute(IReference target, ICustomAttribute attribute, bool newLine, string targetType) {
this.sourceEmitterOutput.Write("[", newLine);
if (targetType != null) {
this.sourceEmitterOutput.Write(targetType);
this.sourceEmitterOutput.Write(": ");
}
this.PrintTypeReferenceName(attribute.Constructor.ContainingType);
if (attribute.NumberOfNamedArguments > 0 || IteratorHelper.EnumerableIsNotEmpty(attribute.Arguments)) {
this.sourceEmitterOutput.Write("(");
bool first = true;
foreach (var argument in attribute.Arguments) {
if (first)
first = false;
else
this.sourceEmitterOutput.Write(", ");
this.Traverse(argument);
}
foreach (var namedArgument in attribute.NamedArguments) {
if (first)
first = false;
else
this.sourceEmitterOutput.Write(", ");
this.Traverse(namedArgument);
}
this.sourceEmitterOutput.Write(")");
}
this.sourceEmitterOutput.Write("]");
if (newLine) this.sourceEmitterOutput.WriteLine("");
}
示例3: ScriptAttribute
/// <summary>
/// Creates a new instance of the class.
/// </summary>
/// <param name="type">The attribute type.</param>
/// <param name="attribute">The CCI attribute.</param>
internal ScriptAttribute(ICustomAttribute attribute)
{
if (attribute == null)
throw new InvalidOperationException();
var typeRef = attribute.Type as INamedTypeReference;
if (typeRef == null)
{
throw new InvalidOperationException("Attribute type must be a named type.");
}
var type = ScriptDomain.CurrentDomain.ResolveType(typeRef);
if (type == null)
{
throw new InvalidOperationException("Unable to resolve type for attribute: " + typeRef.Name);
}
_type = type;
_cciAttribute = attribute;
_arguments = _cciAttribute.Arguments
.Select(a => GetConstantValue(a)).ToArray();
_namedArgs = _cciAttribute.NamedArguments.ToDictionary(a =>
a.ArgumentName.Value, a => GetConstantValue(a));
}
示例4: GetCustomAttributes
/// <summary>
///
/// </summary>
/// <param name="customAttributeData"></param>
/// <returns></returns>
public IEnumerable<ICustomAttribute> GetCustomAttributes(IList<CustomAttributeData> customAttributeData) {
int n = customAttributeData.Count;
ICustomAttribute[] customAttributes = new ICustomAttribute[n];
for (int i = 0; i < n; i++)
customAttributes[i] = this.GetCustomAttribute(customAttributeData[i]);
return IteratorHelper.GetReadonly(customAttributes);
}
示例5: Include
public virtual bool Include(ICustomAttribute attribute)
{
if (this.ExcludeAttributes)
return false;
// Always return the custom attributes if ExcludeAttributes is not set
// the PublicOnly mainly concerns the types and members.
return true;
}
示例6: Include
public bool Include(ICustomAttribute attribute)
{
string typeId = attribute.DocId();
string removeUsages = "RemoveUsages:" + typeId;
if (_docIds.Contains(removeUsages))
return false;
return _docIds.Contains(typeId);
}
示例7: GetPropertyString
static string GetPropertyString (ICustomAttribute attribute, string name)
{
if (!attribute.HasProperties)
return String.Empty;
foreach (var namedArg in attribute.Properties) {
if (namedArg.Name == name) {
return (namedArg.Argument.Value as string);
}
}
return String.Empty;
}
示例8: 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;
}
示例9: Include
public bool Include(ICustomAttribute attribute)
{
string typeId = attribute.DocId();
string removeUsages = "RemoveUsages:" + typeId;
// special case: attribute usage can be removed without removing
// the attribute itself
if (_docIds.Contains(removeUsages))
return false;
// include so long as it isn't in the exclude list.
return !_docIds.Contains(typeId);
}
示例10: GetTokenList
public IEnumerable<SyntaxToken> GetTokenList(ICustomAttribute attribute, int indentLevel = -1)
{
EnsureTokenWriter();
_tokenizer.ClearTokens();
if (indentLevel != -1)
_tokenizer.IndentLevel = indentLevel;
_tokenWriter.WriteAttribute(attribute);
return _tokenizer.ToTokenList();
}
示例11: GetString
public string GetString(ICustomAttribute attribute, int indentLevel = -1)
{
EnsureStringWriter();
_string.Clear();
if (indentLevel != -1)
_stringWriter.SyntaxtWriter.IndentLevel = indentLevel;
_stringWriter.WriteAttribute(attribute);
return _string.ToString();
}
示例12: TryGetAttributeByName
/// <summary>
/// Tries to find an attribue by name
/// </summary>
/// <param name="attributes"></param>
/// <param name="attributeName"></param>
/// <param name="attribute"></param>
/// <returns></returns>
public static bool TryGetAttributeByName(
IEnumerable<ICustomAttribute> attributes,
string attributeName,
out ICustomAttribute attribute)
{
Contract.Requires(!String.IsNullOrEmpty(attributeName));
Contract.Ensures(!Contract.Result<bool>() || Contract.ValueAtReturn(out attribute) != null);
if (attributes == null) { attribute = null; return false; }
foreach (var a in attributes)
{
if (AttributeMatchesByName(a, attributeName))
{
attribute = a;
return true;
}
}
attribute = null;
return false;
}
示例13: WriteAttribute
public void WriteAttribute(ICustomAttribute attribute, string prefix = null, SecurityAction action = SecurityAction.ActionNil)
{
if (!string.IsNullOrEmpty(prefix))
{
Write(prefix);
WriteSymbol(":");
}
WriteTypeName(attribute.Constructor.ContainingType, noSpace: true); // Should we strip Attribute from name?
if (attribute.NumberOfNamedArguments > 0 || attribute.Arguments.Any() || action != SecurityAction.ActionNil)
{
WriteSymbol("(");
bool first = true;
if (action != SecurityAction.ActionNil)
{
Write("System.Security.Permissions.SecurityAction." + action.ToString());
first = false;
}
foreach (IMetadataExpression arg in attribute.Arguments)
{
if (!first) WriteSymbol(",", true);
WriteMetadataExpression(arg);
first = false;
}
foreach (IMetadataNamedArgument namedArg in attribute.NamedArguments)
{
if (!first) WriteSymbol(",", true);
WriteIdentifier(namedArg.ArgumentName);
WriteSymbol("=");
WriteMetadataExpression(namedArg.ArgumentValue);
first = false;
}
WriteSymbol(")");
}
}
示例14: Include
public virtual bool Include(ICustomAttribute attribute)
{
if (this.ExcludeAttributes)
return false;
// Ignore attributes not visible outside the assembly
var attributeDef = attribute.Type.GetDefinitionOrNull();
if (attributeDef != null && !attributeDef.IsVisibleOutsideAssembly())
return false;
// Ignore attributes with typeof argument of a type invisible outside the assembly
foreach(var arg in attribute.Arguments.OfType<IMetadataTypeOf>())
{
var typeDef = arg.TypeToGet.GetDefinitionOrNull();
if (typeDef == null)
continue;
if (!typeDef.IsVisibleOutsideAssembly())
return false;
}
return true;
}
示例15: TraverseChildren
public override void TraverseChildren(ICustomAttribute customAttribute) {
// Different uses of custom attributes must print them directly based on context
//base.TraverseChildren(customAttribute);
}