本文整理汇总了C#中System.CodeDom.CodeVariableReferenceExpression类的典型用法代码示例。如果您正苦于以下问题:C# CodeVariableReferenceExpression类的具体用法?C# CodeVariableReferenceExpression怎么用?C# CodeVariableReferenceExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeVariableReferenceExpression类属于System.CodeDom命名空间,在下文中一共展示了CodeVariableReferenceExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildExpressionSetup
internal static void BuildExpressionSetup(ControlBuilder controlBuilder, CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeLinePragma linePragma, bool isTwoWayBound, bool designerMode) {
// {{controlType}} target;
CodeVariableDeclarationStatement targetDecl = new CodeVariableDeclarationStatement(controlBuilder.ControlType, "dataBindingExpressionBuilderTarget");
methodStatements.Add(targetDecl);
CodeVariableReferenceExpression targetExp = new CodeVariableReferenceExpression(targetDecl.Name);
// target = ({{controlType}}) sender;
CodeAssignStatement setTarget = new CodeAssignStatement(targetExp,
new CodeCastExpression(controlBuilder.ControlType,
new CodeArgumentReferenceExpression("sender")));
setTarget.LinePragma = linePragma;
statements.Add(setTarget);
Type bindingContainerType = controlBuilder.BindingContainerType;
CodeVariableDeclarationStatement containerDecl = new CodeVariableDeclarationStatement(bindingContainerType, "Container");
methodStatements.Add(containerDecl);
// {{containerType}} Container = ({{containerType}}) target.BindingContainer;
CodeAssignStatement setContainer = new CodeAssignStatement(new CodeVariableReferenceExpression(containerDecl.Name),
new CodeCastExpression(bindingContainerType,
new CodePropertyReferenceExpression(targetExp,
"BindingContainer")));
setContainer.LinePragma = linePragma;
statements.Add(setContainer);
string variableName = isTwoWayBound ? "BindItem" : "Item";
GenerateItemTypeExpressions(controlBuilder, methodStatements, statements, linePragma, variableName);
//Generate code for other variable as well at design time in addition to runtime variable for intellisense to work.
if (designerMode) {
GenerateItemTypeExpressions(controlBuilder, methodStatements, statements, linePragma, isTwoWayBound ? "Item" : "BindItem");
}
}
示例2: BuildOperation
public override CodeStatementCollection BuildOperation(CodeGenerationContext ctx, ICodeGeneratorNode element, CodeVariableReferenceExpression value)
{
CodeStatementCollection statemets = new CodeStatementCollection();
statemets.Add(new CodeSnippetExpression(
string.Format("{0} = ({2})((int){0} >> {1})", value.VariableName, Value, GetValueType(element.MappedProperty).FullName)));
return statemets;
}
示例3: Serialize
public override object Serialize(IDesignerSerializationManager manager, object value) {
var baseSerializer = (CodeDomSerializer)manager
.GetSerializer(typeof(ResourceManagerSetter).BaseType, typeof(CodeDomSerializer));
object codeObject = baseSerializer.Serialize(manager, value);
var statements = codeObject as CodeStatementCollection;
if (statements != null) {
CodeExpression leftCodeExpression = new CodeVariableReferenceExpression("resources");
var classTypeDeclaration = (CodeTypeDeclaration)manager.GetService(typeof(CodeTypeDeclaration));
CodeExpression typeofExpression = new CodeTypeOfExpression(classTypeDeclaration.Name);
CodeExpression rightCodeExpression =
new CodeObjectCreateExpression(typeof(XafComponentResourceManager),
new[] { typeofExpression });
//CodeExpression rightCodeExpression =
// new CodeTypeReferenceExpression(
// "new DevExpress.ExpressApp.Win.Templates"),
// "XafComponentResourceManager", new[] { typeofExpression });
statements.Insert(0, new CodeAssignStatement(leftCodeExpression, rightCodeExpression));
}
return codeObject;
}
示例4: AddCallbackImplementation
internal static void AddCallbackImplementation(CodeTypeDeclaration codeClass, string callbackName, string handlerName, string handlerArgs, bool methodHasOutParameters)
{
CodeFlags[] parameterFlags = new CodeFlags[1];
CodeMemberMethod method = AddMethod(codeClass, callbackName, parameterFlags, new string[] { typeof(object).FullName }, new string[] { "arg" }, typeof(void).FullName, null, (CodeFlags) 0);
CodeEventReferenceExpression left = new CodeEventReferenceExpression(new CodeThisReferenceExpression(), handlerName);
CodeBinaryOperatorExpression condition = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));
CodeStatement[] trueStatements = new CodeStatement[2];
trueStatements[0] = new CodeVariableDeclarationStatement(typeof(InvokeCompletedEventArgs), "invokeArgs", new CodeCastExpression(typeof(InvokeCompletedEventArgs), new CodeArgumentReferenceExpression("arg")));
CodeVariableReferenceExpression targetObject = new CodeVariableReferenceExpression("invokeArgs");
CodeObjectCreateExpression expression4 = new CodeObjectCreateExpression();
if (methodHasOutParameters)
{
expression4.CreateType = new CodeTypeReference(handlerArgs);
expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "Results"));
}
else
{
expression4.CreateType = new CodeTypeReference(typeof(AsyncCompletedEventArgs));
}
expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "Error"));
expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "Cancelled"));
expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "UserState"));
trueStatements[1] = new CodeExpressionStatement(new CodeDelegateInvokeExpression(new CodeEventReferenceExpression(new CodeThisReferenceExpression(), handlerName), new CodeExpression[] { new CodeThisReferenceExpression(), expression4 }));
method.Statements.Add(new CodeConditionStatement(condition, trueStatements, new CodeStatement[0]));
}
示例5: GenerateMappingCode
public override void GenerateMappingCode(CodeGenerationContext ctx, CodeMemberMethod method)
{
if (!String.IsNullOrEmpty(To))
MappedProperty = TypeReflector.GetProperty(ctx.MappedObjectType, To);
if (MappedProperty != null)
{
if (MapNotBoolProperty)
{
// type value = bitReader.ReadBits(length);
method.Statements.Add(new CodeVariableDeclarationStatement(MappedValueType, "value",
new CodeMethodInvokeExpression(ctx.DataReader, "ReadBits", new CodePrimitiveExpression(Length))));
}
else
{
method.Statements.Add(
new CodeVariableDeclarationStatement(MappedValueType, "value",
new CodeBinaryOperatorExpression(
new CodeMethodInvokeExpression(ctx.DataReader, "ReadBits", new CodePrimitiveExpression(Length)),
CodeBinaryOperatorType.GreaterThan, new CodePrimitiveExpression(0))));
}
// add operations code
CodeVariableReferenceExpression value = new CodeVariableReferenceExpression("value");
foreach (IOperation op in Operations)
method.Statements.AddRange(op.BuildOperation(ctx, this, value));
method.Statements.AddRange(GenerateSetMappedPropertyCode(ctx.MappedObject, value));
}
else
{ // just read
method.Statements.Add(
new CodeMethodInvokeExpression(ctx.DataReader, "ReadBits", new CodePrimitiveExpression(Length)));
}
}
示例6: GenerateBuildCode
public void GenerateBuildCode(GeneratorContext ctx)
{
string varName = ctx.NewId ();
CodeVariableDeclarationStatement varDec = new CodeVariableDeclarationStatement (typeof(Gtk.IconFactory), varName);
varDec.InitExpression = new CodeObjectCreateExpression (typeof(Gtk.IconFactory));
ctx.Statements.Add (varDec);
CodeVariableReferenceExpression var = new CodeVariableReferenceExpression (varName);
foreach (ProjectIconSet icon in icons) {
CodeExpression exp = new CodeMethodInvokeExpression (
var,
"Add",
new CodePrimitiveExpression (icon.Name),
icon.GenerateObjectBuild (ctx)
);
ctx.Statements.Add (exp);
}
CodeExpression addd = new CodeMethodInvokeExpression (
var,
"AddDefault"
);
ctx.Statements.Add (addd);
}
示例7: CodeLocalVariableBinder
/// <summary>
/// Initializes a new instance of the <see cref="CodeLocalVariableBinder"/> class
/// with a reference to a variable.
/// </summary>
/// <param name="method">The method to add a <see cref="CodeTypeReference"/> to.</param>
/// <param name="reference">The reference to a local variable.</param>
internal CodeLocalVariableBinder(CodeMemberMethod method, CodeVariableReferenceExpression reference)
{
Guard.NotNull(() => method, method);
Guard.NotNull(() => reference, reference);
this.method = method;
this.reference = reference;
}
示例8: Is
public static CodeExpression Is(CodeVariableReferenceExpression var,
CodeTypeReferenceExpression type, CodeDomProvider provider)
{
return new CodeSnippetExpression(
"((" + ExpressionToString(var, provider) + ") is " +
ExpressionToString(type, provider) + ")");
}
示例9: Serialize
public override object Serialize(IDesignerSerializationManager manager, object value)
{
CodeExpression expression;
CodeTypeDeclaration declaration = manager.Context[typeof(CodeTypeDeclaration)] as CodeTypeDeclaration;
RootContext context = manager.Context[typeof(RootContext)] as RootContext;
CodeStatementCollection statements = new CodeStatementCollection();
if ((declaration != null) && (context != null))
{
CodeMemberField field = new CodeMemberField(typeof(IContainer), "components") {
Attributes = MemberAttributes.Private
};
declaration.Members.Add(field);
expression = new CodeFieldReferenceExpression(context.Expression, "components");
}
else
{
CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(typeof(IContainer), "components");
statements.Add(statement);
expression = new CodeVariableReferenceExpression("components");
}
base.SetExpression(manager, value, expression);
CodeObjectCreateExpression right = new CodeObjectCreateExpression(typeof(Container), new CodeExpression[0]);
CodeAssignStatement statement2 = new CodeAssignStatement(expression, right);
statement2.UserData["IContainer"] = "IContainer";
statements.Add(statement2);
return statements;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:ContainerCodeDomSerializer.cs
示例10: Serialize
public override object Serialize(IDesignerSerializationManager manager, object obj)
{
if (manager == null)
throw new ArgumentNullException("manager");
if (obj == null)
throw new ArgumentNullException("obj");
CodeExpression retVal = null;
CodeStatementCollection statements = manager.Context[typeof(CodeStatementCollection)] as CodeStatementCollection;
System.Diagnostics.Debug.Assert(statements != null);
if (statements != null)
{
Activity activity = (Activity)manager.Context[typeof(Activity)];
CodeExpression objectExpression = SerializeToExpression(manager, activity);
ICollection<String> handles = obj as ICollection<String>;
if (handles == null)
throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(StringCollection).FullName), "obj");
string variableName = GetUniqueName(manager, new StringCollection());
statements.Add(new CodeVariableDeclarationStatement(obj.GetType(), variableName, new CodeObjectCreateExpression(obj.GetType())));
foreach (string handle in handles)
statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeVariableReferenceExpression(variableName), "Add"), new CodeExpression[] { new CodePrimitiveExpression(handle) }));
retVal = new CodeVariableReferenceExpression(variableName);
}
return retVal;
}
示例11: GetPropertyValueExpression
private CodeExpression GetPropertyValueExpression(Type propertyType, CodeVariableReferenceExpression binaryReader)
{
if (propertyType == typeof(byte))
return new CodeMethodInvokeExpression (binaryReader, "ReadByte");
if (propertyType == typeof(short))
return new CodeMethodInvokeExpression(binaryReader, "ReadInt16");
if (propertyType == typeof(ushort))
return new CodeMethodInvokeExpression(binaryReader, "ReadUInt16");
if (propertyType == typeof(int))
return new CodeMethodInvokeExpression(binaryReader, "ReadInt32");
if (propertyType == typeof(uint))
return new CodeMethodInvokeExpression(binaryReader, "ReadUInt32");
if (propertyType == typeof(float))
return new CodeMethodInvokeExpression(binaryReader, "ReadSingle");
if (propertyType == typeof(double))
return new CodeMethodInvokeExpression(binaryReader, "ReadDouble");
if (propertyType.IsEnum)
{
Type enumBaseType = Enum.GetUnderlyingType(propertyType);
return new CodeCastExpression(propertyType, GetPropertyValueExpression(enumBaseType, binaryReader));
}
throw new NotSupportedException(String.Format("'{0}' doesn't support properties of type '{1}'",
GetType().FullName, propertyType.FullName));
}
示例12: CreateStaticMethod
public static CodeTypeMember CreateStaticMethod(string methodName, string typeT, string typeT1, string parameterName, string parameterType, bool useAutoTyping) {
CodeMemberMethod staticMethod = new CodeMemberMethod();
staticMethod.Name = methodName;
staticMethod.Attributes = MemberAttributes.Static | MemberAttributes.Public;
staticMethod.ReturnType = new CodeTypeReference(typeT);
staticMethod.Parameters.Add(CreateParameter(parameterName, parameterType));
CodeExpression parameterExp = new CodeVariableReferenceExpression(parameterName);
if (useAutoTyping) {
staticMethod.Statements.Add(
new CodeMethodReturnStatement(
new CodeCastExpression(
staticMethod.ReturnType,
CreateMethodCall(
new CodeTypeReferenceExpression(Constants.XTypedServices),
Constants.ToXTypedElement,
CreateMethodCall(new CodeTypeReferenceExpression(Constants.XElement), methodName, parameterExp),
CodeDomHelper.SingletonTypeManager()))));
}
else {
CodeMethodInvokeExpression methodCall = CreateMethodCall(new CodeTypeReferenceExpression(Constants.XTypedServices), methodName + "<" + GetInnerType(typeT, typeT1) + ">", parameterExp);
if (typeT1 != null) {
methodCall.Parameters.Add(CodeDomHelper.SingletonTypeManager());
}
staticMethod.Statements.Add(new CodeMethodReturnStatement(methodCall));
}
return staticMethod;
}
示例13: CodeForEachStatement
public CodeForEachStatement(CodeTypeReference elementType, string elementName, CodeExpression enumerableTarget, params CodeStatement[] statements)
{
_elementType = elementType;
_variableRefExpr = new CodeVariableReferenceExpression(elementName);
_enumerableTarget = enumerableTarget;
Statements.AddRange(statements);
Refresh();
}
示例14: CreateVariable
public static Tuple<CodeVariableDeclarationStatement, CodeVariableReferenceExpression> CreateVariable(CodeTypeReference typeReference, string name, params CodeExpression[] constructorParameters)
{
CodeObjectCreateExpression initializer = new CodeObjectCreateExpression(typeReference, constructorParameters);
CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(typeReference, name, initializer);
CodeVariableReferenceExpression reference = new CodeVariableReferenceExpression(name);
return new Tuple<CodeVariableDeclarationStatement, CodeVariableReferenceExpression>(statement, reference);
}
示例15: JsonCodeWriter
public JsonCodeWriter(CodeVariableReferenceExpression variable, IList list)
{
if (variable == null)
throw new ArgumentNullException("variable");
_variable = variable;
_list = list;
}