コード例 #1
0
        /// <summary>
        /// Adds the property.
        /// </summary>
        /// <param name="codeClass">The code class.</param>
        /// <param name="var">The var.</param>
        /// <returns></returns>
        public static CodeProperty AddProperty(CodeClass codeClass, CodeVariable var)
        {
            CodeProperty prop = null;

            try
            {
                prop = codeClass.AddProperty(
                    FormatPropertyName(var.Name),
                    FormatPropertyName(var.Name),
                    var.Type.AsFullName, -1,
                    vsCMAccess.vsCMAccessPublic, null);

                EditPoint editPoint = prop.Getter.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint();

                //Delete return default(int); added by codeClass.AddProperty
                editPoint.Delete(editPoint.LineLength);

                editPoint.Indent(null, 4);
                editPoint.Insert(string.Format(CultureInfo.InvariantCulture, "return {0};", var.Name));

                editPoint = prop.Setter.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint();

                editPoint.Indent(null, 1);
                editPoint.Insert(string.Format(CultureInfo.InvariantCulture, "{0} = value;", var.Name));
                editPoint.SmartFormat(editPoint);

                return(prop);
            }
            catch
            {
                //Property already exists
                return(null);
            }
        }
コード例 #2
0
        void CreateCodeVariable(string code)
        {
            AddCodeFile("class.cs", code);
            ITypeDefinition typeDefinition = assemblyModel.TopLevelTypeDefinitions.Single().Resolve();

            codeVariable = new CodeVariable(codeModelContext, typeDefinition.Fields.First());
        }
コード例 #3
0
        /// <summary>
        /// Gets the access attribute value for given variable depending on the options.
        /// Returns 'true' if new access value is different than the currently stored one.
        /// Otherwise no action may be taken as variable doesn't need to be changed.
        /// </summary>
        public static bool GetVariableAttributes(CodeVariable var, PropertyGeneratorOptions options, out vsCMAccess access)
        {
            switch (options & PropertyGeneratorOptions.ForceVarMask)
            {
            case PropertyGeneratorOptions.ForceVarDontChange: access = vsCMAccess.vsCMAccessDefault; return(false);

            case PropertyGeneratorOptions.ForceVarPublic: access = vsCMAccess.vsCMAccessPublic; break;

            case PropertyGeneratorOptions.ForceVarInternal: access = vsCMAccess.vsCMAccessAssemblyOrFamily; break;

            case PropertyGeneratorOptions.ForceVarProtected: access = vsCMAccess.vsCMAccessProtected; break;

            case PropertyGeneratorOptions.ForceVarProtectedInternal: access = vsCMAccess.vsCMAccessProjectOrProtected; break;

            case PropertyGeneratorOptions.ForceVarPrivate: access = vsCMAccess.vsCMAccessPrivate; break;

            default:
                // by default decrease to private:
                access = vsCMAccess.vsCMAccessPrivate;
                break;
            }


            // validate if real change has been made:
            return(var.Access != access);
        }
コード例 #4
0
        /// <summary>
        /// Adds the property.
        /// </summary>
        /// <param name="codeClass">The code class.</param>
        /// <param name="var">The var.</param>
        /// <returns></returns>
        public static CodeProperty AddProperty(CodeClass codeClass, CodeVariable var)
        {
            CodeProperty prop = null;

            try
            {
                prop = codeClass.AddProperty(
                    FormatPropertyName(var.Name),
                    FormatPropertyName(var.Name),
                    var.Type.AsFullName, -1,
                    vsCMAccess.vsCMAccessPublic, null);

                EditPoint editPoint = prop.Getter.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint();

                //Delete return default(int); added by codeClass.AddProperty
                editPoint.Delete(editPoint.LineLength);

                editPoint.Indent(null, 4);
                editPoint.Insert(string.Format(CultureInfo.InvariantCulture, "return {0};", var.Name));

                editPoint = prop.Setter.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint();

                editPoint.Indent(null, 1);
                editPoint.Insert(string.Format(CultureInfo.InvariantCulture, "{0} = value;", var.Name));
                editPoint.SmartFormat(editPoint);

                return prop;
            }
            catch
            {
                //Property already exists
                return null;
            }
        }
