/
property_container.go
32 lines (27 loc) · 1.06 KB
/
property_container.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT license.
*/
package astmodel
// PropertyContainer is implemented by Types that contain properties
// Provides readonly access as we need to use a TypeVisitor for modifications to preserve type wrapping
type PropertyContainer interface {
// Properties returns all the properties in this container
Properties() ReadOnlyPropertySet
// Property returns the property and true if the named property is found, nil and false otherwise
Property(name PropertyName) (*PropertyDefinition, bool)
// EmbeddedProperties returns all the embedded properties in this container
EmbeddedProperties() []*PropertyDefinition
}
// AsPropertyContainer converts a type into a property container
// Only use this readonly access as we must use a TypeVisitor for modifications to preserve type wrapping
func AsPropertyContainer(theType Type) (PropertyContainer, bool) {
switch t := theType.(type) {
case PropertyContainer:
return t, true
case MetaType:
return AsPropertyContainer(t.Unwrap())
default:
return nil, false
}
}