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


C# Property.GetTypeName方法代碼示例

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


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

示例1: GetNewDelayedPropertyDeclaration

        } // GetNewDelayedPropertyDeclaration(elementBuilder, oldProperty)

        /// <summary>
        /// Get new property declaration
        /// </summary>
        private string GetNewPropertyDeclaration(ElementBuilder elementBuilder, Property oldProperty)
        {
            string propName = oldProperty.Name;
            string typeName = oldProperty.GetTypeName();
            string fieldVariableName = CodeRush.Strings.Get("FormatFieldName", propName);

            Variable fieldVar = elementBuilder.AddVariable(null, typeName, fieldVariableName);
            fieldVar.IsStatic = oldProperty.IsStatic;
            fieldVar.Visibility = MemberVisibility.Private;

            Property newProperty = elementBuilder.AddProperty(null, typeName, propName);
            newProperty.Visibility = oldProperty.Visibility;
            newProperty.IsStatic = oldProperty.IsStatic;
            newProperty.IsVirtual = oldProperty.IsVirtual;
            newProperty.IsOverride = oldProperty.IsOverride;
            newProperty.IsExplicitInterfaceMember = oldProperty.IsExplicitInterfaceMember;
            
            if (oldProperty.HasGetter)
            {
                Get getter = elementBuilder.AddGetter(newProperty);
                elementBuilder.AddReturn(getter, fieldVariableName);
            }

            if (oldProperty.HasSetter)
            {
                Set setter = elementBuilder.AddSetter(newProperty);
                ExpressionCollection expressionCollection = new ExpressionCollection();
                expressionCollection.Add(new PrimitiveExpression(String.Format("\"{0}\"", propName)));
                expressionCollection.Add(new ArgumentDirectionExpression(ArgumentDirection.Ref,
                    new ElementReferenceExpression(fieldVariableName)));
                expressionCollection.Add(new ElementReferenceExpression("value"));
                elementBuilder.AddMethodCall(setter, "SetPropertyValue", expressionCollection, null);
            } // if

            return elementBuilder.GenerateCode();
        } // GetNewPropertyDeclaration(elementBuilder, oldProperty)
開發者ID:kevinmiles,項目名稱:dxcorecommunityplugins,代碼行數:41,代碼來源:ConvertToXPOPropertyPlugin.cs

示例2: refactoringProvider_Apply

        } // refactoringProvider_Apply(sender, ea)

        /// <summary>
        /// Get new delayed property declaration
        /// </summary>
        private string GetNewDelayedPropertyDeclaration(ElementBuilder elementBuilder, Property oldProperty)
        {
            string propName = oldProperty.Name;
            string typeName = oldProperty.GetTypeName();

            Property newProperty = elementBuilder.AddProperty(null, typeName, propName);
            newProperty.Visibility = oldProperty.Visibility;
            newProperty.IsStatic = oldProperty.IsStatic;
            newProperty.IsVirtual = oldProperty.IsVirtual;
            newProperty.IsOverride = oldProperty.IsOverride;
            newProperty.IsExplicitInterfaceMember = oldProperty.IsExplicitInterfaceMember;

            AttributeSection attrSection = elementBuilder.AddAttributeSection(newProperty);
            elementBuilder.AddAttribute(attrSection, "Delayed");

            if (oldProperty.HasGetter)
            {
                Get getter = elementBuilder.AddGetter(newProperty);
                ExpressionCollection expressionCollection = new ExpressionCollection();
                expressionCollection.Add(new PrimitiveExpression(String.Format("\"{0}\"", propName)));
                string methodName = String.Format("GetDelayedPropertyValue<{0}>", typeName);
                elementBuilder.AddReturn(getter, elementBuilder.BuildMethodCall(methodName, expressionCollection, null));
            }

            if (oldProperty.HasSetter)
            {
                Set setter = elementBuilder.AddSetter(newProperty);
                ExpressionCollection expressionCollection = new ExpressionCollection();
                expressionCollection.Add(new PrimitiveExpression(String.Format("\"{0}\"", propName)));
                expressionCollection.Add(new ElementReferenceExpression("value"));
                string methodName = String.Format("SetDelayedPropertyValue<{0}>", typeName);
                elementBuilder.AddMethodCall(setter, methodName, expressionCollection, null);
            } // if

            return elementBuilder.GenerateCode();
        } // GetNewDelayedPropertyDeclaration(elementBuilder, oldProperty)
開發者ID:kevinmiles,項目名稱:dxcorecommunityplugins,代碼行數:41,代碼來源:ConvertToXPOPropertyPlugin.cs


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