コード例 #5
0
        private void ParseRafyProperty(CodeVariable codeVariable)
        {
            var name         = codeVariable.Name;
            var typeFullName = codeVariable.Type.AsFullName;

            //名字与类型中都有 Property 字样的属性,才是托管属性。
            if (name.EndsWith(PropertyToken) && typeFullName.Contains(PropertyToken))
            {
                var propertyName = name.Substring(0, name.Length - PropertyToken.Length);//去除后缀 Property

                var handled = ParseReference(codeVariable, propertyName, typeFullName);
                if (handled)
                {
                    return;
                }

                handled = ParseChild(codeVariable, propertyName, typeFullName);
                if (handled)
                {
                    return;
                }

                ParseValueProperty(codeVariable, propertyName, typeFullName);
            }
        }
コード例 #6
0
        /// <summary>
        /// Implements the variable.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="name">The name.</param>
        /// <param name="type">The type.</param>
        /// <param name="isReadOnly">if set to <c>true</c> [is read only].</param>
        /// <returns>The Code Variable. </returns>
        public static CodeVariable ImplementVariable(
            this CodeClass instance,
            string name,
            string type,
            bool isReadOnly)
        {
            TraceService.WriteLine("CodeClassExtensions::ImplementVariable name=" + name + " type=" + type);

            CodeVariable codeVariable = instance.AddVariable(name, type, 0, vsCMAccess.vsCMAccessPrivate, 0);

            codeVariable.DocComment = "<doc><summary>\r\nBacking field for " + name + ".\r\n</summary></doc>";
            codeVariable.GetEndPoint().CreateEditPoint().InsertNewLine();

            if (isReadOnly)
            {
                CodeVariable2 codeVariable2 = codeVariable as CodeVariable2;

                if (codeVariable2 != null)
                {
                    codeVariable2.ConstKind = vsCMConstKind.vsCMConstKindReadOnly;
                }
            }

            return(codeVariable);
        }
コード例 #7
0
        /// <summary>
        /// Creates <see cref="TypeMethodInfo" /> for given element.
        /// </summary>
        /// <param name="element">Element which <see cref="TypeMethodInfo" /> is created.</param>
        /// <returns>Created <see cref="TypeMethodInfo" />.</returns>
        internal TypeMethodInfo BuildFrom(CodeVariable element)
        {
            var isShared      = element.IsShared;
            var isAbstract    = false; //variables cannot be abstract
            var declaringType = CreateDescriptor(element.Parent as CodeClass);
            var variableType  = CreateDescriptor(element.Type);

            //variables cannot have type arguments
            var methodTypeArguments = TypeDescriptor.NoDescriptors;

            TypeDescriptor returnType;

            ParameterTypeInfo[] parameters;

            var buildGetter = RequiredName.StartsWith(Naming.GetterPrefix);

            if (buildGetter)
            {
                returnType = variableType;
                parameters = ParameterTypeInfo.NoParams;
            }
            else
            {
                returnType = TypeDescriptor.Void;
                parameters = new[] { ParameterTypeInfo.Create("value", variableType) };
            }

            var methodInfo = new TypeMethodInfo(
                declaringType, RequiredName, returnType, parameters,
                isShared, methodTypeArguments, isAbstract
                );

            return(methodInfo);
        }
