本文整理汇总了C#中System.CodeDom.CodeArrayCreateExpression类的典型用法代码示例。如果您正苦于以下问题:C# CodeArrayCreateExpression类的具体用法?C# CodeArrayCreateExpression怎么用?C# CodeArrayCreateExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeArrayCreateExpression类属于System.CodeDom命名空间,在下文中一共展示了CodeArrayCreateExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitGetFingerprint
public void EmitGetFingerprint (CodeTypeDeclaration ctd)
{
byte[] hash = Hash;
CodeArrayCreateExpression mkdata = new CodeArrayCreateExpression (CDH.Byte, hash.Length);
for (int i = 0; i < hash.Length; i++)
// well, this for loop sucks
mkdata.Initializers.Add (new CodePrimitiveExpression (hash[i]));
CodeMemberMethod m = new CodeMemberMethod ();
m.Name = "GetFingerprint";
m.Attributes = MemberAttributes.Public | MemberAttributes.Override;
m.ReturnType = CDH.Fingerprint;
m.Parameters.Add (CDH.Param (CDH.IContext, "unused1"));
m.Parameters.Add (CDH.Param (CDH.Fingerprint, "unused2"));
CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression ();
invoke.Method = new CodeMethodReferenceExpression (Generic, "Constant");
invoke.Parameters.Add (mkdata);
m.Statements.Add (new CodeMethodReturnStatement (invoke));
ctd.Members.Add (m);
}
示例2: 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;
}
}
示例3: Constructor1_Deny_Unrestricted
public void Constructor1_Deny_Unrestricted ()
{
CodeArrayCreateExpression cace = new CodeArrayCreateExpression (ctr, ce);
Assert.AreEqual ("System.Void", cace.CreateType.BaseType, "CreateType.BaseType");
Assert.AreEqual (0, cace.Initializers.Count, "Initializers");
Assert.AreEqual (0, cace.Size, "Size");
Assert.AreSame (ce, cace.SizeExpression, "SizeExpression");
}
示例4: GetConcatExpression
public static CodeMethodInvokeExpression GetConcatExpression(IList<ExpressionStringToken> values)
{
var stringType = new CodeTypeReference(typeof(string));
var arrayExpression = new CodeArrayCreateExpression
{
CreateType = new CodeTypeReference("System.String", 1)
{
ArrayElementType = stringType
},
Size = 0
};
foreach (var expressionStringToken in values)
{
if (expressionStringToken.IsExpression)
{
var toStringExpression = new CodeMethodInvokeExpression
{
Method = new CodeMethodReferenceExpression
{
MethodName = "ToString",
TargetObject =
new CodeVariableReferenceExpression
{
VariableName = "Convert"
}
}
};
toStringExpression.Parameters.Add(new CodeSnippetExpression
{
Value = expressionStringToken.Value
});
arrayExpression.Initializers.Add(toStringExpression);
}
else
{
var _value3 = new CodePrimitiveExpression
{
Value = expressionStringToken.Value
};
arrayExpression.Initializers.Add(_value3);
}
}
var concatExpression = new CodeMethodInvokeExpression
{
Method = new CodeMethodReferenceExpression
{
MethodName = "Concat",
TargetObject = new CodeTypeReferenceExpression
{
Type = stringType
}
}
};
concatExpression.Parameters.Add(arrayExpression);
return concatExpression;
}
示例5: GenerateArrayCreateExpression
//
// Methods
//
protected override void GenerateArrayCreateExpression (CodeArrayCreateExpression expression)
{
//
// This tries to replicate MS behavior as good as
// possible.
//
// The Code-Array stuff in ms.net seems to be broken
// anyways, or I'm too stupid to understand it.
//
// I'm sick of it. If you try to develop array
// creations, test them on windows. If it works there
// but not in mono, drop me a note. I'd be especially
// interested in jagged-multidimensional combinations
// with proper initialization :}
//
TextWriter output = Output;
output.Write ("new ");
CodeExpressionCollection initializers = expression.Initializers;
CodeTypeReference createType = expression.CreateType;
if (initializers.Count > 0) {
OutputType (createType);
if (expression.CreateType.ArrayRank == 0) {
output.Write ("[]");
}
OutputStartBrace ();
++Indent;
OutputExpressionList (initializers, true);
--Indent;
output.Write ("}");
} else {
CodeTypeReference arrayType = createType.ArrayElementType;
while (arrayType != null) {
createType = arrayType;
arrayType = arrayType.ArrayElementType;
}
OutputType (createType);
output.Write ('[');
CodeExpression size = expression.SizeExpression;
if (size != null)
GenerateExpression (size);
else
output.Write (expression.Size);
output.Write(']');
}
}
示例6: NullCreateType
public void NullCreateType ()
{
CodeArrayCreateExpression cace = new CodeArrayCreateExpression ((CodeTypeReference) null, 0);
Assert.IsNotNull (cace.CreateType, "#1");
Assert.AreEqual (typeof (void).FullName, cace.CreateType.BaseType, "#2");
cace.CreateType = null;
Assert.IsNotNull (cace.CreateType, "#3");
Assert.AreEqual (typeof (void).FullName, cace.CreateType.BaseType, "#4");
}
示例7: VisitCodeArrayCreateExpression
/// <summary>
/// Visits a <see cref="CodeArrayCreateExpression"/>.
/// </summary>
/// <param name="codeArrayCreateExpression">The <see cref="CodeArrayCreateExpression"/> to visit.</param>
protected virtual void VisitCodeArrayCreateExpression(CodeArrayCreateExpression codeArrayCreateExpression)
{
if (codeArrayCreateExpression == null)
{
return;
}
this.VisitCodeTypeReference(codeArrayCreateExpression.CreateType);
this.VisitCodeExpressionCollection(codeArrayCreateExpression.Initializers);
this.VisitCodeExpression(codeArrayCreateExpression.SizeExpression);
}
示例8: Clone
public static CodeArrayCreateExpression Clone(this CodeArrayCreateExpression expression)
{
if (expression == null) return null;
CodeArrayCreateExpression e = new CodeArrayCreateExpression();
e.CreateType = expression.CreateType.Clone();
e.Initializers.AddRange(expression.Initializers.Clone());
e.Size = expression.Size;
e.SizeExpression = expression.SizeExpression.Clone();
e.UserData.AddRange(expression.UserData);
return e;
}
示例9: TypescriptArrayCreateExpression
public TypescriptArrayCreateExpression(
IExpressionFactory expressionFactory,
CodeArrayCreateExpression codeExpression,
CodeGeneratorOptions options,
ITypescriptTypeMapper typescriptTypeMapper)
{
_expressionFactory = expressionFactory;
_codeExpression = codeExpression;
_options = options;
_typescriptTypeMapper = typescriptTypeMapper;
System.Diagnostics.Debug.WriteLine("TypescriptArrayCreateExpression Created");
}
示例10: MaterializeSimpleTypeDef
internal static CodeExpression MaterializeSimpleTypeDef(
ClrSimpleTypeInfo typeInfo,
Dictionary<XmlSchemaObject, string> nameMappings,
LinqToXsdSettings settings)
{
CodeObjectCreateExpression simpleTypeCreate = null;
CodeExpressionCollection expressions = null;
switch(typeInfo.Variety) {
case XmlSchemaDatatypeVariety.Atomic:
simpleTypeCreate = new CodeObjectCreateExpression(
Constants.AtomicSimpleTypeValidator);
expressions = simpleTypeCreate.Parameters;
expressions.Add(CreateGetBuiltInSimpleType(typeInfo.TypeCode));
expressions.Add(CreateFacets(typeInfo));
break;
case XmlSchemaDatatypeVariety.List:
simpleTypeCreate = new CodeObjectCreateExpression(
Constants.ListSimpleTypeValidator);
expressions = simpleTypeCreate.Parameters;
expressions.Add(CreateGetBuiltInSimpleType(typeInfo.TypeCode));
expressions.Add(CreateFacets(typeInfo));
ListSimpleTypeInfo listType = typeInfo as ListSimpleTypeInfo;
ClrSimpleTypeInfo itemType = listType.ItemType;
expressions.Add(CreateSimpleTypeDef(
itemType, nameMappings, settings, true));
break;
case XmlSchemaDatatypeVariety.Union:
simpleTypeCreate = new CodeObjectCreateExpression(
Constants.UnionSimpleTypeValidator);
expressions = simpleTypeCreate.Parameters;
expressions.Add(CreateGetBuiltInSimpleType(typeInfo.TypeCode));
expressions.Add(CreateFacets(typeInfo));
UnionSimpleTypeInfo unionType = typeInfo as UnionSimpleTypeInfo;
CodeArrayCreateExpression memberTypeCreate =
new CodeArrayCreateExpression();
memberTypeCreate.CreateType = new CodeTypeReference(
Constants.SimpleTypeValidator);
foreach (ClrSimpleTypeInfo st in unionType.MemberTypes)
{
memberTypeCreate.Initializers.Add(CreateSimpleTypeDef(
st, nameMappings, settings, true));
}
expressions.Add(memberTypeCreate);
break;
}
return simpleTypeCreate;
}
示例11: Clone
internal override CodeExpression Clone(CodeExpression expression)
{
CodeArrayCreateExpression expression2 = (CodeArrayCreateExpression) expression;
CodeArrayCreateExpression expression3 = new CodeArrayCreateExpression {
CreateType = TypeReferenceExpression.CloneType(expression2.CreateType),
Size = expression2.Size
};
if (expression2.SizeExpression != null)
{
expression3.SizeExpression = RuleExpressionWalker.Clone(expression2.SizeExpression);
}
foreach (CodeExpression expression4 in expression2.Initializers)
{
expression3.Initializers.Add(RuleExpressionWalker.Clone(expression4));
}
return expression3;
}
示例12: Generate
public override void Generate(object codeObject, Entity entity)
{
base.Generate(codeObject, entity);
var attribute = (CodeAttributeDeclaration)codeObject;
var docType = (DocumentType)entity;
var info = (DocumentTypeInfo)docType.Info;
AddAttributeArgumentIfValue(attribute, "DefaultTemplate", info.DefaultTemplate);
var allowedTemplates =
info.AllowedTemplates
.NonNullOrWhiteSpace()
.AsPrimitiveExpressions();
var arrayCreateExpression = new CodeArrayCreateExpression("String", allowedTemplates);
if (allowedTemplates.Any())
AddAttributeArgument(attribute, "AllowedTemplates", arrayCreateExpression);
}
示例13: Generate
public CodeExpression[] Generate(Table table, HardwireCodeGenerationContext generator,
CodeTypeMemberCollection members)
{
List<CodeExpression> initializers = new List<CodeExpression>();
generator.DispatchTablePairs(table.Get("overloads").Table, members, exp =>
{
initializers.Add(exp);
});
var name = new CodePrimitiveExpression((table["name"] as string));
var type = new CodeTypeOfExpression(table["decltype"] as string);
var array = new CodeArrayCreateExpression(typeof(IOverloadableMemberDescriptor), initializers.ToArray());
return new CodeExpression[] {
new CodeObjectCreateExpression(typeof(OverloadedMethodMemberDescriptor), name, type, array)
};
}
示例14: EmitArray
void EmitArray(CodeArrayCreateExpression array)
{
writer.Write(Parser.ArrayOpen);
bool first = true;
depth++;
foreach (CodeExpression expr in array.Initializers)
{
if (first)
first = false;
else
{
writer.Write(Parser.DefaultMulticast);
writer.Write(Parser.SingleSpace);
}
EmitExpression(expr);
}
depth--;
writer.Write(Parser.ArrayClose);
}
示例15: Generate
public override void Generate(object codeObject, Entity entity)
{
var contentType = (ContentType) entity;
var attribute = (CodeAttributeDeclaration) codeObject;
var structure = contentType.Structure;
if (structure.All(String.IsNullOrWhiteSpace))
return;
var typeofExpressions =
structure
.Where(allowedType => !String.IsNullOrWhiteSpace(allowedType))
.Select(allowedType => new CodeTypeOfExpression(allowedType.PascalCase()))
.Cast<CodeExpression>()
.ToArray();
var expression = new CodeArrayCreateExpression(
typeof(Type[]),
typeofExpressions
);
AddAttributeArgument(attribute, "Structure", expression);
}