TypeApplicabilityScope.cs :  » Development » devAdvantage » AnticipatingMinds » Genesis » KnowledgeManagement » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Development » devAdvantage 
devAdvantage » AnticipatingMinds » Genesis » KnowledgeManagement » TypeApplicabilityScope.cs
using System;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Windows.Forms.Design;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using AnticipatingMinds.Genesis.CodeDOM;

namespace AnticipatingMinds.Genesis.KnowledgeManagement{
  /// <summary>
  /// Summary description for TypeApplicabilityScope.
  /// </summary>
  [Serializable]
  public class TypeApplicabilityScope : ApplicabilityScope, ICloneable,ISerializable
  {
    #region Instance constructors
    public TypeApplicabilityScope():base(){}

    /// <summary>
    /// Copy constructor
    /// </summary>
    /// <param name="typeApplicabilityScope"></param>
    public TypeApplicabilityScope(TypeApplicabilityScope typeApplicabilityScope):base(typeApplicabilityScope)
    {
      DeclarationModifiers = typeApplicabilityScope.DeclarationModifiers;
      if(typeApplicabilityScope.TypeName != null)
        TypeName = new Regex(typeApplicabilityScope.TypeName.ToString());
      else
        TypeName = null;

      foreach(string attributeName in typeApplicabilityScope.Attributes)
        attributes.Add(attributeName);
    }
    #endregion Instance constructors
    #region ISerializable Implementation
    protected TypeApplicabilityScope(SerializationInfo info, StreamingContext context) : base(info,context)
    {
      DeclarationModifiers = (CodeTypeDeclaration.TypeDeclarationModifiers) info.GetInt32("DeclarationModifiers");
      string typeNamePattern = info.GetString("TypeName");
      if(typeNamePattern != string.Empty)
                TypeName = new Regex(typeNamePattern);
      else
        TypeName = null;

      attributes = info.GetValue("Attributes",typeof(StringCollection)) as StringCollection;
    }
    
    public override void GetObjectData(
      SerializationInfo info, StreamingContext context) 
    {
      base.GetObjectData(info,context);
      info.AddValue("DeclarationModifiers",(Int32)DeclarationModifiers);
      
      if(TypeName != null)
        info.AddValue("TypeName",TypeName.ToString());
      else
        info.AddValue("TypeName",String.Empty);
      
      info.AddValue("Attributes",Attributes,typeof(StringCollection));
    }
    #endregion
    #region Public instance properties
    [Category("Behavior")]
    [DefaultValue(0)]
    [TypeConverter(typeof(EnumConverter))]
    [Description("The declaring modifiers such as new, abstract, sealed as well as visibility modifies such as public, private, etc.")]
    public virtual CodeTypeDeclaration.TypeDeclarationModifiers DeclarationModifiers
    {
      get
      {
        return declarationModifiers;
      }
      set
      {
        declarationModifiers = value;
      }
    }
    [Category("Behavior")]
    [DefaultValue(null)]
    [TypeConverter(typeof(RegExpTypeConverter))]
    [Description("Regular expression used to define the criteria for the class name to be used in scope definition.")]
    public virtual Regex TypeName
    {
      get
      {
        return typeName;
      }
      set
      {
        typeName = value;
      }
    }


    [Category("Behavior")]
    [System.ComponentModel.Editor(typeof(StringCollectionEditor),typeof(System.Drawing.Design.UITypeEditor))]
    [TypeConverter(typeof(StringCollectionTypeConverter))]
    [DefaultValue("(any)")]
    [Description("A list of zero or more C# Attributes associated with the type or member declaration. Value must be fully qualified, such as 'System.SerializableAttribute'")]
    public virtual StringCollection Attributes
    {
      get
      {
        return attributes;
      }
    }

    public override string Title
    {
      get
      {
        return "Type declaration";
      }
    }

    #endregion Public instance properties
    #region Public instance methods
    /// <summary>
    /// This function will check only name pattern for CodeTypeReference
    /// </summary>
    /// <param name="codeElement"></param>
    /// <returns></returns>
    protected override bool DoesElementMatchScopeConditions(CodeElement codeElement)
    {
      if(!(codeElement is CodeTypeDeclaration))
        return false;

      CodeTypeDeclaration typeDeclaration = codeElement as CodeTypeDeclaration;
      
      ///Verify declaration modifiers (if any)
      ///All the modifiers specified must be present in the target 
      ///declaration
      if(((Int32)DeclarationModifiers) != 0)
      {
        CodeTypeDeclaration.TypeDeclarationModifiers typeModifiers = typeDeclaration.Modifiers;
        
        //If no explicit visibility is set - set private or internal
        if((typeModifiers & CodeTypeDeclaration.TypeDeclarationModifiers.Public ) == 0 &&
          (typeModifiers & CodeTypeDeclaration.TypeDeclarationModifiers.Private ) == 0 && 
          (typeModifiers & CodeTypeDeclaration.TypeDeclarationModifiers.Assembly ) == 0 && 
          (typeModifiers & CodeTypeDeclaration.TypeDeclarationModifiers.Family ) == 0 && 
          (typeModifiers & CodeTypeDeclaration.TypeDeclarationModifiers.FamilyAndAssembly ) == 0 && 
          (typeModifiers & CodeTypeDeclaration.TypeDeclarationModifiers.FamilyOrAssembly ) == 0)
        {
          //Set private for nested classes
          //set internal for all othar classes
          if(typeDeclaration.DeclaringType != null)
            typeModifiers |= CodeTypeDeclaration.TypeDeclarationModifiers.Private;
          else
            typeModifiers |= CodeTypeDeclaration.TypeDeclarationModifiers.Assembly;
        }


        if((DeclarationModifiers & typeModifiers) == 0)
          return false;
      }
      
      //Check type name if needed.
      if(TypeName != null)
        if(!TypeName.Match(typeDeclaration.FullName).Success)
          return false;

      //Check attributes if any!
      if(Attributes != null && Attributes.Count != 0)
      {
        //Check if type has any. If not - not match
        if(typeDeclaration.Attributes.Count == 0)
          return false;

        StringCollection typeAttributes = new StringCollection();
        foreach(CodeAttribute declaredAttribute in typeDeclaration.Attributes)
          if(declaredAttribute.AttributeType.TypeInfo != null)
            typeAttributes.Add(declaredAttribute.AttributeType.TypeInfo.FullName);
          else
            typeAttributes.Add(declaredAttribute.AttributeType.TypeName);

        //We require all of the specified attributes present in target declaration.
        foreach(string requestedAttribute in Attributes)
        {
          if(!typeAttributes.Contains(requestedAttribute))
            return false;
        }
      }

      //If all the conditions work fine and we just fell 
      //through - then element matches scope conditions
      return true;
    }
    public virtual object Clone()
    {
      return new TypeApplicabilityScope(this);
    }
    #endregion Public instance methods
    #region Private instance fields
    private StringCollection attributes = new StringCollection();
    private CodeTypeDeclaration.TypeDeclarationModifiers declarationModifiers;
    private Regex typeName = null;
    #endregion Private instance fields
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.