コード例 #8
0
        /// <summary>
        /// Implements the mock variable.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="name">The name.</param>
        /// <param name="type">The type.</param>
        /// <param name="mockVariableDeclaration">The mock variable declaration.</param>
        /// <returns>The code variable.</returns>
        public static CodeVariable ImplementMockVariable(
            this CodeClass instance,
            string name,
            string type,
            string mockVariableDeclaration)
        {
            TraceService.WriteLine("CodeClassExtensions::ImplementMockVariable file=" + instance.Name);

            CodeVariable codeVariable = instance.AddVariable(name, type, 0, vsCMAccess.vsCMAccessPrivate, 0);

            string typeDescriptor = name.Substring(4, 1).ToUpper() + name.Substring(5);

            codeVariable.DocComment = "<doc><summary>\r\nMock " + typeDescriptor + ".\r\n</summary></doc>";

            EditPoint startPoint = codeVariable.StartPoint.CreateEditPoint();
            EditPoint endPoint   = codeVariable.EndPoint.CreateEditPoint();

            //// if we are Moq then we change the variable declaration.
            if (string.IsNullOrEmpty(mockVariableDeclaration) == false)
            {
                string substitution = mockVariableDeclaration.Replace("%TYPE%", type);

                string text    = startPoint.GetText(endPoint);
                string newText = text.Replace("private " + type, "private " + substitution);
                startPoint.ReplaceText(endPoint, newText, 0);
            }

            // get the new endpoint before inserting new line.
            endPoint = codeVariable.EndPoint.CreateEditPoint();
            endPoint.InsertNewLine();

            return(codeVariable);
        }
コード例 #9
0
        public static void Write(CodeTerm codeTerm, int indentation, TextWriter wtr)
        {
            CodeCompoundTerm codeCompoundTerm = codeTerm as CodeCompoundTerm;

            if (codeCompoundTerm != null)
            {
                Write(codeCompoundTerm, indentation, wtr);
                return;
            }

            CodeVariable codeVariable = codeTerm as CodeVariable;

            if (codeVariable != null)
            {
                Write(codeVariable, indentation, wtr);
                return;
            }

            CodeValue codeValue = codeTerm as CodeValue;

            if (codeValue != null)
            {
                Write(codeValue, indentation, wtr);
                return;
            }
        }
コード例 #10
0
 /// <summary>
 /// Checks element for local declaration scope.
 /// </summary>
 /// <param name="variable">CodeVariable instance.</param>
 protected void CheckLocalDeclaration(CodeVariable variable)
 {
     if (variable != null)
     {
         IsLocalDeclaration = variable.Access == vsCMAccess.vsCMAccessPrivate;
     }
 }
コード例 #11
0
        //Returns the first class in the file
        public CodeClass GetClass(ProjectItem activeDocument)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            CodeElements  fileCodeModel = activeDocument.FileCodeModel.CodeElements;
            TextSelection textSelection = Dte.ActiveDocument.Selection as TextSelection;
            VirtualPoint  point         = textSelection.ActivePoint;
            CodeElement   codeElement   = point.CodeElement[vsCMElement.vsCMElementClass];

            if (codeElement != null)
            {
                if (codeElement.Kind == vsCMElement.vsCMElementClass) //verify if it's a class
                {
                    return(codeElement as CodeClass);
                }
                else if (codeElement.Kind == vsCMElement.vsCMElementVariable)
                {
                    CodeVariable codeVariable = codeElement as CodeVariable;
                    codeElement = codeVariable.Parent as CodeElement;
                    return(codeElement as CodeClass);
                }
                else if (codeElement.Kind == vsCMElement.vsCMElementFunction)
                {
                    CodeFunction codeFunction = codeElement as CodeFunction;
                    codeElement = codeFunction.Parent as CodeElement;
                    return(codeElement as CodeClass);
                }
            }

            ErrorHandler.ShowMessageBox("Please select a class element.");
            return(null);
        }
