本文整理汇总了C#中NamespaceDeclaration类的典型用法代码示例。如果您正苦于以下问题:C# NamespaceDeclaration类的具体用法?C# NamespaceDeclaration怎么用?C# NamespaceDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NamespaceDeclaration类属于命名空间,在下文中一共展示了NamespaceDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyDefaultCtorWithComment
public void VerifyDefaultCtorWithComment()
{
NamespaceDeclaration nsdecl = new NamespaceDeclaration("My.Stuff");
nsdecl.AddClass("SomeClass")
.AddConstructor("Initializes a new instance of SomeClass");
new CodeBuilder().GenerateCode(Console.Out, nsdecl);
}
示例2: VerifyDefaultCtor
public void VerifyDefaultCtor()
{
NamespaceDeclaration nsdecl = new NamespaceDeclaration("My.NS");
nsdecl.AddClass("MyClass").AddConstructor();
CodeBuilder builder = new CodeBuilder();
builder.GenerateCode(Console.Out, nsdecl);
}
示例3: VisitNamespaceDeclaration
public override void VisitNamespaceDeclaration (NamespaceDeclaration namespaceDeclaration)
{
AddUsings (namespaceDeclaration);
if (!namespaceDeclaration.RBraceToken.IsNull)
AddFolding (namespaceDeclaration.LBraceToken.GetPrevNode ().EndLocation, namespaceDeclaration.RBraceToken.EndLocation);
base.VisitNamespaceDeclaration (namespaceDeclaration);
}
示例4: Visit
public override void Visit(ModuleContainer mc)
{
bool first = true;
foreach (var container in mc.Containers) {
var nspace = container as NamespaceContainer;
if (nspace == null) {
container.Accept(this);
continue;
}
NamespaceDeclaration nDecl = null;
var loc = LocationsBag.GetLocations(nspace);
if (nspace.NS != null && !string.IsNullOrEmpty(nspace.NS.Name)) {
nDecl = new NamespaceDeclaration ();
if (loc != null) {
nDecl.AddChild(new CSharpTokenNode (Convert(loc [0]), Roles.NamespaceKeyword), Roles.NamespaceKeyword);
}
ConvertNamespaceName(nspace.RealMemberName, nDecl);
if (loc != null && loc.Count > 1) {
nDecl.AddChild(new CSharpTokenNode (Convert(loc [1]), Roles.LBrace), Roles.LBrace);
}
AddToNamespace(nDecl);
namespaceStack.Push(nDecl);
}
if (nspace.Usings != null) {
foreach (var us in nspace.Usings) {
us.Accept(this);
}
}
if (first) {
first = false;
if (mc.OptAttributes != null) {
foreach (var attr in mc.OptAttributes.Sections) {
unit.AddChild (ConvertAttributeSection (attr), SyntaxTree.MemberRole);
}
}
}
if (nspace.Containers != null) {
foreach (var subContainer in nspace.Containers) {
subContainer.Accept(this);
}
}
if (nDecl != null) {
AddAttributeSection (nDecl, nspace.UnattachedAttributes, EntityDeclaration.UnattachedAttributeRole);
if (loc != null && loc.Count > 2)
nDecl.AddChild (new CSharpTokenNode (Convert (loc [2]), Roles.RBrace), Roles.RBrace);
if (loc != null && loc.Count > 3)
nDecl.AddChild (new CSharpTokenNode (Convert (loc [3]), Roles.Semicolon), Roles.Semicolon);
namespaceStack.Pop ();
} else {
AddAttributeSection (unit, nspace.UnattachedAttributes, EntityDeclaration.UnattachedAttributeRole);
}
}
AddAttributeSection (unit, mc.UnattachedAttributes, EntityDeclaration.UnattachedAttributeRole);
}
示例5: VerifySingleArg
public void VerifySingleArg()
{
NamespaceDeclaration nsdecl = new NamespaceDeclaration("My.NS");
nsdecl.AddClass("MyClass")
.AddConstructor(typeof(int), "id", "_id");
CodeBuilder builder = new CodeBuilder();
builder.GenerateCode(Console.Out, nsdecl);
}
示例6: VisitNamespaceDeclaration
public object VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data)
{
if (module.Namespace != null) {
AddError(namespaceDeclaration, "Only one namespace declaration per file is supported.");
return null;
}
module.Namespace = new B.NamespaceDeclaration(GetLexicalInfo(namespaceDeclaration));
module.Namespace.Name = namespaceDeclaration.Name;
return namespaceDeclaration.AcceptChildren(this, data);
}
示例7: VerifyMultipleArgs
public void VerifyMultipleArgs()
{
NamespaceDeclaration nsdecl = new NamespaceDeclaration("My.Stuff");
nsdecl.AddClass("SomeClass")
.AddConstructor("Initializes a new instance of SomeClass",
new ConstructorArg(typeof(int), "id", "_id", "ID of the person"),
new ConstructorArg(typeof(string), "name", "_name", "Name of the person")
);
new CodeBuilder().GenerateCode(Console.Out, nsdecl);
}
示例8: WriteNamespace
private void WriteNamespace(NamespaceDeclaration namespaceDeclarationNode)
{
if (Bag.Current.Type != null)
{
Bag.PushScope();
}
var prefix = namespaceDeclarationNode.Prefix;
var ns = namespaceDeclarationNode.Namespace;
xamlTypeRepository.RegisterPrefix(new PrefixRegistration(prefix, ns));
}
示例9: ParseExpandedElement
private IEnumerable<ProtoInstruction> ParseExpandedElement(XamlType xamlType, NamespaceDeclaration namespaceDeclaration, AttributeFeed attributes)
{
var element = instructionBuilder.NonEmptyElement(xamlType.UnderlyingType, namespaceDeclaration);
foreach (var instruction in CommonNodesOfElement(xamlType, element, attributes)) yield return instruction;
reader.Read();
foreach (var instruction in ParseInnerTextIfAny()) yield return instruction;
foreach (var instruction in ParseNestedElements(xamlType)) yield return instruction;
yield return instructionBuilder.EndTag();
}
示例10: VisitNamespaceDeclaration
public override void VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration)
{
var old = this.m_CurrentNamespace;
if (this.m_CurrentNamespace == "")
this.m_CurrentNamespace = namespaceDeclaration.Name;
else
this.m_CurrentNamespace += "." + namespaceDeclaration.Name;
base.VisitNamespaceDeclaration(namespaceDeclaration);
this.m_CurrentNamespace = old;
}
示例11: AddNamespace
public virtual void AddNamespace(string prefix, string uri)
{
if (uri == null)
{
throw new ArgumentNullException("uri");
}
if (prefix == null)
{
throw new ArgumentNullException("prefix");
}
prefix = this.nameTable.Add(prefix);
uri = this.nameTable.Add(uri);
if (Ref.Equal(this.xml, prefix) && !uri.Equals("http://www.w3.org/XML/1998/namespace"))
{
throw new ArgumentException(Res.GetString("Xml_XmlPrefix"));
}
if (Ref.Equal(this.xmlNs, prefix))
{
throw new ArgumentException(Res.GetString("Xml_XmlnsPrefix"));
}
int namespaceDecl = this.LookupNamespaceDecl(prefix);
int previousNsIndex = -1;
if (namespaceDecl != -1)
{
if (this.nsdecls[namespaceDecl].scopeId == this.scopeId)
{
this.nsdecls[namespaceDecl].uri = uri;
return;
}
previousNsIndex = namespaceDecl;
}
if (this.lastDecl == (this.nsdecls.Length - 1))
{
NamespaceDeclaration[] destinationArray = new NamespaceDeclaration[this.nsdecls.Length * 2];
Array.Copy(this.nsdecls, 0, destinationArray, 0, this.nsdecls.Length);
this.nsdecls = destinationArray;
}
this.nsdecls[++this.lastDecl].Set(prefix, uri, this.scopeId, previousNsIndex);
if (this.useHashtable)
{
this.hashTable[prefix] = this.lastDecl;
}
else if (this.lastDecl >= 0x10)
{
this.hashTable = new Dictionary<string, int>(this.lastDecl);
for (int i = 0; i <= this.lastDecl; i++)
{
this.hashTable[this.nsdecls[i].prefix] = i;
}
this.useHashtable = true;
}
}
示例12: VisitNamespace
public override bool VisitNamespace(NamespaceDeclaration ns)
{
if (!identifierService.IsValidNamespaceName(ns.Name))
{
errorReport.Error( "TODOFILENAME", ns.Position, "'{0}' is an invalid namespace name.", ns.Name );
return false;
}
ns.SymbolTable.CurrentNamespace = ns.SymbolTable.TypeGraphView.DefineNamespace(ns.Name);
return base.VisitNamespace(ns);
}
示例13: Execute
public override async void Execute(EditorRefactoringContext context)
{
SyntaxTree st = await context.GetSyntaxTreeAsync().ConfigureAwait(false);
ICompilation compilation = await context.GetCompilationAsync().ConfigureAwait(false);
CSharpFullParseInformation info = await context.GetParseInformationAsync().ConfigureAwait(false) as CSharpFullParseInformation;
EntityDeclaration node = (EntityDeclaration)st.GetNodeAt(context.CaretLocation, n => n is TypeDeclaration || n is DelegateDeclaration);
IDocument document = context.Editor.Document;
FileName newFileName = FileName.Create(Path.Combine(Path.GetDirectoryName(context.FileName), MakeValidFileName(node.Name)));
string header = CopyFileHeader(document, info);
string footer = CopyFileEnd(document, info);
AstNode newNode = node.Clone();
foreach (var ns in node.Ancestors.OfType<NamespaceDeclaration>()) {
var newNS = new NamespaceDeclaration(ns.Name);
newNS.Members.AddRange(ns.Children.Where(ch => ch is UsingDeclaration
|| ch is UsingAliasDeclaration
|| ch is ExternAliasDeclaration).Select(usingDecl => usingDecl.Clone()));
newNS.AddMember(newNode);
newNode = newNS;
}
var topLevelUsings = st.Children.Where(ch => ch is UsingDeclaration
|| ch is UsingAliasDeclaration
|| ch is ExternAliasDeclaration);
StringBuilder newCode = new StringBuilder(header);
CSharpOutputVisitor visitor = new CSharpOutputVisitor(new StringWriter(newCode), FormattingOptionsFactory.CreateSharpDevelop());
foreach (var topLevelUsing in topLevelUsings)
topLevelUsing.AcceptVisitor(visitor);
newNode.AcceptVisitor(visitor);
newCode.AppendLine(footer);
IViewContent viewContent = FileService.NewFile(newFileName, newCode.ToString());
viewContent.PrimaryFile.SaveToDisk(newFileName);
// now that the code is saved in the other file, remove it from the original document
RemoveExtractedNode(context, node);
IProject project = (IProject)compilation.GetProject();
if (project != null) {
FileProjectItem projectItem = new FileProjectItem(project, ItemType.Compile);
projectItem.FileName = newFileName;
ProjectService.AddProjectItem(project, projectItem);
FileService.FireFileCreated(newFileName, false);
project.Save();
ProjectBrowserPad.RefreshViewAsync();
}
}
示例14: AddChildTypeDeclaration
public static void AddChildTypeDeclaration(this AstNode tree, TypeDeclaration newClass,
NamespaceDeclaration parentNamespace = null)
{
if (null != parentNamespace)
{
var newNamespaceNode = new NamespaceDeclaration(
parentNamespace.Name);
newNamespaceNode.AddMember(newClass);
tree.AddChild(newNamespaceNode, SyntaxTree.MemberRole);
}
else
{
tree.AddChild(newClass, Roles.TypeMemberRole);
}
}
示例15: VisitNamespaceDeclaration
public override void VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration)
{
FixOpenBrace(policy.NamespaceBraceStyle, namespaceDeclaration.LBraceToken);
if (policy.IndentNamespaceBody)
curIndent.Push(IndentType.Block);
bool first = true;
bool startFormat = false;
VisitChildrenToFormat(namespaceDeclaration, child => {
if (first) {
startFormat = child.StartLocation > namespaceDeclaration.LBraceToken.StartLocation;
}
if (child.Role == Roles.LBrace) {
var next = child.GetNextSibling(NoWhitespacePredicate);
var blankLines = 1;
if (next is UsingDeclaration || next is UsingAliasDeclaration) {
blankLines += policy.BlankLinesBeforeUsings;
} else {
blankLines += policy.BlankLinesBeforeFirstDeclaration;
}
EnsureNewLinesAfter(child, blankLines);
startFormat = true;
return;
}
if (child.Role == Roles.RBrace) {
startFormat = false;
return;
}
if (!startFormat || !NoWhitespacePredicate (child))
return;
if (first && (child is UsingDeclaration || child is UsingAliasDeclaration)) {
// TODO: policy.BlankLinesBeforeUsings
first = false;
}
if (NoWhitespacePredicate(child))
FixIndentationForceNewLine(child);
child.AcceptVisitor(this);
if (NoWhitespacePredicate(child))
EnsureNewLinesAfter(child, GetGlobalNewLinesFor(child));
});
if (policy.IndentNamespaceBody)
curIndent.Pop();
FixClosingBrace(policy.NamespaceBraceStyle, namespaceDeclaration.RBraceToken);
}