Exemplo n.º 1
0
        static StructModel ParseStruct(StructDeclarationSyntax s, ClassDeclarationSyntax matchingProxy)
        {
            bool isObsolete = false;
            bool isEditable = false;

            var allAttributes = s.AttributeLists.SelectMany(al => al.Attributes);

            foreach (var attribute in allAttributes)
            {
                isObsolete |= attribute.Name.ToString() == "Obsolete";
                isEditable |= attribute.Name.ToString() == "ComponentEditor";
            }

            if (isObsolete || !isEditable)
            {
                return(null);
            }

            if (s.BaseList != null)
            {
                foreach (var baseTypeSyntax in s.BaseList.Types.OfType <SimpleBaseTypeSyntax>())
                {
                    var t = StructModel.ParseType(baseTypeSyntax, s.AttributeLists.SelectMany(l => l.Attributes));
                    if (t != StructType.Unknown)
                    {
                        return(new StructModel(s, t, matchingProxy));
                    }
                }
            }

            return(null);
        }
Exemplo n.º 2
0
 void SetStructType(StructModel structModel, StructType type)
 {
     structModel.Type = type;
     SetModelDirty();
     Reload();
     m_StructTypeLabel.text = MakeStructTypeTooltip(type);
 }
Exemplo n.º 3
0
 static void PickStructType(StructModel structModel, Action <StructModel, StructType> action)
 {
     EditorUtility.DisplayCustomMenu(
         new Rect(Event.current.mousePosition, Vector2.one),
         s_StructTypeOptions,
         UnsafeUtility.EnumToInt(structModel.Type),
         (data, options, selected) =>
     {
         StructType type = (StructType)selected;
         action(structModel, type);
     },
         null);
 }
Exemplo n.º 4
0
        void CreateStructView(StructModel structModel)
        {
            m_StructNameField.value     = structModel.Name;
            m_PickStructTypeButton.text = structModel.Type.ToString();
            if (CurrentStruct != null)
            {
                m_StructTypeLabel.text = MakeStructTypeTooltip(CurrentStruct.Type);
            }

            m_FieldsSection.Clear();
            foreach (var fieldModel in structModel.Fields)
            {
                var fieldRow = MakeFieldRow(fieldModel);
                m_FieldsSection.Add(fieldRow);
            }
        }
Exemplo n.º 5
0
        internal FileModel(Microsoft.CodeAnalysis.SyntaxTree tree, ParseOptions options)
        {
            Tree = tree;
            var structs = tree.GetCompilationUnitRoot().DescendantNodes(n => !(n is StructDeclarationSyntax)).OfType <StructDeclarationSyntax>();
            var classes = tree.GetCompilationUnitRoot().DescendantNodes(n => !(n is ClassDeclarationSyntax)).OfType <ClassDeclarationSyntax>();

            Structs = new List <StructModel>();
            foreach (var s in structs)
            {
                var matchingProxy = classes.SingleOrDefault(c => c.Identifier.Text == StructModel.MakeProxyName(s.Identifier.Text));
                var model         = ParseStruct(s, matchingProxy);
                if (model != null)
                {
                    Structs.Add(model);
                }
            }

            if (Structs.Count > 1 && options == ParseOptions.DisallowMultipleStructs)
            {
                throw new InvalidOperationException("File contains multiple component definitions");
            }
        }