コード例 #12
0
        /// <summary>
        /// Implements the mock variable.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="name">The name.</param>
        /// <param name="type">The type.</param>
        /// <returns>The code variable.</returns>
        public static CodeVariable ImplementMockVariable(
            this CodeClass instance,
            string name,
            string type)
        {
            TraceService.WriteLine("CodeClassExtensions::ImplementMockVariable file=" + instance.Name);

            CodeVariable codeVariable = instance.AddVariable(name, type, 0, vsCMAccess.vsCMAccessPrivate, 0);

            string typeDescriptor = name.Substring(4, 1).ToUpper() + name.Substring(5);

            codeVariable.DocComment = "<doc><summary>\r\nMock " + typeDescriptor + ".\r\n</summary></doc>";


            EditPoint startPoint = codeVariable.StartPoint.CreateEditPoint();
            EditPoint endPoint   = codeVariable.EndPoint.CreateEditPoint();

            string text    = startPoint.GetText(endPoint);
            string newText = text.Replace(type, "Mock<" + type + ">");

            startPoint.ReplaceText(endPoint, newText, 0);

            // get the new endpoint before inserting new line.
            endPoint = codeVariable.EndPoint.CreateEditPoint();
            endPoint.InsertNewLine();

            return(codeVariable);
        }
コード例 #13
0
ファイル: AddFieldAction.cs プロジェクト: johnx7271/OpenGAX
 /// <summary>
 /// <seealso cref="IAction.Execute"/>
 /// </summary>
 public override void Execute()
 {
     this.Field = this.CodeClass.AddVariable(this.FieldName,
                                             this.FieldType,
                                             this.Position,
                                             this.Access,
                                             null);
 }
コード例 #14
0
        void CreateFieldEditPoint()
        {
            var       codeVariable = new CodeVariable(fieldHelper.Field, documentLoader);
            TextPoint startPoint   = codeVariable.GetStartPoint();

            endPoint  = codeVariable.GetEndPoint();
            editPoint = startPoint.CreateEditPoint();
        }
コード例 #15
0
        public async Task Parent()
        {
            CodeVariable testObject = await GetCodeVariableAsync("A", "intC");

            CodeClass testObjectParent = testObject.Parent as CodeClass;

            Assert.Equal("A", testObjectParent.Name);
        }
コード例 #16
0
        public void DocComment()
        {
            CodeVariable testObject = GetCodeVariable("A", "intB");

            string expected = "<doc>\r\n<summary>\r\nThis is a summary.\r\n</summary>\r\n</doc>";

            Assert.Equal(expected, testObject.DocComment);
        }
コード例 #17
0
        public async Task DocComment()
        {
            CodeVariable testObject = await GetCodeVariableAsync("A", "intB");

            string expected = "<doc>\r\n<summary>\r\nThis is a summary.\r\n</summary>\r\n</doc>";

            Assert.Equal(expected, testObject.DocComment);
        }
コード例 #18
0
 private static string GetVariableType(CodeVariable n)
 {
     if (n.Type.TypeKind == vsCMTypeRef.vsCMTypeRefArray)
     {
         return(GenericNameMangler.MangleParameterName(getArray(n.Type)));
     }
     return(GenericNameMangler.MangleParameterName(n.Type.AsFullName));
 }
コード例 #19
0
        public void Parent()
        {
            CodeVariable testObject = GetCodeVariable("A", "intC");

            CodeClass testObjectParent = testObject.Parent as CodeClass;

            Assert.Equal("A", testObjectParent.Name);
        }
コード例 #20
0
 public MemberNode(CodeVariable cv, CodeModelEditorForm context)
     : base(CodeModelEditor.BrowseKind.ClassMember, context)
 {
     base.Tag              = cv;
     base.ImageKey         = "Member";
     base.SelectedImageKey = "Member";
     SetText(cv.Name);
 }
