/// <summary> /// コンストラクタ /// </summary> /// <param name="node">対象Node</param> /// <param name="semanticModel">対象ソースのsemanticModel</param> /// <param name="parent">親IAnalyzeItem</param> /// <param name="container">イベントコンテナ</param> public ItemProperty(PropertyDeclarationSyntax node, SemanticModel semanticModel, IAnalyzeItem parent, EventContainer container) : base(parent, node, semanticModel, container) { ItemType = ItemTypes.Property; var declaredSymbol = semanticModel.GetDeclaredSymbol(node); // プロパティの型設定 var parts = ((IPropertySymbol)declaredSymbol).Type.ToDisplayParts(SymbolDisplayFormat.MinimallyQualifiedFormat); foreach (var part in parts) { // スペースの場合は型設定に含めない if (part.Kind == SymbolDisplayPartKind.Space) { continue; } var name = Expression.GetSymbolName(part, true); var type = Expression.GetSymbolTypeName(part.Symbol); if (part.Kind == SymbolDisplayPartKind.ClassName) { // 外部ファイル参照イベント発行 RaiseOtherFileReferenced(node, part.Symbol); } PropertyTypes.Add(new Expression(name, type)); } // アクセサ設定 if (node.AccessorList is null) { AccessorList.Add(ItemFactory.Create(node.ExpressionBody, semanticModel, container, this)); } else { AccessorList.AddRange(node.AccessorList.Accessors.Select(accessor => ItemFactory.Create(accessor, semanticModel, container, this))); } // デフォルト設定 if (node.Initializer == null) { return; } var propertyInitializer = semanticModel.GetOperation(node.Initializer.Value); DefaultValues.AddRange(OperationFactory.GetExpressionList(propertyInitializer, container)); }
public PropertyType EnsurePropertyType(string name, DataType dataType) { if (_editor == null) { _editor = new SchemaEditor(); } var existing = PropertyTypes.FirstOrDefault(x => x.Name == name); if (existing != null) { if (existing.DataType != dataType) { throw new ApplicationException($"DataType mismatch {existing.DataType} <-> {dataType}. PropertyType name: {name}, "); } return(existing); } var pt = _editor.CreatePropertyType(name, dataType); PropertyTypes.Add(pt); return(pt); }