本文整理汇总了C#中System.CodeDom.CodeArrayIndexerExpression类的典型用法代码示例。如果您正苦于以下问题:C# CodeArrayIndexerExpression类的具体用法?C# CodeArrayIndexerExpression怎么用?C# CodeArrayIndexerExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeArrayIndexerExpression类属于System.CodeDom命名空间,在下文中一共展示了CodeArrayIndexerExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Constructor0_Deny_Unrestricted
public void Constructor0_Deny_Unrestricted ()
{
CodeArrayIndexerExpression caie = new CodeArrayIndexerExpression ();
Assert.AreEqual (0, caie.Indices.Count, "Indices");
Assert.IsNull (caie.TargetObject, "TargetObject");
caie.TargetObject = new CodeExpression ();
}
示例2: EmitArrayIndexer
void EmitArrayIndexer(CodeArrayIndexerExpression array)
{
if (array.TargetObject is CodePropertyReferenceExpression &&
((CodePropertyReferenceExpression)array.TargetObject).PropertyName == Parser.VarProperty &&
array.Indices.Count == 1 && array.Indices[0] is CodePrimitiveExpression)
{
var name = ((CodePrimitiveExpression)array.Indices[0]).Value as string;
if (name != null)
{
var sep = name.IndexOf(Parser.ScopeVar);
if (sep != -1)
name = name.Substring(sep + 1);
writer.Write(name);
return;
}
}
EmitExpression(array.TargetObject);
foreach (CodeExpression index in array.Indices)
{
writer.Write(Parser.ArrayOpen);
EmitExpression(index);
writer.Write(Parser.ArrayClose);
}
}
示例3: Constructor1_Deny_Unrestricted
public void Constructor1_Deny_Unrestricted ()
{
CodeExpression target = new CodeExpression ();
CodeExpression[] parameters = new CodeExpression[1] { target };
CodeArrayIndexerExpression caie = new CodeArrayIndexerExpression (target, parameters);
Assert.AreEqual (1, caie.Indices.Count, "Indices");
Assert.AreSame (target, caie.TargetObject, "TargetObject");
caie.TargetObject = new CodeExpression ();
}
示例4: Clone
public static CodeArrayIndexerExpression Clone(this CodeArrayIndexerExpression expression)
{
if (expression == null) return null;
CodeArrayIndexerExpression e = new CodeArrayIndexerExpression();
e.Indices.AddRange(expression.Indices.Clone());
e.TargetObject = expression.TargetObject.Clone();
e.UserData.AddRange(expression.UserData);
return e;
}
示例5: EmitArrayIndexerExpression
private void EmitArrayIndexerExpression(CodeArrayIndexerExpression Indexer)
{
var index = (CodeArrayIndexerExpression) Indexer;
Generator.Emit(OpCodes.Ldloc, VarsProperty);
EmitExpression(index.Indices[0]);
Generator.Emit(OpCodes.Callvirt, GetVariable);
}
示例6: VisitCodeArrayIndexerExpression
/// <summary>
/// Visits a <see cref="CodeArrayIndexerExpression"/>.
/// </summary>
/// <param name="codeArrayIndexerExpression">The <see cref="CodeArrayIndexerExpression"/> to visit.</param>
protected virtual void VisitCodeArrayIndexerExpression(CodeArrayIndexerExpression codeArrayIndexerExpression)
{
if (codeArrayIndexerExpression == null)
{
return;
}
this.VisitCodeExpression(codeArrayIndexerExpression.TargetObject);
this.VisitCodeExpressionCollection(codeArrayIndexerExpression.Indices);
}
示例7: BuildArray
private CodeExpression BuildArray(CodeStatementCollection statements, string name, object value)
{
Array array = (Array) value;
Type type = value.GetType();
string uniqueVariableName = GetUniqueVariableName(name, statements);
CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(type.FullName, uniqueVariableName);
statement.InitExpression = new CodeArrayCreateExpression(type.GetElementType(), array.Length);
statements.Add(statement);
CodeVariableReferenceExpression targetObject = new CodeVariableReferenceExpression(uniqueVariableName);
string str2 = name + "_";
for (int i = 0; i < array.Length; i++)
{
CodeArrayIndexerExpression left = new CodeArrayIndexerExpression(targetObject, new CodeExpression[0]);
left.Indices.Add(new CodePrimitiveExpression(i));
CodeExpression right = this.BuildObject(statements, str2 + i.ToString(), array.GetValue(i));
statements.Add(new CodeAssignStatement(left, right));
}
return targetObject;
}
示例8: CreateProperty
static CodeMemberProperty CreateProperty(PropertyNameType nameType, string constantsClassName, string defaultValuesClassName)
{
CodeMemberProperty publicProp = new CodeMemberProperty();
publicProp.Name = nameType.propertyName;
publicProp.Attributes = CodeDomHelperObjects.PublicFinal;
publicProp.HasGet = true;
publicProp.HasSet = true;
publicProp.Type = new CodeTypeReference(nameType.propertyType);
CodeAttributeDeclarationCollection attributes = new CodeAttributeDeclarationCollection();
CodeAttributeArgument arg1 = new CodeAttributeArgument(
new CodeFieldReferenceExpression(
new CodeTypeReferenceExpression(constantsClassName),
nameType.propertyName));
CodeAttributeArgument arg2 = new CodeAttributeArgument(
PropertyNameConstants.DefaultValueProperty,
new CodeFieldReferenceExpression(
new CodeTypeReferenceExpression(defaultValuesClassName),
Constants.DefaultPrefix + nameType.propertyName));
// Future TODO: Provide a library with attributes that custom channel writes
// can use to adorn their properties with default values and validators, we can
// then add it here.
attributes.Add(new CodeAttributeDeclaration(
new CodeTypeReference(TypeNameConstants.ConfigurationProperty),
arg1, arg2));
publicProp.CustomAttributes = new CodeAttributeDeclarationCollection(attributes);
string nameInConfig = constantsClassName + "." + nameType.propertyName;
CodeArrayIndexerExpression baseIndexedProperty
= new CodeArrayIndexerExpression(
CodeDomHelperObjects.BaseRef,
new CodeFieldReferenceExpression(
new CodeTypeReferenceExpression(constantsClassName),
nameType.propertyName));
publicProp.GetStatements.Add(new CodeMethodReturnStatement(
new CodeCastExpression(
nameType.propertyType,
baseIndexedProperty)));
publicProp.SetStatements.Add(new CodeAssignStatement(
baseIndexedProperty,
new CodePropertySetValueReferenceExpression()));
return publicProp;
}
示例9: CreateConstructor
protected override void CreateConstructor (CodeStatementCollection localVars,
CodeStatementCollection trueStmt)
{
#if NET_2_0
if (!String.IsNullOrEmpty (pageParser.MasterPageFile))
// This is here just to trigger master page build, so that its type
// is available when compiling the page itself.
BuildManager.GetCompiledType (pageParser.MasterPageFile);
#endif
if (pageParser.ClientTarget != null) {
CodeExpression prop;
prop = new CodePropertyReferenceExpression (thisRef, "ClientTarget");
CodeExpression ct = new CodePrimitiveExpression (pageParser.ClientTarget);
if (localVars == null)
localVars = new CodeStatementCollection ();
localVars.Add (new CodeAssignStatement (prop, ct));
}
ArrayList deps = pageParser.Dependencies;
int depsCount = deps != null ? deps.Count : 0;
if (depsCount > 0) {
if (localVars == null)
localVars = new CodeStatementCollection ();
if (trueStmt == null)
trueStmt = new CodeStatementCollection ();
CodeAssignStatement assign;
#if NET_2_0
localVars.Add (
new CodeVariableDeclarationStatement (
typeof (string[]),
"dependencies")
);
CodeVariableReferenceExpression dependencies = new CodeVariableReferenceExpression ("dependencies");
trueStmt.Add (
new CodeAssignStatement (dependencies, new CodeArrayCreateExpression (typeof (string), depsCount))
);
CodeArrayIndexerExpression arrayIndex;
object o;
for (int i = 0; i < depsCount; i++) {
o = deps [i];
arrayIndex = new CodeArrayIndexerExpression (dependencies, new CodeExpression[] {new CodePrimitiveExpression (i)});
assign = new CodeAssignStatement (arrayIndex, new CodePrimitiveExpression (o));
trueStmt.Add (assign);
}
CodeMethodInvokeExpression getDepsCall = new CodeMethodInvokeExpression (
thisRef,
"GetWrappedFileDependencies",
new CodeExpression[] {dependencies}
);
assign = new CodeAssignStatement (GetMainClassFieldReferenceExpression ("__fileDependencies"), getDepsCall);
#else
localVars.Add (new CodeVariableDeclarationStatement (
typeof (ArrayList),
"dependencies")
);
CodeVariableReferenceExpression dependencies = new CodeVariableReferenceExpression ("dependencies");
trueStmt.Add (
new CodeAssignStatement (dependencies, new CodeObjectCreateExpression (typeof (ArrayList), new CodeExpression[] {new CodePrimitiveExpression (depsCount)}))
);
CodeMethodInvokeExpression invoke;
for (int i = 0; i < depsCount; i++) {
invoke = new CodeMethodInvokeExpression (dependencies, "Add", new CodeExpression[] {new CodePrimitiveExpression (deps [i])});
trueStmt.Add (invoke);
}
assign = new CodeAssignStatement (GetMainClassFieldReferenceExpression ("__fileDependencies"), dependencies);
#endif
trueStmt.Add (assign);
}
base.CreateConstructor (localVars, trueStmt);
}
示例10: CreateVertexInputMethods
private void CreateVertexInputMethods()
{
AsmListing asmVS = this.source.GetAsmTechnique(this.techniqueName, this.platform).VertexShader;
//create the GetVertexInputCount() and GetVertexInput() methods
CodeMemberMethod count = new CodeMemberMethod();
count.Name = "GetVertexInputCountImpl";
count.Attributes = MemberAttributes.Family | MemberAttributes.Override;
count.ReturnType = new CodeTypeReference(typeof(int));
Comment(count, "Returns the number of vertex inputs used by this shader");
count.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(asmVS.InputCount)));
classDom.Members.Add(count);
//inputs are stored in a static array
//create it...
int[] arrayValues = new int[asmVS.InputCount * 2];
for (int i = 0; i < asmVS.InputCount; i++)
{
arrayValues[i] = (int)asmVS.GetInput(i).Usage;
arrayValues[i + asmVS.InputCount] = (int)asmVS.GetInput(i).Index;
}
this.vsInputField = new CodeMemberField(typeof(int[]), "vin");
this.vsInputField.Attributes = MemberAttributes.Private | MemberAttributes.Static | MemberAttributes.Final;
this.vsInputField.InitExpression = ShaderBytes.ToArray(arrayValues, this.directives);
CodeFieldReferenceExpression vsInputRef = new CodeFieldReferenceExpression(ShaderClassEx, vsInputField.Name);
//protected internal abstract void GetVertexInput(int index, out VertexElementUsage elementUsage, out int elementIndex);
CodeMemberMethod getInput = new CodeMemberMethod();
getInput.Name = "GetVertexInputImpl";
getInput.Attributes = MemberAttributes.Family | MemberAttributes.Override;
CodeParameterDeclarationExpression indexParam = new CodeParameterDeclarationExpression(typeof(int),"i");
getInput.Parameters.Add(indexParam);
CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression(typeof(VertexElementUsage), "usage");
param.Direction = FieldDirection.Out;
getInput.Parameters.Add(param);
param = new CodeParameterDeclarationExpression(typeof(int), "index");
param.Direction = FieldDirection.Out;
getInput.Parameters.Add(param);
CodeArgumentReferenceExpression indexRef = new CodeArgumentReferenceExpression(indexParam.Name);
//the element index is stored at 'i + asmVS.InputCount'
CodeExpression indexArray = new CodeArrayIndexerExpression(vsInputRef,
new CodeBinaryOperatorExpression(indexRef, CodeBinaryOperatorType.Add, new CodePrimitiveExpression(asmVS.InputCount)));
//and the usage must be cast
CodeExpression usageCast = new CodeCastExpression(typeof(VertexElementUsage), new CodeArrayIndexerExpression(vsInputRef,indexRef));
getInput.Statements.Add(new CodeAssignStatement(new CodeArgumentReferenceExpression("usage"), usageCast));
getInput.Statements.Add(new CodeAssignStatement(new CodeArgumentReferenceExpression("index"), indexArray));
Comment(getInput, "Returns a vertex input used by this shader");
classDom.Members.Add(getInput);
}
示例11: GenerateArrayIndexerExpression
protected override void GenerateArrayIndexerExpression (CodeArrayIndexerExpression e)
{
}
示例12: GenerateArrayIndexerExpression
protected abstract void GenerateArrayIndexerExpression (CodeArrayIndexerExpression e);
示例13: GenerateArrayIndexerExpression
protected override void GenerateArrayIndexerExpression (CodeArrayIndexerExpression expression)
{
TextWriter output = Output;
GenerateExpression (expression.TargetObject);
output.Write ("(");
OutputExpressionList (expression.Indices);
output.Write (')');
}
示例14: GenerateArrayIndexerExpression
protected override void GenerateArrayIndexerExpression(CodeArrayIndexerExpression e)
{
Output.Write("[CodeArrayIndexerExpression: {0}]", e.ToString());
}
示例15: GenerateArrayIndexerExpression
/// <summary>
/// Generates code for the specified array indexer expression.
/// </summary>
/// <remarks><c>TARGET[INDEX1][INDEX2]...</c></remarks>
protected override void GenerateArrayIndexerExpression(CodeArrayIndexerExpression e)
{
OutputArrayIndexerExpression(e.TargetObject, e.Indices);
}