Mono.Cecil.Fluent.SystemTypeOrTypeReference.GetTypeReference C# (CSharp) Method

GetTypeReference() private method

private GetTypeReference ( ModuleDefinition module ) : TypeReference
module ModuleDefinition
return TypeReference
        internal TypeReference GetTypeReference(ModuleDefinition module)
        {
            var ret = _type as Type;
            return ret != null 
                ? module.SafeImport(ret) 
                : module.SafeImport(_type as TypeReference);
        }

Usage Example

コード例 #1
0
        public FluentEmitter NewObj(SystemTypeOrTypeReference type, params SystemTypeOrTypeReference[] paramtypes)
        {
            // todo: generic and base constructors don't work currently

            // todo: newobj for primitives should emit initobj and not throw any exception
            if (type.GetTypeReference(Module).IsPrimitive)
            {
                throw new Exception("primitive value types like int, bool, long .. don't have a constructor. newobj instruction not possible");
            }

            var constructors = type.GetTypeReference(Module).Resolve().GetConstructors()
                               .Where(c => AreParameterListsEqual(c.Parameters.Select(p => p.ParameterType), paramtypes.Select(p => p.GetTypeReference(Module)))).ToList();

            if (constructors.Count() != 1)
            {
                throw new Exception("Can not find constructor"); // todo: better exception info, ncrunch: no coverage
            }
            return(Emit(OpCodes.Newobj, constructors.First()));
        }
All Usage Examples Of Mono.Cecil.Fluent.SystemTypeOrTypeReference::GetTypeReference