本文整理汇总了C#中System.Compiler.AssemblyNode.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyNode.GetType方法的具体用法?C# AssemblyNode.GetType怎么用?C# AssemblyNode.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Compiler.AssemblyNode
的用法示例。
在下文中一共展示了AssemblyNode.GetType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTypeNodeFor
internal TypeNode GetTypeNodeFor(AssemblyNode assembly, Type t) {
if (t.IsArray) {
int rank = t.GetArrayRank();
Type et = t.GetElementType();
TypeNode type = assembly.GetType(Identifier.For(et.Namespace), Identifier.For(et.Name));
return type.GetArrayType(rank);
} else {
return assembly.GetType(Identifier.For(t.Namespace), Identifier.For(t.Name));
}
}
示例2: FindShadow
public static TypeNode FindShadow(this TypeNode typeNode, AssemblyNode shadowAssembly)
{
if (typeNode.DeclaringType != null)
{
// nested type
var parent = typeNode.DeclaringType.FindShadow(shadowAssembly);
if (parent == null) return null;
return parent.GetNestedType(typeNode.Name);
}
// namespace type
return shadowAssembly.GetType(typeNode.Namespace, typeNode.Name);
}
示例3: FindType
public static TypeNode FindType(AssemblyNode startingPoint, Identifier ns, Identifier name)
{
return startingPoint.GetType(ns, name, true);
}
示例4: GetRuntimeContractsAttributeCtor
/// <summary>
/// Tries to reuse or create the attribute
/// </summary>
private static InstanceInitializer GetRuntimeContractsAttributeCtor(AssemblyNode assembly)
{
EnumNode runtimeContractsFlags = assembly.GetType(ContractNodes.ContractNamespace, Identifier.For("RuntimeContractsFlags")) as EnumNode;
Class RuntimeContractsAttributeClass = assembly.GetType(ContractNodes.ContractNamespace, Identifier.For("RuntimeContractsAttribute")) as Class;
if (runtimeContractsFlags == null)
{
#region Add [Flags]
Member flagsConstructor = RewriteHelper.flagsAttributeNode.GetConstructor();
AttributeNode flagsAttribute = new AttributeNode(new MemberBinding(null, flagsConstructor), null, AttributeTargets.Class);
#endregion Add [Flags]
runtimeContractsFlags = new EnumNode(assembly,
null, /* declaringType */
new AttributeList(2),
TypeFlags.Sealed,
ContractNodes.ContractNamespace,
Identifier.For("RuntimeContractsFlags"),
new InterfaceList(),
new MemberList());
runtimeContractsFlags.Attributes.Add(flagsAttribute);
RewriteHelper.TryAddCompilerGeneratedAttribute(runtimeContractsFlags);
runtimeContractsFlags.UnderlyingType = SystemTypes.Int32;
Type copyFrom = typeof(RuntimeContractEmitFlags);
foreach (System.Reflection.FieldInfo fi in copyFrom.GetFields())
{
if (fi.IsLiteral)
{
AddEnumValue(runtimeContractsFlags, fi.Name, fi.GetRawConstantValue());
}
}
assembly.Types.Add(runtimeContractsFlags);
}
InstanceInitializer ctor = (RuntimeContractsAttributeClass == null) ? null : RuntimeContractsAttributeClass.GetConstructor(runtimeContractsFlags);
if (RuntimeContractsAttributeClass == null)
{
RuntimeContractsAttributeClass = new Class(assembly,
null, /* declaringType */
new AttributeList(),
TypeFlags.Sealed,
ContractNodes.ContractNamespace,
Identifier.For("RuntimeContractsAttribute"),
SystemTypes.Attribute,
new InterfaceList(),
new MemberList(0));
RewriteHelper.TryAddCompilerGeneratedAttribute(RuntimeContractsAttributeClass);
assembly.Types.Add(RuntimeContractsAttributeClass);
}
if (ctor == null) {
Block returnBlock = new Block(new StatementList(new Return()));
Block body = new Block(new StatementList());
Block b = new Block(new StatementList());
ParameterList pl = new ParameterList();
Parameter levelParameter = new Parameter(Identifier.For("contractFlags"), runtimeContractsFlags);
pl.Add(levelParameter);
ctor = new InstanceInitializer(RuntimeContractsAttributeClass, null, pl, body);
ctor.Flags = MethodFlags.Assembly | MethodFlags.HideBySig | MethodFlags.SpecialName | MethodFlags.RTSpecialName;
Method baseCtor = SystemTypes.Attribute.GetConstructor();
b.Statements.Add(new ExpressionStatement(new MethodCall(new MemberBinding(null, baseCtor), new ExpressionList(ctor.ThisParameter))));
b.Statements.Add(returnBlock);
body.Statements.Add(b);
RuntimeContractsAttributeClass.Members.Add(ctor);
}
return ctor;
}
示例5: GetPossiblyNestedType
private static TypeNode GetPossiblyNestedType(AssemblyNode assem, string namespaceName, string className)
{
Contract.Requires(assem != null);
Contract.Requires(className != null);
var ns = Identifier.For(namespaceName);
string[] pieces = className.Split('.');
// Get outermost type
string outerMost = pieces[0];
TypeNode t = assem.GetType(ns, Identifier.For(outerMost));
if (t == null) return null;
for (int i = 1; i < pieces.Length; i++)
{
var piece = pieces[i];
t = t.GetNestedType(Identifier.For(piece));
if (t == null) return null;
}
return t;
}
示例6: Initialize
internal static void Initialize(){
RuntimeAssembly = Runtime.GetRuntimeAssembly();
PostCompilationPluginAttributeType = RuntimeAssembly.GetType(Identifier.For("Microsoft.SpecSharp"), Identifier.For("PostCompilationPluginAttribute"));
ObjectConstructor = SystemTypes.Object.GetConstructor();
IListAdd = SystemTypes.IList.GetMethod(StandardIds.Add, SystemTypes.Object);
#if CCINamespace
const string ContractsNs = "Microsoft.Contracts";
#else
const string ContractsNs = "Microsoft.Contracts";
#endif
MustOverrideAttribute = (Class)GetCompilerRuntimeTypeNodeFor(ContractsNs, "MustOverrideAttribute");
}
示例7: ContractNodes
/// <summary>
/// Creates a new instance of this class that contains the CCI nodes for contract class.
/// </summary>
/// <param name="errorHandler">Delegate receiving errors. If null, errors are thrown as exceptions.</param>
///
private ContractNodes(AssemblyNode assembly, Action<System.CodeDom.Compiler.CompilerError> errorHandler)
{
if (errorHandler != null) this.ErrorFound += errorHandler;
AssemblyNode assemblyContainingContractClass = null;
// Get the contract class and all of its members
assemblyContainingContractClass = assembly;
ContractClass = assembly.GetType(ContractNamespace, Identifier.For("Contract")) as Class;
if (ContractClass == null)
{
// This is not a candidate, no warning as we try to find the right place where contracts live
return;
}
ContractHelperClass = assembly.GetType(ContractInternalNamespace, Identifier.For("ContractHelper")) as Class;
if (ContractHelperClass == null || !ContractHelperClass.IsPublic)
{
// look in alternate location
var alternateNs = Identifier.For("System.Diagnostics.Contracts.Internal");
ContractHelperClass = assembly.GetType(alternateNs, Identifier.For("ContractHelper")) as Class;
}
// Get ContractFailureKind
ContractFailureKind = assemblyContainingContractClass.GetType(ContractNamespace, Identifier.For("ContractFailureKind")) as EnumNode;
// Look for each member of the contract class
var requiresMethods = ContractClass.GetMethods(Identifier.For("Requires"), SystemTypes.Boolean);
for (int i = 0; i < requiresMethods.Count; i++)
{
var method = requiresMethods[i];
if (method.TemplateParameters != null && method.TemplateParameters.Count == 1)
{
// Requires<E>
RequiresExceptionMethod = method;
}
else if (method.TemplateParameters == null || method.TemplateParameters.Count == 0)
{
RequiresMethod = method;
}
}
// early test to see if the ContractClass we found has a Requires(bool) method. If it doesn't, we
// silently think that this is not the right place.
// We use this because contract reference assemblies have a Contract class, but it is not the right one, as it holds
// just the 3 argument versions of all the contract methods.
if (RequiresMethod == null)
{
ContractClass = null;
return;
}
var requiresMethodsWithMsg = ContractClass.GetMethods(Identifier.For("Requires"), SystemTypes.Boolean, SystemTypes.String);
for (int i = 0; i < requiresMethodsWithMsg.Count; i++)
{
var method = requiresMethodsWithMsg[i];
if (method.TemplateParameters != null && method.TemplateParameters.Count == 1)
{
// Requires<E>
RequiresExceptionWithMsgMethod = method;
}
else if (method.TemplateParameters == null || method.TemplateParameters.Count == 0)
{
RequiresWithMsgMethod = method;
}
}
EnsuresMethod = ContractClass.GetMethod(Identifier.For("Ensures"), SystemTypes.Boolean);
EnsuresWithMsgMethod = ContractClass.GetMethod(Identifier.For("Ensures"), SystemTypes.Boolean, SystemTypes.String);
EnsuresOnThrowTemplate = ContractClass.GetMethod(Identifier.For("EnsuresOnThrow"), SystemTypes.Boolean);
EnsuresOnThrowWithMsgTemplate = ContractClass.GetMethod(Identifier.For("EnsuresOnThrow"), SystemTypes.Boolean, SystemTypes.String);
InvariantMethod = ContractClass.GetMethod(Identifier.For("Invariant"), SystemTypes.Boolean);
InvariantWithMsgMethod = ContractClass.GetMethod(Identifier.For("Invariant"), SystemTypes.Boolean, SystemTypes.String);
AssertMethod = ContractClass.GetMethod(Identifier.For("Assert"), SystemTypes.Boolean);
AssertWithMsgMethod = ContractClass.GetMethod(Identifier.For("Assert"), SystemTypes.Boolean, SystemTypes.String);
AssumeMethod = ContractClass.GetMethod(Identifier.For("Assume"), SystemTypes.Boolean);
AssumeWithMsgMethod = ContractClass.GetMethod(Identifier.For("Assume"), SystemTypes.Boolean, SystemTypes.String);
ResultTemplate = ContractClass.GetMethod(ResultName);
TypeNode GenericPredicate = SystemTypes.SystemAssembly.GetType(
Identifier.For("System"),
Identifier.For("Predicate" + TargetPlatform.GenericTypeNamesMangleChar + "1"));
if (GenericPredicate != null)
{
ForAllGenericTemplate = ContractClass.GetMethod(ForallName, SystemTypes.GenericIEnumerable, GenericPredicate);
//.........这里部分代码省略.........
示例8: FuzzilyForwardReferencesFromSource2Target
private void FuzzilyForwardReferencesFromSource2Target(AssemblyNode targetAssembly, AssemblyNode sourceAssembly)
{
Contract.Requires(targetAssembly != null);
Contract.Requires(sourceAssembly != null);
for (int i = 1, n = sourceAssembly.Types.Count; i < n; i++)
{
TypeNode currentType = sourceAssembly.Types[i];
if (currentType == null) continue;
TypeNode targetType = targetAssembly.GetType(currentType.Namespace, currentType.Name);
if (targetType == null)
{
if (Duplicator.TypesToBeDuplicated[currentType.UniqueKey] == null)
{
Duplicator.FindTypesToBeDuplicated(new TypeNodeList(currentType));
}
Trace("COPYOOB: type to be duplicated {0}", currentType.FullName);
}
else
{
if (HelperMethods.IsContractTypeForSomeOtherType(currentType as Class))
{
// dummy contract target type. Ignore it.
targetType.Members = new MemberList();
targetType.ClearMemberTable();
}
Contract.Assume(TemplateParameterCount(currentType) == TemplateParameterCount(targetType),
"Name mangling should ensure this");
Duplicator.DuplicateFor[currentType.UniqueKey] = targetType;
Trace("COPYOOB: forwarding {1} to {0}", currentType.FullName, targetType.FullName);
FuzzilyForwardType(currentType, targetType);
}
}
}