本文整理汇总了C#中dnlib.DotNet.TypeSig类的典型用法代码示例。如果您正苦于以下问题:C# TypeSig类的具体用法?C# TypeSig怎么用?C# TypeSig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeSig类属于dnlib.DotNet命名空间,在下文中一共展示了TypeSig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToBaseSig
/// <summary>
/// Get the base TypeSig.
/// </summary>
/// <param name="typeSig">TypeSig</param>
/// <param name="modifiers">Modifiers to set</param>
/// <returns>Base TypeSig</returns>
public static TypeSig ToBaseSig(TypeSig typeSig, out Stack<String> modifiers)
{
modifiers = new Stack<String>();
// While a non-leaf sig
while (typeSig.Next != null)
{
if (typeSig.IsSZArray)
{
modifiers.Push("[]");
typeSig = typeSig.Next;
}
else if (typeSig.IsPointer)
{
modifiers.Push("*");
typeSig = typeSig.Next;
}
else if (typeSig.IsByRef)
{
modifiers.Push("&");
typeSig = typeSig.Next;
}
//else if (typeSig.IsArray)
//{
//}
else
return null;
}
return typeSig;
}
示例2: ValueToString
public static string ValueToString(object value, TypeSig storageType) {
var t = storageType.RemovePinnedAndModifiers();
bool addCast = t.GetElementType() == ElementType.Object;
if (t is SZArraySig)
addCast = t.Next.RemovePinnedAndModifiers().GetElementType() == ElementType.Object;
return ValueToString(value, addCast);
}
示例3: create
public static TypeSig create(TypeSig type, IList<TypeSig> genericArgs, IList<TypeSig> genericMethodArgs)
{
if (type == null || ((genericArgs == null || genericArgs.Count == 0) &&
(genericMethodArgs == null || genericMethodArgs.Count == 0)))
return type;
return new GenericArgsSubstitutor(genericArgs, genericMethodArgs).create(type);
}
示例4: GetInformationAmount
public static int GetInformationAmount(TypeSig type)
{
type = GetEnumUnderlyingType(type) ?? type;
if (type == null)
return 0;
switch (type.ElementType) {
case ElementType.Void:
return 0;
case ElementType.Boolean:
return 1;
case ElementType.I1:
case ElementType.U1:
return 8;
case ElementType.Char:
case ElementType.I2:
case ElementType.U2:
return 16;
case ElementType.I4:
case ElementType.U4:
case ElementType.R4:
return 32;
case ElementType.I8:
case ElementType.U8:
case ElementType.R8:
return 64;
case ElementType.I:
case ElementType.U:
return NativeInt;
default:
return 100; // we consider structs/objects to have more information than any primitives
}
}
示例5: IsFnPtrSig
bool IsFnPtrSig(TypeSig sig) {
while (sig != null) {
if (sig is FnPtrSig)
return true;
sig = sig.Next;
}
return false;
}
示例6: CreateDelegate
public static TypeDef CreateDelegate(this DNContext context, string @namespace, string name, TypeSig returnType, out MethodDef invoke, params TypeSig[] parameters)
{
var cResolver = context.Resolver;
var typeSys = context.PrimaryAssembly.ManifestModule.CorLibTypes;
var delegateType = new TypeDefUser(@namespace, name, cResolver.ReferenceOf(typeof(MulticastDelegate)));
delegateType.Attributes = TypeAttributes.Public | TypeAttributes.AutoClass | TypeAttributes.Sealed;
var ctor = new MethodDefUser(".ctor", MethodSig.CreateInstance(typeSys.Void, typeSys.Object, typeSys.IntPtr),
MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName);
ctor.ImplAttributes |= MethodImplAttributes.Runtime;
// param 0 is 'this'
ctor.Parameters[1].CreateParamDef();
ctor.Parameters[1].ParamDef.Name = "object";
ctor.Parameters[2].CreateParamDef();
ctor.Parameters[2].ParamDef.Name = "method";
delegateType.Methods.Add(ctor);
invoke = new MethodDefUser("Invoke", MethodSig.CreateInstance(returnType, parameters), MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual);
invoke.ImplAttributes |= MethodImplAttributes.Runtime;
for (int i = 1; i <= parameters.Length; i++)
{
invoke.Parameters[i].CreateParamDef();
invoke.Parameters[i].ParamDef.Name = "arg" + (i - 1);
}
delegateType.Methods.Add(invoke);
var beginInvoke = new MethodDefUser("BeginInvoke", MethodSig.CreateInstance(cResolver.ReferenceOf(typeof(IAsyncResult)).ToTypeSig(),
parameters.Concat(new[] { cResolver.ReferenceOf(typeof(AsyncCallback)).ToTypeSig(), typeSys.Object }).ToArray()),
MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual);
beginInvoke.ImplAttributes |= MethodImplAttributes.Runtime;
for (int i = 0; i < parameters.Length; i++)
{
beginInvoke.Parameters[i + 1].CreateParamDef();
beginInvoke.Parameters[i + 1].ParamDef.Name = "arg" + i;
}
beginInvoke.Parameters[beginInvoke.Parameters.Count - 2].CreateParamDef();
beginInvoke.Parameters[beginInvoke.Parameters.Count - 2].ParamDef.Name = "callback";
beginInvoke.Parameters[beginInvoke.Parameters.Count - 1].CreateParamDef();
beginInvoke.Parameters[beginInvoke.Parameters.Count - 1].ParamDef.Name = "object" ;
delegateType.Methods.Add(beginInvoke);
var endInvoke = new MethodDefUser("EndInvoke", MethodSig.CreateInstance(typeSys.Void, cResolver.ReferenceOf(typeof(IAsyncResult)).ToTypeSig()),
MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual);
endInvoke.ImplAttributes |= MethodImplAttributes.Runtime;
endInvoke.Parameters[1].CreateParamDef();
endInvoke.Parameters[1].ParamDef.Name = "result";
delegateType.Methods.Add(endInvoke);
context.PrimaryAssembly.ManifestModule.Types.Add(delegateType);
return delegateType;
}
示例7: ReplaceGenericArg
bool ReplaceGenericArg(ref TypeSig typeSig) {
if (genericArguments == null)
return false;
TypeSig newTypeSig = genericArguments.Resolve(typeSig);
if (newTypeSig != typeSig) {
typeSig = newTypeSig;
return true;
}
return false;
}
示例8: AddTypeSigReference
private void AddTypeSigReference(TypeSig typeSig, INameReference<IDnlibDef> reference)
{
foreach (ITypeDefOrRef type in typeSig.FindTypeRefs()) {
TypeDef typeDef = type.ResolveTypeDefThrow();
if (context.Modules.Contains((ModuleDefMD)typeDef.Module)) {
service.ReduceRenameMode(typeDef, RenameMode.Letters);
service.AddReference(typeDef, reference);
}
}
}
示例9: CorFieldInfo
public CorFieldInfo(CorType ownerType, uint token, string name, TypeSig fieldType, FieldAttributes attrs, object constant, CorElementType constantType, DebuggerBrowsableState? debuggerBrowsableState, bool compilerGeneratedAttribute) {
this.OwnerType = ownerType;
this.Token = token;
this.Name = name;
this.FieldType = fieldType;
this.Attributes = attrs;
this.Constant = constant;
this.ConstantType = constantType;
this.DebuggerBrowsableState = debuggerBrowsableState;
this.CompilerGeneratedAttribute = compilerGeneratedAttribute;
}
示例10: Create
public TypeSig[] Create(TypeSigCreatorOptions options, int? count, TypeSig[] typeSigs) {
var data = new CreateTypeSigArrayVM(options, count);
if (typeSigs != null)
data.TypeSigCollection.AddRange(typeSigs);
var win = new CreateTypeSigArrayDlg();
win.DataContext = data;
win.Owner = ownerWindow ?? Application.Current.MainWindow;
if (win.ShowDialog() != true)
return null;
return data.TypeSigArray;
}
示例11: ReferenceType
private static TypeSig ReferenceType(TypeSig type, ModuleDef module)
{
if (type == null)
return null;
if (type.IsSZArray)
{
var szar = type.ToSZArraySig();
var eleType = ReferenceType(szar.Next, module);
if (eleType == null)
return null;
return new SZArraySig(eleType);
}
if (type.IsArray)
{
var ar = type.ToArraySig();
var eleType = ReferenceType(ar.Next, module);
if (eleType == null)
return null;
return new ArraySig(eleType, ar.Rank, ar.Sizes, ar.LowerBounds);
}
if (type.IsGenericInstanceType)
{
var g = type.ToGenericInstSig();
var gtype = FindType(g.GenericType.FullName, module);
ClassOrValueTypeSig ngt;
if (gtype == null)
ngt = g.GenericType;
else
ngt = gtype.TryGetClassOrValueTypeSig();
TypeSig[] genericArgs = new TypeSig[g.GenericArguments.Count];
for (int i = 0; i < g.GenericArguments.Count; ++i)
{
var subArg = ReferenceType(g.GenericArguments[i], module);
if (subArg != null)
genericArgs[i] = subArg;
else
genericArgs[i] = g.GenericArguments[i];
}
return new GenericInstSig(ngt, genericArgs);
}
var targetType = FindType(type.FullName, module);
if (targetType == null)
return null;
return targetType.ToTypeSig();
}
示例12: GetEnumUnderlyingType
/// <summary>
/// Gets the underlying type, if the specified type is an enum.
/// Otherwise, returns null.
/// </summary>
public static TypeSig GetEnumUnderlyingType(TypeSig enumType)
{
// unfortunately we cannot rely on enumType.IsValueType here - it's not set when the instruction operand is a typeref (as opposed to a typespec)
if (enumType != null && !IsArrayPointerOrReference(enumType)) {
// value type might be an enum
TypeDef typeDef = enumType.Resolve();
if (typeDef != null && typeDef.IsEnum) {
return typeDef.GetEnumUnderlyingType().RemovePinnedAndModifiers();
}
}
return null;
}
示例13: Resolve
/// <summary>
/// Resolves the type signature with the specified generic arguments.
/// </summary>
/// <param name="typeSig">The type signature.</param>
/// <param name="typeGenArgs">The type generic arguments.</param>
/// <returns>Resolved type signature.</returns>
/// <exception cref="System.ArgumentException">No generic arguments to resolve.</exception>
public static TypeSig Resolve(TypeSig typeSig, IList<TypeSig> typeGenArgs) {
if (typeGenArgs == null)
throw new ArgumentException("No generic arguments to resolve.");
var resolver = new GenericArgumentResolver();
resolver.genericArguments = new GenericArguments();
resolver.recursionCounter = new RecursionCounter();
if (typeGenArgs != null)
resolver.genericArguments.PushTypeArgs(typeGenArgs);
return resolver.ResolveGenericArgs(typeSig);
}
示例14: Create
public TypeSig Create(TypeSigCreatorOptions options, TypeSig typeSig, out bool canceled) {
var data = new TypeSigCreatorVM(options, typeSig);
data.TypeSig = typeSig;
var win = new TypeSigCreatorDlg();
win.DataContext = data;
win.Owner = ownerWindow ?? MainWindow.Instance;
if (win.ShowDialog() != true) {
canceled = true;
return null;
}
canceled = false;
return data.TypeSig;
}
示例15: GetDefaultValue
public static object GetDefaultValue(TypeSig type, bool classValueTypeIsEnum = false) {
var t = type.RemovePinnedAndModifiers();
switch (t.GetElementType()) {
case ElementType.Boolean:return false;
case ElementType.Char: return (char)0;
case ElementType.I1: return (sbyte)0;
case ElementType.U1: return (byte)0;
case ElementType.I2: return (short)0;
case ElementType.U2: return (ushort)0;
case ElementType.I4: return (int)0;
case ElementType.U4: return (uint)0;
case ElementType.I8: return (long)0;
case ElementType.U8: return (ulong)0;
case ElementType.R4: return (float)0;
case ElementType.R8: return (double)0;
case ElementType.Class:
case ElementType.ValueType:
var tdr = ((ClassOrValueTypeSig)t).TypeDefOrRef;
if (tdr.IsSystemType())
break;
var td = tdr.ResolveTypeDef();
if (td == null) {
if (classValueTypeIsEnum)
return (int)0;
break;
}
if (!td.IsEnum)
break;
switch (td.GetEnumUnderlyingType().RemovePinnedAndModifiers().GetElementType()) {
case ElementType.Boolean:return false;
case ElementType.Char: return (char)0;
case ElementType.I1: return (sbyte)0;
case ElementType.U1: return (byte)0;
case ElementType.I2: return (short)0;
case ElementType.U2: return (ushort)0;
case ElementType.I4: return (int)0;
case ElementType.U4: return (uint)0;
case ElementType.I8: return (long)0;
case ElementType.U8: return (ulong)0;
case ElementType.R4: return (float)0;
case ElementType.R8: return (double)0;
}
break;
}
return null;
}