/// <summary> /// Given anonymous type provided constructs an implementation type symbol to be used in emit phase; /// if the anonymous type has at least one field the implementation type symbol will be created based on /// a generic type template generated for each 'unique' anonymous type structure, otherwise the template /// type will be non-generic. /// </summary> private NamedTypeSymbol ConstructAnonymousTypeImplementationSymbol(AnonymousTypePublicSymbol anonymous) { Debug.Assert(ReferenceEquals(this, anonymous.Manager)); CheckSourceLocationSeen(anonymous); AnonymousTypeDescriptor typeDescr = anonymous.TypeDescriptor; typeDescr.AssertIsGood(); // Get anonymous type template AnonymousTypeTemplateSymbol template; if (!this.AnonymousTypeTemplates.TryGetValue(typeDescr.Key, out template)) { // NOTE: the newly created template may be thrown away if another thread wins template = this.AnonymousTypeTemplates.GetOrAdd(typeDescr.Key, new AnonymousTypeTemplateSymbol(this, typeDescr)); } // Adjust template location if the template is owned by this manager if (ReferenceEquals(template.Manager, this)) { template.AdjustLocation(typeDescr.Location); } // In case template is not generic, just return it if (template.Arity == 0) { return template; } // otherwise construct type using the field types var typeArguments = typeDescr.Fields.SelectAsArray(f => f.Type); return template.Construct(typeArguments); }
internal AnonymousTypePropertySymbol(AnonymousTypePublicSymbol container, AnonymousTypeField field) { _containingType = container; _type = field.Type; _name = field.Name; _locations = ImmutableArray.Create <Location>(field.Location); _getMethod = new AnonymousTypePropertyGetAccessorSymbol(this); _backingField = null; }
internal AnonymousTypePropertySymbol(AnonymousTypePublicSymbol container, AnonymousTypeField field) { this.containingType = container; this.type = field.Type; this.name = field.Name; this.locations = ImmutableArray.Create<Location>(field.Location); this.getMethod = new AnonymousTypePropertyGetAccessorSymbol(this); this.backingField = null; }
internal AnonymousTypePropertySymbol( AnonymousTypePublicSymbol container, AnonymousTypeField field, int index ) : this( container, field, field.TypeWithAnnotations, index, ImmutableArray.Create <Location>(field.Location), includeBackingField : false ) { }
private void CheckSourceLocationSeen(AnonymousTypePublicSymbol anonymous) { #if DEBUG Location location = anonymous.Locations[0]; if (location.IsInSource) { if (this.AreTemplatesSealed) { Debug.Assert(_sourceLocationsSeen.ContainsKey(location)); } else { _sourceLocationsSeen.TryAdd(location, true); } } #endif }