コード例 #21
0
        private void ParseValueProperty(CodeVariable codeVariable, string propertyName, string typeFullName)
        {
            //如果匹配以下格式,说明此属性是一个一般属性。
            //例如:Rafy.Domain.Property<System.Nullable<System.Double>>
            var match        = Regex.Match(typeFullName, @"Property<(?<name>.+)>");
            var propertyType = match.Groups["name"].Value;

            var property = new ValueProperty();

            property.CodeElement = codeVariable;
            property.Name        = propertyName;

            //System.Nullable<System.Double>
            if (propertyType.Contains(NullableTypeToken))
            {
                property.Nullable = true;
                propertyType      = UnwrapGenericType(propertyType);//去除 System.Nullable< 及 >
            }

            switch (propertyType)
            {
            case "System.String":
                property.PropertyType = ValuePropertyType.String;
                break;

            case "System.Boolean":
                property.PropertyType = ValuePropertyType.Boolean;
                break;

            case "System.Int32":
                property.PropertyType = ValuePropertyType.Int;
                break;

            case "System.Double":
                property.PropertyType = ValuePropertyType.Double;
                break;

            case "System.Decimal":
                property.PropertyType = ValuePropertyType.Decimal;
                break;

            case "System.DateTime":
                property.PropertyType = ValuePropertyType.DateTime;
                break;

            case "System.Byte[]":
                property.PropertyType = ValuePropertyType.Bytes;
                break;

            default:
                property.PropertyType = ValuePropertyType.Unknown;
                property[PropertyTypeFullNameProperty] = propertyType;
                _unknownProperties.Add(property);
                break;
            }

            _currentType.ValueProperties.Add(property);
        }
コード例 #22
0
        public void GetEndPoint_Navigate()
        {
            CodeVariable testObject = GetCodeVariable("A", "intC");

            TextPoint endPoint = testObject.GetEndPoint(vsCMPart.vsCMPartNavigate);

            Assert.Equal(14, endPoint.Line);
            Assert.Equal(21, endPoint.LineCharOffset);
        }
コード例 #23
0
        public async Task GetEndPoint_AttributesWithDelimiter()
        {
            CodeVariable testObject = await GetCodeVariableAsync("A", "intC");

            TextPoint endPoint = testObject.GetEndPoint(vsCMPart.vsCMPartAttributesWithDelimiter);

            Assert.Equal(13, endPoint.Line);
            Assert.Equal(19, endPoint.LineCharOffset);
        }
コード例 #24
0
 private void ParseEnumValue(CodeVariable codeVariable)
 {
     _currentEnum.Items.Add(new EnumItem
     {
         CodeElement = codeVariable,
         Name        = codeVariable.Name,
         //Value = codeVariable
     });
 }
コード例 #25
0
        public async Task GetEndPoint_WholeWithAttributes()
        {
            CodeVariable testObject = await GetCodeVariableAsync("A", "intC");

            TextPoint endPoint = testObject.GetEndPoint(vsCMPart.vsCMPartWholeWithAttributes);

            Assert.Equal(14, endPoint.Line);
            Assert.Equal(26, endPoint.LineCharOffset);
        }
コード例 #26
0
        public async Task GetEndPoint_Navigate()
        {
            CodeVariable testObject = await GetCodeVariableAsync("A", "intC");

            TextPoint endPoint = testObject.GetEndPoint(vsCMPart.vsCMPartNavigate);

            Assert.Equal(14, endPoint.Line);
            Assert.Equal(21, endPoint.LineCharOffset);
        }
コード例 #27
0
        public void EndPoint()
        {
            CodeVariable testObject = GetCodeVariable("A", "intC");

            TextPoint endPoint = testObject.EndPoint;

            Assert.Equal(14, endPoint.Line);
            Assert.Equal(26, endPoint.LineCharOffset);
        }
コード例 #28
0
        public void StartPoint()
        {
            CodeVariable testObject = GetCodeVariable("A", "intC");

            TextPoint startPoint = testObject.StartPoint;

            Assert.Equal(13, startPoint.Line);
            Assert.Equal(5, startPoint.LineCharOffset);
        }
コード例 #29
0
        public async Task StartPoint()
        {
            CodeVariable testObject = await GetCodeVariableAsync("A", "intC");

            TextPoint startPoint = testObject.StartPoint;

            Assert.Equal(13, startPoint.Line);
            Assert.Equal(5, startPoint.LineCharOffset);
        }
