public BoundInterpolatedStringExpression(InterpolatedStringExpressionSyntax node, string builtStr, BoundExpression[] interpolatedExpressions, BindContext context) : base(node) { ValueType = context.GetTypeSymbol(SpecialType.System_String); BuiltStr = new BoundConstantExpression(new ConstantValue <string>(builtStr), ValueType, node); InterpolationExpressions = interpolatedExpressions; ObjectArr = context.GetTypeSymbol(SpecialType.System_Object).MakeArrayType(context); if (interpolatedExpressions.Length > 3) { StringFormatMethod = ValueType.GetMembers <ExternMethodSymbol>("Format", context).First(e => e.Parameters[0].Type == ValueType && e.Parameters[1].Type == ObjectArr); } else { StringFormatMethod = ValueType.GetMembers <ExternMethodSymbol>("Format", context).First(e => e.Parameters[0].Type == ValueType && e.Parameters.Length == interpolatedExpressions.Length + 1); } }
protected override void Initialize() { IDataItemAttribute atd = (IDataItemAttribute)Context.AttributeProvider.GetCustomAttribute(ValueType, typeof(IDataItemAttribute), false); if (atd != null) { if (!string.IsNullOrEmpty(atd.Name)) { Name = atd.Name; } if (atd.FallbackType != null) { fallbackType = atd.FallbackType; if (!typeof(IExtendedDataItem).IsAssignableFrom(fallbackType)) { throw new InvalidOperationException("Fallback type '" + fallbackType + "' must implement IExtendedDataItem"); } if (!ValueType.IsAssignableFrom(fallbackType)) { throw new InvalidOperationException("Fallback type '" + fallbackType + "' must be a subclass of '" + ValueType + "'"); } } } object[] incs = Attribute.GetCustomAttributes(ValueType, typeof(DataIncludeAttribute), true); foreach (DataIncludeAttribute incat in incs) { Context.IncludeType(incat.Type); } if (ValueType.BaseType != null) { ClassDataType baseType = (ClassDataType)Context.GetConfigurationDataType(ValueType.BaseType); baseType.AddSubtype(this); int n = 0; foreach (ItemProperty prop in baseType.Properties) { properties.Add(prop.Name, prop); sortedPoperties.Insert(n++, prop); } // Inherit the fallback type if (fallbackType == null && baseType.fallbackType != null) { fallbackType = baseType.fallbackType; } } foreach (Type interf in ValueType.GetInterfaces()) { ClassDataType baseType = (ClassDataType)Context.GetConfigurationDataType(interf); baseType.AddSubtype(this); } MemberInfo[] members = ValueType.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); foreach (MemberInfo member in members) { if ((member is FieldInfo || member is PropertyInfo) && member.DeclaringType == ValueType) { Type memberType = member is FieldInfo ? ((FieldInfo)member).FieldType : ((PropertyInfo)member).PropertyType; AddProperty(member, member.Name, memberType); } } foreach (ItemMember member in Context.AttributeProvider.GetItemMembers(ValueType)) { AddProperty(member, member.Name, member.Type); } if (fallbackType != null) { Context.IncludeType(fallbackType); } }