本文整理汇总了C#中AttributeSection类的典型用法代码示例。如果您正苦于以下问题:C# AttributeSection类的具体用法?C# AttributeSection怎么用?C# AttributeSection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AttributeSection类属于命名空间,在下文中一共展示了AttributeSection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddSerializibility
/// <summary>
/// Makes sure that the PHP-visible type is serializable.
/// </summary>
private void AddSerializibility(TypeDeclaration type, TypeDeclaration outType)
{
// make the type serializable
if (!Utility.IsDecoratedByAttribute(type, "System.SerializableAttribute"))
{
AttributeSection section = new AttributeSection();
section.Attributes.Add(new ICSharpCode.NRefactory.Parser.AST.Attribute("Serializable", null, null));
outType.Attributes.Add(section);
ConstructorDeclaration ctor = new ConstructorDeclaration(type.Name,
((type.Modifier & Modifier.Sealed) == Modifier.Sealed ? Modifier.Private : Modifier.Protected),
new List<ParameterDeclarationExpression>(), null);
ctor.Parameters.Add(
new ParameterDeclarationExpression(new TypeReference("System.Runtime.Serialization.SerializationInfo"), "info"));
ctor.Parameters.Add(
new ParameterDeclarationExpression(new TypeReference("System.Runtime.Serialization.StreamingContext"), "context"));
ctor.ConstructorInitializer = new ConstructorInitializer();
ctor.ConstructorInitializer.ConstructorInitializerType = ConstructorInitializerType.Base;
ctor.ConstructorInitializer.Arguments.Add(new IdentifierExpression("info"));
ctor.ConstructorInitializer.Arguments.Add(new IdentifierExpression("context"));
ctor.Body = new BlockStatement();
outType.AddChild(ctor);
}
}
示例2: ApplyActionTo
public override ActionResult ApplyActionTo(StringBuilder sb)
{
int startSearch = FieldToAddTo.TextRange.StartOffset;
string text = sb.ToString();
// Put the new Attribute just in front of the property declaration.
int insertionPoint = text.LastIndexOf("\n", startSearch) + 1;
AttributeSection section = new AttributeSection(AttributeToAdd.Controller);
section.AddAttribute(AttributeToAdd);
section.PreceedingBlankLines = -1;
var indentLevel = InsertionHelpers.GetIndentationInFrontOf(text, startSearch);
section.Controller.IndentLevel = indentLevel;
string newText = Helper.StandardizeLineBreaks(section.ToString(), "\n") + "\n";
// Calculate the Attribute's Text Range
// The start index is the insertion point + the number of tabs in front of the attribute, +1 for the \n
AttributeToAdd.TextRange.StartOffset = insertionPoint + indentLevel + 1;
AttributeToAdd.TextRange.EndOffset = AttributeToAdd.TextRange.StartOffset + (newText.Trim()).Length;
sb.Insert(insertionPoint, newText);
FieldToAddTo.AttributeSections.Add(section);
//return new ActionResult(insertionPoint, newText.Length, new[] { AttributeToAdd });
return new ActionResult(AttributeToAdd.TextRange.StartOffset, newText.Length, new[] { AttributeToAdd });
}
示例3: VisitAttributeSection
public virtual object VisitAttributeSection(AttributeSection attributeSection, object data) {
Debug.Assert((attributeSection != null));
Debug.Assert((attributeSection.Attributes != null));
foreach (ICSharpCode.NRefactory.Ast.Attribute o in attributeSection.Attributes) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}
return null;
}
示例4: VisitAttributeSection
public override void VisitAttributeSection(AttributeSection attributeSection)
{
VisitChildrenToFormat(attributeSection, child => {
child.AcceptVisitor(this);
if (child.NextSibling != null && child.NextSibling.Role == Roles.RBracket) {
ForceSpacesAfter(child, false);
}
});
}
示例5: MakeNonBrowsable
/// <summary>
/// Makes the given node [EditorBrowsable(Never)].
/// </summary>
public static void MakeNonBrowsable(AttributedNode node)
{
AttributeSection section = new AttributeSection();
ICSharpCode.NRefactory.Parser.AST.Attribute attribute =
new ICSharpCode.NRefactory.Parser.AST.Attribute("System.ComponentModel.EditorBrowsable",
new List<Expression>(), null);
attribute.PositionalArguments.Add(new FieldReferenceExpression(new TypeReferenceExpression(
"System.ComponentModel.EditorBrowsableState"), "Never"));
section.Attributes.Add(attribute);
node.Attributes.Add(section);
}
示例6: VisitAttributeSection
public override void VisitAttributeSection(AttributeSection attributeSection)
{
if (attributeSection.AttributeTarget != "assembly")
{
return;
}
foreach (var attr in attributeSection.Attributes)
{
var name = attr.Type.ToString();
var resolveResult = this.Resolver.ResolveNode(attr, null);
var handled = //this.ReadAspect(attr, name, resolveResult, AttributeTargets.Assembly, null) ||
this.ReadModuleInfo(attr, name, resolveResult) ||
this.ReadFileNameInfo(attr, name, resolveResult) ||
this.ReadOutputPathInfo(attr, name, resolveResult) ||
this.ReadFileHierarchyInfo(attr, name, resolveResult) ||
this.ReadModuleDependency(attr, name, resolveResult);
}
}
示例7: GetActions
IEnumerable<CodeAction> GetActions(Attribute attribute, AttributeSection attributeSection, FieldDeclaration fieldDeclaration)
{
string removeAttributeMessage = ctx.TranslateString("Remove attribute");
yield return new CodeAction(removeAttributeMessage, script => {
if (attributeSection.Attributes.Count > 1) {
var newSection = new AttributeSection();
newSection.AttributeTarget = attributeSection.AttributeTarget;
foreach (var attr in attributeSection.Attributes) {
if (attr != attribute)
newSection.Attributes.Add((Attribute)attr.Clone());
}
script.Replace(attributeSection, newSection);
} else {
script.Remove(attributeSection);
}
});
var makeStaticMessage = ctx.TranslateString("Make the field static");
yield return new CodeAction(makeStaticMessage, script => {
var newDeclaration = (FieldDeclaration)fieldDeclaration.Clone();
newDeclaration.Modifiers |= Modifiers.Static;
script.Replace(fieldDeclaration, newDeclaration);
});
}
示例8: Generate
private string Generate(String propertyName, String propertyTypeName, string indent)
{
// Create the attribute
AttributeSection attributeSection = new AttributeSection ();
var attribute = GetAttribute(Constants.OBJECTIVE_C_IVAR_SHORTFORM, propertyName);
attributeSection.Attributes.Add (attribute);
// Create the property declaration
PropertyDeclaration propertyDeclaration = GetPropertyDeclaration(propertyName, new SimpleType (propertyTypeName), attributeSection);
{
// Create the member this.GetInstanceVariable<T>
MemberReferenceExpression memberReferenceExpression = new MemberReferenceExpression (new ThisReferenceExpression (), "GetInstanceVariable");
memberReferenceExpression.TypeArguments.Add (new SimpleType (propertyTypeName));
// Create the invocation with arguments
InvocationExpression invocationExpression = new InvocationExpression (memberReferenceExpression, new List<Expression> { new PrimitiveExpression (propertyName) });
// Wrap the invocation with a return
ReturnStatement returnStatement = new ReturnStatement (invocationExpression);
// Create the "get" region
propertyDeclaration.Getter = new Accessor();
propertyDeclaration.Getter.Body = new BlockStatement ();
propertyDeclaration.Getter.Body.Add(returnStatement);
}
{
// Create the member this.SetInstanceVariable<T>
MemberReferenceExpression memberReferenceExpression = new MemberReferenceExpression (new ThisReferenceExpression (), "SetInstanceVariable");
memberReferenceExpression.TypeArguments.Add (new SimpleType (propertyTypeName));
// Create the invocation with arguments
InvocationExpression invocationExpression = new InvocationExpression (memberReferenceExpression, new List<Expression> { new PrimitiveExpression (propertyName), new IdentifierExpression ("value") });
// Wrap the invocation with an expression
ExpressionStatement expressionStatement = new ExpressionStatement (invocationExpression);
// Create the "set" region
propertyDeclaration.Setter = new Accessor();
propertyDeclaration.Setter.Body = new BlockStatement ();
propertyDeclaration.Setter.Body.Add(expressionStatement);
}
// Return the result of the AST generation
String generated = this.Options.OutputNode(propertyDeclaration);
// Add ident space
return Indent(generated, indent);
}
示例9: ConvertAttributeSection
AttributeSection ConvertAttributeSection (List<Mono.CSharp.Attribute> optAttributes)
{
if (optAttributes == null)
return null;
AttributeSection result = new AttributeSection ();
var loc = LocationsBag.GetLocations (optAttributes);
if (loc != null)
result.AddChild (new CSharpTokenNode (Convert (loc [0]), 1), AttributeSection.Roles.LBracket);
result.AttributeTarget = optAttributes.First ().ExplicitTarget;
foreach (var attr in GetAttributes (optAttributes)) {
result.AddChild (attr, AttributeSection.AttributeRole);
}
if (loc != null)
result.AddChild (new CSharpTokenNode (Convert (loc [1]), 1), AttributeSection.Roles.RBracket);
return result;
}
示例10: Bind
void Bind(CXXRecordDecl baseDecl, CXXRecordDecl decl)
{
var name = decl.Name;
//Console.WriteLine(name);
bool isStruct = IsStructure (decl);
PushType(new TypeDeclaration
{
Name = RemapTypeName (decl.Name),
ClassType = isStruct ? ClassType.Struct : ClassType.Class,
Modifiers = Modifiers.Partial | Modifiers.Public | Modifiers.Unsafe
}, StringUtil.GetTypeComments(decl));
if (baseDecl != null) {
foreach (var baseType in decl.Bases) {
var baseName = baseType.Decl?.Name;
if (baseName == null)
continue;
// WorkItem is a structure, with a RefCount base class, avoid that
if (IsStructure(decl))
continue;
//
// Only a (File, MemoryBuffer, VectorBuffer)
// implement that, and the Serializer class is never
// surfaced as an API entry point, so we should just inline the methods
// from those classes into the generated class
//
if (baseName == "GPUObject" || baseName == "Thread" || baseName == "Octant" ||
baseName == "b2Draw" || baseName == "b2ContactListener" || baseName == "btIDebugDraw" || baseName == "btMotionState")
continue;
if (currentType.BaseTypes.Count > 0)
baseName = "I" + baseName;
currentType.BaseTypes.Add(new SimpleType(RemapTypeName(baseName)));
}
}
// Determines if this is a subclass of RefCounted (but not RefCounted itself)
bool refCountedSubclass = decl.TagKind == TagDeclKind.Class && decl.QualifiedName != "Urho3D::RefCounted" && decl.IsDerivedFrom(ScanBaseTypes.UrhoRefCounted);
// Same for Urho3D::Object
bool objectSubclass = decl.TagKind == TagDeclKind.Class && decl.QualifiedName != "Urho3D::Object" && decl.IsDerivedFrom(ScanBaseTypes.UrhoObjectType);
if (refCountedSubclass) {
var nativeCtor = new ConstructorDeclaration
{
Modifiers = Modifiers.Public,
Body = new BlockStatement(),
Initializer = new ConstructorInitializer()
};
nativeCtor.Parameters.Add(new ParameterDeclaration(new SimpleType("IntPtr"), "handle"));
nativeCtor.Initializer.Arguments.Add(new IdentifierExpression("handle"));
currentType.Members.Add(nativeCtor);
// The construtor with the emtpy chain flag
nativeCtor = new ConstructorDeclaration
{
Modifiers = Modifiers.Protected,
Body = new BlockStatement(),
Initializer = new ConstructorInitializer()
};
nativeCtor.Parameters.Add(new ParameterDeclaration(new SimpleType("UrhoObjectFlag"), "emptyFlag"));
nativeCtor.Initializer.Arguments.Add(new IdentifierExpression("emptyFlag"));
currentType.Members.Add(nativeCtor);
} else if (IsStructure(decl)) {
var serializable = new Attribute()
{
Type = new SimpleType("StructLayout")
};
serializable.Arguments.Add(new TypeReferenceExpression(new MemberType(new SimpleType("LayoutKind"), "Sequential")));
var attrs = new AttributeSection();
attrs.Attributes.Add(serializable);
currentType.Attributes.Add(attrs);
}
}
示例11: ConvertCustomAttributes
static void ConvertCustomAttributes(AstNode attributedNode, ICustomAttributeProvider customAttributeProvider, AttributeTarget target = AttributeTarget.None)
{
if (customAttributeProvider.HasCustomAttributes) {
var attributes = new List<ICSharpCode.NRefactory.CSharp.Attribute>();
foreach (var customAttribute in customAttributeProvider.CustomAttributes) {
var attribute = new ICSharpCode.NRefactory.CSharp.Attribute();
attribute.AddAnnotation(customAttribute);
attribute.Type = ConvertType(customAttribute.AttributeType);
attributes.Add(attribute);
SimpleType st = attribute.Type as SimpleType;
if (st != null && st.Identifier.EndsWith("Attribute", StringComparison.Ordinal)) {
st.Identifier = st.Identifier.Substring(0, st.Identifier.Length - "Attribute".Length);
}
if(customAttribute.HasConstructorArguments) {
foreach (var parameter in customAttribute.ConstructorArguments) {
Expression parameterValue = ConvertArgumentValue(parameter);
attribute.Arguments.Add(parameterValue);
}
}
if (customAttribute.HasProperties) {
TypeDefinition resolvedAttributeType = customAttribute.AttributeType.Resolve();
foreach (var propertyNamedArg in customAttribute.Properties) {
var propertyReference = resolvedAttributeType != null ? resolvedAttributeType.Properties.FirstOrDefault(pr => pr.Name == propertyNamedArg.Name) : null;
var propertyName = new IdentifierExpression(propertyNamedArg.Name).WithAnnotation(propertyReference);
var argumentValue = ConvertArgumentValue(propertyNamedArg.Argument);
attribute.Arguments.Add(new AssignmentExpression(propertyName, argumentValue));
}
}
if (customAttribute.HasFields) {
TypeDefinition resolvedAttributeType = customAttribute.AttributeType.Resolve();
foreach (var fieldNamedArg in customAttribute.Fields) {
var fieldReference = resolvedAttributeType != null ? resolvedAttributeType.Fields.FirstOrDefault(f => f.Name == fieldNamedArg.Name) : null;
var fieldName = new IdentifierExpression(fieldNamedArg.Name).WithAnnotation(fieldReference);
var argumentValue = ConvertArgumentValue(fieldNamedArg.Argument);
attribute.Arguments.Add(new AssignmentExpression(fieldName, argumentValue));
}
}
}
if (target == AttributeTarget.Module || target == AttributeTarget.Assembly) {
// use separate section for each attribute
foreach (var attribute in attributes) {
var section = new AttributeSection();
section.AttributeTarget = target;
section.Attributes.Add(attribute);
attributedNode.AddChild(section, AttributedNode.AttributeRole);
}
} else {
// use single section for all attributes
var section = new AttributeSection();
section.AttributeTarget = target;
section.Attributes.AddRange(attributes);
attributedNode.AddChild(section, AttributedNode.AttributeRole);
}
}
}
示例12: GenerateMethod
private String GenerateMethod(IMethod method)
{
// Retrieve the Objective-C message in the attribute
String message = AttributeHelper.GetAttributeValue (method, Constants.OBJECTIVE_C_MESSAGE);
AttributeSection attributeSection = new AttributeSection ();
if (!String.IsNullOrEmpty (message)) {
var attribute = this.GetAttribute (Constants.OBJECTIVE_C_MESSAGE_SHORTFORM, message);
attributeSection.Attributes.Add (attribute);
}
// Create the method declaration
MethodDeclaration methodDeclaration = new MethodDeclaration ();
methodDeclaration.Name = method.Name;
methodDeclaration.Attributes.Add (attributeSection);
methodDeclaration.Modifiers = Modifiers.Public | Modifiers.Virtual;
methodDeclaration.ReturnType = this.Options.CreateShortType (method.ReturnType);
foreach (var parameter in method.Parameters) {
ParameterDeclaration parameterDeclaration = new ParameterDeclaration (this.Options.CreateShortType (parameter.Type), parameter.Name);
if (parameter.IsOut) {
parameterDeclaration.ParameterModifier |= ParameterModifier.Out;
}
if (parameter.IsRef) {
parameterDeclaration.ParameterModifier |= ParameterModifier.Ref;
}
methodDeclaration.Parameters.Add (parameterDeclaration);
}
// Create the method body
methodDeclaration.Body = new BlockStatement ();
ThrowStatement throwStatement = this.GetThrowStatement (Constants.NOT_IMPLEMENTED_EXCEPTION);
methodDeclaration.Body.Add (throwStatement);
// Return the result of the AST generation
return this.Options.OutputNode (methodDeclaration);
}
示例13: VisitAttributeSection
public StringBuilder VisitAttributeSection(AttributeSection attributeSection, int data)
{
throw new SLSharpException("HLSL does not have attributes.");
}
示例14: ConvertAttributeSection
AttributeSection ConvertAttributeSection(IEnumerable<Mono.CSharp.Attribute> optAttributes)
{
if (optAttributes == null)
return null;
var result = new AttributeSection();
var loc = LocationsBag.GetLocations(optAttributes);
int pos = 0;
if (loc != null)
result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.LBracket), Roles.LBracket);
var first = optAttributes.FirstOrDefault();
string target = first != null ? first.ExplicitTarget : null;
if (!string.IsNullOrEmpty(target)) {
if (loc != null && pos < loc.Count - 1) {
result.AddChild(Identifier.Create(target, Convert(loc [pos++])), Roles.Identifier);
} else {
result.AddChild(Identifier.Create(target), Roles.Identifier);
}
if (loc != null && pos < loc.Count)
result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.Colon), Roles.Colon);
}
int attributeCount = 0;
foreach (var attr in GetAttributes (optAttributes)) {
result.AddChild(attr, Roles.Attribute);
if (loc != null && pos + 1 < loc.Count)
result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.Comma), Roles.Comma);
attributeCount++;
}
if (attributeCount == 0)
return null;
// Left and right bracket + commas between the attributes
int locCount = 2 + attributeCount - 1;
// optional comma
if (loc != null && pos < loc.Count - 1 && loc.Count == locCount + 1)
result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.Comma), Roles.Comma);
if (loc != null && pos < loc.Count)
result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.RBracket), Roles.RBracket);
return result;
}
示例15: VisitAttributeSection
public void VisitAttributeSection(AttributeSection attributeSection)
{
StartNode(attributeSection);
WriteToken(Roles.LBracket);
if (!string.IsNullOrEmpty(attributeSection.AttributeTarget)) {
WriteToken(attributeSection.AttributeTarget, Roles.AttributeTargetRole);
WriteToken(Roles.Colon);
Space();
}
WriteCommaSeparatedList(attributeSection.Attributes);
WriteToken(Roles.RBracket);
if (attributeSection.Parent is ParameterDeclaration || attributeSection.Parent is TypeParameterDeclaration) {
Space();
} else {
NewLine();
}
EndNode(attributeSection);
}