本文整理汇总了C#中TypeParameters类的典型用法代码示例。如果您正苦于以下问题:C# TypeParameters类的具体用法?C# TypeParameters怎么用?C# TypeParameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeParameters类属于命名空间,在下文中一共展示了TypeParameters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MemberName
public MemberName (string name, TypeParameters tparams, Location loc)
{
this.Name = name;
this.Location = loc;
this.TypeParameters = tparams;
}
示例2: MakeMemberName
protected static MemberName MakeMemberName (MemberBase host, string name, int unique_id, TypeParameter[] tparams, Location loc)
{
string host_name = host == null ? null : host is InterfaceMemberBase ? ((InterfaceMemberBase)host).GetFullName (host.MemberName) : host.Name;
string tname = MakeName (host_name, "c", name, unique_id);
TypeParameters args = null;
if (tparams != null) {
args = new TypeParameters ();
foreach (TypeParameter tparam in tparams)
args.Add (new TypeParameterName (tparam.Name, null, loc));
}
return new MemberName (tname, args, loc);
}
示例3: MakeMemberName
protected static MemberName MakeMemberName (MemberBase host, string name, int unique_id, TypeParameters tparams, Location loc)
{
string host_name = host == null ? null : host is InterfaceMemberBase ? ((InterfaceMemberBase)host).GetFullName (host.MemberName) : host.MemberName.Name;
string tname = MakeName (host_name, "c", name, unique_id);
TypeParameters args = null;
if (tparams != null) {
args = new TypeParameters (tparams.Count);
// Type parameters will be filled later when we have TypeContainer
// instance, for now we need only correct arity to create valid name
for (int i = 0; i < tparams.Count; ++i)
args.Add ((TypeParameter) null);
}
return new MemberName (tname, args, loc);
}
示例4: AddConstraints
void AddConstraints(AstNode parent, TypeParameters d)
{
if (d == null)
return;
for (int i = 0; i < d.Count; i++) {
var typeParameter = d [i];
if (typeParameter == null)
continue;
var c = typeParameter.Constraints;
if (c == null)
continue;
var location = LocationsBag.GetLocations(c);
var constraint = new Constraint();
constraint.AddChild(new CSharpTokenNode(Convert(c.Location), Roles.WhereKeyword), Roles.WhereKeyword);
constraint.AddChild(new SimpleType(Identifier.Create(c.TypeParameter.Value, Convert(c.TypeParameter.Location))), Roles.ConstraintTypeParameter);
if (location != null)
constraint.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.Colon), Roles.Colon);
var commaLocs = LocationsBag.GetLocations(c.ConstraintExpressions);
int curComma = 0;
if (c.ConstraintExpressions != null) {
foreach (var expr in c.ConstraintExpressions) {
constraint.AddChild(ConvertToType(expr), Roles.BaseType);
var sce = expr as SpecialContraintExpr;
if (sce != null) {
switch (sce.Constraint) {
case SpecialConstraint.Class:
break;
case SpecialConstraint.Struct:
break;
case SpecialConstraint.Constructor:
var bl = LocationsBag.GetLocations(expr);
if (bl != null) {
constraint.AddChild(new CSharpTokenNode(Convert(bl [0]), Roles.LPar), Roles.LPar);
constraint.AddChild(new CSharpTokenNode(Convert(bl [1]), Roles.RPar), Roles.RPar);
}
break;
}
}
if (commaLocs != null && curComma < commaLocs.Count)
constraint.AddChild(new CSharpTokenNode(Convert(commaLocs [curComma++]), Roles.Comma), Roles.Comma);
}
}
// We need to sort the constraints by position; as they might be in a different order than the type parameters
AstNode prevSibling = parent.LastChild;
while (prevSibling.StartLocation > constraint.StartLocation && prevSibling.PrevSibling != null)
prevSibling = prevSibling.PrevSibling;
parent.InsertChildAfter(prevSibling, constraint, Roles.Constraint);
}
}
示例5: AddConstraints
void AddConstraints(AstNode parent, TypeParameters d)
{
if (d == null)
return;
for (int i = d.Count - 1; i >= 0; i--) {
var typeParameter = d [i];
if (typeParameter == null)
continue;
var c = typeParameter.Constraints;
if (c == null)
continue;
var location = LocationsBag.GetLocations (c);
var constraint = new Constraint ();
constraint.AddChild (new CSharpTokenNode (Convert (c.Location), Roles.WhereKeyword), Roles.WhereKeyword);
constraint.AddChild (new SimpleType (Identifier.Create (c.TypeParameter.Value, Convert (c.TypeParameter.Location))), Roles.ConstraintTypeParameter);
if (location != null)
constraint.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.Colon), Roles.Colon);
var commaLocs = LocationsBag.GetLocations (c.ConstraintExpressions);
int curComma = 0;
if (c.ConstraintExpressions != null) {
foreach (var expr in c.ConstraintExpressions) {
constraint.AddChild (ConvertToType (expr), Roles.BaseType);
if (commaLocs != null && curComma < commaLocs.Count)
constraint.AddChild (new CSharpTokenNode (Convert (commaLocs [curComma++]), Roles.Comma), Roles.Comma);
}
}
parent.AddChild (constraint, Roles.Constraint);
}
}
示例6: DoCreateMethodHost
//
// Creates a host for the anonymous method
//
AnonymousMethodMethod DoCreateMethodHost (EmitContext ec)
{
//
// Anonymous method body can be converted to
//
// 1, an instance method in current scope when only `this' is hoisted
// 2, a static method in current scope when neither `this' nor any variable is hoisted
// 3, an instance method in compiler generated storey when any hoisted variable exists
//
Modifiers modifiers;
TypeDefinition parent = null;
var src_block = Block.Original.Explicit;
if (src_block.HasCapturedVariable || src_block.HasCapturedThis) {
parent = storey = FindBestMethodStorey ();
if (storey == null) {
var top_block = src_block.ParametersBlock.TopBlock;
var sm = top_block.StateMachine;
if (src_block.HasCapturedThis) {
//
// Remove hoisted 'this' request when simple instance method is
// enough. No hoisted variables only 'this' and don't need to
// propagate this to value type state machine.
//
StateMachine sm_parent;
var pb = src_block.ParametersBlock;
do {
sm_parent = pb.StateMachine;
pb = pb.Parent == null ? null : pb.Parent.ParametersBlock;
} while (sm_parent == null && pb != null);
if (sm_parent == null) {
top_block.RemoveThisReferenceFromChildrenBlock (src_block);
} else if (sm_parent.Kind == MemberKind.Struct) {
//
// Special case where parent class is used to emit instance method
// because currect storey is of value type (async host) and we cannot
// use ldftn on non-boxed instances either to share mutated state
//
parent = sm_parent.Parent.PartialContainer;
} else if (sm is IteratorStorey) {
//
// For iterators we can host everything in one class
//
parent = storey = sm;
}
}
}
modifiers = storey != null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
} else {
if (ec.CurrentAnonymousMethod != null)
parent = storey = ec.CurrentAnonymousMethod.Storey;
modifiers = Modifiers.STATIC | Modifiers.PRIVATE;
}
if (parent == null)
parent = ec.CurrentTypeDefinition.Parent.PartialContainer;
string name = CompilerGeneratedContainer.MakeName (parent != storey ? block_name : null,
"m", null, parent.PartialContainer.CounterAnonymousMethods++);
MemberName member_name;
if (storey == null && ec.CurrentTypeParameters != null) {
var hoisted_tparams = ec.CurrentTypeParameters;
var type_params = new TypeParameters (hoisted_tparams.Count);
for (int i = 0; i < hoisted_tparams.Count; ++i) {
type_params.Add (hoisted_tparams[i].CreateHoistedCopy (null));
}
member_name = new MemberName (name, type_params, Location);
} else {
member_name = new MemberName (name, Location);
}
return new AnonymousMethodMethod (parent,
this, storey, new TypeExpression (ReturnType, Location), modifiers,
member_name, parameters);
}
示例7: DoResolveCore
protected bool DoResolveCore (ResolveContext rc)
{
foreach (var arg in arguments) {
if (arg.Type == InternalType.VarOutType) {
// Should be special error message about dynamic dispatch
rc.Report.Error (8047, arg.Expr.Location, "Declaration expression cannot be used in this context");
}
}
if (rc.CurrentTypeParameters != null && rc.CurrentTypeParameters[0].IsMethodTypeParameter)
context_mvars = rc.CurrentTypeParameters;
int errors = rc.Report.Errors;
var pt = rc.Module.PredefinedTypes;
binder_type = pt.Binder.Resolve ();
pt.CallSite.Resolve ();
pt.CallSiteGeneric.Resolve ();
eclass = ExprClass.Value;
if (type == null)
type = rc.BuiltinTypes.Dynamic;
if (rc.Report.Errors == errors)
return true;
rc.Report.Error (1969, loc,
"Dynamic operation cannot be compiled without `Microsoft.CSharp.dll' assembly reference");
return false;
}
示例8: CreateTypeParameters
string[] CreateTypeParameters ()
{
string[] names;
int parent_offset = 0;
var parent_all = Parent.all_type_parameters;
if (parent_all != null) {
if (CurrentTypeParameters == null) {
all_type_parameters = Parent.all_type_parameters;
return Parent.all_tp_builders.Select (l => l.Name).ToArray ();
}
names = new string[parent_all.Count + CurrentTypeParameters.Count];
all_type_parameters = new TypeParameters (names.Length);
all_type_parameters.Add (Parent.all_type_parameters);
parent_offset = all_type_parameters.Count;
for (int i = 0; i < parent_offset; ++i)
names[i] = all_type_parameters[i].MemberName.Name;
} else {
names = new string[CurrentTypeParameters.Count];
}
for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
if (all_type_parameters != null)
all_type_parameters.Add (MemberName.TypeParameters[i]);
var name = CurrentTypeParameters[i].MemberName.Name;
names[parent_offset + i] = name;
for (int ii = 0; ii < parent_offset + i; ++ii) {
if (names[ii] != name)
continue;
var tp = CurrentTypeParameters[i];
var conflict = all_type_parameters[ii];
tp.WarningParentNameConflict (conflict);
}
}
if (all_type_parameters == null)
all_type_parameters = CurrentTypeParameters;
return names;
}
示例9: DoResolveCore
protected bool DoResolveCore (ResolveContext rc)
{
if (rc.CurrentTypeParameters != null && rc.CurrentTypeParameters [0].IsMethodTypeParameter)
context_mvars = rc.CurrentTypeParameters;
int errors = rc.Report.Errors;
var pt = rc.Module.PredefinedTypes;
binder_type = pt.GetBinder (rc).Resolve ();
isPlayScriptDynamicMode = pt.IsPlayScriptDynamicMode;
isPlayScriptAotMode = pt.IsPlayScriptAotMode;
// NOTE: Use AsCallSite if in PlayScript AOT mode only.
if (isPlayScriptAotMode) {
pt.AsCallSite.Resolve ();
pt.AsCallSiteGeneric.Resolve ();
} else {
pt.CallSite.Resolve ();
pt.CallSiteGeneric.Resolve ();
}
eclass = ExprClass.Value;
if (type == null)
type = rc.BuiltinTypes.Dynamic;
if (rc.Report.Errors == errors)
return true;
if (isPlayScriptDynamicMode) {
rc.Report.Error (7027, loc,
"PlayScript dynamic operation cannot be compiled without `ascorlib.dll' assembly reference");
} else {
rc.Report.Error (1969, loc,
"Dynamic operation cannot be compiled without `Microsoft.CSharp.dll' assembly reference");
}
return false;
}
示例10: case_357
void case_357()
{
var tparams = new TypeParameters ();
tparams.Add ((TypeParameter)yyVals[0+yyTop]);
yyVal = tparams;
}
示例11: DoCreateMethodHost
//
// Creates a host for the anonymous method
//
AnonymousMethodMethod DoCreateMethodHost (EmitContext ec)
{
//
// Anonymous method body can be converted to
//
// 1, an instance method in current scope when only `this' is hoisted
// 2, a static method in current scope when neither `this' nor any variable is hoisted
// 3, an instance method in compiler generated storey when any hoisted variable exists
//
Modifiers modifiers;
TypeDefinition parent = null;
var src_block = Block.Original.Explicit;
if (src_block.HasCapturedVariable || src_block.HasCapturedThis) {
parent = storey = FindBestMethodStorey ();
if (storey == null) {
var sm = src_block.ParametersBlock.TopBlock.StateMachine;
//
// Remove hoisted this demand when simple instance method is enough (no hoisted variables only this)
//
if (src_block.HasCapturedThis && src_block.ParametersBlock.StateMachine == null) {
src_block.ParametersBlock.TopBlock.RemoveThisReferenceFromChildrenBlock (src_block);
//
// Special case where parent class is used to emit instance method
// because currect storey is of value type (async host) and we don't
// want to create another childer storey to host this reference only
//
if (sm != null && sm.Kind == MemberKind.Struct)
parent = sm.Parent.PartialContainer;
}
//
// For iterators we can host everything in one class
//
if (sm is IteratorStorey)
parent = storey = sm;
}
modifiers = storey != null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
} else {
if (ec.CurrentAnonymousMethod != null)
parent = storey = ec.CurrentAnonymousMethod.Storey;
modifiers = Modifiers.STATIC | Modifiers.PRIVATE;
}
if (parent == null)
parent = ec.CurrentTypeDefinition.Parent.PartialContainer;
string name = CompilerGeneratedContainer.MakeName (parent != storey ? block_name : null,
"m", null, ec.Module.CounterAnonymousMethods++);
MemberName member_name;
if (storey == null && ec.CurrentTypeParameters != null) {
var hoisted_tparams = ec.CurrentTypeParameters;
var type_params = new TypeParameters (hoisted_tparams.Count);
for (int i = 0; i < hoisted_tparams.Count; ++i) {
type_params.Add (hoisted_tparams[i].CreateHoistedCopy (null));
}
member_name = new MemberName (name, type_params, Location);
} else {
member_name = new MemberName (name, Location);
}
return new AnonymousMethodMethod (parent,
this, storey, new TypeExpression (ReturnType, Location), modifiers,
member_name, parameters);
}
示例12: case_364
void case_364()
#line 2999 "cs-parser.jay"
{
var tparams = new TypeParameters ();
tparams.Add ((TypeParameter)yyVals[0+yyTop]);
yyVal = tparams;
locationListStack.Push (new List<Location> ());
}
示例13: MakeName
public static string MakeName (string name, TypeParameters args)
{
if (args == null)
return name;
return name + "`" + args.Count;
}
示例14: AnonymousMethodStorey
public AnonymousMethodStorey (Block block, TypeContainer parent, MemberBase host, TypeParameters tparams, string name)
: base (parent, MakeMemberName (host, name, unique_id, tparams, block.StartLocation),
tparams, Modifiers.SEALED)
{
OriginalSourceBlock = block;
ID = unique_id++;
}
示例15: DoCreateMethodHost
//
// Creates a host for the anonymous method
//
AnonymousMethodMethod DoCreateMethodHost (EmitContext ec)
{
//
// Anonymous method body can be converted to
//
// 1, an instance method in current scope when only `this' is hoisted
// 2, a static method in current scope when neither `this' nor any variable is hoisted
// 3, an instance method in compiler generated storey when any hoisted variable exists
//
Modifiers modifiers;
if (Block.HasCapturedVariable || Block.HasCapturedThis) {
storey = FindBestMethodStorey ();
modifiers = storey != null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
} else {
if (ec.CurrentAnonymousMethod != null)
storey = ec.CurrentAnonymousMethod.Storey;
modifiers = Modifiers.STATIC | Modifiers.PRIVATE;
}
TypeContainer parent = storey != null ? storey : ec.CurrentTypeDefinition.Parent.PartialContainer;
MemberCore mc = ec.MemberContext as MemberCore;
string name = CompilerGeneratedClass.MakeName (parent != storey ? block_name : null,
"m", null, unique_id++);
MemberName member_name;
if (storey == null && ec.CurrentTypeParameters != null) {
var hoisted_tparams = ec.CurrentTypeParameters;
var type_params = new TypeParameters (hoisted_tparams.Count);
for (int i = 0; i < hoisted_tparams.Count; ++i) {
type_params.Add (hoisted_tparams[i].CreateHoistedCopy (null));
}
member_name = new MemberName (name, type_params, Location);
} else {
member_name = new MemberName (name, Location);
}
string real_name = String.Format (
"{0}~{1}{2}", mc.GetSignatureForError (), GetSignatureForError (),
parameters.GetSignatureForError ());
return new AnonymousMethodMethod (parent,
this, storey, new TypeExpression (ReturnType, Location), modifiers,
real_name, member_name, parameters);
}