当前位置: 首页>>代码示例>>C#>>正文


C# DotNet.TypeSig类代码示例

本文整理汇总了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;
		}
开发者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


注:本文中的dnlib.DotNet.TypeSig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。