static IUnresolvedField LanguageItemToIField (IUnresolvedTypeDefinition type, LanguageItem item, string[] contentLines) { var result = new DefaultUnresolvedField (type, item.Name); result.Region = new DomRegion ((int)item.Line, 1, (int)item.Line + 1, 1); return result; }
public IUnresolvedField ReadField(FieldInfo field, IUnresolvedTypeDefinition parentType) { if (field == null) throw new ArgumentNullException("field"); if (parentType == null) throw new ArgumentNullException("parentType"); var f = new DefaultUnresolvedField(parentType, field.Name); f.Accessibility = GetAccessibility(field.Attributes); f.IsReadOnly = field.IsInitOnly; f.IsStatic = field.IsStatic; f.ReturnType = ReadTypeReference(field.FieldType, typeAttributes: field.CustomAttributes); if (field.Attributes.HasFlag (FieldAttributes.HasDefault)) { f.ConstantValue = CreateSimpleConstantValue(f.ReturnType, field.GetRawConstantValue ()); } else { var decConstant = field.CustomAttributes.FirstOrDefault(a => a.AttributeType.FullName == "System.Runtime.CompilerServices.DecimalConstantAttribute"); if (decConstant != null) { var constValue = TryDecodeDecimalConstantAttribute(decConstant); if (constValue != null) f.ConstantValue = CreateSimpleConstantValue(f.ReturnType, constValue); } } AddAttributes(field, f); if (field.GetRequiredCustomModifiers ().Any (mt => mt.FullName == typeof(IsVolatile).FullName)) { f.IsVolatile = true; } FinishReadMember(f, field); return f; }
internal static Task<IUnresolvedAssembly> LoadModuleAsync(Module module, ICorDebugModule corModule) { string name = corModule.GetName(); if (corModule.IsDynamic() == 1 || corModule.IsInMemory() == 1) { var defaultUnresolvedAssembly = new DefaultUnresolvedAssembly(name); var defaultUnresolvedTypeDefinition = new DefaultUnresolvedTypeDefinition("UnknownDynamicType"); var defaultUnresolvedMethod = new DefaultUnresolvedMethod(defaultUnresolvedTypeDefinition, "UnknownMethod"); var defaultUnresolvedField = new DefaultUnresolvedField(defaultUnresolvedTypeDefinition, "UnknownField"); defaultUnresolvedTypeDefinition.Members.Add(defaultUnresolvedMethod); defaultUnresolvedTypeDefinition.Members.Add(defaultUnresolvedField); defaultUnresolvedAssembly.AddTypeDefinition(defaultUnresolvedTypeDefinition); weakTable.Add(defaultUnresolvedAssembly, new ModuleMetadataInfo(module, null)); return Task.FromResult<IUnresolvedAssembly>(defaultUnresolvedAssembly); } //return Task.FromResult(LoadModule(module, name)); return Task.Run(() => LoadModule(module, name)); }
static IUnresolvedMember MakeEnumField(IUnresolvedTypeDefinition type, string name, object value) { var field = new DefaultUnresolvedField(type, name); field.Accessibility = Accessibility.Public; field.IsReadOnly = true; field.IsStatic = true; field.ReturnType = type; field.ConstantValue = CreateSimpleConstantValue(type, value); return field; }
public override void VisitElement(AXmlElement element) { string name = element.GetAttributeValue(XamlConst.XamlNamespace, "Name") ?? element.GetAttributeValue("Name"); string modifier = element.GetAttributeValue(XamlConst.XamlNamespace, "FieldModifier"); if (name != null && TypeDefinition != null) { var field = new DefaultUnresolvedField(TypeDefinition, name); field.Accessibility = Accessibility.Internal; field.ReturnType = CreateTypeReference(element.Namespace, element.LocalName); field.Region = new DomRegion(file.FileName, textDocument.GetLocation(element.StartOffset), textDocument.GetLocation(element.EndOffset)); if (modifier != null) field.Accessibility = ParseAccessibility(modifier); TypeDefinition.Members.Add(field); } base.VisitElement(element); }
static void GenerateCU (XmlParsedDocument doc) { if (doc.XDocument == null || doc.XDocument.RootElement == null) { doc.Add (new Error (ErrorType.Error, "No root node found.", 1, 1)); return; } XAttribute rootClass = doc.XDocument.RootElement.Attributes [new XName ("x", "Class")]; if (rootClass == null) { doc.Add (new Error (ErrorType.Error, "Root node does not contain an x:Class attribute.", 1, 1)); return; } bool isApplication = doc.XDocument.RootElement.Name.Name == "Application"; string rootNamespace, rootType, rootAssembly; XamlG.ParseXmlns (rootClass.Value, out rootType, out rootNamespace, out rootAssembly); var cu = new DefaultParsedDocument (doc.FileName); DomRegion rootRegion = doc.XDocument.RootElement.Region; if (doc.XDocument.RootElement.IsClosed) rootRegion = new DomRegion (doc.XDocument.RootElement.Region.FileName, doc.XDocument.RootElement.Region.Begin, doc.XDocument.RootElement.ClosingTag.Region.End); var declType = new DefaultUnresolvedTypeDefinition (rootNamespace, rootType) { Kind = TypeKind.Class, Accessibility = Accessibility.Public, Region = rootRegion }; cu.TopLevelTypeDefinitions.Add (declType); var initcomp = new DefaultUnresolvedMethod (declType, "InitializeComponent") { ReturnType = KnownTypeReference.Void, Accessibility = Accessibility.Public }; declType.Members.Add (initcomp); var _contentLoaded = new DefaultUnresolvedField (declType, "_contentLoaded") { ReturnType = KnownTypeReference.Boolean }; // was missing in the original code: correct ? // declType.Fields.Add (_contentLoaded); 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) cu.Add (new Error (ErrorType.Error, "Could not find namespace for '" + el.Name.FullName + "'.", el.Region.Begin)); else declType.Members.Add (new DefaultUnresolvedField (declType, name.Value) { Accessibility = Accessibility.Internal, Region = el.Region, ReturnType = new DefaultUnresolvedTypeDefinition (type) }); } } }