コード例 #30
0
        public void GetStartPoint_WholeWithAttributes()
        {
            CodeVariable testObject = GetCodeVariable("A", "intC");

            TextPoint startPoint = testObject.GetStartPoint(vsCMPart.vsCMPartWholeWithAttributes);

            Assert.Equal(13, startPoint.Line);
            Assert.Equal(5, startPoint.LineCharOffset);
        }
コード例 #31
0
        public async Task EndPoint()
        {
            CodeVariable testObject = await GetCodeVariableAsync("A", "intC");

            TextPoint endPoint = testObject.EndPoint;

            Assert.Equal(14, endPoint.Line);
            Assert.Equal(26, endPoint.LineCharOffset);
        }
コード例 #32
0
        public CodeVariable Lookup(WamVariable wamVariable)
        {
            if (wamVariable == null)
            {
                throw new ArgumentNullException("wamVariable");
            }

            CodeVariable codeVariable;
            if (!_variables.TryGetValue(wamVariable, out codeVariable))
            {
                ++_count;
                codeVariable = new CodeVariable(string.Format("V{0}", _count));
                _variables.Add(wamVariable, codeVariable);
            }
            return codeVariable;
        }
コード例 #33
0
 private static string GetVariableType(CodeVariable n)
 {
     if (n.Type.TypeKind == vsCMTypeRef.vsCMTypeRefArray)
         return GenericNameMangler.MangleParameterName(getArray(n.Type));
     return GenericNameMangler.MangleParameterName(n.Type.AsFullName);
 }
コード例 #34
0
ファイル: BaseRenameStrategy.cs プロジェクト: jda808/NPL
 /// <summary>
 /// Checks element for local declaration scope.
 /// </summary>
 /// <param name="variable">CodeVariable instance.</param>
 protected void CheckLocalDeclaration(CodeVariable variable)
 {
     if (variable != null)
         IsLocalDeclaration = variable.Access == vsCMAccess.vsCMAccessPrivate;
 }
コード例 #35
0
ファイル: CodeElementVisitor.cs プロジェクト: 569550384/Rafy
 protected virtual void VisitVariable(CodeVariable codeVariable)
 {
 }
コード例 #36
0
ファイル: EOMReader.cs プロジェクト: 569550384/Rafy
        private bool ParseReference(CodeVariable codeVariable, string propertyName, string typeFullName)
        {
            if (typeFullName.Contains(RefIdProperty))
            {
                _currentReference = new Reference
                {
                    CodeElement = codeVariable,
                    IdProperty = propertyName,
                };

                var initExp = codeVariable.InitExpression.ToString();
                if (initExp.Contains("ReferenceType.Parent"))
                {
                    _currentReference.ReferenceType = ReferenceType.Parent;
                }
                else if (initExp.Contains("ReferenceType.Child"))
                {
                    _currentReference.ReferenceType = ReferenceType.Child;
                }

                //Nullable 放到 VisitProperty 中处理。
                //...

                _currentType.References.Add(_currentReference);
                return true;
            }

            if (typeFullName.Contains(RefEntityProperty))
            {
                var refEntityTypeFullName = UnwrapGenericType(typeFullName);
                _currentReference[RefEntityTypeFullNameProperty] = refEntityTypeFullName;
                _currentReference.EntityProperty = propertyName;
                _currentReference = null;
                return true;
            }

            return false;
        }
