本文整理汇总了C#中System.CodeDom.CodeFieldReferenceExpression类的典型用法代码示例。如果您正苦于以下问题:C# CodeFieldReferenceExpression类的具体用法?C# CodeFieldReferenceExpression怎么用?C# CodeFieldReferenceExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeFieldReferenceExpression类属于System.CodeDom命名空间,在下文中一共展示了CodeFieldReferenceExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCodeStatement
internal CodeStatement GetCodeStatement(BaseTemplateCodeDomTreeGenerator generator, CodeExpression ctrlRefExpr)
{
CodeExpression expression2;
if (this.UseSetAttribute)
{
CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(new CodeCastExpression(typeof(IAttributeAccessor), ctrlRefExpr), "SetAttribute", new CodeExpression[0]);
expression.Parameters.Add(new CodePrimitiveExpression(base.Name));
expression.Parameters.Add(new CodePrimitiveExpression(this.Value));
return new CodeExpressionStatement(expression);
}
CodeExpression right = null;
if (base.PropertyInfo != null)
{
expression2 = CodeDomUtility.BuildPropertyReferenceExpression(ctrlRefExpr, base.Name);
}
else
{
expression2 = new CodeFieldReferenceExpression(ctrlRefExpr, base.Name);
}
if (base.Type == typeof(string))
{
right = generator.BuildStringPropertyExpression(this);
}
else
{
right = CodeDomUtility.GenerateExpressionForValue(base.PropertyInfo, this.Value, base.Type);
}
return new CodeAssignStatement(expression2, right);
}
示例2: TypeReferenceExpressionTest
public void TypeReferenceExpressionTest ()
{
StringBuilder sb = new StringBuilder();
using (StringWriter sw = new StringWriter (sb)) {
CodeThisReferenceExpression thisRef = new CodeThisReferenceExpression();
CodeFieldReferenceExpression parentField = new CodeFieldReferenceExpression();
parentField.TargetObject = thisRef;
parentField.FieldName = "Parent";
CodeBinaryOperatorExpression expression = new CodeBinaryOperatorExpression(
parentField,
CodeBinaryOperatorType.IdentityInequality,
new CodePrimitiveExpression(null));
Assert.AreEqual ("(Not (Me.Parent) Is Nothing)", Generate (expression, sw), "#1");
sw.Close ();
}
sb = new StringBuilder();
using (StringWriter sw = new StringWriter (sb)) {
CodeThisReferenceExpression thisRef = new CodeThisReferenceExpression();
CodeFieldReferenceExpression parentField = new CodeFieldReferenceExpression();
parentField.TargetObject = thisRef;
parentField.FieldName = "Parent";
CodeBinaryOperatorExpression expression = new CodeBinaryOperatorExpression(
new CodePrimitiveExpression(null),
CodeBinaryOperatorType.IdentityInequality,
parentField);
Assert.AreEqual ("(Not (Me.Parent) Is Nothing)", Generate (expression, sw), "#2");
sw.Close ();
}
}
示例3: DeclareCodeType
public override void DeclareCodeType(IDLInterface idlIntf)
{
// Proxy class.
typeProxy = new CodeTypeDeclaration(name + "Proxy");
typeProxy.IsClass = true;
typeProxy.TypeAttributes = TypeAttributes.Public;
eventsDeclarationHolder = new CodeTypeDeferredNamespaceDeclarationHolderEvents(idlIntf);
typeProxy.BaseTypes.Add(genInterfaceName);
// Interface field.
CodeMemberField memberProxy = new CodeMemberField(genInterfaceName, proxyName);
memberProxy.Attributes = MemberAttributes.Private;
typeProxy.Members.Add(memberProxy); // TODO: Going to need a using or a fully qualified name.
// Constructor.
CodeConstructor constructor = new CodeConstructor();
constructor.Attributes = MemberAttributes.Public;
// TODO - use the actual interface type rather than a string.
paramProxy = new CodeParameterDeclarationExpression(genInterfaceName, proxyName);
constructor.Parameters.Add(paramProxy);
thisProxyFieldRef = new CodeFieldReferenceExpression(
new CodeThisReferenceExpression(), proxyName
);
assignProxy = new CodeAssignStatement(thisProxyFieldRef,
new CodeArgumentReferenceExpression(proxyName));
constructor.Statements.Add(assignProxy);
typeProxy.Members.Add(constructor);
declarationHolder = new CodeTypeIgnoredNamespaceDeclarationHolderParams(idlIntf);
contextDeclarationHolder = declarationHolder;
bAddNamespace = false;
}
示例4: AssignValueTo
private CodeAssignStatement AssignValueTo(Expression<Func<IRule, string>> func, string value)
{
var name = Name.Of(func);
var property = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), name);
var assignment = new CodeAssignStatement(property, _(value));
return assignment;
}
示例5: ImportClass
public override void ImportClass()
{
SoapAddressBinding binding = (base.ImportContext.Port == null) ? null : ((SoapAddressBinding) base.ImportContext.Port.Extensions.Find(typeof(SoapAddressBinding)));
if (base.ImportContext.Style == ServiceDescriptionImportStyle.Client)
{
base.ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(SoapHttpClientProtocol).FullName);
CodeConstructor ctor = WebCodeGenerator.AddConstructor(base.ImportContext.CodeTypeDeclaration, new string[0], new string[0], null, CodeFlags.IsPublic);
ctor.Comments.Add(new CodeCommentStatement(Res.GetString("CodeRemarks"), true));
bool flag = true;
if (base.ImportContext is Soap12ProtocolImporter)
{
flag = false;
CodeTypeReferenceExpression targetObject = new CodeTypeReferenceExpression(typeof(SoapProtocolVersion));
CodeFieldReferenceExpression right = new CodeFieldReferenceExpression(targetObject, Enum.Format(typeof(SoapProtocolVersion), SoapProtocolVersion.Soap12, "G"));
CodePropertyReferenceExpression left = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "SoapVersion");
CodeAssignStatement statement = new CodeAssignStatement(left, right);
ctor.Statements.Add(statement);
}
ServiceDescription serviceDescription = base.ImportContext.Binding.ServiceDescription;
string url = (binding != null) ? binding.Location : null;
string appSettingUrlKey = serviceDescription.AppSettingUrlKey;
string appSettingBaseUrl = serviceDescription.AppSettingBaseUrl;
ProtocolImporterUtil.GenerateConstructorStatements(ctor, url, appSettingUrlKey, appSettingBaseUrl, flag && !base.ImportContext.IsEncodedBinding);
}
else if (base.ImportContext.Style == ServiceDescriptionImportStyle.Server)
{
base.ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(WebService).FullName);
}
}
示例6: ImportClass
public override void ImportClass() {
// grab this here so it gets marked "handled" for both client and server
SoapAddressBinding soapAddress = ImportContext.Port == null ? null : (SoapAddressBinding)ImportContext.Port.Extensions.Find(typeof(SoapAddressBinding));
if (ImportContext.Style == ServiceDescriptionImportStyle.Client) {
ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(SoapHttpClientProtocol).FullName);
CodeConstructor ctor = WebCodeGenerator.AddConstructor(ImportContext.CodeTypeDeclaration, new string[0], new string[0], null, CodeFlags.IsPublic);
ctor.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));
bool soap11 = true;
if (ImportContext is Soap12ProtocolImporter) {
soap11 = false;
// add version code
CodeTypeReferenceExpression versionEnumTypeReference = new CodeTypeReferenceExpression(typeof(SoapProtocolVersion));
CodeFieldReferenceExpression versionEnumFieldReference = new CodeFieldReferenceExpression(versionEnumTypeReference, Enum.Format(typeof(SoapProtocolVersion), SoapProtocolVersion.Soap12, "G"));
CodePropertyReferenceExpression versionPropertyReference = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "SoapVersion");
CodeAssignStatement assignVersionStatement = new CodeAssignStatement(versionPropertyReference, versionEnumFieldReference);
ctor.Statements.Add(assignVersionStatement);
}
ServiceDescription serviceDescription = ImportContext.Binding.ServiceDescription;
string url = (soapAddress != null) ? soapAddress.Location : null;
string urlKey = serviceDescription.AppSettingUrlKey;
string baseUrl = serviceDescription.AppSettingBaseUrl;
ProtocolImporterUtil.GenerateConstructorStatements(ctor, url, urlKey, baseUrl, soap11 && !ImportContext.IsEncodedBinding);
}
else if (ImportContext.Style == ServiceDescriptionImportStyle.Server) {
ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(WebService).FullName);
}
}
示例7: 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;
}
示例8: CreateMethod
CodeMemberMethod CreateMethod()
{
CodeMemberMethod method = new CodeMemberMethod();
// BeginInit method call.
CodeExpressionStatement statement = new CodeExpressionStatement();
CodeMethodInvokeExpression methodInvoke = new CodeMethodInvokeExpression();
statement.Expression = methodInvoke;
CodeMethodReferenceExpression methodRef = new CodeMethodReferenceExpression();
methodRef.MethodName = "BeginInit";
CodeCastExpression cast = new CodeCastExpression();
cast.TargetType = new CodeTypeReference();
cast.TargetType.BaseType = "System.ComponentModel.ISupportInitialize";
CodeFieldReferenceExpression fieldRef = new CodeFieldReferenceExpression();
fieldRef.FieldName = "pictureBox1";
fieldRef.TargetObject = new CodeThisReferenceExpression();
cast.Expression = fieldRef;
methodRef.TargetObject = cast;
methodInvoke.Method = methodRef;
method.Statements.Add(statement);
return method;
}
示例9: AddConstructor
/// <summary>
/// Add a constructor to the class.
/// </summary>
public void AddConstructor()
{
// Declare the constructor
CodeConstructor constructor = new CodeConstructor();
constructor.Attributes =
MemberAttributes.Public | MemberAttributes.Final;
// Add parameters.
constructor.Parameters.Add(new CodeParameterDeclarationExpression(
typeof(System.Double), "width"));
constructor.Parameters.Add(new CodeParameterDeclarationExpression(
typeof(System.Double), "height"));
// Add field initialization logic
CodeFieldReferenceExpression widthReference =
new CodeFieldReferenceExpression(
new CodeThisReferenceExpression(), "widthValue");
constructor.Statements.Add(new CodeAssignStatement(widthReference,
new CodeArgumentReferenceExpression("width")));
CodeFieldReferenceExpression heightReference =
new CodeFieldReferenceExpression(
new CodeThisReferenceExpression(), "heightValue");
constructor.Statements.Add(new CodeAssignStatement(heightReference,
new CodeArgumentReferenceExpression("height")));
targetClass.Members.Add(constructor);
}
示例10: ComposeTestTearDownMethod
/// <summary>
/// Compose additional items of the test TearDown method.
/// </summary>
/// <param name="teardownMethod">A reference to the TearDown method of the test.</param>
/// <param name="testObjectMemberField">The member field of the object under test.</param>
/// <param name="testObjectName">The name of the object under test.</param>
/// <param name="testObjectType">Type of the object under test(OuT).</param>
protected override void ComposeTestTearDownMethod(
CodeMemberMethod teardownMethod,
CodeMemberField testObjectMemberField,
string testObjectName,
Type testObjectType)
{
/*var invokeExpression = new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression("Assert"),
"AreEqual",
//new CodePrimitiveExpression("expected")
new CodeFieldReferenceExpression(testObjectMemberField, "bla")
, new CodeVariableReferenceExpression("actual"));*/
var fieldRef1 =
new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), testObjectMemberField.Name);
// var objectCreate1 = new CodeObjectCreateExpression(testObjectName, new CodeExpression[] { });
var as1 =
new CodeAssignStatement(fieldRef1, new CodePrimitiveExpression(null));
// new CodeAssignStatement(fieldRef1, objectCreate1);
// Creates a statement using a code expression.
// var expressionStatement = new CodeExpressionStatement(fieldRef1);
teardownMethod.Statements.Add(as1);
base.ComposeTestTearDownMethod(teardownMethod, testObjectMemberField, testObjectName, testObjectType);
}
示例11: 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
示例12: Constructor0_Deny_Unrestricted
public void Constructor0_Deny_Unrestricted ()
{
CodeFieldReferenceExpression cfre = new CodeFieldReferenceExpression ();
Assert.AreEqual (String.Empty, cfre.FieldName, "FieldName");
cfre.FieldName = "mono";
Assert.IsNull (cfre.TargetObject, "TargetObject");
cfre.TargetObject = new CodeExpression ();
}
示例13: Clone
public static CodeFieldReferenceExpression Clone(this CodeFieldReferenceExpression expression)
{
if (expression == null) return null;
CodeFieldReferenceExpression e = new CodeFieldReferenceExpression();
e.FieldName = expression.FieldName;
e.TargetObject = expression.TargetObject.Clone();
e.UserData.AddRange(expression.UserData);
return e;
}
示例14: DefaultInvocationMethod
public CodeStatementCollection DefaultInvocationMethod(Activity activity)
{
var activityServiceReference = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), VariableHelper.ToVariableName(activity.Name));
var methodInvocation = new CodeMethodInvokeExpression(activityServiceReference, "Execute", new CodeExpression[] { });
var invocationCodeCollection = new CodeStatementCollection();
invocationCodeCollection.AddRange(LogActivity(activity));
invocationCodeCollection.Add(methodInvocation);
return invocationCodeCollection;
}
示例15: Constructor1_Deny_Unrestricted
public void Constructor1_Deny_Unrestricted ()
{
CodeExpression target = new CodeExpression ();
CodeFieldReferenceExpression cfre = new CodeFieldReferenceExpression (target, "mono");
Assert.AreEqual ("mono", cfre.FieldName, "FieldName");
cfre.FieldName = String.Empty;
Assert.AreSame (target, cfre.TargetObject, "TargetObject");
cfre.TargetObject = new CodeExpression ();
}