本文整理汇总了C#中CompilationUnit.Add方法的典型用法代码示例。如果您正苦于以下问题:C# CompilationUnit.Add方法的具体用法?C# CompilationUnit.Add怎么用?C# CompilationUnit.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CompilationUnit
的用法示例。
在下文中一共展示了CompilationUnit.Add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestGetNamespaceContentsCase2
public void TestGetNamespaceContentsCase2 ()
{
CompilationUnit unit = new CompilationUnit ("file.cs");
unit.Add (new DomType ("ANamespace.AnotherNamespace.AClass"));
unit.Add (new DomType ("ANamespace.AnotherNamespace.BClass"));
unit.Add (new DomType ("ANamespace.AnotherNamespace.CClass"));
unit.Add (new DomType ("ANamespace.AClass2"));
unit.Add (new DomType ("ANamespace.BClass2"));
unit.Add (new DomType ("CClass3"));
List<IMember> member = new List<IMember> ();
unit.GetNamespaceContents (member, "ANamespace", true);
Assert.AreEqual (3, member.Count);
Namespace ns = member[0] as Namespace;
Assert.IsNotNull (ns);
Assert.AreEqual ("AnotherNamespace", ns.Name);
IType type = member[1] as IType;
Assert.IsNotNull (type);
Assert.AreEqual ("AClass2", type.Name);
type = member[2] as IType;
Assert.IsNotNull (type);
Assert.AreEqual ("BClass2", type.Name);
}
示例2: Parse
public override ParsedDocument Parse (ProjectDom dom, string fileName, string content)
{
ParsedDocument doc = new ParsedDocument (fileName);
doc.Flags |= ParsedDocumentFlags.NonSerializable;
Project p = (null == dom || null == dom.Project)?
IdeApp.Workspace.GetProjectContainingFile (fileName):
dom.Project;
ProjectInformation pi = ProjectInformationManager.Instance.Get (p);
CompilationUnit cu;
doc.CompilationUnit = cu = new CompilationUnit (fileName);
IType tmp;
IMember member;
string[] contentLines = content.Split (new string[]{Environment.NewLine}, StringSplitOptions.None);
DomType globals = new DomType (cu, ClassType.Unknown, GettextCatalog.GetString ("(Global Scope)"), new DomLocation (1, 1), string.Empty, new DomRegion (1, int.MaxValue), new List<IMember> ());
lock (pi) {
// Add containers to type list
foreach (LanguageItem li in pi.Containers ()) {
if (null == li.Parent && FilePath.Equals (li.File, fileName)) {
tmp = LanguageItemToIMember (pi, li, contentLines) as IType;
if (null != tmp){ cu.Add (tmp); }
}
}
// Add global category for unscoped symbols
foreach (LanguageItem li in pi.InstanceMembers ()) {
if (null == li.Parent && FilePath.Equals (li.File, fileName)) {
member = LanguageItemToIMember (pi, li, contentLines);
if (null != member) {
globals.Add (member);
}
}
}
}
cu.Add (globals);
return doc;
}
示例3: TestGetNamespaceContentsCase4
public void TestGetNamespaceContentsCase4 ()
{
CompilationUnit unit = new CompilationUnit ("file.cs");
unit.Add (new DomType ("ANamespace.AnotherNamespace.AClass"));
unit.Add (new DomType ("ANamespace.AnotherNamespace.BClass"));
unit.Add (new DomType ("ANamespace.AnotherNamespace.CClass"));
unit.Add (new DomType ("ANamespace.AClass2"));
unit.Add (new DomType ("ANamespace.BClass2"));
unit.Add (new DomType ("CClass3"));
List<IMember> member = new List<IMember> ();
unit.GetNamespaceContents (member, "ANamespace.NotExist", true);
Assert.AreEqual (0, member.Count);
}
示例4: GenerateCU
static void GenerateCU (XmlParsedDocument doc)
{
if (doc.XDocument == null || doc.XDocument.RootElement == null) {
doc.Add (new Error (ErrorType.Error, 1, 1, "No root node found."));
return;
}
XAttribute rootClass = doc.XDocument.RootElement.Attributes [new XName ("x", "Class")];
if (rootClass == null) {
doc.Add (new Error (ErrorType.Error, 1, 1, "Root node does not contain an x:Class attribute."));
return;
}
bool isApplication = doc.XDocument.RootElement.Name.Name == "Application";
string rootNamespace, rootType, rootAssembly;
XamlG.ParseXmlns (rootClass.Value, out rootType, out rootNamespace, out rootAssembly);
CompilationUnit cu = new CompilationUnit (doc.FileName);
doc.CompilationUnit = cu;
DomRegion rootRegion = doc.XDocument.RootElement.Region;
if (doc.XDocument.RootElement.IsClosed)
rootRegion.End = doc.XDocument.RootElement.ClosingTag.Region.End;
DomType declType = new DomType (cu, ClassType.Class, Modifiers.Partial | Modifiers.Public, rootType,
doc.XDocument.RootElement.Region.Start, rootNamespace, rootRegion);
cu.Add (declType);
DomMethod initcomp = new DomMethod ();
initcomp.Name = "InitializeComponent";
initcomp.Modifiers = Modifiers.Public;
initcomp.ReturnType = DomReturnType.Void;
declType.Add (initcomp);
DomField _contentLoaded = new DomField ("_contentLoaded");
_contentLoaded.ReturnType = new DomReturnType ("System.Boolean");
if (isApplication)
return;
cu.Add (new DomUsing (DomRegion.Empty, "System"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Documents"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Input"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media.Animation"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Shapes"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls.Primitives"));
// Dictionary<string,string> namespaceMap = new Dictionary<string, string> ();
// namespaceMap["x"] = "http://schemas.microsoft.com/winfx/2006/xaml";
XName nameAtt = new XName ("x", "Name");
foreach (XElement el in doc.XDocument.RootElement.AllDescendentElements) {
XAttribute name = el.Attributes [nameAtt];
if (name != null && name.IsComplete) {
string type = ResolveType (el);
if (type == null || type.Length == 0)
doc.Add (new Error (ErrorType.Error, el.Region.Start, "Could not find namespace for '" + el.Name.FullName + "'."));
else
declType.Add (new DomField (name.Value, Modifiers.Internal, el.Region.Start, new DomReturnType (type)));
}
}
}
示例5: PopulateClasses
/// <summary>
/// Populate a compilation unit with unparented classes
/// </summary>
void PopulateClasses(CompilationUnit cu)
{
foreach (KeyValuePair<int,RubyDeclaration> pair in classes) {
DomType myclass = new DomType (cu, ClassType.Class, pair.Value.name, new DomLocation (pair.Value.beginLine, 1), string.Empty,
new DomRegion (pair.Value.beginLine, pair.Value.beginColumn+1,
pair.Value.endLine, int.MaxValue), new List<IMember> ());
PopulateMethods (myclass);
cu.Add (myclass);
}// Add classes and member methods
}