コード例 #37
0
ファイル: EOMReader.cs プロジェクト: 569550384/Rafy
        private void ParseValueProperty(CodeVariable codeVariable, string propertyName, string typeFullName)
        {
            //如果匹配以下格式,说明此属性是一个一般属性。
            //例如:Rafy.Domain.Property<System.Nullable<System.Double>>
            var match = Regex.Match(typeFullName, @"Property<(?<name>.+)>");
            var propertyType = match.Groups["name"].Value;

            var property = new ValueProperty();

            property.CodeElement = codeVariable;
            property.Name = propertyName;

            //System.Nullable<System.Double>
            if (propertyType.Contains(NullableTypeToken))
            {
                property.Nullable = true;
                propertyType = UnwrapGenericType(propertyType);//去除 System.Nullable< 及 >
            }

            switch (propertyType)
            {
                case "System.String":
                    property.PropertyType = ValuePropertyType.String;
                    break;
                case "System.Boolean":
                    property.PropertyType = ValuePropertyType.Boolean;
                    break;
                case "System.Int32":
                    property.PropertyType = ValuePropertyType.Int;
                    break;
                case "System.Double":
                    property.PropertyType = ValuePropertyType.Double;
                    break;
                case "System.Decimal":
                    property.PropertyType = ValuePropertyType.Decimal;
                    break;
                case "System.DateTime":
                    property.PropertyType = ValuePropertyType.DateTime;
                    break;
                case "System.Byte[]":
                    property.PropertyType = ValuePropertyType.Bytes;
                    break;
                default:
                    property.PropertyType = ValuePropertyType.Unknown;
                    property[PropertyTypeFullNameProperty] = propertyType;
                    _unknownProperties.Add(property);
                    break;
            }

            _currentType.ValueProperties.Add(property);
        }
コード例 #38
0
ファイル: CodeTraverser.cs プロジェクト: dolly22/t4ts
        private bool TryGetEnumMember(CodeVariable variable, TypeContext typeContext, int index, out TypeScriptEnumMember member)
        {
            var values = GetMemberValues(variable, typeContext);
            member = new TypeScriptEnumMember
            {
                Name = values.Name,
                FullName = variable.FullName,
                Ignore = values.Ignore,
                Value = variable.InitExpression == null ? index : Int32.Parse(variable.InitExpression.ToString()),
                Comment = variable.Comment,
                DocComment = variable.DocComment
            };

            if (member.Name == null)
            {
                // The property is not explicit marked with TypeScriptMemberAttribute
                if (variable.Access != vsCMAccess.vsCMAccessPublic)
                    // remove non-public default properties
                    return false;
                member.Name = variable.Name;
            }

            if (member.Ignore)
            {
                return false;
            }

            if (values.CamelCase && values.Name == null)
                member.Name = member.Name.Substring(0, 1).ToLowerInvariant() + member.Name.Substring(1);

            return true;
        }
コード例 #39
0
ファイル: CodeTraverser.cs プロジェクト: dolly22/t4ts
        private TypeScriptMemberAttributeValues GetMemberValues(CodeVariable variable, TypeContext typeContext)
        {
            bool? attributeOptional = null;
            bool? attributeCamelCase = null;
            bool attributeIgnore = false;
            string attributeName = null;
            string attributeType = null;

            CodeAttribute attribute;

            // By default ignore properties marked with MemberIgnoreAttributes
            if (Settings.MemberIgnoreAttributes.Any(a => TryGetAttribute(variable.Attributes, a, out attribute, true)))
            {
                attributeIgnore = true;
            }

            if (TryGetAttribute(variable.Attributes, MemberAttributeFullName, out attribute))
            {
                var values = GetAttributeValues(attribute);
                if (values.ContainsKey("Optional"))
                    attributeOptional = values["Optional"] == "true";

                if (values.ContainsKey("CamelCase"))
                    attributeCamelCase = values["CamelCase"] == "true";

                if (values.ContainsKey("Ignore"))
                    attributeIgnore = values["Ignore"] == "true";

                values.TryGetValue("Name", out attributeName);
                values.TryGetValue("Type", out attributeType);
            }

            return new TypeScriptMemberAttributeValues
            {
                Optional = attributeOptional.HasValue ? attributeOptional.Value : Settings.DefaultOptional,
                Name = attributeName,
                Type = attributeType,
                CamelCase = attributeCamelCase ?? Settings.DefaultCamelCaseMemberNames,
                Ignore = attributeIgnore
            };
        }
