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


C# Snippet类代码示例

本文整理汇总了C#中Snippet的典型用法代码示例。如果您正苦于以下问题:C# Snippet类的具体用法?C# Snippet怎么用?C# Snippet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: CreateKb

        //, string sourceName, string sourceTypeName, string authorFirstName, string authorLastName, string comment = "Default comment")
        public static Snippet CreateKb(string text, string pageOrLocation)
        {
            using (var db = new SnippetAppDB())
            {
                Snippet sp = new Snippet();
                sp.Text = text;
                sp.PageorLocation = pageOrLocation;
                db.Snippets.Add(sp);

                //Source sourcevar = new Source();
                //sourcevar.SourceName = sourceName;
                //db.Sources.Add(sourcevar);

                //Comments commentsvar = new Comments();
                //commentsvar.CommentsText = comment;
                //if (comment != "Default comment")
                //{

                //}
                //db.Comments.Add(commentsvar);

                //SourceType sourcetypevar = new SourceType();
                //sourcetypevar.SourceTypeName = sourceTypeName;
                //db.SoureTypes.Add(sourcetypevar);

                //Author authorvar = new Author();
                //authorvar.AuthorFirstName = authorFirstName;
                //authorvar.AuthorLastName = authorLastName;
                //db.Authors.Add(authorvar);

                db.SaveChanges();
                return sp;

            }
        }
开发者ID:casieo,项目名称:snippetApp,代码行数:36,代码来源:Helper.cs

示例2: SnippetModel

 public SnippetModel(Snippet snippet)
     : this()
 {
     Snippet = snippet;
     if (Snippet != null)
         CategoryId = Snippet.Category.CategoryId;
 }
开发者ID:simplyio,项目名称:snippet-box,代码行数:7,代码来源:SnippetModel.cs

示例3: CreateSnippet

        public CreateSnippetResponse CreateSnippet(CreateSnippetRequest request)
        {
            var response = new CreateSnippetResponse();
            var newSnippet = new Snippet
                                 {
                                     Id = request.Id,
                                     Guid = request.Guid,
                                     Name = request.Name,
                                     Description = request.Description,
                                     PreviewData = request.PreviewData,
                                     Data = request.Data,
                                     LastModified = request.LastModified,
                                     IsPublic = request.IsPublic,
                                     Language_Id = request.Language_Id,
                                     User_Id = request.User_Id,
                                     User_FormsAuthId = request.User_FormsAuthId
                                 };
            try
            {
                _unitOfWork.SnippetRepository.Insert(newSnippet);
                _unitOfWork.Save();

                response.SnippetId = newSnippet.Id;
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.FailureInformation = ex.Message;
                Logger.LogError("CreateSnippet Method Failed", ex);
            }
            return response;
        }
开发者ID:nategreenwood,项目名称:SnippetCache,代码行数:33,代码来源:Snippet.Operations.svc.cs

示例4: CleanFileName

 public Snippet this[string name]
 {
   get
   {
     Snippet result;
     var key = CleanFileName(name);
     if (!_cache.TryGetValue(key, out result))
     {
       var path = GetFolder() + key + ".txt";
       if (System.IO.File.Exists(path))
         result = new Snippet(System.IO.File.ReadAllText(path));
       else
         result = new Snippet();
       _cache[key] = result;
     }
     return result;
   }
   set
   {
     var key = CleanFileName(name);
     _cache[key] = value;
     var path = GetFolder() + key + ".txt";
     WriteAllText(path, value.ToString());
   }
 }
开发者ID:rneuber1,项目名称:InnovatorAdmin,代码行数:25,代码来源:SnippetManager.cs

示例5: st

        public Emitter st(Snippet dest)
        {
            if (dest is NodeSnippet)
            {
                var ns = dest as NodeSnippet;
                if (ns.Node is Ref)
                {
                    var @ref = (Ref)ns.Node;
                    var layout = _alloc[@ref].AssertCast<SlotLayout>();
                    return st((Atom)layout.Slot);
                }
                else
                {
                    throw AssertionHelper.Fail();
                }
            }
            else if (dest is PtxexprSnippet)
            {
                var pes = dest as PtxexprSnippet;
                if (pes.Expr is Reg) st((Reg)pes.Expr);
                else if (pes.Expr is Var) st((Var)pes.Expr);
                else throw AssertionHelper.Fail();
            }
            else
            {
                throw AssertionHelper.Fail();
            }

            return this;
        }
开发者ID:xeno-by,项目名称:conflux,代码行数:30,代码来源:Emitter.Stack.cs

