Beispiel #1
0
        private void ImportMemberDetails(MemberSymbol memberSymbol, MethodDefinition methodDefinition, ICustomAttributeProvider attributeProvider)
        {
            if (methodDefinition != null)
            {
                MemberVisibility visibility = MemberVisibility.PrivateInstance;
                if (methodDefinition.IsStatic)
                {
                    visibility |= MemberVisibility.Static;
                }
                if (methodDefinition.IsPublic)
                {
                    visibility |= MemberVisibility.Public;
                }
                else if (methodDefinition.IsFamily || methodDefinition.IsFamilyOrAssembly)
                {
                    visibility |= MemberVisibility.Protected;
                }

                memberSymbol.SetVisibility(visibility);
            }

            memberSymbol.SetNameCasing(MetadataHelpers.ShouldPreserveCase(attributeProvider));

            string scriptName = MetadataHelpers.GetScriptName(attributeProvider);

            if (scriptName != null)
            {
                memberSymbol.SetTransformedName(scriptName);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates a MethodSpecifier.
        /// </summary>
        /// <param name="name">Name of the method without any prefixes.</param>
        /// <param name="arguments">Specifiers for the arguments of the method.</param>
        /// <param name="returnTypes">Specifiers for the return types of the method.</param>
        /// <param name="modifiers">Modifiers of the method.</param>
        /// <param name="declaringType">Specifier for the type this method is contained in.</param>
        /// <param name="genericArguments">Generic arguments this method takes.</param>
        public MethodSpecifier
        (
            string name,
            IEnumerable <MethodParameter> arguments,
            IEnumerable <BaseType> returnTypes,
            MethodModifiers modifiers,
            MemberVisibility visibility,
            TypeSpecifier declaringType,
            IEnumerable <BaseType> genericArguments
        )
        {
            this.Name             = name;
            this.DeclaringType    = declaringType;
            this.Parameters       = arguments.ToList();
            this.ReturnTypes      = returnTypes.ToList();
            this.Modifiers        = modifiers;
            this.Visibility       = visibility;
            this.GenericArguments = genericArguments.ToList();

            this.HashCodeCache = HashCode.Combine
                                 (
                this.Name,
                this.Modifiers,
                string.Join(",", this.GenericArguments),
                string.Join(",", this.ReturnTypes),
                string.Join(",", this.Parameters),
                this.Visibility,
                this.DeclaringType
                                 );
        }
Beispiel #3
0

        
Beispiel #4
0

        
Beispiel #5
0
        /// <summary>
        /// Adds the given mixin to the given target type with a number of explicit dependencies and suppressed mixins. This is a shortcut
        /// method for calling <see cref="ForClass"/>, <see cref="ClassContextBuilder.AddMixin(System.Type,Remotion.Mixins.Context.MixinContextOrigin)"/>,
        /// <see cref="MixinContextBuilder.WithDependencies"/>, and <see cref="MixinContextBuilder.ReplaceMixins"/> in a row.
        /// </summary>
        /// <param name="mixinKind">The kind of relationship the mixin has with its target class.</param>
        /// <param name="targetType">The target type to add a mixin for.</param>
        /// <param name="mixinType">The mixin type to add.</param>
        /// <param name="introducedMemberVisibility">The default visibility to be used for introduced members.</param>
        /// <param name="explicitDependencies">The explicit dependencies of the mixin in the context of the target type.</param>
        /// <param name="suppressedMixins">The mixins suppressed by this mixin in the context of the target type.</param>
        /// <param name="origin">A <see cref="MixinContextOrigin"/> object describing where the mixin configuration originates from.</param>
        public virtual MixinConfigurationBuilder AddMixinToClass(
            MixinKind mixinKind,
            Type targetType,
            Type mixinType,
            MemberVisibility introducedMemberVisibility,
            IEnumerable <Type> explicitDependencies,
            IEnumerable <Type> suppressedMixins,
            MixinContextOrigin origin)
        {
            ArgumentUtility.CheckNotNull("targetType", targetType);
            ArgumentUtility.CheckNotNull("mixinType", mixinType);
            ArgumentUtility.CheckNotNull("explicitDependencies", explicitDependencies);
            ArgumentUtility.CheckNotNull("suppressedMixins", suppressedMixins);
            ArgumentUtility.CheckNotNull("origin", origin);

            MixinContextBuilder mixinContextBuilder = AddMixinToClass(targetType, mixinType, origin);

            mixinContextBuilder
            .OfKind(mixinKind)
            .WithDependencies(explicitDependencies.ToArray())
            .WithIntroducedMemberVisibility(introducedMemberVisibility)
            .ReplaceMixins(suppressedMixins.ToArray());

            return(this);
        }
Beispiel #6
0
        private void ImportMemberDetails(MemberSymbol memberSymbol, MethodDefinition methodDefinition,
                                         ICustomAttributeProvider attributeProvider)
        {
            if (methodDefinition != null)
            {
                MemberVisibility visibility = MemberVisibility.PrivateInstance;

                if (methodDefinition.IsStatic)
                {
                    visibility |= MemberVisibility.Static;
                }

                if (methodDefinition.IsPublic)
                {
                    visibility |= MemberVisibility.Public;
                }
                else if (methodDefinition.IsFamily || methodDefinition.IsFamilyOrAssembly)
                {
                    visibility |= MemberVisibility.Protected;
                }

                memberSymbol.SetVisibility(visibility);
            }

            string scriptName = MetadataHelpers.GetScriptName(attributeProvider, out bool _, out bool preserveCase);

            memberSymbol.SetNameCasing(preserveCase);

            if (scriptName != null)
            {
                memberSymbol.SetTransformedName(scriptName);
            }

            // PreserveName is ignored - it only is used for internal members, which are not imported.
        }
        /// <summary>
        /// Initializes the preset with the specified visiblity. The preset must be initialized before the preset values are applied so the delegates can be created.
        /// </summary>
        /// <param name="obj">The object to map the delegates to.</param>
        /// <param name="visibility">Specifies the visibility of the field/properties that should be retrieved.</param>
        public virtual void Initialize(object obj, MemberVisibility visibility)
        {
            var properties = Serialization.GetSerializedProperties(obj.GetType(), visibility);
            var valueCount = 0;

            m_Delegates = new BaseDelegate[properties.Length];
            for (int i = 0; i < properties.Length; ++i)
            {
                // The property may not be valid.
                if (Serialization.GetValidGetMethod(properties[i], visibility) == null)
                {
                    continue;
                }

                // Create a generic delegate based on the property type.
                var genericDelegateType = typeof(GenericDelegate <>).MakeGenericType(properties[i].PropertyType);
                m_Delegates[valueCount] = Activator.CreateInstance(genericDelegateType) as BaseDelegate;

                // Initialize the delegate.
                if (m_Delegates[valueCount] != null)
                {
                    m_Delegates[valueCount].Initialize(obj, properties[i], visibility);
                }
                else
                {
                    Debug.LogWarning("Warning: Unable to create preset of type " + properties[i].PropertyType);
                }
                valueCount++;
            }
            if (m_Delegates.Length != valueCount)
            {
                Array.Resize(ref m_Delegates, valueCount);
            }
        }
Beispiel #8
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        protected AbstractMember(MemberVisibility visibility, MemberModifier modifier, string name)
            : this()
        {
            this.Visibility = visibility;
            this.Modifier   = modifier;
            this.Name       = name;
        }
Beispiel #9
0
        private MemberVisibility GetVisibility(MemberNode node, TypeSymbol typeSymbol)
        {
            if (typeSymbol.Type == SymbolType.Interface)
            {
                return(MemberVisibility.Public);
            }

            MemberVisibility visibility = MemberVisibility.PrivateInstance;

            if (((node.Modifiers & Modifiers.Static) != 0) ||
                (node.NodeType == ParseNodeType.ConstFieldDeclaration))
            {
                visibility |= MemberVisibility.Static;
            }

            if ((node.Modifiers & Modifiers.Public) != 0)
            {
                visibility |= MemberVisibility.Public;
            }
            else
            {
                if ((node.Modifiers & Modifiers.Protected) != 0)
                {
                    visibility |= MemberVisibility.Protected;
                }
                if ((node.Modifiers & Modifiers.Internal) != 0)
                {
                    visibility |= MemberVisibility.Internal;
                }
            }

            return(visibility);
        }
Beispiel #10
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public TypeMember(MemberVisibility visibility, TypeMemberKind typeKind, string name, params TypeMember[] genericArguments)
            : this()
        {
            this.Visibility = visibility;
            this.TypeKind   = typeKind;
            this.Name       = name;

            if (genericArguments != null)
            {
                this.IsGenericType = (genericArguments.Length > 0);

                if (this.IsGenericType)
                {
                    this.IsGenericTypeDefinition = genericArguments.Any(arg => arg.TypeKind == TypeMemberKind.GenericParameter);

                    if (this.IsGenericTypeDefinition)
                    {
                        this.GenericTypeParameters.AddRange(genericArguments);
                    }
                    else
                    {
                        this.GenericTypeArguments.AddRange(genericArguments);
                    }
                }
            }
        }
Beispiel #11
0

        
Beispiel #12
0
        public void CanEmitConstructorDeclaration(
            string expectedCode,
            MemberVisibility visibility,
            MemberModifier modifier,
            Delegate signaturePrototype,
            Action <ConstructorMember> constructorSetup)
        {
            //-- arrange

            var constructor = new ConstructorMember(visibility, modifier, "ClassOne", new MethodSignature(signaturePrototype.GetMethodInfo()));

            if (constructorSetup != null)
            {
                constructorSetup(constructor);
            }

            var enclosingClassMember = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "ClassOne");

            enclosingClassMember.Members.Add(constructor);

            var enclosingClassEmitter = new ClassSyntaxEmitter(enclosingClassMember);
            var expectedClassCode     = "public class ClassOne { " + expectedCode + " }";

            //-- act

            var actualClassSyntax = enclosingClassEmitter.EmitSyntax();

            //-- assert

            actualClassSyntax.Should().BeEquivalentToCode(expectedClassCode);
        }
 public ClassImporter(string xamlFileName, string localAssemblyName, string rootNamespace)
 {
     this.xamlFileName = xamlFileName;
     this.localAssemblyName = localAssemblyName;
     this.rootNamespace = rootNamespace;
     this.DefaultClassIsPublic = true;
     this.DefaultFieldVisibility = MemberVisibility.Assembly;
     this.namespaceTable = new NamespaceTable(localAssemblyName);
 }
 public InterfaceIntroductionDefinitionBuilder(MixinDefinition mixin, MemberVisibility defaultVisibility)
 {
     _mixin                   = mixin;
     _defaultVisibility       = defaultVisibility;
     _nonIntroducedInterfaces = new HashSet <Type> {
         typeof(ISerializable), typeof(IDeserializationCallback), typeof(IInitializableMixin)
     };
     AnalyzeNonIntroducedInterfaces();
 }
Beispiel #15
0
 public ClassImporter(string xamlFileName, string localAssemblyName, string rootNamespace)
 {
     this.xamlFileName           = xamlFileName;
     this.localAssemblyName      = localAssemblyName;
     this.rootNamespace          = rootNamespace;
     this.DefaultClassIsPublic   = true;
     this.DefaultFieldVisibility = MemberVisibility.Assembly;
     this.namespaceTable         = new NamespaceTable(localAssemblyName);
 }
Beispiel #16
0
        private void ImportFields(TypeSymbol typeSymbol)
        {
            TypeDefinition type = (TypeDefinition)typeSymbol.MetadataReference;

            foreach (FieldDefinition field in type.Fields)
            {
                if (field.IsSpecialName)
                {
                    continue;
                }

                if (field.IsPrivate || field.IsAssembly || field.IsFamilyAndAssembly)
                {
                    continue;
                }

                string fieldName = field.Name;

                TypeSymbol fieldType = ResolveType(field.FieldType);

                if (fieldType == null)
                {
                    continue;
                }

                MemberVisibility visibility = MemberVisibility.PrivateInstance;

                if (field.IsStatic)
                {
                    visibility |= MemberVisibility.Static;
                }

                if (field.IsPublic)
                {
                    visibility |= MemberVisibility.Public;
                }
                else if (field.IsFamily || field.IsFamilyOrAssembly)
                {
                    visibility |= MemberVisibility.Protected;
                }

                FieldSymbol fieldSymbol = new FieldSymbol(fieldName, typeSymbol, fieldType);

                fieldSymbol.SetVisibility(visibility);
                ImportMemberDetails(fieldSymbol, null, field);

                if (field.IsLiteral && field.HasConstant && !typeSymbol.IsCoreType &&
                    (field.FieldType.IsPrimitive || field.FieldType.Name == "String"))
                {
                    fieldSymbol.SetConstant();
                    fieldSymbol.Value = field.Constant;
                }

                typeSymbol.AddMember(fieldSymbol);
            }
        }
        /// <summary>
        /// Initializes the preset with the specified visiblity. The preset must be initialized before the preset values are applied so the delegates can be created.
        /// </summary>
        /// <param name="obj">The object to map the delegates to.</param>
        /// <param name="visibility">Specifies the visibility of the field/properties that should be retrieved.</param>
        public override void Initialize(object obj, MemberVisibility visibility)
        {
            base.Initialize(obj, visibility);

            m_DelegateIndexMap = new Dictionary <MethodInfo, int>();
            for (int i = 0; i < m_Delegates.Length; ++i)
            {
                m_DelegateIndexMap.Add(m_Delegates[i].SetMethod, i);
            }
        }
Beispiel #18
0
        private readonly List<AssemblyName> _referencedAssemblies; // = new List<AssemblyName>();

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="T:AssemblyFetcher"/> class.
        /// </summary>
        /// <param name="methodVisibility">The method visibility to parse.</param>
        /// <param name="assemblyName">Description text of the root assembly node.</param>
        /// <param name="inputAssemblies">The list of input assemblies.</param>
        public AssemblyFetcher(MemberVisibility methodVisibility, string assemblyName, IEnumerable<string> inputAssemblies)
        {
            Guard.NotNullOrEmpty(() => assemblyName, assemblyName);
            Guard.NotNull(() => inputAssemblies, inputAssemblies);

            _assemblyGraphTreeView = new TestNode() { Text = assemblyName };
            _inputAssemblyOpenFileDialog = inputAssemblies.ToList();
            _referencedAssemblies = new List<AssemblyName>();
            this.methodVisibility = methodVisibility;
        }
Beispiel #19
0
 public VariableSpecifier(string name, TypeSpecifier type, MemberVisibility getterVisibility, MemberVisibility setterVisibility,
                          TypeSpecifier declaringType, VariableModifiers modifiers)
 {
     Name             = name;
     Type             = type;
     GetterVisibility = getterVisibility;
     SetterVisibility = setterVisibility;
     DeclaringType    = declaringType;
     Modifiers        = modifiers;
 }
        /// <summary>
        /// Creates a persistable preset based off of the specified component and visibility.
        /// </summary>
        /// <param name="obj">The object to retrieve the property values of.</param>
        /// <param name="visibility">Specifies the visibility of the field/properties that should be retrieved.</param>
        /// <returns>The created preset. Null if no properties have been found to create the preset with.</returns>
        public static PersistablePreset CreatePreset(object obj, MemberVisibility visibility)
        {
            var data = new Serialization();

            data.Serialize(obj, false, visibility);
            var preset = CreateInstance <PersistablePreset>();

            preset.Data = data;
            return(preset);
        }
Beispiel #21
0
 public ConstructorMember(
     MemberVisibility visibility,
     MemberModifier modifier,
     string name,
     MethodSignature signature)
 {
     this.Visibility = visibility;
     this.Modifier   = modifier;
     this.Name       = name;
     this.Signature  = signature;
 }
Beispiel #22
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public TypeMember(
            TypeGeneratorInfo generator,
            string namespaceName,
            MemberVisibility visibility,
            TypeMemberKind typeKind,
            string name,
            params TypeMember[] genericTypeArguments)
            : this(namespaceName, visibility, typeKind, name, genericTypeArguments)
        {
            this.Generator = generator;
        }
        protected MemberIntroductionDefinitionBase(
            InterfaceIntroductionDefinition declaringInterface, TMemberInfo interfaceMember, TMemberDefinition implementingMember, MemberVisibility visibility)
        {
            ArgumentUtility.CheckNotNull("interfaceMember", interfaceMember);
            ArgumentUtility.CheckNotNull("declaringInterface", declaringInterface);
            ArgumentUtility.CheckNotNull("implementingMember", implementingMember);

            _declaringInterface = declaringInterface;
            _implementingMember = implementingMember;
            _interfaceMember    = interfaceMember;
            _visibility         = visibility;
        }
 public static string ToCSharp(this MemberVisibility value, MemberVisibility defaultValue)
 {
     if(value == defaultValue) return "";
     switch(value) {
     case MemberVisibility.Internal: return "internal ";
     case MemberVisibility.Private: return "private ";
     case MemberVisibility.Protected: return "protected ";
     case MemberVisibility.ProtectedInternal: return "protected internal ";
     case MemberVisibility.Public: return "public ";
     default: throw new InvalidOperationException();
     }
 }
Beispiel #25
0
            /// <summary>
            /// Initialize the delegate.
            /// </summary>
            /// <param name="obj">The object which the delegate operates on.</param>
            /// <param name="property">The property that the delegate will invoke.</param>
            /// <param name="visibility">Specifies the visibility of the field/properties that should be retrieved.</param>
            public override void Initialize(object obj, PropertyInfo property, MemberVisibility visibility)
            {
                m_SetMethod = property.GetSetMethod(visibility != MemberVisibility.Public);
                if (m_SetMethod != null)
                {
                    m_Setter = (Action <T>)Delegate.CreateDelegate(typeof(Action <T>), obj, m_SetMethod);
                }

                var getMethod = property.GetGetMethod(visibility != MemberVisibility.Public);

                if (getMethod != null)
                {
                    m_Getter = (Func <T>)Delegate.CreateDelegate(typeof(Func <T>), obj, getMethod);

                    // Create an instance of the value if it is an array or a list. This will allow a snapshot of the array/list elements to be saved without having the
                    // array/list change because it is later modified by reference.
                    var type = typeof(T);
                    m_IsIList = typeof(IList).IsAssignableFrom(type);
                    if (m_IsIList)
                    {
                        if (typeof(T).IsArray)
                        {
                            var value = m_Getter() as Array;
#if NET_4_6 || UNITY_2018_3_OR_NEWER || UNITY_WEBGL || UNITY_IOS || UNITY_ANDROID || UNITY_WII || UNITY_WIIU || UNITY_SWITCH || UNITY_PS3 || UNITY_PS4 || UNITY_XBOXONE || UNITY_WSA
                            m_Value = (T)(object)Array.CreateInstance(type.GetElementType(), value == null ? 0 : value.Length);
#else
                            m_Value = Array.CreateInstance(type.GetElementType(), value == null ? 0 : value.Length) as T;
#endif
                        }
                        else
                        {
                            var baseType = type;
                            while (!baseType.IsGenericType)
                            {
                                baseType = baseType.BaseType;
                            }
                            var elementType = baseType.GetGenericArguments()[0];
                            if (type.IsGenericType)
                            {
                                m_Value = (T)Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType));
                            }
                            else
                            {
                                m_Value = (T)Activator.CreateInstance(type);
                            }
                        }
                    }

                    // The value should be set at the same time the delegate is initailized.
                    UpdateValue();
                }
            }
