本文整理汇总了C#中System.CodeDom.CodeSnippetExpression类的典型用法代码示例。如果您正苦于以下问题:C# CodeSnippetExpression类的具体用法?C# CodeSnippetExpression怎么用?C# CodeSnippetExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeSnippetExpression类属于System.CodeDom命名空间,在下文中一共展示了CodeSnippetExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CodeAssignStatementTest
public void CodeAssignStatementTest ()
{
CodeSnippetExpression cse1 = new CodeSnippetExpression("A");
CodeSnippetExpression cse2 = new CodeSnippetExpression("B");
CodeAssignStatement assignStatement = new CodeAssignStatement (cse1, cse2);
statement = assignStatement;
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"A = B;{0}", NewLine), Generate (), "#1");
assignStatement.Left = null;
try {
Generate ();
Assert.Fail ("#2");
} catch (ArgumentNullException) {
}
assignStatement.Left = cse1;
Generate ();
assignStatement.Right = null;
try {
Generate ();
Assert.Fail ("#3");
} catch (ArgumentNullException) {
}
assignStatement.Right = cse2;
Generate ();
}
开发者ID:zxlin25,项目名称:mono,代码行数:31,代码来源:CodeGeneratorFromStatementTest.cs
示例2: Constructor1
public void Constructor1 ()
{
string value = "mono";
CodeSnippetExpression cse = new CodeSnippetExpression (value);
Assert.IsNotNull (cse.Value, "#1");
Assert.AreSame (value, cse.Value, "#2");
}
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:CodeSnippetExpressionTest.cs
示例3: TypescriptSnippetExpression
public TypescriptSnippetExpression(
CodeSnippetExpression codeExpression,
CodeGeneratorOptions options)
{
_codeExpression = codeExpression;
_options = options;
System.Diagnostics.Debug.WriteLine("TypescriptSnippetExpression Created");
}
开发者ID:s2quake,项目名称:TypescriptCodeDom,代码行数:8,代码来源:TypescriptSnippetExpression.cs
示例4: Constructor0
public void Constructor0 ()
{
CodeSnippetExpression cse = new CodeSnippetExpression ();
Assert.IsNotNull (cse.Value, "#1");
Assert.AreEqual (string.Empty, cse.Value, "#2");
string value = "mono";
cse.Value = value;
Assert.IsNotNull (cse.Value, "#3");
Assert.AreSame (value, cse.Value, "#4");
cse.Value = null;
Assert.IsNotNull (cse.Value, "#5");
Assert.AreEqual (string.Empty, cse.Value, "#6");
}
开发者ID:nlhepler,项目名称:mono,代码行数:15,代码来源:CodeSnippetExpressionTest.cs
示例5: LoadEnumElement
private static void LoadEnumElement(XmlElement element, CodeTypeDeclaration codeType,
out CodeMemberProperty codeProperty)
{
codeProperty = new CodeMemberProperty();
string name = element.GetAttribute("name");
CodeTypeDeclaration codeEnum = new CodeTypeDeclaration(ToPublicName(name) + "Enum");
codeEnum.IsEnum = true;
codeEnum.Members.Add(new CodeSnippetTypeMember(element.InnerText));
codeType.Members.Add(codeEnum);
CodeExpression defaultValue = null;
if(element.HasAttribute("default"))
defaultValue = new CodeSnippetExpression(
JoinNames(codeEnum.Name, element.GetAttribute("default")));
GenerateProperty(codeType, codeEnum.Name, name, out codeProperty, defaultValue);
}
开发者ID:jaggedsoft,项目名称:aesirtk,代码行数:15,代码来源:Program.cs
示例6: CreateAndInitializeCollectionField
/// <summary>
/// Creates a reference to a collection based member field and initializes it with a new instance of the
/// specified parameter type and adds a collection item to it.
/// Sample values are used as the initializing expression.
/// </summary>
/// <param name="memberCollectionField">Name of the referenced collection field.</param>
/// <param name="collectionInitializers">Defines the types of the new object list.</param>
/// <returns>
/// An assignment statement for the specified collection member field.
/// </returns>
/// <remarks>
/// With a custom Type, this method produces a statement with a initializer like:
/// <code>this.paths = new[] { pathsItem };</code>.
/// where the item is defined like:
/// <code>this.pathsItem = new PathItemType();</code>.
/// myType of type System.Type:
/// <code>this.pathsItem = "An Item";</code>.
/// </remarks>
public static CodeAssignStatement CreateAndInitializeCollectionField(
//Type type,
string memberCollectionField,
params string[] collectionInitializers)
{
/*if (type == typeof(object))
{
}*/
var fieldRef1 = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), memberCollectionField);
//CodeExpression assignExpr = CreateExpressionByType(type, memberCollectionField);
var para = collectionInitializers.Aggregate((x, y) => x += "," + y);
CodeExpression assignExpr = new CodeSnippetExpression("new[] { " + para + " }");
return new CodeAssignStatement(fieldRef1, assignExpr);
}
开发者ID:Jedzia,项目名称:NStub,代码行数:34,代码来源:CodeMethodComposer.cs
示例7: AddArgument
public static void AddArgument(this CodeAttributeDeclaration attribute, string name, string value)
{
if (value == null)
throw new ArgumentNullException("value");
CodeExpression expression;
// Use convention that if string starts with $ its a const
if (value.StartsWith(SnippetIndicator.ToString()))
{
expression = new CodeSnippetExpression(value.TrimStart(SnippetIndicator));
}
else
{
expression = new CodePrimitiveExpression(value);
}
attribute.AddArgument(name, expression);
}
开发者ID:nordseth,项目名称:ComposerMigration,代码行数:17,代码来源:CodeDomExtensions.cs
示例8: CreateMappingStatements
public static CodeStatement[] CreateMappingStatements(ClassMappingDescriptor descriptor, CodeGeneratorContext context)
{
Dictionary<string, List<MemberMappingDescriptor>> aggregateGroups = new Dictionary<string, List<MemberMappingDescriptor>>();
List<CodeStatement> statements = new List<CodeStatement>(20);
foreach (MemberMappingDescriptor member in descriptor.MemberDescriptors)
{
if (member.IsAggregateExpression)
{
// group all agregates by expression to avoid multiple traversals over same path
//string path = GetPath(member.Expression);
string path = GetPath(descriptor, member);
if(!aggregateGroups.ContainsKey(path))
aggregateGroups[path] = new List<MemberMappingDescriptor>(1);
aggregateGroups[path].Add(member);
}
else
{
CodeStatement[] st = CreateNonAggregateMappingStatements(descriptor, member, context);
if(member.HasNullValue)
{
CodeStatement[] falseStatements = st;
CodeStatement[] trueStatements = new CodeStatement[1];
trueStatements[0] = new CodeAssignStatement(
new CodeVariableReferenceExpression("target." + member.Member),
new CodeSnippetExpression(member.NullValue.ToString()));
string checkExpression = GetNullablePartsCheckExpression(member);
CodeExpression ifExpression = new CodeSnippetExpression(checkExpression);
st = new CodeStatement[1];
st[0] = new CodeConditionStatement(ifExpression, trueStatements, falseStatements);
}
statements.AddRange(st);
}
}
foreach (List<MemberMappingDescriptor> group in aggregateGroups.Values)
{
CodeStatement[] st = CreateAggregateMappingStatements(descriptor, group, context);
statements.AddRange(st);
}
return statements.ToArray();
}
开发者ID:varunkumarmnnit,项目名称:otis-lib,代码行数:44,代码来源:FunctionMappingGenerator.cs
示例9: CreateEntryPoint
//Create main method
private void CreateEntryPoint(List<string> statements)
{
//Create an object and assign the name as "Main"
CodeEntryPointMethod mymain = new CodeEntryPointMethod();
mymain.Name = "Main";
//Mark the access modifier for the main method as Public and //static
mymain.Attributes = MemberAttributes.Public | MemberAttributes.Static;
//Change string to statements
if(statements != null){
foreach (string item in statements) {
if (item != null) {
CodeSnippetExpression exp1 = new CodeSnippetExpression(@item);
CodeExpressionStatement ces1 = new CodeExpressionStatement(exp1);
mymain.Statements.Add(ces1);
}
}
}
myclass.Members.Add(mymain);
}
开发者ID:Ngauet,项目名称:automatedframework,代码行数:21,代码来源:CCodeGenerator.cs
示例10: CreateWithApiKey
/// <summary>
/// if (string.IsNullOrEmpty(APIKey) == false)
/// request = request.WithAPIKey(APIKey)
/// </summary>
/// <returns></returns>
internal CodeConditionStatement CreateWithApiKey()
{
// !string.IsNullOrEmpty(Key)
var condition =
new CodeSnippetExpression("!string.IsNullOrEmpty(" + ApiKeyServiceDecorator.PropertyName + ")");
// if (...) {
var block = new CodeConditionStatement(condition);
// request = request.WithKey(APIKey)
var getProperty = new CodePropertyReferenceExpression(
new CodeThisReferenceExpression(), ApiKeyServiceDecorator.PropertyName);
var request = new CodeMethodInvokeExpression(
new CodeVariableReferenceExpression("request"), "WithKey", getProperty);
var trueCase = new CodeAssignStatement(new CodeVariableReferenceExpression("request"), request);
// }
block.TrueStatements.Add(trueCase);
return block;
}
开发者ID:nick0816,项目名称:LoggenCSG,代码行数:27,代码来源:CreateRequestMethodServiceDecorator.cs
示例11: Constructor1
public void Constructor1 ()
{
CodeSnippetExpression expression = new CodeSnippetExpression("exp");
CodeEventReferenceExpression cere = new CodeEventReferenceExpression (
expression, "mono");
Assert.AreEqual ("mono", cere.EventName, "#1");
Assert.IsNotNull (cere.TargetObject, "#2");
Assert.AreSame (expression, cere.TargetObject, "#3");
cere.EventName = null;
Assert.IsNotNull (cere.EventName, "#4");
Assert.AreEqual (string.Empty, cere.EventName, "#5");
cere.TargetObject = null;
Assert.IsNull (cere.TargetObject, "#6");
cere = new CodeEventReferenceExpression ((CodeExpression) null,
(string) null);
Assert.IsNotNull (cere.EventName, "#7");
Assert.AreEqual (string.Empty, cere.EventName, "#8");
Assert.IsNull (cere.TargetObject, "#9");
}
开发者ID:nlhepler,项目名称:mono,代码行数:23,代码来源:CodeEventReferenceExpressionTest.cs
示例12: CreateEntryPoint
public void CreateEntryPoint(ref CodeTypeDeclaration customClass)
{
//Create an object and assign the name as “Main”
CodeEntryPointMethod main = new CodeEntryPointMethod();
main.Name = "Main";
//Mark the access modifier for the main method as Public and //static
main.Attributes = MemberAttributes.Public | MemberAttributes.Static;
//Provide defenition to the main method.
//Create an object of the “Cmyclass” and invoke the method
//by passing the required parameters.
CodeSnippetExpression exp = new CodeSnippetExpression(CallingMethod(customClass));
//Create expression statements for the snippets
CodeExpressionStatement ces = new CodeExpressionStatement(exp);
//Add the expression statements to the main method.
main.Statements.Add(ces);
//Add the main method to the class
customClass.Members.Add(main);
}
开发者ID:govinda777,项目名称:WorkflowPoc,代码行数:23,代码来源:FactoryCode.cs
示例13: GenerateConstructor
private void GenerateConstructor(CodeTypeDeclaration taskClass)
{
CodeConstructor constructor = new CodeConstructor {
Attributes = MemberAttributes.Public
};
CodeTypeReference createType = new CodeTypeReference("System.Resources.ResourceManager");
CodeSnippetExpression expression = new CodeSnippetExpression(this.SurroundWithQuotes(this.taskParser.ResourceNamespace));
CodeTypeReferenceExpression targetObject = new CodeTypeReferenceExpression("System.Reflection.Assembly");
CodeMethodReferenceExpression method = new CodeMethodReferenceExpression(targetObject, "GetExecutingAssembly");
CodeMethodInvokeExpression expression4 = new CodeMethodInvokeExpression(method, new CodeExpression[0]);
CodeObjectCreateExpression expression5 = new CodeObjectCreateExpression(createType, new CodeExpression[] { expression, expression4 });
CodeTypeReference reference2 = new CodeTypeReference(new CodeTypeReference("System.String"), 1);
List<CodeExpression> list = new List<CodeExpression>();
foreach (string str in this.taskParser.SwitchOrderList)
{
list.Add(new CodeSnippetExpression(this.SurroundWithQuotes(str)));
}
CodeArrayCreateExpression expression6 = new CodeArrayCreateExpression(reference2, list.ToArray());
constructor.BaseConstructorArgs.Add(expression6);
constructor.BaseConstructorArgs.Add(expression5);
taskClass.Members.Add(constructor);
if (this.GenerateComments)
{
constructor.Comments.Add(new CodeCommentStatement(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("StartSummary", new object[0]), true));
string text = Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("ConstructorDescription", new object[0]);
constructor.Comments.Add(new CodeCommentStatement(text, true));
constructor.Comments.Add(new CodeCommentStatement(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("EndSummary", new object[0]), true));
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:29,代码来源:TaskGenerator.cs
示例14: GenerateSnippetExpression
protected override void GenerateSnippetExpression (CodeSnippetExpression e)
{
}
开发者ID:Profit0004,项目名称:mono,代码行数:3,代码来源:CodeGeneratorCas.cs
示例15: GenerateSnippetExpression
protected override void GenerateSnippetExpression (CodeSnippetExpression expression)
{
Output.Write (expression.Value);
}
开发者ID:nlhepler,项目名称:mono,代码行数:4,代码来源:VBCodeGenerator.cs
示例16: GenerateSnippetExpression
protected abstract void GenerateSnippetExpression (CodeSnippetExpression e);
开发者ID:carrie901,项目名称:mono,代码行数:1,代码来源:CodeGenerator.cs
示例17: Visit
public void Visit (CodeSnippetExpression o)
{
g.GenerateSnippetExpression (o);
}
开发者ID:carrie901,项目名称:mono,代码行数:4,代码来源:CodeGenerator.cs
示例18: MakeWriteMethodBody
private CodeStatement[] MakeWriteMethodBody(Type type)
{
List<CodeStatement> statements = new List<CodeStatement>();
CodeExpression objExpr = new CodeArgumentReferenceExpression("obj");
CodeExpression writerExpr = new CodeArgumentReferenceExpression("writer");
if (type.IsArray)
{
if (type.GetElementType() == typeof(object))
{
throw new DryadLinqException(DryadLinqErrorCode.CannotHandleObjectFields,
String.Format(SR.CannotHandleObjectFields, type.FullName));
}
int rank = type.GetArrayRank();
for (int i = 0; i < rank; i++)
{
CodeExpression lenExpr = new CodeMethodInvokeExpression(objExpr, "GetLength", new CodePrimitiveExpression(i));
CodeExpression lenCall = new CodeMethodInvokeExpression(writerExpr, "Write", lenExpr);
statements.Add(new CodeExpressionStatement(lenCall));
}
// Generate the writing code
if (type.GetElementType().IsPrimitive)
{
// Use a single WriteRawBytes for primitive array
string lenStr = "sizeof(" + type.GetElementType() + ")";
for (int i = 0; i < rank; i++)
{
lenStr += "*obj.GetLength(" + i + ")";
}
string writeBytes = " unsafe { fixed (void *p = obj) writer.WriteRawBytes((byte*)p, " + lenStr + "); }";
statements.Add(new CodeSnippetStatement(writeBytes));
}
else
{
CodeVariableReferenceExpression[] indexExprs = new CodeVariableReferenceExpression[rank];
for (int i = 0; i < rank; i++)
{
indexExprs[i] = new CodeVariableReferenceExpression("i" + i);
}
bool canBeNull = StaticConfig.AllowNullArrayElements && !type.GetElementType().IsValueType;
if (canBeNull)
{
string lenString = "obj.GetLength(0)";
for (int i = 1; i < rank; i++)
{
lenString += "*obj.GetLength(" + i + ")";
}
CodeExpression lenExpr = new CodeSnippetExpression(lenString);
CodeExpression bvExpr = new CodeObjectCreateExpression(typeof(BitVector), lenExpr);
CodeStatement bvStmt = new CodeVariableDeclarationStatement("BitVector", "bv", bvExpr);
statements.Add(bvStmt);
}
CodeStmtPair pair = this.MakeWriteFieldStatements(type.GetElementType(), objExpr, null, indexExprs);
CodeStatement[] writeStmts = pair.Key;
if (writeStmts != null)
{
for (int i = rank - 1; i >= 0; i--)
{
CodeVariableDeclarationStatement
initStmt = new CodeVariableDeclarationStatement(
typeof(int), indexExprs[i].VariableName, ZeroExpr);
CodeExpression lenExpr = new CodeMethodInvokeExpression(
objExpr, "GetLength", new CodePrimitiveExpression(i));
CodeExpression testExpr = new CodeBinaryOperatorExpression(
indexExprs[i],
CodeBinaryOperatorType.LessThan,
lenExpr);
CodeStatement incStmt = new CodeAssignStatement(
indexExprs[i],
new CodeBinaryOperatorExpression(
indexExprs[i], CodeBinaryOperatorType.Add, OneExpr));
writeStmts = new CodeStatement[] { new CodeIterationStatement(initStmt, testExpr, incStmt, writeStmts) };
}
statements.AddRange(writeStmts);
}
if (canBeNull)
{
CodeExpression bvWriteExpr = new CodeSnippetExpression("BitVector.Write(writer, bv)");
statements.Add(new CodeExpressionStatement(bvWriteExpr));
}
writeStmts = pair.Value;
for (int i = rank - 1; i >= 0; i--)
{
CodeVariableDeclarationStatement
initStmt = new CodeVariableDeclarationStatement(
typeof(int), indexExprs[i].VariableName, ZeroExpr);
CodeExpression lenExpr = new CodeMethodInvokeExpression(
objExpr, "GetLength", new CodePrimitiveExpression(i));
CodeExpression testExpr = new CodeBinaryOperatorExpression(
indexExprs[i], CodeBinaryOperatorType.LessThan, lenExpr);
CodeStatement incStmt = new CodeAssignStatement(
indexExprs[i],
new CodeBinaryOperatorExpression(
indexExprs[i], CodeBinaryOperatorType.Add, OneExpr));
writeStmts = new CodeStatement[] { new CodeIterationStatement(initStmt, testExpr, incStmt, writeStmts) };
//.........这里部分代码省略.........
开发者ID:pszmyd,项目名称:Dryad,代码行数:101,代码来源:DryadLinqCodeGen.cs
示例19: Constructor1_Deny_Unrestricted
public void Constructor1_Deny_Unrestricted ()
{
CodeSnippetExpression cse = new CodeSnippetExpression ("mono");
Assert.AreEqual ("mono", cse.Value, "Value");
cse.Value = String.Empty;
}
开发者ID:nlhepler,项目名称:mono,代码行数:6,代码来源:CodeSnippetExpressionCas.cs
示例20: AddEntityOptionSetEnumDeclaration
private static void AddEntityOptionSetEnumDeclaration(CodeTypeDeclarationCollection types)
{
var enumClass = new CodeTypeDeclaration("EntityOptionSetEnum")
{
IsClass = true,
TypeAttributes = TypeAttributes.Sealed | TypeAttributes.NotPublic,
};
// public static int? GetEnum(Microsoft.Xrm.Sdk.Entity entity, string attributeLogicalName)
var get = new CodeMemberMethod
{
Name = "GetEnum",
ReturnType = new CodeTypeReference(typeof(int?)),
// ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
Attributes = System.CodeDom.MemberAttributes.Static | System.CodeDom.MemberAttributes.Public,
};
get.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Microsoft.Xrm.Sdk.Entity), "entity"));
get.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "attributeLogicalName"));
// entity.Attributes.ContainsKey(attributeLogicalName)
var entityAttributesContainsKey =
new CodeMethodReferenceExpression(
new CodePropertyReferenceExpression(
new CodeArgumentReferenceExpression("entity"),
"Attributes"),
"ContainsKey");
var invokeContainsKey = new CodeMethodInvokeExpression(entityAttributesContainsKey, new CodeArgumentReferenceExpression("attributeLogicalName"));
// Microsoft.Xrm.Sdk.OptionSetValue value = entity.GetAttributeValue<Microsoft.Xrm.Sdk.OptionSetValue>(attributeLogicalName).Value;
var declareAndSetValue =
new CodeVariableDeclarationStatement
{
Type = new CodeTypeReference(typeof(OptionSetValue)),
Name = "value",
InitExpression = new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(
new CodeArgumentReferenceExpression("entity"), "GetAttributeValue", new CodeTypeReference(typeof(OptionSetValue))),
new CodeArgumentReferenceExpression("attributeLogicalName"))
};
// value != null
var valueNeNull = new CodeSnippetExpression("value != null");
// value.Value
var invokeValueGetValue = new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("value"), "Value");
// if(invokeContainsKey){return invokeGetAttributeValue;}else{return null}
get.Statements.Add(new CodeConditionStatement(invokeContainsKey, declareAndSetValue,
new CodeConditionStatement(valueNeNull, new CodeMethodReturnStatement(invokeValueGetValue))));
// return null;
get.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(null)));
enumClass.Members.Add(get);
types.Add(enumClass);
}
开发者ID:ms-crm,项目名称:DLaB.Xrm.XrmToolBoxTools,代码行数:57,代码来源:EnumPropertyGenerator.cs
注:本文中的System.CodeDom.CodeSnippetExpression类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论