示例#1
0
        public static void AddMethodParameters(this IDeclarationContext context, IEnumerable<ParameterSyntax> parameters)
        {
            if (null != parameters)
            {
                foreach (var par in parameters)
                {
                    // Trace("parameter {0}", par);
                    // SyntaxTreeHelper.PrintTree(par);

                    ITypeItem ltype = null;
                    string typename = null;
                    if (null != par.Type)
                    {
                        typename = par.Type.ExtractTypeName();
                        ltype = context.ResolveLType(typename);
                    }

                    if (null == ltype && null != par.Type)
                    {
                        // TraceTarget.Trace("WARNING: unresolved parameter type '{0}'.", typename);
                    }

                    context.AddVariable(par.Identifier.ToString(), ltype);
                }
            }
        }
示例#2
0
文件: Env.cs 项目: takuto-h/rhea
 public static void AddVariable(
     this IEnv env,
     string symbolName,
     IValue value
 )
 {
     env.AddVariable(
         ValueSymbol.Intern(symbolName), value
     );
 }
        /// <summary>
        /// Creates new axis variable of type float and and adds it to the dataset. The values of the variable correspond to centers of the cell. Also the method adds another variable depicting cells bounds according to CF conventions 1.5
        /// </summary>
        /// <param name="ds">Target datas set</param>
        /// <param name="name">Name of the axis</param>
        /// <param name="units">Units of measurement of values of the axis</param>
        /// <param name="min">The lower bound of the first cell</param>
        /// <param name="max">The upper bound of the last cell</param>
        /// <param name="delta">The size of cells</param>
        /// <param name="boundsVariableName">A name of varaible containing bounds of the cell. If it is omited the name will be chosen automaticly</param>
        /// <returns>New axis variable</returns>
        public static Variable AddAxisCells(this DataSet ds, string name, string units, float min, float max, float delta, string boundsVariableName = null)
        {
            var names = EnsureAddAxisCellsNames(ds, name, boundsVariableName);

            var axis = ds.AddAxis(name, units, min + delta / 2, max - delta / 2, delta);
            axis.Metadata["bounds"] = names.Item1;
            int n = axis.Dimensions[0].Length;
            float[,] boundsData = new float[n, 2];
            for (int i = 0; i < n; i++)
            {
                boundsData[i, 0] = min + delta * i;
                boundsData[i, 1] = min + delta * (i + 1);
            }
            ds.AddVariable<float>(names.Item1, boundsData, axis.Dimensions[0].Name, names.Item2);

            return axis;

        }
        /// <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);

            string variableName = name;

            bool placeHolderVariable = false;

            //// are we a place holder variable (used in snippets!)
            if (variableName.Contains("%"))
            {
                variableName = variableName.Replace("%", string.Empty);
                placeHolderVariable = true;
            }

            CodeVariable codeVariable = instance.AddVariable(variableName, 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;
                }
            }

            if (placeHolderVariable)
            {
                EditPoint startPoint = codeVariable.StartPoint.CreateEditPoint();
                EditPoint endPoint = codeVariable.EndPoint.CreateEditPoint();
                string text = startPoint.GetText(endPoint);
                string newText = text.Replace(variableName, name);
                startPoint.ReplaceText(endPoint, newText, 0);
            }

            return codeVariable;
        }
        /// <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("private " + type, "private Mock<" + type + ">");
            startPoint.ReplaceText(endPoint, newText, 0);

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

            return codeVariable;
        }
        /// <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;
        }
 /// <summary>
 /// Adds a variable to a package
 /// </summary>
 /// <param name="package"></param>
 /// <param name="name"></param>
 /// <param name="value"></param>
 /// <param name="readyOnly"></param>
 /// <returns></returns>
 public static Variable AddVariable(this DtsContainer package, string name, object value, bool readyOnly)
 {
     return package.AddVariable(name, value, readyOnly, SsisConstants.PackageVarUserNamespace);
 }
 /// <summary>
 /// Adds a variable to a package
 /// </summary>
 /// <param name="package"></param>
 /// <param name="name"></param>
 /// <param name="value"></param>
 /// <param name="nameSpace"></param>
 /// <returns></returns>
 public static Variable AddVariable(this DtsContainer package, string name, object value, string nameSpace)
 {
     return package.AddVariable(name, value, false, nameSpace);
 }