Beispiel #26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:AssemblyFetcher"/> class.
        /// </summary>
        /// <param name="methodVisibility">The method visibility to parse.</param>
        /// <param name="assemblyName">Description text of the root assembly node.</param>
        /// <param name="inputAssemblies">The list of input assemblies.</param>
        public AssemblyFetcher(MemberVisibility methodVisibility, string assemblyName, IEnumerable <string> inputAssemblies)
        {
            Guard.NotNullOrEmpty(() => assemblyName, assemblyName);
            Guard.NotNull(() => inputAssemblies, inputAssemblies);

            _assemblyGraphTreeView = new TestNode()
            {
                Text = assemblyName
            };
            _inputAssemblyOpenFileDialog = inputAssemblies.ToList();
            _referencedAssemblies        = new List <AssemblyName>();
            this.methodVisibility        = methodVisibility;
        }
        /// <summary>
        /// Initializes the available property array.
        /// </summary>
        private void OnEnable()
        {
            // If the preset is a child of a StateConfiguration asset then the AllPublic MemberVisiblity type should be shown.
            if (!AssetDatabase.IsMainAsset(target))
            {
                var mainAsset = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(target), TypeUtility.GetType("Opsive.UltimateCharacterController.StateSystem.StateConfiguration"));
                if (mainAsset != null)
                {
                    m_Visiblity = MemberVisibility.AllPublic;
                }
            }

            InitializeAvailablePropertyArray();
        }
