本文整理汇总了C#中System.CodeDom.CodePrimitiveExpression类的典型用法代码示例。如果您正苦于以下问题:C# CodePrimitiveExpression类的具体用法?C# CodePrimitiveExpression怎么用?C# CodePrimitiveExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodePrimitiveExpression类属于System.CodeDom命名空间,在下文中一共展示了CodePrimitiveExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getInvokeDetailStatement
private static CodeExpressionStatement getInvokeDetailStatement(RecordStep step, string dataClass)
{
CodeExpressionStatement statement = new CodeExpressionStatement();
CodeExpression[] paras;
if (step.ActionParams != null)
{
paras = new CodeExpression[step.ActionParams.Count];
///判断是否参数化函数代码
if(dataClass == null)
{
for (int i = 0; i < step.ActionParams.Count; i++)
{
paras[i] = new CodePrimitiveExpression(step.ActionParams[i].Value);
}
}
else
{
for (int i = 0; i < step.ActionParams.Count; i++)
{
paras[i] = step.ActionParams[i].GetVariableReference(dataClass);
}
}
}
else
{
paras = new CodeExpression[0];
}
CodeMethodInvokeExpression method = new CodeMethodInvokeExpression(step.CompInfo.FindMethod, step.ActionName, paras);
statement.Expression = method;
return statement;
}
示例2: EmitPrimitive
Type EmitPrimitive(CodePrimitiveExpression Primitive)
{
Type T;
if(Primitive.Value == null) T = null;
else T = Primitive.Value.GetType();
if(T != null && T.IsArray)
{
var Contents = Primitive.Value as object[];
Type Element = T.GetElementType();
Generator.Emit(OpCodes.Ldc_I4, Contents.Length);
Generator.Emit(OpCodes.Newarr, Element);
int i = 0;
foreach(var Value in Contents)
{
Generator.Emit(OpCodes.Dup);
Generator.Emit(OpCodes.Ldc_I4, i);
EmitLiteral(Element, Value);
Generator.Emit(OpCodes.Stelem_Ref);
i++;
}
return T;
}
else return EmitLiteral(T, Primitive.Value);
}
示例3: CreateConstructor
protected override void CreateConstructor (CodeStatementCollection localVars,
CodeStatementCollection trueStmt)
{
if (pageParser.ClientTarget != null) {
CodeExpression prop;
prop = new CodePropertyReferenceExpression (thisRef, "ClientTarget");
CodeExpression ct = new CodePrimitiveExpression (pageParser.ClientTarget);
if (localVars == null)
localVars = new CodeStatementCollection ();
localVars.Add (new CodeAssignStatement (prop, ct));
}
#if NET_2_0
if (pageParser.MasterPageFile != null) {
CodeExpression prop;
prop = new CodePropertyReferenceExpression (thisRef, "MasterPageFile");
CodeExpression ct = new CodePrimitiveExpression (pageParser.MasterPageFile);
if (localVars == null)
localVars = new CodeStatementCollection ();
localVars.Add (new CodeAssignStatement (prop, ct));
}
#endif
base.CreateConstructor (localVars, trueStmt);
}
示例4: SetRow
public void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable<string> arguments, IEnumerable<string> tags, bool isIgnored)
{
var args = arguments.Select(
arg => new CodeAttributeArgument(new CodePrimitiveExpression(arg))).ToList();
// addressing ReSharper bug: TestCase attribute with empty string[] param causes inconclusive result - https://github.com/techtalk/SpecFlow/issues/116
bool hasExampleTags = tags.Any();
var exampleTagExpressionList = tags.Select(t => new CodePrimitiveExpression(t));
CodeExpression exampleTagsExpression = hasExampleTags ?
(CodeExpression)new CodePrimitiveExpression(null) :
new CodeArrayCreateExpression(typeof(string[]), exampleTagExpressionList.ToArray());
args.Add(new CodeAttributeArgument(exampleTagsExpression));
// adds 'Category' named parameter so that NUnit also understands that this test case belongs to the given categories
if (hasExampleTags)
{
CodeExpression exampleTagsStringExpr = new CodePrimitiveExpression(string.Join(",", tags.ToArray()));
args.Add(new CodeAttributeArgument("Category", exampleTagsStringExpr));
}
if (isIgnored)
args.Add(new CodeAttributeArgument("Ignored", new CodePrimitiveExpression(true)));
CodeDomHelper.AddAttribute(testMethod, ROW_ATTR, args.ToArray());
}
示例5: GetCodeExpression
public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
{
if (!entry.Expression.Contains(","))
{
throw new ArgumentException("Must include two numbers separated by a comma.");
}
else
{
// get two numbers
string[] numbers = entry.Expression.Split(',');
if (numbers.Length != 2)
{
throw new ArgumentException("Only include two numbers");
}
else
{
int lowerLimit, upperLimit;
if (Int32.TryParse(numbers[0], out lowerLimit) && Int32.TryParse(numbers[1], out upperLimit))
{
CodeTypeReferenceExpression typeRef = new CodeTypeReferenceExpression(this.GetType());
CodeExpression[] methodParameters = new CodeExpression[2];
methodParameters[0] = new CodePrimitiveExpression(lowerLimit);
methodParameters[1] = new CodePrimitiveExpression(upperLimit);
return new CodeMethodInvokeExpression(typeRef, "GetRandomNumber", methodParameters);
}
else
{
throw new ArgumentException("Use valid Integers");
}
}
}
}
示例6: ConvertTo
protected CodeExpression ConvertTo(string value, Type type)
{
var valueExpression = new CodePrimitiveExpression(value);
var converter = TypeDescriptor.GetConverter(type);
if (type == typeof(string) || type == typeof(object))
return valueExpression;
if (type == typeof(double))
return new CodePrimitiveExpression(double.Parse(value, CultureInfo.InvariantCulture));
if (type == typeof(BindingBase))
{
var bindingParser = new BindingParser(State);
var bindingVariableName = bindingParser.Parse(value);
return new CodeVariableReferenceExpression(bindingVariableName);
}
// there is no conversion availabe, the generated code won't compile, but there is nothing we can do about that
if (converter == null)
return valueExpression;
var conversion = new CodeCastExpression(
type.Name,
new CodeMethodInvokeExpression(
new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("TypeDescriptor"), "GetConverter",
new CodeTypeOfExpression(type.Name)), "ConvertFromInvariantString",
new CodePrimitiveExpression(value)));
return conversion;
}
示例7: Constructor1_Deny_Unrestricted
public void Constructor1_Deny_Unrestricted ()
{
object o = new object ();
CodePrimitiveExpression cpe = new CodePrimitiveExpression (o);
Assert.AreSame (o, cpe.Value, "Value");
cpe.Value = new object ();
}
示例8: AppendCreateDictionaryLocalVariable
private static string AppendCreateDictionaryLocalVariable(string dictionary, CodeDomClassBuilder builder)
{
var parser = new AttributeParser(dictionary);
parser.Parse();
var keyValuePairType = new CodeTypeReference(typeof(KeyValuePair<string,object>));
var createDictionaryMethod = new CodeMethodInvokeExpression();
foreach (var attribute in parser.Attributes)
{
var newKeyValueExpression = new CodeObjectCreateExpression {CreateType = keyValuePairType};
var keyExpression = new CodePrimitiveExpression {Value = attribute.Name};
newKeyValueExpression.Parameters.Add(keyExpression);
if (attribute.Type == ParsedAttributeType.String)
{
AppendStringDictValue(attribute, newKeyValueExpression);
}
else
{
newKeyValueExpression.Parameters.Add(new CodeSnippetExpression
{
Value = attribute.Value
});
}
createDictionaryMethod.Parameters.Add(newKeyValueExpression);
}
var getDictionaryMethod = new CodeMethodReferenceExpression
{
MethodName = "GetDictionaryFromKeyValue",
TargetObject =
new CodeVariableReferenceExpression
{
VariableName = "NHamlMonoRailView"
}
};
createDictionaryMethod.Method = getDictionaryMethod;
var variableName = string.Format("nhamlTempDictionary{0}", tempDictionaryCount);
tempDictionaryCount++;
var dictionaryDecleration = new CodeVariableDeclarationStatement
{
InitExpression = createDictionaryMethod,
Name = variableName,
Type = new CodeTypeReference(typeof (IDictionary<string, object>))
};
builder.RenderMethod.Statements.Add(dictionaryDecleration);
return variableName;
}
示例9: TypescriptPrimitiveExpression
public TypescriptPrimitiveExpression(
CodePrimitiveExpression codeExpression,
CodeGeneratorOptions options)
{
_codeExpression = codeExpression;
_options = options;
System.Diagnostics.Debug.WriteLine("TypescriptPrimitiveExpression Created");
}
示例10: GetStringArrayAttributeArgument
public static CodeAttributeArgument GetStringArrayAttributeArgument(string[] values)
{
CodeExpression[] initializers = new CodeExpression[values.Length];
for (int i = 0; i < values.Length; i++)
initializers[i] = new CodePrimitiveExpression(values[i]);
return new CodeAttributeArgument(new CodeArrayCreateExpression(typeof(string), initializers));
}
示例11: CreateDataArray
private static CodeExpression CreateDataArray(byte[] data)
{
CodeExpression[] initializers = new CodeExpression[data.Length];
for (int i = 0; i < data.Length; i++)
{
initializers[i] = new CodePrimitiveExpression(data[i]);
}
return new CodeArrayCreateExpression(typeof(byte), initializers);
}
示例12: AddXmlEnumAttribute
private static void AddXmlEnumAttribute(CodeTypeMember member)
{
CodeTypeReference attributeType = new CodeTypeReference(typeof (XmlEnumAttribute));
CodePrimitiveExpression argumentValue = new CodePrimitiveExpression(member.Name);
CodeAttributeArgument argument = new CodeAttributeArgument(argumentValue);
CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(attributeType, argument);
member.CustomAttributes.Add(attribute);
}
示例13: GetCodeExpression
public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
{
string property = (string) parsedData;
CodePrimitiveExpression prim = new CodePrimitiveExpression(property);
CodeExpression[] args = new[] {prim};
CodeTypeReferenceExpression refType = new CodeTypeReferenceExpression(this.GetType());
return new CodeMethodInvokeExpression(refType, "GetProperty", args);
}
示例14: AddRootElementName
private static void AddRootElementName(CodeTypeMember type)
{
foreach (CodeAttributeDeclaration attribute in type.CustomAttributes)
if (attribute.Name == typeof (XmlRootAttribute).FullName)
{
CodePrimitiveExpression value = new CodePrimitiveExpression(type.Name);
CodeAttributeArgument argument = new CodeAttributeArgument("", value);
attribute.Arguments.Insert(0, argument);
}
}
示例15: GetCodeExpression
/// <summary>
/// When overridden in a derived class, returns code that is used during page execution to obtain the evaluated expression.
/// </summary>
/// <param name="entry">The object that represents information about the property bound to by the expression.</param>
/// <param name="parsedData">The object containing parsed data as returned by <see cref="M:System.Web.Compilation.ExpressionBuilder.ParseExpression(System.String,System.Type,System.Web.Compilation.ExpressionBuilderContext)" />.</param>
/// <param name="context">Contextual information for the evaluation of the expression.</param>
/// <returns>
/// A <see cref="T:System.CodeDom.CodeExpression" /> that is used for property assignment.
/// </returns>
public override CodeExpression GetCodeExpression( BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context )
{
// from http://msdn.microsoft.com/en-us/library/system.web.compilation.expressionbuilder.getcodeexpression.aspx
Type type1 = entry.DeclaringType;
PropertyDescriptor descriptor1 = TypeDescriptor.GetProperties( type1 )[entry.PropertyInfo.Name];
CodeExpression[] expressionArray1 = new CodeExpression[3];
expressionArray1[0] = new CodePrimitiveExpression( entry.Expression.Trim() );
expressionArray1[1] = new CodeTypeOfExpression( type1 );
expressionArray1[2] = new CodePrimitiveExpression( entry.Name );
return new CodeCastExpression( descriptor1.PropertyType, new CodeMethodInvokeExpression( new CodeTypeReferenceExpression( base.GetType() ), "GetEvalData", expressionArray1 ) );
}