本文整理汇总了C#中System.CodeDom.CodeObjectCreateExpression类的典型用法代码示例。如果您正苦于以下问题:C# CodeObjectCreateExpression类的具体用法?C# CodeObjectCreateExpression怎么用?C# CodeObjectCreateExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodeObjectCreateExpression类属于System.CodeDom命名空间,在下文中一共展示了CodeObjectCreateExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssignParametersCheckCreatorParameters
public void AssignParametersCheckCreatorParameters()
{
var testClass = new CodeTypeDeclaration();
var creator = new CodeObjectCreateExpression();
// standard parameterless ctor, "public ComposeMeCtorVoid()"
testObject.BuildTestObject(MemberVisibility.Public);
testObject.AssignParameters(testClass, creator);
var actualCreatorParameters = creator.Parameters.OfType<CodeFieldReferenceExpression>().ToArray();
Assert.Count(0, actualCreatorParameters);
// with a constructor from "public ComposeMeTwoCtor(string para1, int para2)"
testClass = new CodeTypeDeclaration();
CreateTestObject(typeof(ComposeMeTwoCtor));
testObject.BuildTestObject(MemberVisibility.Public);
testObject.AssignParameters(testClass, creator);
actualCreatorParameters = creator.Parameters.OfType<CodeFieldReferenceExpression>().ToArray();
Assert.Count(2, actualCreatorParameters);
var expected = "para1";
var actual = actualCreatorParameters[0].FieldName;
Assert.AreEqual(expected, actual);
expected = "para2";
actual = actualCreatorParameters[1].FieldName;
Assert.AreEqual(expected, actual);
}
示例2: AddEntryPoint
static void AddEntryPoint()
{
CodeEntryPointMethod start = new CodeEntryPointMethod();
CodeObjectCreateExpression objectCreate =
new CodeObjectCreateExpression(
new CodeTypeReference("CodeDOMCreatedClass"),
new CodePrimitiveExpression(5.3),
new CodePrimitiveExpression(6.9));
// Add the statement:
// "CodeDOMCreatedClass testClass =
// new CodeDOMCreatedClass(5.3, 6.9);"
start.Statements.Add(new CodeVariableDeclarationStatement(
new CodeTypeReference("CodeDOMCreatedClass"), "testClass",
objectCreate));
// Creat the expression:
// "testClass.ToString()"
CodeMethodInvokeExpression toStringInvoke =
new CodeMethodInvokeExpression(
new CodeVariableReferenceExpression("testClass"), "ToString");
// Add a System.Console.WriteLine statement with the previous
// expression as a parameter.
start.Statements.Add(new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression("System.Console"),
"WriteLine", toStringInvoke));
targetClass.Members.Add(start);
}
示例3: Emit
// Generates a codedom instantiation expression: new foo() or new foo[x].
public static CodeExpression Emit(Instantiation instantiation)
{
// Array instantiation needs a different treatment.
if (instantiation.IsArray)
{
var c = new CodeArrayCreateExpression();
c.CreateType = new CodeTypeReference(instantiation.Name);
c.SizeExpression = CodeDomEmitter.EmitCodeExpression(instantiation.Parameters.ChildExpressions[0]);
return c;
}
else // Non-array instantiation
{
var c = new CodeObjectCreateExpression();
// The type that is being created
var createType = new CodeTypeReference(instantiation.Name);
// Apply the generic type names, if any.
foreach (var g in instantiation.GenericTypes)
{
createType.TypeArguments.Add(new CodeTypeReference(g));
}
c.CreateType = createType;
// Translate the instantiation parameters.
foreach (var a in instantiation.Parameters.ChildExpressions)
c.Parameters.Add(CodeDomEmitter.EmitCodeExpression(a));
return c;
}
}
示例4: OnProcessGeneratedCode
public override void OnProcessGeneratedCode(ControlBuilder controlBuilder, CodeCompileUnit codeCompileUnit, CodeTypeDeclaration baseType, CodeTypeDeclaration derivedType, CodeMemberMethod buildMethod, CodeMemberMethod dataBindingMethod, System.Collections.IDictionary additionalState)
{
// only run this once during page compilation, and only use this one builder (so that we don't get master pages, etc.)
if (controlBuilder.GetType() == typeof(FileLevelPageControlBuilder))
{
// the page will only contain one namespace and one type
var ns = codeCompileUnit.Namespaces.Cast<CodeNamespace>().FirstOrDefault();
if (ns != null)
{
var type = ns.Types.Cast<CodeTypeDeclaration>().FirstOrDefault();
if (type != null)
{
/* When this is output, it will inject this into every page:
*
* protected override PageStatePersister PageStatePersister {
* get { return new CompressedHiddenFieldPageStatePersister(this); }
* }
*
*/
CodeMemberProperty property = new CodeMemberProperty()
{
Name = "PageStatePersister",
HasGet = true,
Attributes = MemberAttributes.Override | MemberAttributes.Family,
Type = new CodeTypeReference(typeof(PageStatePersister))
};
var newObj = new CodeObjectCreateExpression(typeof(CompressedHiddenFieldPageStatePersister), new CodeThisReferenceExpression());
property.GetStatements.Add(new CodeMethodReturnStatement(newObj));
type.Members.Add(property);
}
}
}
base.OnProcessGeneratedCode(controlBuilder, codeCompileUnit, baseType, derivedType, buildMethod, dataBindingMethod, additionalState);
}
开发者ID:GrabYourPitchforks,项目名称:viewstate-compression,代码行数:35,代码来源:ViewStateCompressorControlBuilderInterceptor.cs
示例5: CreateNewWizardStepReference
protected CodeExpression CreateNewWizardStepReference(WizardControllerTreeNode node, string wizardStepPage)
{
CodeExpression createMethodSignature = new CodeObjectCreateExpression(
source[typeof (MethodSignature)],
new CodeExpression[]
{
new CodeTypeOfExpression(node.FullName),
new CodePrimitiveExpression(node.Name),
new CodeArrayCreateExpression(source[typeof (Type)], 0)
});
var constructionArguments = new[]
{
new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), naming.ToMemberVariableName(serviceIdentifier)),
new CodeTypeOfExpression(node.FullName),
new CodePrimitiveExpression(node.Area),
new CodePrimitiveExpression(naming.ToControllerName(node.Name)),
new CodePrimitiveExpression(wizardStepPage),
createMethodSignature,
new CodeArrayCreateExpression(source[typeof (ActionArgument)], 0)
};
return new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(
new CodePropertyReferenceExpression(
new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), naming.ToMemberVariableName(serviceIdentifier)),
"ControllerReferenceFactory"),
"CreateActionReference"),
constructionArguments);
}
示例6: 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]));
}
示例7: 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;
}
示例8: Constructor0_Deny_Unrestricted
public void Constructor0_Deny_Unrestricted ()
{
CodeObjectCreateExpression coce = new CodeObjectCreateExpression ();
Assert.AreEqual ("System.Void", coce.CreateType.BaseType, "CreateType.BaseType");
coce.CreateType = new CodeTypeReference ("System.Int32");
Assert.AreEqual (0, coce.Parameters.Count, "Parameters");
}
示例9: Process
private void Process(ref CodeObject target, CodeObject parent, int indent)
{
CodeMethodInvokeExpression methodInvokeExpr = target as CodeMethodInvokeExpression;
if (methodInvokeExpr != null &&
methodInvokeExpr.Method.TargetObject == null &&
StringUtils.CaseInsensitiveEquals(methodInvokeExpr.Method.MethodName, "CreateObject") &&
methodInvokeExpr.Parameters.Count == 1)
{
CodePrimitiveExpression primitiveExpr = methodInvokeExpr.Parameters[0] as CodePrimitiveExpression;
if (primitiveExpr != null)
{
string progId = primitiveExpr.Value as string;
if (progId != null)
{
Type type = (_importer == null
? Type.GetTypeFromProgID(progId)
: _importer.ImportProgId(progId));
if (type != null)
{
target = new CodeObjectCreateExpression(Utils.CreateTypeReference(type));
}
}
}
}
}
示例10: 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
示例11: 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;
}
示例12: 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);
}
示例13: Constructor1_Deny_Unrestricted
public void Constructor1_Deny_Unrestricted ()
{
CodeTypeReference create = new CodeTypeReference ("System.Int32");
CodeExpression[] parameters = new CodeExpression[1] { new CodeExpression () };
CodeObjectCreateExpression coce = new CodeObjectCreateExpression (create, parameters);
Assert.AreSame (create, coce.CreateType, "CreateType");
coce.CreateType = new CodeTypeReference ("System.Void");
Assert.AreEqual (1, coce.Parameters.Count, "Parameters");
}
示例14: Clone
public static CodeObjectCreateExpression Clone(this CodeObjectCreateExpression expression)
{
if (expression == null) return null;
CodeObjectCreateExpression e = new CodeObjectCreateExpression();
e.CreateType = expression.CreateType.Clone();
e.Parameters.AddRange(expression.Parameters.Clone());
e.UserData.AddRange(expression.UserData);
return e;
}
示例15: Compile
public override void Compile(IEnumerable<IColumInfoModel> columnInfos, Stream to = null)
{
if (string.IsNullOrEmpty(TableName))
{
TableName = TargetCsName;
}
var spAttribute = new CodeAttributeDeclaration(typeof(StoredProcedureAttribute).Name);
_base.CustomAttributes.Add(spAttribute);
if (_base.TypeParameters.Count == 0)
{
//_base.TypeParameters.Add(new CodeTypeParameter(typeof ().FullName));
}
//Create Caller
var createFactoryMethod = new CodeMemberMethod();
createFactoryMethod.Name = "Invoke" + TableName;
createFactoryMethod.ReturnType = new CodeTypeReference(typeof(QueryFactoryResult));
createFactoryMethod.CustomAttributes.Add(
new CodeAttributeDeclaration(typeof(SelectFactoryMethodAttribute).FullName));
//Create the Params
string query = "EXEC " + TableName;
var nameOfListOfParamater = "paramaters";
var listOfParams = new CodeObjectCreateExpression(typeof(List<IQueryParameter>));
var listOfParamscreator = new CodeVariableDeclarationStatement(typeof(List<IQueryParameter>), nameOfListOfParamater, listOfParams);
createFactoryMethod.Statements.Add(listOfParamscreator);
int i = 0;
foreach (var item in _base.Members)
{
if (item is CodeMemberProperty)
{
var variable = item as CodeMemberProperty;
var paramName = "param" + i++;
query += " @" + paramName + " ";
var createParams = new CodeObjectCreateExpression(typeof(QueryParameter),
new CodePrimitiveExpression(paramName),
new CodeVariableReferenceExpression(variable.Name));
var addToList =
new CodeMethodInvokeExpression(new CodeVariableReferenceExpression(nameOfListOfParamater),
"Add", createParams);
createFactoryMethod.Statements.Add(addToList);
}
}
//Finaly create the instance
var createFactory = new CodeObjectCreateExpression(typeof(QueryFactoryResult),
new CodePrimitiveExpression(query),
new CodeMethodInvokeExpression(new CodeVariableReferenceExpression(nameOfListOfParamater), "ToArray"));
var queryFactoryVariable = new CodeMethodReturnStatement(createFactory);
createFactoryMethod.Statements.Add(queryFactoryVariable);
_base.Members.Add(createFactoryMethod);
}