本文整理汇总了C#中CallingConventions类的典型用法代码示例。如果您正苦于以下问题:C# CallingConventions类的具体用法?C# CallingConventions怎么用?C# CallingConventions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CallingConventions类属于命名空间,在下文中一共展示了CallingConventions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConstructParameters
internal static string ConstructParameters(Type[] parameters, CallingConventions callingConvention)
{
StringBuilder builder = new StringBuilder();
string str = "";
for (int i = 0; i < parameters.Length; i++)
{
Type type = parameters[i];
builder.Append(str);
string str2 = type.SigToString();
if (type.IsByRef)
{
builder.Append(str2.TrimEnd(new char[] { '&' }));
builder.Append(" ByRef");
}
else
{
builder.Append(str2);
}
str = ", ";
}
if ((callingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
{
builder.Append(str);
builder.Append("...");
}
return builder.ToString();
}
示例2: PropertySignature
private PropertySignature(CallingConventions callingConvention, Type propertyType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
{
this.callingConvention = callingConvention;
this.propertyType = propertyType;
this.parameterTypes = parameterTypes;
this.customModifiers = customModifiers;
}
示例3: MonoArrayMethod
#pragma warning restore 649
internal MonoArrayMethod (Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) {
name = methodName;
parent = arrayClass;
ret = returnType;
parameters = (Type[])parameterTypes.Clone();
call_conv = callingConvention;
}
示例4: GetArrayMethod_ValidArrayValues_ReferenceParameterType
public void GetArrayMethod_ValidArrayValues_ReferenceParameterType(CallingConventions callingConvention)
{
ModuleBuilder module = Helpers.DynamicModule();
VerifyGetArrayMethod(module, typeof(ModuleBuilderGetArrayMethod[]), callingConvention.ToString() + "1", callingConvention, typeof(int), new Type[] { typeof(object) });
VerifyGetArrayMethod(module, typeof(ModuleBuilderGetArrayMethod[]), callingConvention.ToString() + "2", callingConvention, typeof(int), new Type[] { typeof(object), typeof(string), typeof(ModuleBuilderGetArrayMethod) });
}
示例5: GetArrayMethod_MultiDimensionalArray
public void GetArrayMethod_MultiDimensionalArray(CallingConventions callingConvention)
{
ModuleBuilder module = Helpers.DynamicModule();
VerifyGetArrayMethod(module, typeof(ModuleBuilderGetArrayMethod[,]), callingConvention.ToString() + "1", callingConvention, typeof(int), new Type[] { typeof(object) });
VerifyGetArrayMethod(module, typeof(ModuleBuilderGetArrayMethod[,]), callingConvention.ToString() + "2", callingConvention, typeof(int), new Type[] { typeof(object), typeof(int), typeof(ModuleBuilderGetArrayMethod) });
}
示例6: DefineConstructor
public void DefineConstructor(MethodAttributes methodAttributes, Type[] parameterTypes, CallingConventions callingConvention, BindingFlags bindingFlags)
{
TypeBuilder type = Helpers.DynamicType(TypeAttributes.Class | TypeAttributes.Public);
FieldBuilder fieldBuilderA = type.DefineField("TestField", typeof(int), FieldAttributes.Private);
FieldBuilder fieldBuilderB = type.DefineField("TestField", typeof(int), FieldAttributes.Private);
ConstructorBuilder ctorBuilder = type.DefineConstructor(methodAttributes, callingConvention, parameterTypes);
ILGenerator ctorIlGenerator = ctorBuilder.GetILGenerator();
if (parameterTypes.Length != 0)
{
//Calling base class constructor
ctorIlGenerator.Emit(OpCodes.Ldarg_0);
ctorIlGenerator.Emit(OpCodes.Call, typeof(object).GetConstructor(new Type[0]));
ctorIlGenerator.Emit(OpCodes.Ldarg_0);
ctorIlGenerator.Emit(OpCodes.Ldarg_1);
ctorIlGenerator.Emit(OpCodes.Stfld, fieldBuilderA);
ctorIlGenerator.Emit(OpCodes.Ldarg_0);
ctorIlGenerator.Emit(OpCodes.Ldarg_2);
ctorIlGenerator.Emit(OpCodes.Stfld, fieldBuilderB);
}
ctorIlGenerator.Emit(OpCodes.Ret);
Type createdType = type.CreateTypeInfo().AsType();
Assert.NotNull(createdType.GetConstructors(bindingFlags).FirstOrDefault());
}
示例7: SymbolMethod
//***********************************************
//
// Constructor
//
//***********************************************
internal SymbolMethod(
ModuleBuilder mod,
MethodToken token,
Type arrayClass,
String methodName,
CallingConventions callingConvention,
Type returnType,
Type[] parameterTypes)
{
m_module = mod;
m_containingType = arrayClass;
m_name = methodName;
m_callingConvention = callingConvention;
m_returnType = returnType;
m_mdMethod = token;
if (parameterTypes != null)
{
m_parameterTypes = new Type[parameterTypes.Length];
Array.Copy(parameterTypes, m_parameterTypes, parameterTypes.Length);
}
else
m_parameterTypes = null;
m_signature = SignatureHelper.GetMethodSigHelper(mod, callingConvention, returnType, parameterTypes);
}
示例8: DefineMethod
public void DefineMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
{
bool defaultReturnTypeAndParameters = returnType == null && parameterTypes == null;
if (callingConvention == CallingConventions.Standard)
{
if (defaultReturnTypeAndParameters)
{
// Use DefineMethod(string, MethodAttributes)
TypeBuilder type1 = Helpers.DynamicType(TypeAttributes.Public);
MethodBuilder method1 = type1.DefineMethod(name, attributes);
VerifyMethod(type1, method1, name, attributes, callingConvention, returnType, parameterTypes);
}
// Use DefineMethod(string, MethodAttributes, Type, Type[])
TypeBuilder type2 = Helpers.DynamicType(TypeAttributes.Public);
MethodBuilder method2 = type2.DefineMethod(name, attributes, returnType, parameterTypes);
VerifyMethod(type2, method2, name, attributes, callingConvention, returnType, parameterTypes);
}
if (defaultReturnTypeAndParameters)
{
// Use DefineMethod(string, MethodAttributes, CallingConventions)
TypeBuilder type3 = Helpers.DynamicType(TypeAttributes.Public);
MethodBuilder method3 = type3.DefineMethod(name, attributes, callingConvention);
VerifyMethod(type3, method3, name, attributes, callingConvention, returnType, parameterTypes);
}
// Use DefineMethod(string, MethodAttributes, CallingConventions, Type, Type[])
TypeBuilder type4 = Helpers.DynamicType(TypeAttributes.Public);
MethodBuilder method4 = type4.DefineMethod(name, attributes, callingConvention, returnType, parameterTypes);
VerifyMethod(type4, method4, name, attributes, callingConvention, returnType, parameterTypes);
}
示例9: DefineConstructor
/// <summary>
/// Defines a constructor.
/// </summary>
/// <param name="typeBuilder">The type builder.</param>
/// <param name="methodAttributes">The method attributes.</param>
/// <param name="callingConvention">The calling convention.</param>
/// <param name="parameterTypes">The parameter types.</param>
/// <param name="parameterNames">The parameter names.</param>
/// <returns>The constructor builder.</returns>
public static ConstructorBuilder DefineConstructor(this TypeBuilder typeBuilder,
MethodAttributes methodAttributes,
CallingConventions callingConvention,
Type[] parameterTypes,
string[] parameterNames)
{
if (typeBuilder == null)
throw new ArgumentNullException("typeBuilder");
if (parameterTypes == null)
throw new ArgumentNullException("parameterTypes");
if (parameterNames == null)
throw new ArgumentNullException("parameterNames");
if (parameterTypes.Length != parameterNames.Length)
throw new ArgumentException(Resources.NumberOfParameterTypesAndNamesMustBeEqual);
// Define constructor.
var constructorBuilder = typeBuilder.DefineConstructor(
methodAttributes,
callingConvention,
parameterTypes);
// Define constructor parameters.
constructorBuilder.DefineParameters(parameterNames);
return constructorBuilder;
}
示例10: DefineConstructor
public void DefineConstructor(MethodAttributes attributes, Type[] parameterTypes, CallingConventions callingConvention)
{
TypeBuilder type = Helpers.DynamicType(TypeAttributes.Class | TypeAttributes.Public);
FieldBuilder fieldBuilderA = type.DefineField("TestField", typeof(int), FieldAttributes.Private);
FieldBuilder fieldBuilderB = type.DefineField("TestField", typeof(int), FieldAttributes.Private);
ConstructorBuilder constructor = type.DefineConstructor(attributes, callingConvention, parameterTypes);
ILGenerator ctorIlGenerator = constructor.GetILGenerator();
if (parameterTypes.Length != 0)
{
// Calling base class constructor
ctorIlGenerator.Emit(OpCodes.Ldarg_0);
ctorIlGenerator.Emit(OpCodes.Call, typeof(object).GetConstructor(new Type[0]));
ctorIlGenerator.Emit(OpCodes.Ldarg_0);
ctorIlGenerator.Emit(OpCodes.Ldarg_1);
ctorIlGenerator.Emit(OpCodes.Stfld, fieldBuilderA);
ctorIlGenerator.Emit(OpCodes.Ldarg_0);
ctorIlGenerator.Emit(OpCodes.Ldarg_2);
ctorIlGenerator.Emit(OpCodes.Stfld, fieldBuilderB);
}
ctorIlGenerator.Emit(OpCodes.Ret);
Helpers.VerifyConstructor(constructor, type, attributes, callingConvention, parameterTypes);
}
示例11: ConstructorBuilder
/// <summary>
/// Constructor
/// </summary>
/// <param name="typeBuilder">Type builder</param>
/// <param name="attributes">Attributes for the constructor (public, private, etc.)</param>
/// <param name="parameters">Parameter types for the constructor</param>
/// <param name="callingConventions">Calling convention for the constructor</param>
public ConstructorBuilder(TypeBuilder typeBuilder, MethodAttributes attributes,
IEnumerable<Type> parameters, CallingConventions callingConventions)
{
if (typeBuilder == null)
throw new ArgumentNullException("typeBuilder");
Type = typeBuilder;
Attributes = attributes;
Parameters = new List<ParameterBuilder>();
Parameters.Add(new ParameterBuilder(null, 0));
if (parameters != null)
{
int x = 1;
foreach (var parameterType in parameters)
{
Parameters.Add(new ParameterBuilder(parameterType, x));
++x;
}
}
CallingConventions = callingConventions;
Builder = Type.Builder.DefineConstructor(attributes, callingConventions,
(parameters != null && parameters.Count() > 0)
? parameters.ToArray()
: System.Type.EmptyTypes);
Generator = Builder.GetILGenerator();
}
示例12: CreateConstructor
/// <summary>
/// 타입의 생성자를 생성합니다.
/// </summary>
/// <param name="methodAttributes"> 생성자 메서드인 .ctor 의 메서드 특성입니다. </param>
/// <param name="callingConventions"> 메서드의 유효한 호출 규칙입니다. </param>
/// <param name="parameterCriteriaMetadataInfos"> 매개 변수의 표준적인 메타데이터 정보입니다. </param>
/// <returns>
/// 생성자를 생성할 때 사용하는 <see cref="ConstructorBuilder"/> 객체를 반환합니다.
/// </returns>
public ConstructorBuilder CreateConstructor(MethodAttributes methodAttributes, CallingConventions callingConventions, IEnumerable<ParameterCriteriaMetadataInfo> parameterCriteriaMetadataInfos)
{
if (isStaticMethod(methodAttributes))
{
methodAttributes = MethodAttributes.Static | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName | MethodAttributes.Private | MethodAttributes.HideBySig;
callingConventions = CallingConventions.Standard;
}
else
{
callingConventions = CallingConventions.HasThis;
}
var constructorBuilder = this.TypeBuilder.DefineConstructor(methodAttributes, callingConventions, parameterCriteriaMetadataInfos.Select( o => o.Type).ToArray());
int iSeqence = 0;
foreach (var parameter in parameterCriteriaMetadataInfos)
{
iSeqence++;
constructorBuilder.DefineParameter(iSeqence, parameter.ParameterAttribute, parameter.Name);
}
var il = constructorBuilder.GetILGenerator();
if (isStaticMethod(methodAttributes)) // 정적 생성자는 Object 개체 파생이 아니므로 Object 생성을 하지 않음
{
il.Emit(OpCodes.Nop);
}
else
{
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, this.TypeBuilder.BaseType.GetConstructors()[0]);
}
return constructorBuilder;
}
示例13: GetMethodImpl
protected sealed override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
{
Debug.Assert(name != null);
// GetMethodImpl() is a funnel for two groups of api. We can distinguish by comparing "types" to null.
if (types == null)
{
// Group #1: This group of api accept only a name and BindingFlags. The other parameters are hard-wired by the non-virtual api entrypoints.
Debug.Assert(binder == null);
Debug.Assert(callConvention == CallingConventions.Any);
Debug.Assert(modifiers == null);
return LowLevelTypeExtensions.GetMethod(this, name, bindingAttr);
}
else
{
if (!OnlySearchRelatedBitsSet(bindingAttr)) // We don't yet have proper handling for BindingFlags not related to search so throw rather return a wrong result.
throw new NotImplementedException();
// Group #2: This group of api takes a set of parameter types and an optional binder.
if (callConvention != CallingConventions.Any)
throw new NotImplementedException();
if (binder == null)
binder = Type.DefaultBinder;
MethodInfo[] candidates = LowLevelTypeExtensions.GetMethods(this, name, bindingAttr);
return (MethodInfo)binder.SelectMethod(bindingAttr, candidates, types, modifiers);
}
}
示例14: SymbolMethod
internal SymbolMethod(ModuleBuilder mod, MethodToken token, Type arrayClass, String methodName,
CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
{
// This is a kind of MethodInfo to represent methods for array type of unbaked type
// Another way to look at this class is as a glorified MethodToken wrapper. At the time of this comment
// this class is only constructed inside ModuleBuilder.GetArrayMethod and the only interesting thing
// passed into it is this MethodToken. The MethodToken was forged using a TypeSpec for an Array type and
// the name of the method on Array.
// As none of the methods on Array have CustomModifiers their is no need to pass those around in here.
m_mdMethod = token;
// The ParameterTypes are also a bit interesting in that they may be unbaked TypeBuilders.
m_returnType = returnType;
if (parameterTypes != null)
{
m_parameterTypes = new Type[parameterTypes.Length];
Array.Copy(parameterTypes, 0, m_parameterTypes, 0, parameterTypes.Length);
}
else
{
m_parameterTypes = EmptyArray<Type>.Value;
}
m_module = mod;
m_containingType = arrayClass;
m_name = methodName;
m_callingConvention = callingConvention;
m_signature = SignatureHelper.GetMethodSigHelper(
mod, callingConvention, returnType, null, null, parameterTypes, null, null);
}
示例15: FormatParameters
internal static void FormatParameters (StringBuilder sb, ParameterInfo[] p, CallingConventions callingConvention, bool serialization)
{
for (int i = 0; i < p.Length; ++i) {
if (i > 0)
sb.Append (", ");
Type t = p[i].ParameterType;
string typeName = t.FormatTypeName (serialization);
// Legacy: Why use "ByRef" for by ref parameters? What language is this?
// VB uses "ByRef" but it should precede (not follow) the parameter name.
// Why don't we just use "&"?
if (t.IsByRef && !serialization) {
sb.Append (typeName.TrimEnd (new char[] { '&' }));
sb.Append (" ByRef");
} else {
sb.Append (typeName);
}
}
if ((callingConvention & CallingConventions.VarArgs) != 0) {
if (p.Length > 0)
sb.Append (", ");
sb.Append ("...");
}
}