示例6: lookForNewSnippet

        private void lookForNewSnippet(string text, int lineNumber)
        {
            var name = _scanner.DetermineName(text);

            if (name.IsNotEmpty())
            {
                var snippet = new Snippet(name){
                    Class = _scanner.LanguageClass,
                    File = _file.RelativePath,
                    BottleName = _file.Provenance
                };

                _readAction = (txt, num) =>
                {
                    if (_scanner.IsAtEnd(txt))
                    {
                        _onFound(snippet);
                        _readAction = lookForNewSnippet;
                    }
                    else
                    {
                        snippet.Append(txt, num);
                    }
                };
            }
        }
开发者ID:DarthFubuMVC,项目名称:FubuMVC.CodeSnippets,代码行数:26,代码来源:SnippetReader.cs

示例7: SnippetExpander

 private SnippetExpander(string snippetName, string originalText, int caretPosition)
 {
     _snippetName = snippetName;
     _caretPosition = caretPosition;
     _originalText = originalText;
     _snippet = Snippets[snippetName];
 }
开发者ID:markrendle,项目名称:PocketIDE,代码行数:7,代码来源:SnippetExpander.cs

示例8: ReadXml

 public void ReadXml(XmlReader reader)
 {
     var elementName = string.Empty;
     while (reader.Read())
     {
         if (reader.NodeType == XmlNodeType.Element)
         {
             elementName = reader.Name;
             switch (elementName)
             {
                 case "TypeAliases":
                     {
                         var subReader = reader.ReadSubtree();
                         var aliases = new List<NetTypeAlias>();
                         while (subReader.ReadToFollowing("TypeAlias"))
                         {
                             var aliasReader = subReader.ReadSubtree();
                             var typeAlias = new NetTypeAlias();
                             typeAlias.ReadXml(aliasReader);
                             aliases.Add(typeAlias);
                         }
                         TypeAliases = aliases.ToArray();
                         break;
                     }
                 case "Snippets":
                     {
                         var subReader = reader.ReadSubtree();
                         var snippets = new List<Snippet>();
                         while (subReader.ReadToFollowing("Snippet"))
                         {
                             var snippet = new Snippet();
                             snippet.ReadXml(subReader);
                             snippets.Add(snippet);
                         }
                         Snippets = snippets.ToArray();
                         break;
                     }
             }
         }
         else if (reader.NodeType == XmlNodeType.Text)
         {
             switch (elementName)
             {
                 case "Modifiers":
                     Modifiers = reader.Value.Split(' ');
                     break;
                 case "MemberIdentifiers":
                     MemberIdentifiers = reader.Value.Split(' ');
                     break;
                 case "Keywords":
                     Keywords = reader.Value.Split(' ');
                     break;
             }
         }
         else if (reader.NodeType == XmlNodeType.EndElement)
         {
             elementName = string.Empty; 
         }
     }
 }
开发者ID:die-Deutsche-Orthopaedie,项目名称:LiteDevelop,代码行数:60,代码来源:NetLanguageData.cs

示例9: SnippetLibrary_Remove

        public void SnippetLibrary_Remove()
        {
            List<string> s1Content = new List<string>()
            {
                "lorem ipsum dot sit amet,",
                "consectetur adipisicing elit"
            };
            Snippet s1 = new Snippet("lorem", s1Content);
            List<string> s2Content = new List<string>()
            {
                "if ()",
                "{",
                "",
                "}"
            };
            Snippet s2 = new Snippet("if", s2Content);

            snippetLibrary.Add(s1);
            snippetLibrary.Add(s2);
            this.snippetLibrary = null;
            this.snippetLibrary = new SnippetLibrary();
            this.snippetLibrary.Remove("lorem");
            Assert.IsNull(this.snippetLibrary.GetByName("lorem"));
            Assert.AreEqual(1, this.snippetLibrary.Names.Count);
        }
开发者ID:burntheroad,项目名称:TextEditor,代码行数:25,代码来源:SnippetLibraryTests.cs

