本文整理汇总了C#中System.CodeDom.CodeDelegateCreateExpression类的典型用法代码示例。如果您正苦于以下问题:C# CodeDelegateCreateExpression类的具体用法?C# CodeDelegateCreateExpression怎么用?C# CodeDelegateCreateExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodeDelegateCreateExpression类属于System.CodeDom命名空间,在下文中一共展示了CodeDelegateCreateExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
public override void Serialize (IDesignerSerializationManager manager, object value, MemberDescriptor descriptor, CodeStatementCollection statements)
{
if (statements == null)
throw new ArgumentNullException ("statements");
if (manager == null)
throw new ArgumentNullException ("manager");
if (value == null)
throw new ArgumentNullException ("value");
if (descriptor == null)
throw new ArgumentNullException ("descriptor");
IEventBindingService service = manager.GetService (typeof (IEventBindingService)) as IEventBindingService;
if (service != null) {
// In the propertygrid the events are represented by PropertyDescriptors and the value is a string
// which contains the method name to bind to. The propertydescriptors are managed and created by the
// IEventBindingService
//
EventDescriptor ev = (EventDescriptor) descriptor;
string methodName = (string) service.GetEventProperty (ev).GetValue (value);
CodeDelegateCreateExpression listener = new CodeDelegateCreateExpression (new CodeTypeReference (ev.EventType), _thisReference, methodName);
CodeExpression targetObject = base.SerializeToExpression (manager, value);
CodeEventReferenceExpression eventRef = new CodeEventReferenceExpression (targetObject, ev.Name);
statements.Add (new CodeAttachEventStatement (eventRef, listener));
}
}
示例2: Constructor1
public void Constructor1 ()
{
CodeExpression expression = new CodeExpression ();
CodeTypeReference type = new CodeTypeReference ("mono");
string methodName = "mono";
CodeDelegateCreateExpression cdce = new CodeDelegateCreateExpression (
type, expression, methodName);
Assert.IsNotNull (cdce.DelegateType, "#1");
Assert.AreSame (type, cdce.DelegateType, "#2");
Assert.IsNotNull (cdce.MethodName, "#3");
Assert.AreSame (methodName, cdce.MethodName, "#4");
Assert.IsNotNull (cdce.TargetObject, "#5");
Assert.AreSame (expression, cdce.TargetObject, "#6");
cdce = new CodeDelegateCreateExpression ((CodeTypeReference) null,
(CodeExpression) null, (string) null);
Assert.IsNotNull (cdce.DelegateType, "#7");
Assert.AreEqual (typeof (void).FullName, cdce.DelegateType.BaseType, "#8");
Assert.IsNotNull (cdce.MethodName, "#9");
Assert.AreEqual (string.Empty, cdce.MethodName, "#10");
Assert.IsNull (cdce.TargetObject, "#11");
}
示例3: AddAsyncMethod
internal static CodeMemberMethod AddAsyncMethod(CodeTypeDeclaration codeClass, string methodName, string[] parameterTypeNames, string[] parameterNames, string callbackMember, string callbackName, string userState)
{
CodeMemberMethod method = AddMethod(codeClass, methodName, new CodeFlags[parameterNames.Length], parameterTypeNames, parameterNames, typeof(void).FullName, null, CodeFlags.IsPublic);
method.Comments.Add(new CodeCommentStatement(Res.GetString("CodeRemarks"), true));
CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), methodName, new CodeExpression[0]);
for (int i = 0; i < parameterNames.Length; i++)
{
expression.Parameters.Add(new CodeArgumentReferenceExpression(parameterNames[i]));
}
expression.Parameters.Add(new CodePrimitiveExpression(null));
method.Statements.Add(expression);
method = AddMethod(codeClass, methodName, new CodeFlags[parameterNames.Length], parameterTypeNames, parameterNames, typeof(void).FullName, null, CodeFlags.IsPublic);
method.Comments.Add(new CodeCommentStatement(Res.GetString("CodeRemarks"), true));
method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), userState));
CodeFieldReferenceExpression left = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), callbackMember);
CodeBinaryOperatorExpression condition = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null));
CodeDelegateCreateExpression right = new CodeDelegateCreateExpression {
DelegateType = new CodeTypeReference(typeof(SendOrPostCallback)),
TargetObject = new CodeThisReferenceExpression(),
MethodName = callbackName
};
CodeStatement[] trueStatements = new CodeStatement[] { new CodeAssignStatement(left, right) };
method.Statements.Add(new CodeConditionStatement(condition, trueStatements, new CodeStatement[0]));
return method;
}
示例4: Serialize
public override void Serialize (IDesignerSerializationManager manager, object value, MemberDescriptor descriptor,
CodeStatementCollection statements)
{
if (statements == null)
throw new ArgumentNullException ("statements");
if (manager == null)
throw new ArgumentNullException ("manager");
if (value == null)
throw new ArgumentNullException ("value");
if (descriptor == null)
throw new ArgumentNullException ("descriptor");
IEventBindingService service = manager.GetService (typeof (IEventBindingService)) as IEventBindingService;
if (service != null) {
EventDescriptor eventDescriptor = (EventDescriptor) descriptor;
string methodName = (string) service.GetEventProperty (eventDescriptor).GetValue (value);
if (methodName != null) {
CodeDelegateCreateExpression listener = new CodeDelegateCreateExpression (new CodeTypeReference (eventDescriptor.EventType),
_thisReference, methodName);
CodeExpression targetObject = base.SerializeToExpression (manager, value);
CodeEventReferenceExpression eventRef = new CodeEventReferenceExpression (targetObject, eventDescriptor.Name);
statements.Add (new CodeAttachEventStatement (eventRef, listener));
}
}
}
示例5: Clone
public static CodeDelegateCreateExpression Clone(this CodeDelegateCreateExpression expression)
{
if (expression == null) return null;
CodeDelegateCreateExpression e = new CodeDelegateCreateExpression();
e.DelegateType = expression.DelegateType.Clone();
e.MethodName = expression.MethodName;
e.TargetObject = expression.TargetObject.Clone();
e.UserData.AddRange(expression.UserData);
return e;
}
示例6: TypescriptDelegateCreateExpression
public TypescriptDelegateCreateExpression(
IExpressionFactory expressionFactory,
CodeDelegateCreateExpression codeExpression,
CodeGeneratorOptions options)
{
_expressionFactory = expressionFactory;
_codeExpression = codeExpression;
_options = options;
System.Diagnostics.Debug.WriteLine("TypescriptDelegateCreateExpression Created");
}
示例7: Constructor0_Deny_Unrestricted
public void Constructor0_Deny_Unrestricted ()
{
CodeDelegateCreateExpression cdce = new CodeDelegateCreateExpression ();
Assert.AreEqual ("System.Void", cdce.DelegateType.BaseType, "DelegateType");
cdce.DelegateType = new CodeTypeReference ("System.Int32");
Assert.AreEqual (String.Empty, cdce.MethodName, "MethodName");
cdce.MethodName = "mono";
Assert.IsNull (cdce.TargetObject, "TargetObject");
cdce.TargetObject = new CodeExpression ();
}
示例8: Constructor1_Deny_Unrestricted
public void Constructor1_Deny_Unrestricted ()
{
CodeTypeReference delegate_type = new CodeTypeReference ("System.Int32");
CodeExpression target = new CodeExpression ();
string method = "mono";
CodeDelegateCreateExpression cdce = new CodeDelegateCreateExpression (delegate_type, target, method);
Assert.AreSame (delegate_type, cdce.DelegateType, "DelegateType");
cdce.DelegateType = new CodeTypeReference ("System.Void");
Assert.AreEqual (method, cdce.MethodName, "MethodName");
cdce.MethodName = String.Empty;
Assert.AreSame (target, cdce.TargetObject, "TargetObject");
cdce.TargetObject = new CodeExpression ();
}
示例9: Serialize
public override void Serialize(IDesignerSerializationManager manager, object value, MemberDescriptor descriptor, CodeStatementCollection statements)
{
EventDescriptor e = descriptor as EventDescriptor;
if (manager == null)
{
throw new ArgumentNullException("manager");
}
if (value == null)
{
throw new ArgumentNullException("value");
}
if (e == null)
{
throw new ArgumentNullException("descriptor");
}
if (statements == null)
{
throw new ArgumentNullException("statements");
}
try
{
IEventBindingService service = (IEventBindingService) manager.GetService(typeof(IEventBindingService));
if (service != null)
{
string methodName = (string) service.GetEventProperty(e).GetValue(value);
if (methodName != null)
{
CodeExpression targetObject = base.SerializeToExpression(manager, value);
if (targetObject != null)
{
CodeTypeReference delegateType = new CodeTypeReference(e.EventType);
CodeDelegateCreateExpression listener = new CodeDelegateCreateExpression(delegateType, _thisRef, methodName);
CodeEventReferenceExpression eventRef = new CodeEventReferenceExpression(targetObject, e.Name);
CodeAttachEventStatement statement = new CodeAttachEventStatement(eventRef, listener);
statement.UserData[typeof(Delegate)] = e.EventType;
statements.Add(statement);
}
}
}
}
catch (Exception innerException)
{
if (innerException is TargetInvocationException)
{
innerException = innerException.InnerException;
}
manager.ReportError(System.Design.SR.GetString("SerializerPropertyGenFailed", new object[] { e.Name, innerException.Message }));
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:49,代码来源:EventMemberCodeDomSerializer.cs
示例10: Visit
public void Visit(ProcedureCall call)
{
var domArg = new CodeDomArg();
CodeMemberMethod method = new CodeMemberMethod();
method.Name = "Exec_" + domArg.MethodIdentifier;
method.Attributes = MemberAttributes.Private;
GenerateCallStatement(method.Statements, call.Line.Line);
_mainType.Type.Members.Add(method);
var methodStatements = new CodeStatementCollection();
var argList = new List<CodeExpression>();
foreach(var arg in call.Args)
{
domArg = VisitChild(arg);
argList.Add(domArg.CodeExpression);
}
methodStatements.Add(
new CodeVariableDeclarationStatement(call.Name, "r",
new CodeObjectCreateExpression(call.Name, argList.ToArray()))
);
methodStatements.Add(
new CodeAssignStatement(
new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("r"), "RequestFactory"),
new CodePropertyReferenceExpression(null, "RequestFactory"))
);
var delegateGen = new CodeDelegateCreateExpression(new CodeTypeReference(typeof(Action<ProgressArgs>)),
new CodeThisReferenceExpression(), "OnProgress");
methodStatements.Add(new CodeAttachEventStatement(new CodeVariableReferenceExpression("r"), "Progress", delegateGen));
methodStatements.Add(
new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("r"), "Run")
);
methodStatements.Add(new CodeRemoveEventStatement(new CodeVariableReferenceExpression("r"), "Progress", delegateGen));
method.Statements.AddRange(methodStatements);
var methodcall = new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(null, method.Name));
_codeStack.Peek().ParentStatements.Add(methodcall);
}
示例11: BuildControlSkinAssignmentStatement
private CodeStatement BuildControlSkinAssignmentStatement(ControlBuilder builder, string skinID)
{
Type controlType = builder.ControlType;
string name = base.GetMethodNameForBuilder(BaseTemplateCodeDomTreeGenerator.buildMethodPrefix, builder) + "_skinKey";
CodeMemberField field = new CodeMemberField(typeof(object), name) {
Attributes = MemberAttributes.Private | MemberAttributes.Static
};
CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression {
Method = new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(typeof(PageTheme)), "CreateSkinKey")
};
expression.Parameters.Add(new CodeTypeOfExpression(controlType));
expression.Parameters.Add(new CodePrimitiveExpression(skinID));
field.InitExpression = expression;
base._sourceDataClass.Members.Add(field);
CodeFieldReferenceExpression targetObject = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "__controlSkins");
CodeIndexerExpression left = new CodeIndexerExpression(targetObject, new CodeExpression[] { new CodeVariableReferenceExpression(name) });
CodeDelegateCreateExpression expression4 = new CodeDelegateCreateExpression(this._controlSkinDelegateType, new CodeThisReferenceExpression(), base.GetMethodNameForBuilder(BaseTemplateCodeDomTreeGenerator.buildMethodPrefix, builder));
CodeObjectCreateExpression right = new CodeObjectCreateExpression(this._controlSkinType, new CodeExpression[0]);
right.Parameters.Add(new CodeTypeOfExpression(controlType));
right.Parameters.Add(expression4);
return new CodeAssignStatement(left, right);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:22,代码来源:PageThemeCodeDomTreeGenerator.cs
示例12: AddEventAssign
void AddEventAssign (CodeMemberMethod method, ControlBuilder builder, string name, Type type, string value)
{
//"__ctrl.{0} += new {1} (this.{2});"
CodeEventReferenceExpression evtID = new CodeEventReferenceExpression (ctrlVar, name);
CodeDelegateCreateExpression create;
create = new CodeDelegateCreateExpression (new CodeTypeReference (type), thisRef, value);
CodeAttachEventStatement attach = new CodeAttachEventStatement (evtID, create);
method.Statements.Add (attach);
}
示例13: GenerateDelegateCreateExpression
protected override void GenerateDelegateCreateExpression (CodeDelegateCreateExpression e)
{
}
示例14: GenerateDelegateCreateExpression
protected override void GenerateDelegateCreateExpression (CodeDelegateCreateExpression expression)
{
TextWriter output = Output;
output.Write ("AddressOf ");
CodeExpression targetObject = expression.TargetObject;
if (targetObject != null) {
GenerateExpression (targetObject);
Output.Write ('.');
}
output.Write (expression.MethodName);
}
示例15: GenerateDelegateCreateExpression
protected abstract void GenerateDelegateCreateExpression (CodeDelegateCreateExpression e);