本文整理汇总了C#中System.CodeDom.CodeAssignStatement类的典型用法代码示例。如果您正苦于以下问题:C# CodeAssignStatement类的具体用法?C# CodeAssignStatement怎么用?C# CodeAssignStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodeAssignStatement类属于System.CodeDom命名空间,在下文中一共展示了CodeAssignStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Visit
public void Visit(ProcedureDefinition statement)
{
var argList = new List<CodeParameterDeclarationExpression>();
foreach (var arg in statement.Args)
{
var variableType = TablePrimitive.FromString(arg.Type).Type;
var codeParam = new CodeParameterDeclarationExpression(variableType, arg.Variable);
Scope.Current.RegisterPrimitive(codeParam.Name, variableType, codeParam.Type);
Scope.Current.Type.Type.Members.Add(new CodeMemberField() { Name = codeParam.Name, Type = codeParam.Type, Attributes = MemberAttributes.Public | MemberAttributes.Final });
var assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + codeParam.Name), new CodeVariableReferenceExpression(codeParam.Name));
_mainType.Constructor.Statements.Add(assignment);
argList.Add(codeParam);
}
_mainType.Type.Name = statement.Name;
_mainType.Constructor.Parameters.Clear();
_mainType.Constructor.BaseConstructorArgs.Clear();
_mainType.Constructor.Parameters.AddRange(argList.ToArray());
_mainType.Constructor.BaseConstructorArgs.Add(new CodeArrayCreateExpression(new CodeTypeReference(typeof(string[])), 0));
//visit block
var blockArgs = VisitChild(statement.Block);
_codeStack.Peek().ParentStatements.AddRange(blockArgs.ParentStatements);
}
示例2: 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;
}
示例3: ExampleDependencyInjectionLogic
public static void ExampleDependencyInjectionLogic(CodeMemberMethod buildMethod)
{
// Non file based controls are different than file based controls.
// Non file based controls are instantiated with "new" inside of a method and returned.
// They are declared in the first statement.
CodeVariableDeclarationStatement declaration = (CodeVariableDeclarationStatement)buildMethod.Statements[0];
// Use the type of the declaration to get the type of the control.
Type type = Type.GetType(declaration.Type.BaseType);
// Standard reflection to get all of the properties. You could also look for fields.
PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
foreach(PropertyInfo property in properties) {
// See if the property has the specific attribute we care about.
object[] injectDeps = property.GetCustomAttributes(typeof(InjectDepAttribute), true);
if(injectDeps.Length == 1) {
// Create the code dom to perform the injection.
// In this example, set the property to the literal the attribute was given.
CodeStatement setProperty = new CodeAssignStatement(
new CodePropertyReferenceExpression(new CodeVariableReferenceExpression(declaration.Name), property.Name),
new CodePrimitiveExpression((injectDeps[0] as InjectDepAttribute).Name + " (the builder method this is set in is '" + buildMethod.Name + "')")
);
// Add the statement to the list of statements that make up the builder method.
// The last statement is the return statement that returns the control.
// So we insert out injection statement(s) right before it.
buildMethod.Statements.Insert(buildMethod.Statements.Count - 1, setProperty);
}
}
}
示例4: 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 ();
}
示例5: 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);
}
}
示例6: 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);
}
示例7: Visit
public void Visit(FileTable table)
{
var descriptor = new TableDescriptor(typeof(FileTable<>));
var fileTable = new CodeTypeDeclaration(table.Variable) { TypeAttributes = TypeAttributes.NestedPrivate };
fileTable.BaseTypes.Add(new CodeTypeReference("IRowWriter"));
fileTable.BaseTypes.Add(new CodeTypeReference("IRowReader"));
//field
var fileTableCodeDomType = new CodeTypeReference("FileTable", new CodeTypeReference(table.Variable));
Scope.Current.Type.Type.Members.Add(
new CodeMemberField(fileTableCodeDomType, table.Variable) { Attributes = MemberAttributes.Public | MemberAttributes.Final });
var locationArg = VisitChild(table.Location);
//constructor
Scope.Current.Type.Constructor.Statements.Add(new CodeAssignStatement(
new CodeSnippetExpression(table.Variable),
new CodeObjectCreateExpression(
new CodeTypeReference("FileTable", new CodeTypeReference(table.Variable)))));
BuildIRowWriterImplementation(fileTable, table.Args);
BuildIRowReaderImplementation(fileTable, table.Args);
foreach (var arg in table.Args)
{
var domArg = VisitChild(arg);
fileTable.Members.AddRange(domArg.ParentMemberDefinitions);
descriptor.Variables.Add(new VariableTypePair { Variable = arg.Variable, Primitive= TablePrimitive.FromString(arg.Type)});
}
_mainType.Type.Members.Add(fileTable);
if (Scope.Current.IsCurrentScopeRegistered(table.Variable))
Errors.Add(new VariableAlreadyExists(new Semantic.LineInfo(table.Line.Line, table.Line.CharacterPosition), table.Variable));
Scope.Current.RegisterTable(table.Variable, descriptor, fileTableCodeDomType);
//Init Code
CodeMemberMethod method = new CodeMemberMethod();
method.Name = "Init_" + fileTable.Name;
method.Attributes = MemberAttributes.Private;
_mainType.Type.Members.Add(method);
var assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable + ".Location"), locationArg.CodeExpression);
method.Statements.Add(assignment);
assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable + ".FieldTerminator"), new CodePrimitiveExpression(table.FieldTerminator));
method.Statements.Add(assignment);
assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable + ".RowTerminator"), new CodePrimitiveExpression(table.RowTerminator));
method.Statements.Add(assignment);
method.Statements.Add(new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable), "Load"));
var methodcall = new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(null, method.Name));
_codeStack.Peek().ParentStatements.Add(methodcall);
_codeStack.Peek().CodeExpression = methodcall;
}
示例8: 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
示例9: GenerateSetMappedPropertyCode
protected CodeStatementCollection GenerateSetMappedPropertyCode(CodeExpression targetObj, CodeExpression value)
{
CodeStatementCollection statements = new CodeStatementCollection();
CodePropertyReferenceExpression property = new CodePropertyReferenceExpression(targetObj, MappedProperty.Name);
if (_mappedProperty.PropertyType.IsArray)
{
statements.Add(new CodeAssignStatement(
new CodeIndexerExpression(property, new CodePrimitiveExpression(_index)), value));
return statements;
}
if (IsCollection(_mappedProperty.PropertyType))
{
CodeBinaryOperatorExpression isNull =
new CodeBinaryOperatorExpression(property, CodeBinaryOperatorType.ValueEquality, new CodeSnippetExpression("null"));
CodeAssignStatement create = new CodeAssignStatement(property, new CodeObjectCreateExpression(_mappedProperty.PropertyType));
statements.Add(new CodeConditionStatement(isNull, create));
statements.Add(new CodeMethodInvokeExpression(property, "Add", value));
return statements;
}
statements.Add(new CodeAssignStatement(property, value));
return statements;
}
示例10: 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);
}
}
示例11: 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;
}
示例12: GenerateAssignStatement
protected override void GenerateAssignStatement(CodeAssignStatement e)
{
Output.Write("[CodeAssignStatement: Left=");
base.GenerateExpression(e.Left);
Output.Write(", Right=");
base.GenerateExpression(e.Right);
Output.WriteLine("]");
}
示例13: Constructor0_Deny_Unrestricted
public void Constructor0_Deny_Unrestricted ()
{
CodeAssignStatement cas = new CodeAssignStatement ();
Assert.IsNull (cas.Left, "Left");
cas.Left = new CodeExpression ();
Assert.IsNull (cas.Right, "Right");
cas.Right = new CodeExpression ();
}
示例14: GenerateDefaultConstructor
private void GenerateDefaultConstructor(CodeTypeDeclaration classObject, JsonObject jsonObject)
{
CodeConstructor constructor = new CodeConstructor();
classObject.Members.Add(constructor);
constructor.Attributes = MemberAttributes.Public;
CodeAssignStatement statement = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "RootObject"), new CodeObjectCreateExpression(jsonObject.GetType(), new CodeExpression[0]));
constructor.Statements.Add(statement);
}
示例15: TypescriptAssignStatement
public TypescriptAssignStatement(
IExpressionFactory expressionFactory,
CodeAssignStatement codeAssignStatement,
CodeGeneratorOptions options)
{
_expressionFactory = expressionFactory;
_codeAssignStatement = codeAssignStatement;
_options = options;
}