Пример #1
0
        public override void ApplyPropertyMeta(BaseMightyMember mightyMember, BaseMetaAttribute metaAttribute)
        {
            var infoBoxAttribute = (InfoBoxAttribute)metaAttribute;

            if (!m_infoBoxCache.Contains(mightyMember))
            {
                InitDrawer(mightyMember, metaAttribute);
            }
            var visibleInfo = m_infoBoxCache[mightyMember];

            if (visibleInfo.Value)
            {
                DrawInfoBox(infoBoxAttribute.Text, infoBoxAttribute.Type);
            }
            else
            {
                EditorDrawUtility.DrawHelpBox($"{typeof(InfoBoxAttribute).Name} needs a valid boolean condition to work");
            }
        }
Пример #2
0
 public abstract void ApplyPropertyMeta(BaseMightyMember mightyMember, BaseMetaAttribute metaAttribute);
Пример #3
0
        private CodeMemberProperty CreateAttribute(MetaType metaType, BaseMetaAttribute attr)
        {
            var resultAttribute = new CodeMemberProperty();

            var targetAttr = attr as MetaAttribute;

            if (attr is MetaReferenceAttribute refAttr)
            {
                var relation = GetMembers(metaType).ToList().Find(i => i is MetaRelation r && r.Name == refAttr.RelationName) as MetaRelation;
                if (relation == null)
                {
                    throw new CodeGeneratorException($"Can't find relation for reference attribute {attr.Name}");
                }

                var targetType = this.Model.GetMetaType(relation.TargetTypeName);
                if (targetType == null)
                {
                    if (this.Interfaces.Exists(i => i.Name == relation.TargetTypeName))
                    {
                        targetAttr = GetMembers(this.Interfaces.Find(i => i.Name == relation.TargetTypeName))
                                     .ToList().Find(i => i is MetaAttribute a && a.Name == refAttr.TargetAttributeName) as MetaAttribute;
                        if (targetAttr == null)
                        {
                            throw new CodeGeneratorException($"Can't find target attribute {refAttr.TargetAttributeName} for {refAttr.Name}");
                        }
                    }
                    else
                    {
                        throw new CodeGeneratorException($"Can't find type {relation.TargetTypeName} for relation {relation.Name}");
                    }
                }
                else
                {
                    targetAttr = GetMembers(targetType).ToList().Find(i => i is MetaAttribute a && a.Name == refAttr.TargetAttributeName) as MetaAttribute;
                    if (targetAttr == null)
                    {
                        throw new CodeGeneratorException($"Can't find target attribute {refAttr.TargetAttributeName} for {refAttr.Name}");
                    }
                }
            }

            resultAttribute.Name       = attr.Name;
            resultAttribute.Type       = new CodeTypeReference(ValueTypeMap[targetAttr.DataType]);
            resultAttribute.Attributes = MemberAttributes.Public;

            if (IsInherited(metaType, attr.Name))
            {
                resultAttribute.Attributes |= MemberAttributes.Override;
            }

            resultAttribute.CustomAttributes.Add(new CodeAttributeDeclaration(
                                                     new CodeTypeReference(typeof(DisplayNameAttribute).FullName),
                                                     new CodeAttributeArgument(new CodePrimitiveExpression(string.IsNullOrEmpty(attr.DisplayName) ? attr.Name : attr.DisplayName))));
            resultAttribute.CustomAttributes.Add(new CodeAttributeDeclaration(
                                                     new CodeTypeReference(typeof(DescriptionAttribute).FullName),
                                                     new CodeAttributeArgument(new CodePrimitiveExpression(attr.Description ?? ""))));
            resultAttribute.CustomAttributes.Add(new CodeAttributeDeclaration(
                                                     new CodeTypeReference(typeof(BrowsableAttribute).FullName),
                                                     new CodeAttributeArgument(new CodePrimitiveExpression(attr.Browsable))));
            resultAttribute.CustomAttributes.Add(new CodeAttributeDeclaration(
                                                     new CodeTypeReference(typeof(CategoryAttribute).FullName),
                                                     new CodeAttributeArgument(new CodePrimitiveExpression(attr.Category))));
            resultAttribute.CustomAttributes.Add(new CodeAttributeDeclaration(
                                                     new CodeTypeReference(typeof(ReadOnlyAttribute).FullName),
                                                     new CodeAttributeArgument(new CodePrimitiveExpression(attr.Readonly))));

            resultAttribute.GetStatements.Add(new CodeMethodReturnStatement(
                                                  new CodeCastExpression(ValueTypeMap[targetAttr.DataType], new CodeMethodInvokeExpression(
                                                                             new CodeThisReferenceExpression(), attr is MetaAttribute ? "GetAttribute" : "GetReferenceAttribute", new CodePrimitiveExpression(attr.Name))
                                                                         ))
                                              );

            if (attr is MetaAttribute)
            {
                resultAttribute.SetStatements.Add(new CodeMethodInvokeExpression(
                                                      new CodeThisReferenceExpression(), "SetAttribute", new CodePrimitiveExpression(attr.Name), new CodePropertySetValueReferenceExpression()
                                                      ));

                resultAttribute.SetStatements.Add(new CodeMethodInvokeExpression(
                                                      new CodeThisReferenceExpression(), "OnPropertyChanged", new CodePrimitiveExpression(attr.Name)
                                                      ));
            }

            return(resultAttribute);
        }