本文整理汇总了C#中TypeReference类的典型用法代码示例。如果您正苦于以下问题:C# TypeReference类的具体用法?C# TypeReference怎么用?C# TypeReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeReference类属于命名空间,在下文中一共展示了TypeReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDefaultValueForType
public static Expression CreateDefaultValueForType(TypeReference type)
{
if (type != null && !type.IsArrayType) {
switch (type.Type) {
case "System.SByte":
case "System.Byte":
case "System.Int16":
case "System.UInt16":
case "System.Int32":
case "System.UInt32":
case "System.Int64":
case "System.UInt64":
case "System.Single":
case "System.Double":
return new PrimitiveExpression(0, "0");
case "System.Char":
return new PrimitiveExpression('\0', "'\\0'");
case "System.Object":
case "System.String":
return new PrimitiveExpression(null, "null");
case "System.Boolean":
return new PrimitiveExpression(false, "false");
default:
return new DefaultValueExpression(type);
}
} else {
return new PrimitiveExpression(null, "null");
}
}
示例2: CloneMethodWithDeclaringType
private static MethodReference CloneMethodWithDeclaringType(MethodDefinition methodDef, TypeReference declaringTypeRef)
{
if (!declaringTypeRef.IsGenericInstance || methodDef == null)
{
return methodDef;
}
var methodRef = new MethodReference(methodDef.Name, methodDef.ReturnType, declaringTypeRef)
{
CallingConvention = methodDef.CallingConvention,
HasThis = methodDef.HasThis,
ExplicitThis = methodDef.ExplicitThis
};
foreach (var paramDef in methodDef.Parameters)
{
methodRef.Parameters.Add(new ParameterDefinition(paramDef.Name, paramDef.Attributes, paramDef.ParameterType));
}
foreach (var genParamDef in methodDef.GenericParameters)
{
methodRef.GenericParameters.Add(new GenericParameter(genParamDef.Name, methodRef));
}
return methodRef;
}
示例3: FieldDefinition
public FieldDefinition(ClassDefinition owner, string name, TypeReference fieldType)
: this()
{
Owner = owner;
Name = name;
Type = fieldType;
}
示例4: FindCoreReferences
public void FindCoreReferences()
{
var coreTypes = new List<TypeDefinition>();
AppendTypes("mscorlib", coreTypes);
AppendTypes("System.IO", coreTypes);
AppendTypes("System.Runtime", coreTypes);
AppendTypes("System.Reflection", coreTypes);
var textReaderTypeDefinition = coreTypes.First(x => x.Name == "TextReader");
ReadToEndMethod = ModuleDefinition.ImportReference(textReaderTypeDefinition.Find("ReadToEnd"));
var exceptionTypeDefinition = coreTypes.First(x => x.Name == "Exception");
ExceptionConstructorReference = ModuleDefinition.ImportReference(exceptionTypeDefinition.Find(".ctor", "String"));
var stringTypeDefinition = coreTypes.First(x => x.Name == "String");
ConcatReference = ModuleDefinition.ImportReference(stringTypeDefinition.Find("Concat", "String", "String", "String"));
DisposeTextReaderMethod = ModuleDefinition.ImportReference(textReaderTypeDefinition.Find("Dispose"));
var streamTypeDefinition = coreTypes.First(x => x.Name == "Stream");
DisposeStreamMethod = ModuleDefinition.ImportReference(streamTypeDefinition.Find("Dispose"));
StreamTypeReference = ModuleDefinition.ImportReference(streamTypeDefinition);
var streamReaderTypeDefinition = coreTypes.First(x => x.Name == "StreamReader");
StreamReaderTypeReference = ModuleDefinition.ImportReference(streamReaderTypeDefinition);
StreamReaderConstructorReference = ModuleDefinition.ImportReference(streamReaderTypeDefinition.Find(".ctor", "Stream"));
var assemblyTypeDefinition = coreTypes.First(x => x.Name == "Assembly");
AssemblyTypeReference = ModuleDefinition.ImportReference(assemblyTypeDefinition);
GetExecutingAssemblyMethod = ModuleDefinition.ImportReference(assemblyTypeDefinition.Find("GetExecutingAssembly"));
GetManifestResourceStreamMethod = ModuleDefinition.ImportReference(assemblyTypeDefinition.Find("GetManifestResourceStream", "String"));
}
示例5: FindWinRTMsCoreReferences
public void FindWinRTMsCoreReferences()
{
var systemRuntime = assemblyResolver.Resolve("System.Runtime");
var systemRuntimeTypes = systemRuntime.MainModule.Types;
var voidDefinition = systemRuntimeTypes.First(x => x.Name == "Void");
VoidTypeReference = Module.Import(voidDefinition);
}
示例6: FindMsCoreReferences
void FindMsCoreReferences()
{
var msCoreLibDefinition = AssemblyResolver.Resolve("mscorlib");
msCoreTypes = msCoreLibDefinition.MainModule.Types.ToList();
var objectDefinition = msCoreTypes.FirstOrDefault(x => x.Name == "Object");
if (objectDefinition == null)
{
throw new WeavingException("Only compat with desktop .net");
}
var voidDefinition = msCoreTypes.First(x => x.Name == "Void");
voidTypeReference = ModuleDefinition.ImportReference(voidDefinition);
var dictionary = msCoreTypes.First(x => x.Name == "Dictionary`2");
var dictionaryOfStringOfString = ModuleDefinition.ImportReference(dictionary);
dictionaryOfStringOfStringAdd = ModuleDefinition.ImportReference(dictionaryOfStringOfString.Resolve().Methods.First(m => m.Name == "Add"))
.MakeHostInstanceGeneric(ModuleDefinition.TypeSystem.String, ModuleDefinition.TypeSystem.String);
var list = msCoreTypes.First(x => x.Name == "List`1");
var listOfString = ModuleDefinition.ImportReference(list);
listOfStringAdd = ModuleDefinition.ImportReference(listOfString.Resolve().Methods.First(m => m.Name == "Add"))
.MakeHostInstanceGeneric(ModuleDefinition.TypeSystem.String);
var compilerGeneratedAttribute = msCoreTypes.First(x => x.Name == "CompilerGeneratedAttribute");
compilerGeneratedAttributeCtor = ModuleDefinition.ImportReference(compilerGeneratedAttribute.Methods.First(x => x.IsConstructor));
}
示例7: AddAppliesToType
internal void AddAppliesToType(string typeName)
{
TypeReference tr = new TypeReference();
tr.name = typeName;
this.referenceList.Add(tr);
}
示例8: IsType
/// <summary>
/// Determines whether a type given by its full name corresponds to a type reference.
/// </summary>
public static bool IsType(TypeReference type, string typeName)
{
if (type.SystemType == typeName) return true;
int index = typeName.LastIndexOf('.');
return (index > 0 && type.SystemType == typeName.Substring(index + 1));
}
示例9: Fill
internal static void Fill(string tdString, TypeReference item)
{
if (!string.IsNullOrEmpty(tdString))
{
char prefix = tdString[0];
var td = (TypeDescriptors) prefix;
switch (td)
{
case TypeDescriptors.Array:
var atype = (ArrayType) item;
TypeReference elementType = Allocate(tdString.Substring(1));
Fill(tdString.Substring(1), elementType);
/* All types are already allocated
* We want to reuse object reference if already in type repository
* BUT if not, we don't want to add a new reference to this type:
* it's a 'transient' type only used in the Dexer object model but
* not persisted in dex file.
*/
atype.ElementType = elementType; //context.Import(elementType, false);
break;
case TypeDescriptors.FullyQualifiedName:
var cref = (ClassReference) item;
cref.Fullname = tdString.Substring(1, tdString.Length - 2);
break;
}
}
}
示例10: GetName
public static string GetName(TypeReference type)
{
if (type.IsNested)
return GetName (type.DeclaringType) + "+" + type.Name;
return type.Name;
}
示例11: CheckTypeReferenceForProperWinRTHome
public void CheckTypeReferenceForProperWinRTHome(TypeReference typeReference, string module)
{
ScopeReference scope = GetScopeReferenceOfType(typeReference);
Assert.Equal(module, scope.Name.Value);
int windowsRuntimeFlag = ((int)System.Reflection.AssemblyContentType.WindowsRuntime << 9);
Assert.True((((int)scope.Flags) & windowsRuntimeFlag) == windowsRuntimeFlag);
}
示例12: Execute
public void Execute()
{
var msCoreLibDefinition = assemblyResolver.Resolve("mscorlib");
var msCoreTypes = msCoreLibDefinition.MainModule.Types;
var objectDefinition = msCoreTypes.FirstOrDefault(x => x.Name == "Object");
if (objectDefinition == null)
{
ExecuteWinRT();
return;
}
var module = moduleWeaver.ModuleDefinition;
var methodBaseDefinition = msCoreTypes.First(x => x.Name == "MethodBase");
GetMethodFromHandle = module.ImportReference(methodBaseDefinition.Methods.First(x => x.Name == "GetMethodFromHandle"));
var methodInfo = msCoreTypes.FirstOrDefault(x => x.Name == "MethodInfo");
MethodInfoTypeReference = module.ImportReference(methodInfo);
var compilerGeneratedDefinition = msCoreTypes.First(x => x.Name == "CompilerGeneratedAttribute");
CompilerGeneratedReference = module.ImportReference(compilerGeneratedDefinition.Methods.First(x => x.IsConstructor));
var systemCoreDefinition = GetSystemCoreDefinition();
var expressionTypeDefinition = systemCoreDefinition.MainModule.Types.First(x => x.Name == "Expression");
var propertyMethodDefinition =
expressionTypeDefinition.Methods.First(
x => x.Name == "Property" && x.Parameters.Last().ParameterType.Name == "MethodInfo");
PropertyReference = module.ImportReference(propertyMethodDefinition);
}
示例13: VariableStartEntry
/// <summary>
/// Default ctor
/// </summary>
public VariableStartEntry(int offset, Register register, IVariable variable, TypeReference type) : base(offset)
{
this.register = register;
Variable = variable;
name = variable.OriginalName;
this.type = type;
}
示例14: PointerTypeReference
//=====================================================================
/// <summary>
/// Constructor
/// </summary>
/// <param name="pointedToType">The pointed to type</param>
public PointerTypeReference(TypeReference pointedToType)
{
if(pointedToType == null)
throw new ArgumentNullException("pointedToType");
this.PointedToType = pointedToType;
}
示例15: ReadObject
private TypeReference ReadObject(JsonReader reader)
{
reader.Read();
if (reader.TokenType != JsonToken.PropertyName || ((string)reader.Value != "__ref__" && (string)reader.Value != "type"))
{
throw new ArgumentException("Unexpected token type " + reader.TokenType);
}
var isRef = (string) reader.Value == "__ref__";
reader.Read();
if (reader.TokenType != JsonToken.String)
{
throw new ArgumentException("Unexpected token type " + reader.TokenType);
}
var retval = new TypeReference
{
IsReference = isRef,
Name = (string)reader.Value
};
reader.Read();
return retval;
}