本文整理汇总了C#中dnlib.DotNet.TypeSig类的典型用法代码示例。如果您正苦于以下问题:C# TypeSig类的具体用法?C# TypeSig怎么用?C# TypeSig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeSig类属于dnlib.DotNet命名空间,在下文中一共展示了TypeSig类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:misharcrack,项目名称:eazdevirt,代码行数:37,代码来源:SigUtil.cs
示例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);
}
开发者ID:arkanoid1,项目名称:dnSpy,代码行数:7,代码来源:DlgUtils.cs
示例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);
}
开发者ID:n017,项目名称:ConfuserDeobfuscator,代码行数:7,代码来源:GenericArgsSubstitutor.cs
示例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
}
}
开发者ID:hmemcpy,项目名称:dnSpy,代码行数:32,代码来源:TypeAnalysis.cs
示例5: IsFnPtrSig
bool IsFnPtrSig(TypeSig sig) {
while (sig != null) {
if (sig is FnPtrSig)
return true;
sig = sig.Next;
}
return false;
}
开发者ID:GreenDamTan,项目名称:de4dot,代码行数:8,代码来源:TypeNames.cs
示例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;
}
开发者ID:TerrariaPrismTeam,项目名称:Prism,代码行数:57,代码来源:DNHelperExtensions.cs
示例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;
}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:10,代码来源:GenericArgumentResolver.cs
示例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);
}
}
}
开发者ID:2sic4you,项目名称:ConfuserEx,代码行数:10,代码来源:BAMLAnalyzer.cs
示例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;
}
开发者ID:nakijun,项目名称:dnSpy,代码行数:11,代码来源:MetaDataUtils.cs
示例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;
}
开发者ID:GreenDamTan,项目名称:dnSpy,代码行数:12,代码来源:CreateTypeSigArray.cs
示例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();
}
开发者ID:john-guo,项目名称:hodgepodge,代码行数:53,代码来源:Program.cs
示例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;
}
开发者ID:hmemcpy,项目名称:dnSpy,代码行数:16,代码来源:TypeAnalysis.cs
示例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);
}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:20,代码来源:GenericArgumentResolver.cs
示例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;
}
开发者ID:arkanoid1,项目名称:dnSpy,代码行数:14,代码来源:TypeSigCreator.cs
示例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;
}
开发者ID:GreenDamTan,项目名称:dnSpy,代码行数:46,代码来源:ModelUtils.cs
示例16: FromBaseSig
/// <summary>
/// Apply a series of modifiers ("[]", "*", "&") to a base TypeSig.
/// </summary>
/// <param name="baseSig">Base TypeSig</param>
/// <param name="modifiers">Modifier strings</param>
/// <returns>TypeSig</returns>
public static TypeSig FromBaseSig(TypeSig baseSig, Stack<String> modifiers)
{
String mod;
while (modifiers.Count > 0)
{
mod = modifiers.Pop();
switch (mod)
{
case "[]": baseSig = new SZArraySig(baseSig); break;
case "*": baseSig = new PtrSig(baseSig); break;
case "&": baseSig = new ByRefSig(baseSig); break;
default:
throw new Exception(String.Format("Unknown modifier: {0}", mod));
}
}
return baseSig;
}
开发者ID:misharcrack,项目名称:eazdevirt,代码行数:23,代码来源:SigUtil.cs
示例17: TypeSigCreatorVM
public TypeSigCreatorVM(TypeSigCreatorOptions options, TypeSig defaultTypeSig = null)
{
this.options = options.Clone();
this.defaultTypeSig = defaultTypeSig;
this.arrayRank = new UInt32VM(2, a => { });
this.arraySizes = new UInt32ListDataFieldVM(a => { }) {
Min = ModelUtils.COMPRESSED_UINT32_MIN,
Max = ModelUtils.COMPRESSED_UINT32_MAX,
};
this.arrayLowerBounds = new Int32ListDataFieldVM(a => { }) {
Min = ModelUtils.COMPRESSED_INT32_MIN,
Max = ModelUtils.COMPRESSED_INT32_MAX,
};
this.genericVariableNumber = new UInt32VM(0, a => { });
Reinitialize();
}
开发者ID:damnya,项目名称:dnSpy,代码行数:17,代码来源:TypeSigCreatorVM.cs
示例18: create
public string create(TypeSig typeRef)
{
typeRef = typeRef.RemovePinnedAndModifiers();
if (typeRef == null)
return unknownNameCreator.create();
var gis = typeRef as GenericInstSig;
if (gis != null) {
if (gis.FullName == "System.Nullable`1" &&
gis.GenericArguments.Count == 1 && gis.GenericArguments[0] != null) {
typeRef = gis.GenericArguments[0];
}
}
string prefix = getPrefix(typeRef);
var elementType = typeRef.ScopeType;
if (elementType == null && isFnPtrSig(typeRef))
return fnPtrNameCreator.create();
if (isGenericParam(elementType))
return genericParamNameCreator.create();
NameCreator nc;
var typeFullName = typeRef.FullName;
if (typeNames.TryGetValue(typeFullName, out nc))
return nc.create();
var fullName = elementType == null ? typeRef.FullName : elementType.FullName;
string shortName;
var dict = prefix == "" ? fullNameToShortName : fullNameToShortNamePrefix;
if (!dict.TryGetValue(fullName, out shortName)) {
fullName = fullName.Replace('/', '.');
int index = fullName.LastIndexOf('.');
shortName = index > 0 ? fullName.Substring(index + 1) : fullName;
index = shortName.LastIndexOf('`');
if (index > 0)
shortName = shortName.Substring(0, index);
}
return addTypeName(typeFullName, shortName, prefix).create();
}
开发者ID:GodLesZ,项目名称:ConfuserDeobfuscator,代码行数:41,代码来源:TypeNames.cs
示例19: TryRelocateTypeSig
/// <summary>
/// Relocates the <see cref="TypeSig"/>.
/// </summary>
/// <param name="typeSig">The type sig.</param>
/// <returns>A new type if it was relocated, null otherwise</returns>
/// <exception cref="InvalidOperationException">If signature is of unknown type.</exception>
public virtual TypeSig TryRelocateTypeSig(TypeSig typeSig)
{
if (typeSig == null)
return null;
if (typeSig is CorLibTypeSig)
return null;
if (typeSig is GenericInstSig)
return TryRelocateGeneric((GenericInstSig)typeSig);
if (typeSig is PtrSig)
return null;
if (typeSig is ByRefSig)
return TryRelocateByRef((ByRefSig)typeSig);
if (typeSig is ArraySig)
return TryRelocateArray((ArraySig)typeSig);
if (typeSig is SZArraySig)
return TryRelocateSZArray((SZArraySig)typeSig);
if (typeSig is GenericVar)
return null; // TODO constraints
if (typeSig is GenericMVar)
return null; // TODO constraints
if (typeSig is ValueTypeSig || typeSig is ClassSig)
{
var typeRef = typeSig.TryGetTypeRef();
if (typeRef != null)
return TryRelocateTypeRef(typeRef);
var typeDefOrRef = TryRelocateTypeDefOrRef(typeSig.ToTypeDefOrRef());
return typeDefOrRef?.ToTypeSig();
}
throw new InvalidOperationException();
}
开发者ID:picrap,项目名称:StitcherBoy,代码行数:46,代码来源:TypeRelocator.cs
示例20: OwnerModule
/// <summary>
/// Returns the owner module. The type was created from metadata in this module.
/// </summary>
/// <param name="typeSig">The <c>TypeSig</c></param>
/// <returns>A <see cref="ModuleDef"/> or <c>null</c> if none found</returns>
public static ModuleDef OwnerModule(TypeSig typeSig) {
return new FullNameCreator().GetOwnerModule(typeSig);
}
开发者ID:GodLesZ,项目名称:ConfuserDeobfuscator,代码行数:8,代码来源:FullNameCreator.cs
注:本文中的dnlib.DotNet.TypeSig类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论