當前位置: 首頁>>代碼示例>>C#>>正文


C# Property.RemoveAllNodes方法代碼示例

本文整理匯總了C#中System.Property.RemoveAllNodes方法的典型用法代碼示例。如果您正苦於以下問題:C# Property.RemoveAllNodes方法的具體用法?C# Property.RemoveAllNodes怎麽用?C# Property.RemoveAllNodes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Property的用法示例。


在下文中一共展示了Property.RemoveAllNodes方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ChangeProperty

        private string ChangeProperty(Property propertyClone)
        {
            if (propertyClone == null)
                return String.Empty;

            ElementBuilder eb = CodeRush.Language.GetActiveElementBuilder();

            // convert auto-implemented property...
            if (propertyClone.IsAutoImplemented)
            {
                // so it's no longer an auto-implemented property....
                propertyClone.IsAutoImplemented = false;
                // remove all nodes and create new ones...
                propertyClone.RemoveAllNodes();

                // create a field variable...
                string varName = CodeRush.Strings.Get("FormatFieldName", propertyClone.Name);
                Variable var = eb.BuildVariable(propertyClone.MemberTypeReference, varName);

                // add property getter...
                Get getter = GetGetter(eb, varName);
                propertyClone.AddNode(getter);

                // create property setter...
                Set setter = GetSetter(eb, propertyClone, varName);
                propertyClone.AddNode(setter);

                return CodeRush.Language.GenerateElement(var) + CodeRush.Language.GenerateElement(propertyClone);
            }
            else
            {
                Set setter = propertyClone.Setter;
                if (setter == null)
                    return String.Empty;

                Assignment assignment = setter.Nodes[0] as Assignment;
                if (assignment == null)
                    return String.Empty;

                string varName = assignment.LeftSide.Name;
                propertyClone.RemoveNode(setter);

                // recreate setter...
                Set newSetter = GetSetter(eb, propertyClone, varName);
                propertyClone.AddNode(newSetter);
            }
            return CodeRush.Language.GenerateElement(propertyClone);
        }
開發者ID:kevinmiles,項目名稱:dxcorecommunityplugins,代碼行數:48,代碼來源:ConvertPropertyPlugIn.cs

示例2: ChangeProperty

        private string ChangeProperty(Property propertyClone, bool baseClassVersion, LanguageElement classExpression)
        {
            if (propertyClone == null)
                return String.Empty;

            ElementBuilder eb = CodeRush.Language.GetActiveElementBuilder();

            // so it's no longer an auto-implemented property....
            propertyClone.IsAutoImplemented = false;
            // remove all nodes and create new ones...
            propertyClone.RemoveAllNodes();

            // create a field variable if it doesn't already exist...
            string varName = CodeRush.Strings.Get("FormatFieldName", propertyClone.Name);
            Variable var = eb.BuildVariable(propertyClone.MemberTypeReference, varName);

            // add property getter...
            //Get getter = GetGetter(eb, varName);
            //propertyClone.AddNode(getter);
            string propDecl = String.Format("public {0} {1}\n{{\n", propertyClone.MemberTypeReference, propertyClone.Name);
            string getter = String.Format("get {{ return {0}; }}\n", varName);

            // create property setter...

            Set setter;
            if (!baseClassVersion)
                setter = GetSetter(eb, propertyClone, varName);
            else
                setter = GetOnPropertyChangedLambdaSetter(eb, propertyClone, varName);
            //propertyClone.AddNode(setter);
            string setterStr = CodeRush.Language.GenerateElement(setter);
            string propBlock = String.Format("{0}{1}{2}}}", propDecl, getter, setterStr);

            // See if member is needed
            bool createField = true;
            foreach (LanguageElement member in classExpression)
            {
                if (member is IFieldElement && member.Name == varName) { createField = false; break; }
            }
            if (createField)
                return CodeRush.Language.GenerateElement(var) + propBlock;//CodeRush.Language.GenerateElement(propertyClone);
            else
                return propBlock;// CodeRush.Language.GenerateElement(propertyClone);
        }
開發者ID:kevinmiles,項目名稱:dxcorecommunityplugins,代碼行數:44,代碼來源:ConvertPropertyPlugIn.cs


注:本文中的System.Property.RemoveAllNodes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。