Beispiel #28
0
        /// <summary>
        /// Initializes the available property array.
        /// </summary>
        private void OnEnable()
        {
            // If the preset is a child of a StateConfiguration asset then the AllPublic MemberVisiblity type should be shown.
            if (!AssetDatabase.IsMainAsset(target))
            {
                var mainAsset = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(target), typeof(StateConfiguration)) as StateConfiguration;
                if (mainAsset != null)
                {
                    m_Visiblity = MemberVisibility.AllPublic;
                }
            }

            InitializeAvailablePropertyArray();
        }
Beispiel #29
0
 public static MixinContext Create(
     MixinKind mixinKind = MixinKind.Extending,
     Type mixinType      = null,
     MemberVisibility introducedMemberVisibility = MemberVisibility.Private,
     IEnumerable <Type> explicitDependencies     = null,
     MixinContextOrigin origin = null)
 {
     return(new MixinContext(
                mixinKind,
                mixinType ?? typeof(UnspecifiedType),
                introducedMemberVisibility,
                explicitDependencies ?? new[] { typeof(object), typeof(string) },
                origin ?? MixinContextOriginObjectMother.Create()));
 }
Beispiel #30
0
        public void SetUp()
        {
            var assemblies = new[]
            {
                typeof(AssemblyFetcher).Assembly,
                typeof(AssemblyFetcherTest).Assembly,
                typeof(Rhino.Mocks.MockRepository).Assembly,
            }.ToList();

            this.methodVisibility = MemberVisibility.Public;
            this.assemblyName     = typeof(AssemblyFetcherTest).Assembly.Location;
            this.inputAssemblies  = assemblies.Select(e => e.Location).ToList();
            this.testObject       = new AssemblyFetcher(this.methodVisibility, this.assemblyName, this.inputAssemblies);
        }
        private void AnalyzeEvents(InterfaceIntroductionDefinition introducedInterface, MemberImplementationFinder memberFinder,
                                   HashSet <MethodInfo> specialMethods)
        {
            foreach (EventInfo interfaceEvent in introducedInterface.InterfaceType.GetEvents())
            {
                EventDefinition implementer = memberFinder.FindEventImplementation(interfaceEvent);
                CheckMemberImplementationFound(implementer, interfaceEvent);
                MemberVisibility visibility = GetVisibility(implementer.MemberInfo);
                introducedInterface.IntroducedEvents.Add(new EventIntroductionDefinition(introducedInterface, interfaceEvent, implementer, visibility));

                specialMethods.Add(interfaceEvent.GetAddMethod());
                specialMethods.Add(interfaceEvent.GetRemoveMethod());
            }
        }
 private void AnalyzeMethods(InterfaceIntroductionDefinition introducedInterface, MemberImplementationFinder memberFinder,
                             HashSet <MethodInfo> specialMethods)
 {
     foreach (MethodInfo interfaceMethod in introducedInterface.InterfaceType.GetMethods())
     {
         if (!specialMethods.Contains(interfaceMethod))
         {
             MethodDefinition implementer = memberFinder.FindMethodImplementation(interfaceMethod);
             CheckMemberImplementationFound(implementer, interfaceMethod);
             MemberVisibility visibility = GetVisibility(implementer.MemberInfo);
             introducedInterface.IntroducedMethods.Add(new MethodIntroductionDefinition(introducedInterface, interfaceMethod, implementer, visibility));
         }
     }
 }
