当前位置: 首页>>代码示例>>C#>>正文


C# IElement.GetCustomVariableRecursively方法代码示例

本文整理汇总了C#中IElement.GetCustomVariableRecursively方法的典型用法代码示例。如果您正苦于以下问题:C# IElement.GetCustomVariableRecursively方法的具体用法?C# IElement.GetCustomVariableRecursively怎么用?C# IElement.GetCustomVariableRecursively使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IElement的用法示例。


在下文中一共展示了IElement.GetCustomVariableRecursively方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetRightSideAssignmentValueAsString

        public static string GetRightSideAssignmentValueAsString(IElement element, InstructionSave instruction)
        {
            CustomVariable customVariable = element.GetCustomVariableRecursively(instruction.Member);

            IElement referencedElement = null;

            #region Determine if the assignment is a file

            bool isFile = false;

            if (customVariable != null)
            {
                referencedElement =
                    BaseElementTreeNode.GetElementIfCustomVariableIsVariableState(customVariable, element);

                isFile = customVariable.GetIsFile();

            }

            #endregion

            string valueAsString = "";

            if (referencedElement == null)
            {

                valueAsString = CodeParser.ParseObjectValue(instruction.Value);

                if (isFile)
                {
                    valueAsString = valueAsString.Replace("\"", "");

                    if (valueAsString == "<NONE>")
                    {
                        valueAsString = "null";
                    }
                }
                else if (CustomVariableCodeGenerator.ShouldAssignToCsv(customVariable, valueAsString))
                {
                    valueAsString = CustomVariableCodeGenerator.GetAssignmentToCsvItem(customVariable, element, valueAsString);
                }
                else if (customVariable != null && customVariable.Type == "Color")
                {
                    valueAsString = "Color." + valueAsString.Replace("\"", "");
                }
                if (customVariable != null && !string.IsNullOrEmpty(customVariable.SourceObject) && !isFile)
                {
                    NamedObjectSave namedObject = element.GetNamedObjectRecursively(customVariable.SourceObject);

                    bool isVariableState = customVariable.GetIsVariableState();

                    IElement objectElement = null;

                    if (namedObject != null)
                    {
                        ObjectFinder.Self.GetIElement(namedObject.SourceClassType);
                    }

                    if (objectElement != null)
                    {
                        if (isVariableState)
                        {
                            string typeName = "VariableState";

                            StateSaveCategory category = objectElement.GetStateCategoryRecursively(customVariable.Type);

                            if(category != null && category.SharesVariablesWithOtherCategories == false)
                            {
                                typeName = category.Name;
                            }
                            valueAsString = objectElement.Name.Replace("/", ".").Replace("\\", ".") + "." + typeName + "." + valueAsString.Replace("\"", "");
                        }
                    }

                    valueAsString = CodeWriter.MakeLocalizedIfNecessary(
                        namedObject,
                        instruction.Member,
                        instruction.Value,
                        valueAsString,
                        customVariable);
                }
            }
            else
            {
                string enumValue = (string)instruction.Value;

                if (!string.IsNullOrEmpty(enumValue))
                {
                    string variableType = "VariableState";

                    if (customVariable != null && customVariable.Type.ToLower() != "string")
                    {
                        variableType = customVariable.Type;
                    }
                    valueAsString = FullyQualifyStateValue(referencedElement, enumValue, variableType);
                }

            }
            return valueAsString;
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:100,代码来源:StateCodeGenerator.cs

示例2: GenerateCurrentStateCodeForIndividualState

        private static ICodeBlock GenerateCurrentStateCodeForIndividualState(IElement element, ICodeBlock codeBlock, StateSave stateSave, string enumType)
        {
            var curBlock = codeBlock.Case(enumType + "." + stateSave.Name);
            bool doesStateAssignAbsoluteValues = GetDoesStateAssignAbsoluteValues(stateSave, element);

            foreach (InstructionSave instruction in stateSave.InstructionSaves)
            {
                if (instruction.Value != null)
                {
                    // Get the valueAsString, which is the right-side of the equals sign
                    string rightSideOfEquals = GetRightSideAssignmentValueAsString(element, instruction);
                    
                    if (!string.IsNullOrEmpty(rightSideOfEquals))
                    {
                        CustomVariable customVariable = element.GetCustomVariableRecursively(instruction.Member);
                        NamedObjectSave referencedNos = element.GetNamedObjectRecursively(customVariable.SourceObject);

                        if (referencedNos != null)
                        {
                            NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(curBlock, referencedNos);
                        }

                        string leftSideOfEquals = GetLeftSideOfEquals(element, customVariable, instruction, false);
                        string leftSideOfEqualsWithRelative = GetLeftSideOfEquals(element, customVariable, instruction, true);




                        if (leftSideOfEquals != leftSideOfEqualsWithRelative)
                        {
                            string objectWithParent = null;

                            if (string.IsNullOrEmpty(customVariable.SourceObject))
                            {
                                objectWithParent = "this";
                            }
                            else
                            {
                                objectWithParent = customVariable.SourceObject;
                            }

                            curBlock
                                .If(objectWithParent + ".Parent == null")
                                    .Line(leftSideOfEquals + " = " + rightSideOfEquals + ";")
                                .End()

                                .Else()
                                    .Line(leftSideOfEqualsWithRelative + " = " + rightSideOfEquals + ";");
                        }
                        else
                        {
                            curBlock.Line(leftSideOfEquals + " = " + rightSideOfEquals + ";");
                        }

                        if (referencedNos != null)
                        {
                            NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(curBlock, referencedNos);
                        }

                    }
                }
            }

            return codeBlock;
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:65,代码来源:StateCodeGenerator.cs

示例3: GetDoesStateAssignAbsoluteValues

        private static bool GetDoesStateAssignAbsoluteValues(StateSave stateSave, IElement element)
        {
            bool returnValue = false;
            foreach (InstructionSave instruction in stateSave.InstructionSaves)
            {
                CustomVariable customVariable = element.GetCustomVariableRecursively(instruction.Member);

                if (customVariable != null)
                {
                    returnValue |= !string.IsNullOrEmpty(RelativeValueForInstruction(instruction, customVariable, element));
                }
            }

            return returnValue;
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:15,代码来源:StateCodeGenerator.cs

示例4: CreateInstanceMembersForVariables

        private static void CreateInstanceMembersForVariables(IElement element, MemberCategory category)
        {
            foreach (CustomVariable variable in element.CustomVariables)
            {
                Type type = variable.GetRuntimeType();
                if (type == null)
                {
                    type = typeof(string);
                }

                string name = variable.Name;
                //object value = variable.DefaultValue;

                // todo - do something with converter

                var instanceMember = new DataGridItem();
                instanceMember.CustomGetTypeEvent += (throwaway) => type;
                string displayName = StringFunctions.InsertSpacesInCamelCaseString(name);

                
                instanceMember.DisplayName = displayName;
                instanceMember.UnmodifiedVariableName = name;

                TypeConverter converter = variable.GetTypeConverter(element);
                instanceMember.TypeConverter = converter;

                instanceMember.CustomSetEvent += (intance, value) =>
                    {
                        instanceMember.IsDefault = false;

                        RefreshLogic.IgnoreNextRefresh();


                        element.GetCustomVariableRecursively(name).DefaultValue = value;


                        GlueCommands.Self.GluxCommands.SaveGlux();

                        GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();

                        GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode();
                    };

                instanceMember.CustomGetEvent += (instance) =>
                    {
                        return element.GetCustomVariableRecursively(name).DefaultValue;
                    };

                instanceMember.IsDefaultSet += (owner, args) =>
                {
                    
                    element.GetCustomVariableRecursively(name).DefaultValue = null;


                    GlueCommands.Self.GluxCommands.SaveGlux();

                    GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();

                    GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode();

                };

                instanceMember.SetValueError = (newValue) =>
                {
                    if (newValue is string && string.IsNullOrEmpty(newValue as string))
                    {
                        element.GetCustomVariableRecursively(name).DefaultValue = null;

                        GlueCommands.Self.GluxCommands.SaveGlux();

                        GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();

                        GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode();
                    }
                };

                category.Members.Add(instanceMember);
            }
        }
开发者ID:GorillaOne,项目名称:FlatRedBall,代码行数:79,代码来源:ElementVariableShowingLogic.cs


注:本文中的IElement.GetCustomVariableRecursively方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。