本文整理汇总了C#中TypeParameters.Add方法的典型用法代码示例。如果您正苦于以下问题:C# TypeParameters.Add方法的具体用法?C# TypeParameters.Add怎么用?C# TypeParameters.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeParameters
的用法示例。
在下文中一共展示了TypeParameters.Add方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: Create
public static AnonymousTypeClass Create (TypeContainer parent, IList<AnonymousTypeParameter> parameters, Location loc)
{
string name = ClassNamePrefix + parent.Module.CounterAnonymousTypes++;
ParametersCompiled all_parameters;
TypeParameters tparams = null;
SimpleName[] t_args;
if (parameters.Count == 0) {
all_parameters = ParametersCompiled.EmptyReadOnlyParameters;
t_args = null;
} else {
t_args = new SimpleName[parameters.Count];
tparams = new TypeParameters ();
Parameter[] ctor_params = new Parameter[parameters.Count];
for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = parameters[i];
for (int ii = 0; ii < i; ++ii) {
if (parameters[ii].Name == p.Name) {
parent.Compiler.Report.Error (833, parameters[ii].Location,
"`{0}': An anonymous type cannot have multiple properties with the same name",
p.Name);
p = new AnonymousTypeParameter (null, "$" + i.ToString (), p.Location);
parameters[i] = p;
break;
}
}
t_args[i] = new SimpleName ("<" + p.Name + ">__T", p.Location);
tparams.Add (new TypeParameter (i, new MemberName (t_args[i].Name, p.Location), null, null, Variance.None));
ctor_params[i] = new Parameter (t_args[i], p.Name, Parameter.Modifier.NONE, null, p.Location);
}
all_parameters = new ParametersCompiled (ctor_params);
}
//
// Create generic anonymous type host with generic arguments
// named upon properties names
//
AnonymousTypeClass a_type = new AnonymousTypeClass (parent.Module, new MemberName (name, tparams, loc), parameters, loc);
Constructor c = new Constructor (a_type, name, Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN,
null, all_parameters, loc);
c.Block = new ToplevelBlock (parent.Module.Compiler, c.ParameterInfo, loc);
//
// Create fields and constructor body with field initialization
//
bool error = false;
for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = parameters [i];
Field f = new Field (a_type, t_args [i], Modifiers.PRIVATE | Modifiers.READONLY | Modifiers.DEBUGGER_HIDDEN,
new MemberName ("<" + p.Name + ">", p.Location), null);
if (!a_type.AddField (f)) {
error = true;
continue;
}
c.Block.AddStatement (new StatementExpression (
new SimpleAssign (new MemberAccess (new This (p.Location), f.Name),
c.Block.GetParameterReference (i, p.Location))));
ToplevelBlock get_block = new ToplevelBlock (parent.Module.Compiler, p.Location);
get_block.AddStatement (new Return (
new MemberAccess (new This (p.Location), f.Name), p.Location));
Property prop = new Property (a_type, t_args [i], Modifiers.PUBLIC,
new MemberName (p.Name, p.Location), null);
prop.Get = new Property.GetMethod (prop, 0, null, p.Location);
prop.Get.Block = get_block;
a_type.AddMember (prop);
}
if (error)
return null;
a_type.AddConstructor (c);
return a_type;
}
示例4: 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);
}
示例5: CreateHoistedBaseCallProxy
//
// Creates a proxy base method call inside this container for hoisted base member calls
//
public MethodSpec CreateHoistedBaseCallProxy (ResolveContext rc, MethodSpec method)
{
Method proxy_method;
//
// One proxy per base method is enough
//
if (hoisted_base_call_proxies == null) {
hoisted_base_call_proxies = new Dictionary<MethodSpec, Method> ();
proxy_method = null;
} else {
hoisted_base_call_proxies.TryGetValue (method, out proxy_method);
}
if (proxy_method == null) {
string name = CompilerGeneratedContainer.MakeName (method.Name, null, "BaseCallProxy", hoisted_base_call_proxies.Count);
MemberName member_name;
TypeArguments targs = null;
TypeSpec return_type = method.ReturnType;
var local_param_types = method.Parameters.Types;
if (method.IsGeneric) {
//
// Copy all base generic method type parameters info
//
var hoisted_tparams = method.GenericDefinition.TypeParameters;
var tparams = new TypeParameters ();
targs = new TypeArguments ();
targs.Arguments = new TypeSpec[hoisted_tparams.Length];
for (int i = 0; i < hoisted_tparams.Length; ++i) {
var tp = hoisted_tparams[i];
var local_tp = new TypeParameter (tp, null, new MemberName (tp.Name, Location), null);
tparams.Add (local_tp);
targs.Add (new SimpleName (tp.Name, Location));
targs.Arguments[i] = local_tp.Type;
}
member_name = new MemberName (name, tparams, Location);
//
// Mutate any method type parameters from original
// to newly created hoisted version
//
var mutator = new TypeParameterMutator (hoisted_tparams, tparams);
return_type = mutator.Mutate (return_type);
local_param_types = mutator.Mutate (local_param_types);
} else {
member_name = new MemberName (name);
}
var base_parameters = new Parameter[method.Parameters.Count];
for (int i = 0; i < base_parameters.Length; ++i) {
var base_param = method.Parameters.FixedParameters[i];
base_parameters[i] = new Parameter (new TypeExpression (local_param_types [i], Location),
base_param.Name, base_param.ModFlags, null, Location);
base_parameters[i].Resolve (this, i);
}
var cloned_params = ParametersCompiled.CreateFullyResolved (base_parameters, method.Parameters.Types);
if (method.Parameters.HasArglist) {
cloned_params.FixedParameters[0] = new Parameter (null, "__arglist", Parameter.Modifier.NONE, null, Location);
cloned_params.Types[0] = Module.PredefinedTypes.RuntimeArgumentHandle.Resolve ();
}
// Compiler generated proxy
proxy_method = new Method (this, new TypeExpression (return_type, Location),
Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED | Modifiers.DEBUGGER_HIDDEN,
member_name, cloned_params, null);
var block = new ToplevelBlock (Compiler, proxy_method.ParameterInfo, Location) {
IsCompilerGenerated = true
};
var mg = MethodGroupExpr.CreatePredefined (method, method.DeclaringType, Location);
mg.InstanceExpression = new BaseThis (method.DeclaringType, Location);
if (targs != null)
mg.SetTypeArguments (rc, targs);
// Get all the method parameters and pass them as arguments
var real_base_call = new Invocation (mg, block.GetAllParametersArguments ());
Statement statement;
if (method.ReturnType.Kind == MemberKind.Void)
statement = new StatementExpression (real_base_call);
else
statement = new Return (real_base_call, Location);
block.AddStatement (statement);
proxy_method.Block = block;
members.Add (proxy_method);
proxy_method.Define ();
proxy_method.PrepareEmit ();
hoisted_base_call_proxies.Add (method, proxy_method);
//.........这里部分代码省略.........
示例6: CreateTypeParameters
string[] CreateTypeParameters (TypeParameters parentAllTypeParameters)
{
string[] names;
int parent_offset = 0;
if (parentAllTypeParameters != null) {
if (CurrentTypeParameters == null) {
all_type_parameters = parentAllTypeParameters;
return parentAllTypeParameters.GetAllNames ();
}
names = new string[parentAllTypeParameters.Count + CurrentTypeParameters.Count];
all_type_parameters = new TypeParameters (names.Length);
all_type_parameters.Add (parentAllTypeParameters);
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;
}
示例7: 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);
}
示例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: 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> ());
}
示例10: 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);
}
示例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;
var src_block = Block.Original.Explicit;
if (src_block.HasCapturedVariable || src_block.HasCapturedThis) {
storey = FindBestMethodStorey ();
//
// For iterators we can host everything in one class
//
if (storey == null && Block.TopBlock.StateMachine is IteratorStorey)
storey = block.TopBlock.StateMachine;
modifiers = storey != null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
} else {
if (ec.CurrentAnonymousMethod != null)
storey = ec.CurrentAnonymousMethod.Storey;
modifiers = Modifiers.STATIC | Modifiers.PRIVATE;
}
var parent = storey != null ? storey : 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_357
void case_357()
{
var tparams = new TypeParameters ();
tparams.Add ((TypeParameter)yyVals[0+yyTop]);
yyVal = tparams;
}
示例13: case_347
void case_347()
#line 2854 "cs-parser.jay"
{
var tparams = new TypeParameters ();
tparams.Add ((TypeParameter)yyVals[0+yyTop]);
yyVal = tparams;
}