本文整理汇总了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;
}
}
示例2: SnippetModel
public SnippetModel(Snippet snippet)
: this()
{
Snippet = snippet;
if (Snippet != null)
CategoryId = Snippet.Category.CategoryId;
}
示例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;
}
示例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());
}
}
示例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;
}
示例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);
}
};
}
}
示例7: SnippetExpander
private SnippetExpander(string snippetName, string originalText, int caretPosition)
{
_snippetName = snippetName;
_caretPosition = caretPosition;
_originalText = originalText;
_snippet = Snippets[snippetName];
}
示例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;
}
}
}
示例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);
}
示例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;
}
示例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");
}
示例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();
}
}
示例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;
}
示例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);
}
示例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();
}
}