本文整理汇总了C#中System.Reflection.Emit.GenericTypeParameterBuilder类的典型用法代码示例。如果您正苦于以下问题:C# GenericTypeParameterBuilder类的具体用法?C# GenericTypeParameterBuilder怎么用?C# GenericTypeParameterBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GenericTypeParameterBuilder类属于System.Reflection.Emit命名空间,在下文中一共展示了GenericTypeParameterBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefineGenericTypeParameter
protected virtual unsafe void DefineGenericTypeParameter(TypeBuilder typeBuilder, GenericTypeParameterBuilder paramBuilder, BCSYM_GenericParam* pParam)
{
paramBuilder.SetGenericParameterAttributes(GetGenericParameterAttributes(pParam));
List<Type> list = new List<Type>();
for (BCSYM_GenericConstraint* constraintPtr = *((BCSYM_GenericConstraint**) (pParam + 0x54)); constraintPtr != null; constraintPtr = *((BCSYM_GenericConstraint**) (constraintPtr + 8)))
{
if (((byte) (*(((byte*) constraintPtr)) == 0x26)) != 0)
{
BCSYM* pSymbol = BCSYM.DigThroughNamedType(*((BCSYM* modopt(IsConst) modopt(IsConst)*) (constraintPtr + 12)));
Type item = this.GetType(typeBuilder, pSymbol);
if (BCSYM.IsInterface(pSymbol))
{
list.Add(item);
}
else
{
paramBuilder.SetBaseTypeConstraint(item);
}
}
}
if (list.Count > 0)
{
paramBuilder.SetInterfaceConstraints(list.ToArray());
}
}
示例2: HandlerClassBuildingContext
public HandlerClassBuildingContext(IReadOnlyList<ServiceDescription> serviceDescriptionChain, MethodDescription methodDescription,
TypeBuilder builder, GenericTypeParameterBuilder[] genericTypeParameterBuilders, HandlerClassFieldCache fields)
{
ServiceDescriptionChain = serviceDescriptionChain;
MethodDescription = methodDescription;
Builder = builder;
GenericTypeParameterBuilders = genericTypeParameterBuilders;
Fields = fields;
}
示例3: RegisterBuilder
internal void RegisterBuilder(GenericTypeParameterBuilder builder)
{
if (Builder != null)
{
throw new InvalidOperationException();
}
Builder = builder;
Info = Builder;
}
示例4: StubInfo
public StubInfo(MethodBase methodBase, ParameterInfo[] parameters,
GenericTypeParameterBuilder[] typeParameters, Type returnType)
{
Debug.Assert(methodBase is MethodBuilder || methodBase is ConstructorBuilder);
this.methodBase = methodBase;
this.Parameters = parameters;
this.TypeParameters = typeParameters;
this.ReturnType = returnType;
}
示例5: BindDelegateExpression
public BindDelegateExpression(Type @delegate, Expression owner, MethodInfo methodToBindTo, GenericTypeParameterBuilder[] genericTypeParams)
{
delegateCtor = @delegate.GetConstructors()[0];
this.methodToBindTo = methodToBindTo;
if(@delegate.IsGenericTypeDefinition)
{
var closedDelegate = @delegate.MakeGenericType(genericTypeParams);
delegateCtor = TypeBuilder.GetConstructor(closedDelegate, delegateCtor);
this.methodToBindTo = methodToBindTo.MakeGenericMethod(genericTypeParams);
}
this.owner = owner;
}
示例6: FinishDefinition
internal void FinishDefinition(GenericTypeParameterBuilder arg)
{
Contracts.Require.IsNotNull("arg", arg);
arg.SetGenericParameterAttributes(Attributes);
if (_baseTypeConstraint != null)
{
arg.SetBaseTypeConstraint(_baseTypeConstraint.Target);
}
if (_interfaceConstraints.Count > 0)
{
arg.SetInterfaceConstraints((from i in _interfaceConstraints
select i.Target).ToArray());
}
}
示例7: RegisterBuilders
public static void RegisterBuilders(this IReadOnlyList<GenericParameterStructure> gnr, GenericTypeParameterBuilder[] builders)
{
for (var i = 0; i < gnr.Count; ++i)
{
gnr[i].RegisterBuilder(builders[i]);
}
}
示例8: AdjustGenericConstraints
private static Type[] AdjustGenericConstraints(MethodInfo methodToCopyGenericsFrom,
GenericTypeParameterBuilder[] newGenericParameters,
Type[] originalGenericArguments,
Type[] constraints)
{
for (var i = 0; i < constraints.Length; i++)
{
constraints[i] = AdjustConstraintToNewGenericParameters(constraints[i],
methodToCopyGenericsFrom,
originalGenericArguments,
newGenericParameters);
}
return constraints;
}
示例9: Define
//
// This is the first method which is called during the resolving
// process; we're called immediately after creating the type parameters
// with SRE (by calling `DefineGenericParameters()' on the TypeBuilder /
// MethodBuilder).
//
public void Define (GenericTypeParameterBuilder type, TypeSpec declaringType)
{
if (builder != null)
throw new InternalErrorException ();
this.builder = type;
spec.DeclaringType = declaringType;
spec.SetMetaInfo (type);
}
示例10: BuildProperties
private static void BuildProperties(DynamicTypeInfo info, TypeBuilder typBuilder,
List<FieldBuilder> fieldBuilders, GenericTypeParameterBuilder[] parameterBuilders) {
for (int i = 0; i < info.PropertyNames.Count; i++) {
//var propBuilder = typBuilder.DefineProperty(
// info.PropertyNames[i], PropertyAttributes.None, parameterBuilders[i], Type.EmptyTypes);
var propBuilder = typBuilder.DefineProperty(
info.PropertyNames[i], PropertyAttributes.HasDefault, parameterBuilders[i], Type.EmptyTypes);
// Build Get prop
var getMethBuilder = typBuilder.DefineMethod(
"get_" + info.PropertyNames[i], MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig,
parameterBuilders[i], Type.EmptyTypes);
var generator = getMethBuilder.GetILGenerator();
generator.Emit(OpCodes.Ldarg_0); // load 'this'
generator.Emit(OpCodes.Ldfld, fieldBuilders[i]); // load the field
generator.Emit(OpCodes.Ret);
propBuilder.SetGetMethod(getMethBuilder);
// Build Set prop
var setMethBuilder = typBuilder.DefineMethod(
"set_" + info.PropertyNames[i], MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig,
typeof(void), new Type[] { fieldBuilders[i].FieldType });
generator = setMethBuilder.GetILGenerator();
generator.Emit(OpCodes.Ldarg_0); // load 'this'
generator.Emit(OpCodes.Ldarg_1); // load value
generator.Emit(OpCodes.Stfld, fieldBuilders[i]);
generator.Emit(OpCodes.Ret);
propBuilder.SetSetMethod(setMethBuilder);
}
}
示例11: DefineGenericParameters
public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names)
{
if (names == null)
throw new ArgumentNullException("names");
if (names.Length == 0)
throw new ArgumentException();
Contract.EndContractBlock();
for (int i = 0; i < names.Length; i ++)
if (names[i] == null)
throw new ArgumentNullException("names");
if (m_inst != null)
throw new InvalidOperationException();
m_inst = new GenericTypeParameterBuilder[names.Length];
for(int i = 0; i < names.Length; i ++)
m_inst[i] = new GenericTypeParameterBuilder(new TypeBuilder(names[i], i, this));
return m_inst;
}
示例12: CopyNonInheritableAttributes
private static void CopyNonInheritableAttributes(GenericTypeParameterBuilder newGenericParameter,
Type originalGenericArgument)
{
foreach (var attribute in originalGenericArgument.GetTypeInfo().GetNonInheritableAttributes())
{
newGenericParameter.SetCustomAttribute(attribute);
}
}
示例13: AdjustConstraintToNewGenericParameters
private static Type AdjustConstraintToNewGenericParameters(
Type constraint, MethodInfo methodToCopyGenericsFrom, Type[] originalGenericParameters,
GenericTypeParameterBuilder[] newGenericParameters)
{
if (constraint.GetTypeInfo().IsGenericType)
{
var genericArgumentsOfConstraint = constraint.GetGenericArguments();
for (var i = 0; i < genericArgumentsOfConstraint.Length; ++i)
{
genericArgumentsOfConstraint[i] =
AdjustConstraintToNewGenericParameters(genericArgumentsOfConstraint[i], methodToCopyGenericsFrom,
originalGenericParameters, newGenericParameters);
}
return constraint.GetGenericTypeDefinition().MakeGenericType(genericArgumentsOfConstraint);
}
else if (constraint.GetTypeInfo().IsGenericParameter)
{
// Determine the source of the parameter
if (constraint.GetTypeInfo().DeclaringMethod != null)
{
// constraint comes from the method
var index = Array.IndexOf(originalGenericParameters, constraint);
Trace.Assert(index != -1,
"When a generic method parameter has a constraint on another method parameter, both parameters must be declared on the same method.");
return newGenericParameters[index].AsType();
}
else // parameter from surrounding type
{
Trace.Assert(constraint.DeclaringType.GetTypeInfo().IsGenericTypeDefinition);
Trace.Assert(methodToCopyGenericsFrom.DeclaringType.GetTypeInfo().IsGenericType
&& constraint.DeclaringType == methodToCopyGenericsFrom.DeclaringType.GetGenericTypeDefinition(),
"When a generic method parameter has a constraint on a generic type parameter, the generic type must be the declaring typer of the method.");
var index = Array.IndexOf(constraint.DeclaringType.GetGenericArguments(), constraint);
Trace.Assert(index != -1, "The generic parameter comes from the given type.");
return methodToCopyGenericsFrom.DeclaringType.GetGenericArguments()[index]; // these are the actual, concrete types
}
}
else
{
return constraint;
}
}
示例14: VerificationHelper
private void VerificationHelper(GenericTypeParameterBuilder[] desiredParameters, Type[] actualParameters)
{
if (null == desiredParameters)
Assert.Null(actualParameters);
if (null != desiredParameters)
{
Assert.NotNull(actualParameters);
Assert.Equal(desiredParameters.Length, actualParameters.Length);
for (int i = 0; i < actualParameters.Length; ++i)
{
Assert.True(desiredParameters[i].Equals(actualParameters[i]));
}
}
}
示例15: Define
/// <summary>
/// This is the first method which is called during the resolving
/// process; we're called immediately after creating the type parameters
/// with SRE (by calling `DefineGenericParameters()' on the TypeBuilder /
/// MethodBuilder).
///
/// We're either called from TypeContainer.DefineType() or from
/// GenericMethod.Define() (called from Method.Define()).
/// </summary>
public void Define (GenericTypeParameterBuilder type)
{
if (this.type != null)
throw new InvalidOperationException ();
this.type = type;
TypeManager.AddTypeParameter (type, this);
}