當前位置: 首頁>>代碼示例>>C#>>正文


C# AssemblyNode.GetType方法代碼示例

本文整理匯總了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));
   }    
 }
開發者ID:hesam,項目名稱:SketchSharp,代碼行數:10,代碼來源:Serializer.cs

示例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);
 }
開發者ID:asvishnyakov,項目名稱:CodeContracts,代碼行數:15,代碼來源:ExtractorExtensions.cs

示例3: FindType

 public static TypeNode FindType(AssemblyNode startingPoint, Identifier ns, Identifier name)
 {
     return startingPoint.GetType(ns, name, true);
 }
開發者ID:Yatajga,項目名稱:CodeContracts,代碼行數:4,代碼來源:HelperMethods.cs

示例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;
    }
開發者ID:nbulp,項目名稱:CodeContracts,代碼行數:80,代碼來源:Rewriter.cs

示例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;
        }
開發者ID:asvishnyakov,項目名稱:CodeContracts,代碼行數:25,代碼來源:Program.cs

示例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");
    
    }
開發者ID:hesam,項目名稱:SketchSharp,代碼行數:16,代碼來源:Runtime.cs

示例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);
//.........這裏部分代碼省略.........
開發者ID:a780201,項目名稱:CodeContracts,代碼行數:101,代碼來源:ContractNodes.cs

示例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);
                }
            }
        }
開發者ID:asvishnyakov,項目名稱:CodeContracts,代碼行數:40,代碼來源:CopyOutOfBandContracts.cs


注:本文中的System.Compiler.AssemblyNode.GetType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。