Beispiel #33
0
        /// <summary>
        /// Returns whether a given visibility for a member of a type is visible from another type.
        /// </summary>
        /// <param name="fromType">Type that we are seeing from.</param>
        /// <param name="type">Type that we are looking at.</param>
        /// <param name="visibility">Visibility of the member on type.</param>
        /// <returns></returns>
        public static bool IsVisible(TypeSpecifier fromType, TypeSpecifier type, MemberVisibility visibility, Func <TypeSpecifier, TypeSpecifier, bool> isSubclassOf)
        {
            // TODO: Internal

            if (fromType == type)
            {
                return(true);
            }
            else if (isSubclassOf(fromType, type))
            {
                return(visibility.HasFlag(MemberVisibility.ProtectedOrPublic));
            }

            return(visibility.HasFlag(MemberVisibility.Public));
        }
 MemberAttributes GetMemberAttributes(MemberVisibility visibility)
 {
     switch (visibility)
     {
         case MemberVisibility.Private:
             return MemberAttributes.Private;
         case MemberVisibility.Public:
             return MemberAttributes.Public;
         case MemberVisibility.Family:
             return MemberAttributes.Family;
         case MemberVisibility.Assembly:
             return MemberAttributes.Assembly;
         case MemberVisibility.FamilyOrAssembly:
             return MemberAttributes.FamilyOrAssembly;
         case MemberVisibility.FamilyAndAssembly:
             return MemberAttributes.FamilyAndAssembly;
         default:
             throw Fx.AssertAndThrow("Invalid MemberVisibility value");
     }
 }