示例10: MapFromElement

        /// <summary>
        /// Maps a specified <see cref="CodeSnippetElement"/> to the newly created <see cref="Snippet"/>.
        /// </summary>
        /// <param name="element">A <see cref="CodeSnippetElement"/> that contains deserialized snippet data.</param>
        /// <returns>Newly created <see cref="Snippet"/>.</returns>
        public static Snippet MapFromElement(CodeSnippetElement element)
        {
            if (element == null)
                throw new ArgumentNullException(nameof(element));

            var snippet = new Snippet();

            if (element.Format != null)
            {
                Version version = null;

                if (Version.TryParse(element.Format, out version)
                    && ValidationHelper.IsValidVersion(version))
                {
                    snippet.FormatVersion = version;
                }
            }

            if (element.Header != null)
                LoadHeaderElement(element.Header, snippet);

            if (element.Snippet != null)
                LoadSnippetElement(element.Snippet, snippet);

            return snippet;
        }
开发者ID:JosefPihrt,项目名称:SnippetManager,代码行数:31,代码来源:SnippetMapper.cs

示例11: Create

 public ActionResult Create(SnippetBindingModel model,string language, string labels)
 {
     if (model != null && this.ModelState.IsValid)
     {
         var userId = this.User.Identity.GetUserId();
         var snippet = new Snippet()
         {
             Title = model.Title,
             Description = model.Description,
             Author = this.Data.Users.Find(userId),
             Language = this.Data.Languages.All().FirstOrDefault(l => l.Name == language),
         };
         if (!labels.IsEmpty())
         {
             var allLabels = labels.Split(';');
             foreach (var l in allLabels)
             {
                 var labelToCheck = l.Trim();
                 var label = this.Data.Labels.All().FirstOrDefault(la => la.Text.ToLower() == labelToCheck.ToLower());
                 if (label == null)
                 {
                     var newLabel = new Label(){Text = l};
                     this.Data.Labels.Add(newLabel);
                     this.Data.SaveChanges();
                 }
                 label = this.Data.Labels.All().FirstOrDefault(la => la.Text == l);
                 snippet.Labels.Add(label);
             }
         }
         this.Data.SaveChanges();
         return RedirectToAction("Details", "Snippets", new { id = snippet.Id });
     }
     return RedirectToAction("Index", "Users");
 }
开发者ID:archlicher,项目名称:Snippy_ASP.NET_MVC5_Exam,代码行数:34,代码来源:SnippetsController.cs

示例12: CreateSnippet

        public ActionResult CreateSnippet(CreateSnippetVM vm)
        {
            if (ModelState.IsValid)
            {
                Snippet snippet = new Snippet
                {
                    Title = vm.Title,
                    Content = vm.Content,
                    DatePublished = DateTime.Now
                };

                if (webSecurity.IsAuthenticated)
                {
                    snippet.UserId = webSecurity.CurrentUserId;
                }

                this.snippetRepo.Add(snippet);

                return RedirectToAction("Show", new { id = snippet.Id });
            }
            else
            {
                return View();
            }
        }
开发者ID:nikolay-spasov,项目名称:SnippetShare,代码行数:25,代码来源:HomeController.cs

示例13: Format

        public Snippet Format(IFubuFile file, string languageClass = null)
        {
            var snippet = new Snippet(file.Path){
                Class = languageClass ?? "lang-" + Path.GetExtension(file.Path).Replace(".", "")
            };

            file.ReadContents(stream =>
            {
                using (var reader = new StreamReader(stream))
                {
                    int lineNumber = 0;

                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        lineNumber++;

                        if (line.Contains(Snippets.SAMPLE) || line.Contains(Snippets.END))
                        {
                            snippet.Append(string.Empty, lineNumber);
                        }
                        else
                        {
                            snippet.Append(line, lineNumber);
                        }
                    }
                }
            });



            return snippet;
        }
开发者ID:DarthFubuMVC,项目名称:FubuMVC.CodeSnippets,代码行数:33,代码来源:CodeFormatter.cs

示例14: SnippetInstance

 public SnippetInstance(Snippet snippet, SnippetInstance parent)
 {
     Debug.Assert(!snippet.IsTopLevel);
     this.Snippet = snippet;
     this.Snippet.UI.SnippetInstances.Add(this);
     this.parent = parent;
     this.node = new SnippetTNode(snippet.Title, this);
 }
开发者ID:drosenstark,项目名称:KBase,代码行数:8,代码来源:SnippetInstance.cs

示例15: Add

 /// <summary>
 /// Adds new snippet to library.
 /// </summary>
 /// <param name="snippet">Snippet to add.</param>
 public void Add(Snippet snippet)
 {
     if (this.snippets.Where(s => s.Name == snippet.Name).Count() == 0)
     {
         this.snippets.Add(snippet);
         this.Save();
     }
 }
开发者ID:burntheroad,项目名称:TextEditor,代码行数:12,代码来源:SnippetLibrary.cs


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