コード例 #40
0
ファイル: EOMReader.cs プロジェクト: 569550384/Rafy
        private void ParseRafyProperty(CodeVariable codeVariable)
        {
            var name = codeVariable.Name;
            var typeFullName = codeVariable.Type.AsFullName;
            //名字与类型中都有 Property 字样的属性,才是托管属性。
            if (name.EndsWith(PropertyToken) && typeFullName.Contains(PropertyToken))
            {
                var propertyName = name.Substring(0, name.Length - PropertyToken.Length);//去除后缀 Property

                var handled = ParseReference(codeVariable, propertyName, typeFullName);
                if (handled) return;

                handled = ParseChild(codeVariable, propertyName, typeFullName);
                if (handled) return;

                ParseValueProperty(codeVariable, propertyName, typeFullName);
            }
        }
コード例 #41
0
ファイル: EOMReader.cs プロジェクト: 569550384/Rafy
 private void ParseEnumValue(CodeVariable codeVariable)
 {
     _currentEnum.Items.Add(new EnumItem
     {
         CodeElement = codeVariable,
         Name = codeVariable.Name,
         //Value = codeVariable
     });
 }
コード例 #42
0
        /// <summary>
        /// Gets the declaration of the specified code field as a string.
        /// </summary>
        /// <param name="codeField">The code field.</param>
        /// <returns>The string declaration.</returns>
        internal static string GetFieldDeclaration(CodeVariable codeField)
        {
            // Get the start point at the end of the attributes if there are any (vsCMPartHeader is
            // not available for fields).
            var startPoint = codeField.Attributes.Count > 0
                ? codeField.GetEndPoint(vsCMPart.vsCMPartAttributesWithDelimiter)
                : codeField.StartPoint;

            return TextDocumentHelper.GetTextToFirstMatch(startPoint, @"[,;]");
        }
コード例 #43
0
ファイル: Compiler.cs プロジェクト: wallymathieu/Prolog.NET
 private void Get(CodeVariable codeVariable, WamInstructionRegister sourceRegister)
 {
     WamInstructionRegister targetRegister = GetRegisterAssignment(codeVariable.Name);
     if (targetRegister.IsUnused)
     {
         targetRegister = GetNextPermanentRegister(codeVariable.Name);
         InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.GetUnboundVariable, sourceRegister, targetRegister));
     }
     else
     {
         InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.GetBoundVariable, sourceRegister, targetRegister));
     }
 }
コード例 #44
0
ファイル: EOMReader.cs プロジェクト: 569550384/Rafy
        private bool ParseChild(CodeVariable codeVariable, string propertyName, string typeFullName)
        {
            if (typeFullName.Contains(ListProperty))
            {
                var initExp = codeVariable.InitExpression as string;
                if (!initExp.Contains(ListAsAggregationToken))
                {
                    var child = new Child
                    {
                        CodeElement = codeVariable,
                        Name = propertyName,
                        ListTypeFullName = UnwrapGenericType(typeFullName)
                    };
                    _currentType.Children.Add(child);
                    return true;
                }
            }

            return false;
        }
コード例 #45
0
 public static void Write(CodeVariable codeVariable, int indentation, TextWriter wtr)
 {
     wtr.WriteLine("{0}{1} - CodeVariable", Indentation(indentation), codeVariable.Name);
 }
コード例 #46
0
ファイル: EOMReader.cs プロジェクト: 569550384/Rafy
        protected override void VisitVariable(CodeVariable codeVariable)
        {
            if (_currentType != null)
            {
                //只读取静态字段。
                if (codeVariable.IsShared)
                {
                    ParseRafyProperty(codeVariable);
                }
            }
            else if (_currentEnum != null)
            {
                ParseEnumValue(codeVariable);
            }

            base.VisitVariable(codeVariable);
        }
コード例 #47
0
 private static string GetSummary(CodeVariable property) { return GetSummary(property.InfoLocation, property.DocComment, property.Comment, property.FullName); }
コード例 #48
0
 public static void Rule(ListTailItem lhs, Variable variable)
 {
     var codeVariable = new CodeVariable(variable.Text);
     lhs.CodeTerm = codeVariable;
 }