Beispiel #35
0
        public void SetUp()
        {
            var assemblies = new[]
            {
                typeof(AssemblyFetcher).Assembly,
                typeof(AssemblyFetcherTest).Assembly,
                typeof(Rhino.Mocks.MockRepository).Assembly,
            }.ToList();

            this.methodVisibility = MemberVisibility.Public;
            this.assemblyName = typeof(AssemblyFetcherTest).Assembly.Location;
            this.inputAssemblies = assemblies.Select(e => e.Location).ToList();
            this.testObject = new AssemblyFetcher(this.methodVisibility, this.assemblyName, this.inputAssemblies);
        }
Beispiel #36
0
 public MethodSymbol(string name, TypeSymbol parent, TypeSymbol returnType, MemberVisibility visibility)
     : this(SymbolType.Method, name, parent, returnType) {
     SetVisibility(visibility);
 }
Beispiel #37
0
 /// <summary>
 /// Creates a code generation expression for an object to test with a member field and initialization
 /// in the previous specified <see cref="SetUpMethod"/> method.
 /// </summary>
 /// <param name="visibility">The visibility level of the objects to parse. Default should be public.</param>
 /// <returns>
 /// The initialization expression of the object under test.
 /// </returns>
 public abstract CodeObjectCreateExpression BuildTestObject(MemberVisibility visibility);
 public IndexerSymbol(TypeSymbol parent, TypeSymbol propertyType, MemberVisibility visibility)
     : this(parent, propertyType)
 {
     SetVisibility(visibility);
 }
Beispiel #39
0
 public void SetVisibility(MemberVisibility visibility)
 {
     _visibility = visibility;
 }
Beispiel #40
0
        private static bool TryGetMemberVisibility(IToken token, out MemberVisibility visibility)
        {
            if (token.EqualsStringInvariant(AnalyzerConstants.Visibility_Private))
            {
                visibility = MemberVisibility.Private;
                return true;
            }

            if (token.EqualsStringInvariant(AnalyzerConstants.Visibility_Public))
            {
                visibility = MemberVisibility.Public;
                return true;
            }

            visibility = MemberVisibility.Default;
            return false;
        }